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
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'
Return Return
(string|WP_Error) A refund ID on success or an error object.
Source Source
File: includes/models/model.llms.transaction.php
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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 7.0.0 | Refactored code into multiple methods. |
| 3.0.0 | Introduced. |