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


(float) (Required) Amount to refund.


(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: ''


(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

	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(
				__( '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(
					// 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

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.