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

1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
* @return void
 */
public function maybe_schedule_payment( $recalc = true ) {
 
    if ( ! $this->is_recurring() ) {
        return;
    }
 
    if ( $recalc ) {
        $this->set( 'date_next_payment', $this->calculate_next_payment_date() );
    }
 
    $date = $this->get_next_payment_due_date();
 
    // Unschedule and reschedule.
    if ( $date && ! is_wp_error( $date ) ) {
 
        $this->schedule_recurring_payment( $date );
 
    } elseif ( is_wp_error( $date ) ) {
 
        if ( 'plan-ended' === $date->get_error_code() ) {
 
            // Unschedule the next action (does nothing if no action scheduled).
            $this->unschedule_recurring_payment();
 
            // Add a note that the plan has completed.
            $this->add_note( __( 'Order payment plan completed.', 'lifterlms' ) );
            $this->set( 'plan_ended', 'yes' );
 
        }
    }
 
}
 
/**
 * Handles scheduling recurring payment retries when the gateway supports them
 *
 * @since 3.10.0
 * @since 7.0.0 Added return value.
 *
 * @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.
 */
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.
         */


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.