LLMS_Order::maybe_schedule_retry()

Handles scheduling recurring payment retries when the gateway supports them


Return Return

(null|boolean) Returns null if the order cannot be retried, false when all retry rules have been tried (or none exist), and true when a retry is scheduled.


Top ↑

Source Source

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

	public function maybe_schedule_retry() {

		if ( ! $this->can_be_retried() ) {
			return null;
		}

		// Get the index of the rule to use for this retry.
		$current_rule_index = $this->get( 'last_retry_rule' );
		if ( '' === $current_rule_index ) {
			$current_rule_index = 0;
		} else {
			++$current_rule_index;
		}

		$rules        = $this->get_retry_rules();
		$current_rule = $rules[ $current_rule_index ] ?? false;

		// No rule to run.
		if ( ! $current_rule ) {

			$this->set_status( 'failed' );
			$this->set( 'last_retry_rule', '' );

			$this->add_note( esc_html__( 'Maximum retry attempts reached.', 'lifterlms' ) );

			/**
			 * Action triggered when there are not more recurring payment retry rules.
			 *
			 * @since 3.10.0
			 *
			 * @param LLMS_Order $order The order object.
			 */
			do_action( 'llms_automatic_payment_maximum_retries_reached', $this );

			return false;

		}

		$timestamp = current_time( 'timestamp' ) + $current_rule['delay'];

		$this->set_date( 'next_payment', date_i18n( 'Y-m-d H:i:s', $timestamp ) );
		$this->set_status( $current_rule['status'] );
		$this->set( 'last_retry_rule', $current_rule_index );

		$this->add_note(
			sprintf(
				// Translators: %s = next attempt date.
				esc_html__( 'Automatic retry attempt scheduled for %s', 'lifterlms' ),
				date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $timestamp )
			)
		);

		// If notifications should be sent, trigger them.
		if ( $current_rule['notifications'] ) {
			/**
			 * Triggers the "Payment Retry Scheduled" notification.
			 *
			 * @since 3.10.0
			 *
			 * @param LLMS_Order $order The order object.
			 */
			do_action( 'llms_send_automatic_payment_retry_notification', $this );
		}

		/**
		 * Action triggered after a recurring payment retry is successfully scheduled.
		 *
		 * @since 3.10.0
		 *
		 * @param LLMS_Order $order The order object.
		 */
		do_action( 'llms_automatic_payment_retry_scheduled', $this );

		return true;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Added return value.
3.10.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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