LLMS_Transaction::process_refund( float $amount, string $note = '', string $method = 'manual' )

Processes a refund against the transaction.


Description Description

This method is called called from the admin panel by clicking a refund (manual or gateway) button.

See also See also


Top ↑

Parameters Parameters

$amount

(float) (Required) Amount to refund.

$note

(string) (Optional) note to record as an order note. This is passed to the gateway to do store in the gateway if available.

Default value: ''

$method

(string) (Optional) Method used to refund, either "manual" (available for all transactions) or "gateway" (when supported by the gateway that processed the transaction).

Default value: 'manual'


Top ↑

Return Return

(string|WP_Error) A refund ID on success or an error object.


Top ↑

Source Source

File: includes/models/model.llms.transaction.php

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
public function process_refund( $amount, $note = '', $method = 'manual' ) {
 
    // Ensure the transaction is still eligible for a refund.
    if ( ! $this->can_be_refunded() ) {
        return new WP_Error(
            'llms-txn-refund-not-eligible',
            __( 'The selected transaction is not eligible for a refund.', 'lifterlms' )
        );
    }
 
    $amount = floatval( $amount );
 
    // Ensure we can refund the requested amount.
    $refundable = $this->get_refundable_amount();
    if ( $amount > $refundable ) {
        return new WP_Error(
            'llms-txn-refund-amount-too-high',
            sprintf(
                // Translators: %1$s = The requested refund amount; %2$s = the available refundable amount.
                __( 'Requested refund amount was %1$s, the maximum possible refund for this transaction is %2$s.', 'lifterlms' ),
                llms_price( $amount ),
                llms_price( $refundable )
            )
        );
    }
 
    $id = $this->generate_refund_id( $method, $amount, $note );
    if ( is_string( $id ) ) {
        $this->record_refund( compact( 'amount', 'id', 'method' ), $note );
    } elseif ( ! is_wp_error( $id ) ) {
        $id = new WP_Error( 'llms-txn-refund-unknown-error', __( 'An unknown error occurred while processing the refund.', 'lifterlms' ) );
    }
 
    return $id;
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Refactored code into multiple methods.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.