LLMS_Order::maybe_schedule_retry()

Handles scheduling recurring payment retries when the gateway supports them


Return Return

(void)


Top ↑

Source Source

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

	public function maybe_schedule_retry() {

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

		$current_rule = $this->get( 'last_retry_rule' );
		if ( '' === $current_rule ) {
			$current_rule = 0;
		} else {
			++$current_rule;
		}
		$rules = $this->get_retry_rules();

		if ( isset( $rules[ $current_rule ] ) ) {

			$rule = $rules[ $current_rule ];

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

			// Update the status.
			$this->set_status( $rule['status'] );

			// Set the next payment date based on the rule's delay.
			$this->set_date( 'next_payment', date_i18n( 'Y-m-d H:i:s', $next_payment_time ) );

			// Save the rule for reference on potential future retries.
			$this->set( 'last_retry_rule', $current_rule );

			// If notifications should be sent, trigger them.
			if ( $rule['notifications'] ) {
				do_action( 'llms_send_automatic_payment_retry_notification', $this );
			}

			$this->add_note( sprintf( esc_html__( 'Automatic retry attempt scheduled for %s', 'lifterlms' ), date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $next_payment_time ) ) );

			// Generic action.
			do_action( 'llms_automatic_payment_retry_scheduled', $this );

			// We are out of rules, fail the order, move on with our lives.
		} else {

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

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

			do_action( 'llms_automatic_payment_maximum_retries_reached', $this );

		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.10.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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