Plugin Directory

Changeset 3250888


Ignore:
Timestamp:
03/05/2025 07:41:17 AM (12 months ago)
Author:
PerfectSolution
Message:

Update trunk/ - 7.4.0

Location:
woocommerce-quickpay
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woocommerce-quickpay/tags/7.4.0/README.txt

    r3239254 r3250888  
    2828
    2929== Changelog ==
     30= 7.4.0 =
     31* Fix: Subscription switching was not always creating a subscription payment when upgrading from a free subscription to a paid variant where no previous payments have been made.
     32
    3033= 7.3.5 =
    3134* Fix: woocommerce_quickpay_get_order now makes a specific check on WC_Order instance to avoid possible direct property access on a WC_Order object.
  • woocommerce-quickpay/tags/7.4.0/classes/utils/woocommerce-quickpay-order-payments-utils.php

    r2924617 r3250888  
    154154        if ( WC_QuickPay_Subscription::is_subscription( $order_id ) ) {
    155155            $order_number = $order_id;
    156         } // On initial subscription authorizations
    157         else if ( ! $recurring && ! WC_QuickPay_Order_Utils::contains_switch_order( $order ) && WC_QuickPay_Order_Utils::contains_subscription( $order ) ) {
     156        }
     157        // On initial subscription authorizations
     158        // 1. Either on parent orders
     159        // 2. Or if the customer tries to upgrade a free subscription to a not-free variation.
     160        else if ( ( ! $recurring || WC_QuickPay_Order_Utils::switches_from_free_to_paid( $order ) ) && WC_QuickPay_Order_Utils::contains_subscription( $order ) ) {
    158161            // Find all subscriptions
    159162            $subscriptions = WC_QuickPay_Subscription::get_subscriptions_for_order( $order_id );
  • woocommerce-quickpay/tags/7.4.0/classes/utils/woocommerce-quickpay-order-transaction-data-utils.php

    r2924617 r3250888  
    131131
    132132        // Get the correct order_post_id. We want to fetch the ID of the subscription to store data on subscription (if available).
    133         // But only on the first attempt. In case of failed auto capture on the initial order, we dont want to add the subscription ID.
    134         // If we are handlong a product switch, we will not need this ID as we are making a regular payment.
    135         if ( ! WC_QuickPay_Order_Utils::contains_switch_order( $order ) ) {
    136             $subscription_id = WC_QuickPay_Subscription::get_subscription_id( $order );
    137             if ( $subscription_id ) {
    138                 $custom_vars['subscription_post_id'] = $subscription_id;
    139             }
     133        if ( $subscription_id = WC_QuickPay_Subscription::get_subscription_id( $order ) ) {
     134            $custom_vars['subscription_post_id'] = $subscription_id;
    140135        }
    141136
  • woocommerce-quickpay/tags/7.4.0/classes/utils/woocommerce-quickpay-order-utils.php

    r2924617 r3250888  
    5757    }
    5858
     59    /**
     60     * Checks if the order switches a subscription from free to paid.
     61     * In this case we would often require authorization of a subscription transaction in order to
     62     * be able to authorize payments automatically in the future.
     63     *
     64     * @param $order
     65     *
     66     * @return bool
     67     */
     68    public static function switches_from_free_to_paid( $order ): bool {
     69        if ( ! self::contains_switch_order( $order ) ) {
     70            return false;
     71        }
     72
     73        if ( ! ( $subscription_id = $order->get_meta( '_subscription_switch' ) ) || ! ( $subscription = woocommerce_quickpay_get_subscription( $subscription_id ) ) ) {
     74            return false;
     75        }
     76
     77        // Make sure to cast the return value as WC returns the total as a string regardless of context.
     78        $old_total = (float) $subscription->get_total();
     79        $new_total = (float) $order->get_total();
     80
     81        return $old_total === 0.0 && $new_total > 0;
     82    }
     83
     84    /**
     85     * @param WC_Order $order
     86     * @param string|null $message
     87     *
     88     * @return void
     89     */
    5990    public static function add_note( WC_Order $order, ?string $message ): void {
    6091        if ( $message ) {
  • woocommerce-quickpay/tags/7.4.0/classes/woocommerce-quickpay-callbacks.php

    r3239254 r3250888  
    123123        // Only make an instant payment if the order total is more than 0
    124124        if ( $related_order->get_total() > 0 ) {
    125             // Check if this is an order containing a subscription or if it is a renewal order
    126             if ( ! WC_QuickPay_Subscription::is_subscription( $related_order ) && ( WC_QuickPay_Order_Utils::contains_subscription( $related_order ) || WC_QuickPay_Subscription::is_renewal( $related_order ) ) ) {
    127                 // Process a recurring payment, but only if the subscription needs a payment.
    128                 // This check was introduced to avoid possible double payments in case Quickpay sends callbacks more than once.
    129                 if ( ( $wcs_subscription = wcs_get_subscription( $subscription->get_id() ) ) && $wcs_subscription->needs_payment() ) {
     125            // Determine if the order is a subscription or renewal order
     126            $is_subscription       = WC_QuickPay_Subscription::is_subscription( $related_order );
     127            $contains_subscription = WC_QuickPay_Order_Utils::contains_subscription( $related_order );
     128            $is_renewal            = WC_QuickPay_Subscription::is_renewal( $related_order );
     129
     130            if ( ! $is_subscription && ( $contains_subscription || $is_renewal ) ) {
     131                // Retrieve the subscription and check if a payment is needed
     132                $wcs_subscription = wcs_get_subscription( $subscription->get_id() );
     133                // Checks if the subscription needs a payment. Also checks specifically on the related order as switch orders will not flag a subscription as needing a payment
     134                $needs_payment = $wcs_subscription && ( $wcs_subscription->needs_payment() || $related_order->needs_payment() );
     135
     136                if ( $needs_payment ) {
    130137                    WC_QP()->process_recurring_payment( new WC_QuickPay_API_Subscription(), $transaction->id, $related_order->get_total(), $related_order );
    131138                }
     
    134141        // If there is no initial payment, we will mark the order as complete.
    135142        // This is usually happening if a subscription has a free trial.
    136         else {
    137             // Only complete the order payment if we are not changing payment method.
    138             // This is to avoid the subscription going into a 'processing' limbo.
    139             if ( empty( $transaction->variables->change_payment ) ) {
    140                 $related_order->payment_complete();
    141             }
     143        else if ( empty( $transaction->variables->change_payment ) ) {
     144            $related_order->payment_complete();
    142145        }
    143146
  • woocommerce-quickpay/tags/7.4.0/classes/woocommerce-quickpay-subscription.php

    r2924617 r3250888  
    113113
    114114    /**
     115     * @param $order
     116     * @param array $args
     117     *
     118     * @return WC_Subscription|null
     119     */
     120    public static function get_last_subscription_for_order( $order, array $args = [] ): ?WC_Subscription {
     121        $subscriptions = self::get_subscriptions_for_order( $order, $args );
     122
     123        if ( ! empty( $subscriptions ) ) {
     124            return end( $subscriptions );
     125        }
     126
     127        return null;
     128    }
     129
     130    /**
    115131     * @param WC_Order $order
    116132     *
     
    135151            return end( $subscriptions )->get_id();
    136152        }
     153
    137154        return null;
    138155    }
  • woocommerce-quickpay/tags/7.4.0/helpers/transactions.php

    r3239254 r3250888  
    1616
    1717    // If the order is a subscription or an attempt of updating the payment method
    18     if ( ! WC_QuickPay_Subscription::cart_contains_switches() && ( WC_QuickPay_Order_Utils::contains_subscription( $order ) || WC_QuickPay_Requests_Utils::is_request_to_change_payment() ) ) {
    19         // Instantiate a subscription transaction instead of a payment transaction
    20         $api_transaction = new WC_QuickPay_API_Subscription();
     18    if ( WC_QuickPay_Order_Utils::contains_subscription( $order ) || WC_QuickPay_Requests_Utils::is_request_to_change_payment() ) {
     19        if ( WC_QuickPay_Subscription::cart_contains_switches() ) {
     20            $subscription   = WC_QuickPay_Subscription::get_last_subscription_for_order( $order );
     21            $transaction_id = $subscription ? WC_QuickPay_Order_Utils::get_transaction_id( $subscription ) : null;
     22
     23            if ( ! $transaction_id && $order->needs_payment() ) {
     24                // Instantiate a subscription transaction instead of a payment transaction
     25                $api_transaction = new WC_QuickPay_API_Subscription();
     26            }
     27        } else {
     28            // Instantiate a subscription transaction instead of a payment transaction
     29            $api_transaction = new WC_QuickPay_API_Subscription();
     30        }
    2131    }
    2232
  • woocommerce-quickpay/tags/7.4.0/woocommerce-quickpay.php

    r3239254 r3250888  
    44 * Plugin URI: http://wordpress.org/plugins/woocommerce-quickpay/
    55 * Description: Integrates your Quickpay payment gateway into your WooCommerce installation.
    6  * Version: 7.3.5
     6 * Version: 7.4.0
    77 * Author: Perfect Solution
    88 * Text Domain: woo-quickpay
     
    2020}
    2121
    22 define( 'WCQP_VERSION', '7.3.5' );
     22define( 'WCQP_VERSION', '7.4.0' );
    2323define( 'WCQP_URL', plugins_url( __FILE__ ) );
    2424define( 'WCQP_PATH', plugin_dir_path( __FILE__ ) );
  • woocommerce-quickpay/trunk/README.txt

    r3239254 r3250888  
    2828
    2929== Changelog ==
     30= 7.4.0 =
     31* Fix: Subscription switching was not always creating a subscription payment when upgrading from a free subscription to a paid variant where no previous payments have been made.
     32
    3033= 7.3.5 =
    3134* Fix: woocommerce_quickpay_get_order now makes a specific check on WC_Order instance to avoid possible direct property access on a WC_Order object.
  • woocommerce-quickpay/trunk/classes/utils/woocommerce-quickpay-order-payments-utils.php

    r2924617 r3250888  
    154154        if ( WC_QuickPay_Subscription::is_subscription( $order_id ) ) {
    155155            $order_number = $order_id;
    156         } // On initial subscription authorizations
    157         else if ( ! $recurring && ! WC_QuickPay_Order_Utils::contains_switch_order( $order ) && WC_QuickPay_Order_Utils::contains_subscription( $order ) ) {
     156        }
     157        // On initial subscription authorizations
     158        // 1. Either on parent orders
     159        // 2. Or if the customer tries to upgrade a free subscription to a not-free variation.
     160        else if ( ( ! $recurring || WC_QuickPay_Order_Utils::switches_from_free_to_paid( $order ) ) && WC_QuickPay_Order_Utils::contains_subscription( $order ) ) {
    158161            // Find all subscriptions
    159162            $subscriptions = WC_QuickPay_Subscription::get_subscriptions_for_order( $order_id );
  • woocommerce-quickpay/trunk/classes/utils/woocommerce-quickpay-order-transaction-data-utils.php

    r2924617 r3250888  
    131131
    132132        // Get the correct order_post_id. We want to fetch the ID of the subscription to store data on subscription (if available).
    133         // But only on the first attempt. In case of failed auto capture on the initial order, we dont want to add the subscription ID.
    134         // If we are handlong a product switch, we will not need this ID as we are making a regular payment.
    135         if ( ! WC_QuickPay_Order_Utils::contains_switch_order( $order ) ) {
    136             $subscription_id = WC_QuickPay_Subscription::get_subscription_id( $order );
    137             if ( $subscription_id ) {
    138                 $custom_vars['subscription_post_id'] = $subscription_id;
    139             }
     133        if ( $subscription_id = WC_QuickPay_Subscription::get_subscription_id( $order ) ) {
     134            $custom_vars['subscription_post_id'] = $subscription_id;
    140135        }
    141136
  • woocommerce-quickpay/trunk/classes/utils/woocommerce-quickpay-order-utils.php

    r2924617 r3250888  
    5757    }
    5858
     59    /**
     60     * Checks if the order switches a subscription from free to paid.
     61     * In this case we would often require authorization of a subscription transaction in order to
     62     * be able to authorize payments automatically in the future.
     63     *
     64     * @param $order
     65     *
     66     * @return bool
     67     */
     68    public static function switches_from_free_to_paid( $order ): bool {
     69        if ( ! self::contains_switch_order( $order ) ) {
     70            return false;
     71        }
     72
     73        if ( ! ( $subscription_id = $order->get_meta( '_subscription_switch' ) ) || ! ( $subscription = woocommerce_quickpay_get_subscription( $subscription_id ) ) ) {
     74            return false;
     75        }
     76
     77        // Make sure to cast the return value as WC returns the total as a string regardless of context.
     78        $old_total = (float) $subscription->get_total();
     79        $new_total = (float) $order->get_total();
     80
     81        return $old_total === 0.0 && $new_total > 0;
     82    }
     83
     84    /**
     85     * @param WC_Order $order
     86     * @param string|null $message
     87     *
     88     * @return void
     89     */
    5990    public static function add_note( WC_Order $order, ?string $message ): void {
    6091        if ( $message ) {
  • woocommerce-quickpay/trunk/classes/woocommerce-quickpay-callbacks.php

    r3239254 r3250888  
    123123        // Only make an instant payment if the order total is more than 0
    124124        if ( $related_order->get_total() > 0 ) {
    125             // Check if this is an order containing a subscription or if it is a renewal order
    126             if ( ! WC_QuickPay_Subscription::is_subscription( $related_order ) && ( WC_QuickPay_Order_Utils::contains_subscription( $related_order ) || WC_QuickPay_Subscription::is_renewal( $related_order ) ) ) {
    127                 // Process a recurring payment, but only if the subscription needs a payment.
    128                 // This check was introduced to avoid possible double payments in case Quickpay sends callbacks more than once.
    129                 if ( ( $wcs_subscription = wcs_get_subscription( $subscription->get_id() ) ) && $wcs_subscription->needs_payment() ) {
     125            // Determine if the order is a subscription or renewal order
     126            $is_subscription       = WC_QuickPay_Subscription::is_subscription( $related_order );
     127            $contains_subscription = WC_QuickPay_Order_Utils::contains_subscription( $related_order );
     128            $is_renewal            = WC_QuickPay_Subscription::is_renewal( $related_order );
     129
     130            if ( ! $is_subscription && ( $contains_subscription || $is_renewal ) ) {
     131                // Retrieve the subscription and check if a payment is needed
     132                $wcs_subscription = wcs_get_subscription( $subscription->get_id() );
     133                // Checks if the subscription needs a payment. Also checks specifically on the related order as switch orders will not flag a subscription as needing a payment
     134                $needs_payment = $wcs_subscription && ( $wcs_subscription->needs_payment() || $related_order->needs_payment() );
     135
     136                if ( $needs_payment ) {
    130137                    WC_QP()->process_recurring_payment( new WC_QuickPay_API_Subscription(), $transaction->id, $related_order->get_total(), $related_order );
    131138                }
     
    134141        // If there is no initial payment, we will mark the order as complete.
    135142        // This is usually happening if a subscription has a free trial.
    136         else {
    137             // Only complete the order payment if we are not changing payment method.
    138             // This is to avoid the subscription going into a 'processing' limbo.
    139             if ( empty( $transaction->variables->change_payment ) ) {
    140                 $related_order->payment_complete();
    141             }
     143        else if ( empty( $transaction->variables->change_payment ) ) {
     144            $related_order->payment_complete();
    142145        }
    143146
  • woocommerce-quickpay/trunk/classes/woocommerce-quickpay-subscription.php

    r2924617 r3250888  
    113113
    114114    /**
     115     * @param $order
     116     * @param array $args
     117     *
     118     * @return WC_Subscription|null
     119     */
     120    public static function get_last_subscription_for_order( $order, array $args = [] ): ?WC_Subscription {
     121        $subscriptions = self::get_subscriptions_for_order( $order, $args );
     122
     123        if ( ! empty( $subscriptions ) ) {
     124            return end( $subscriptions );
     125        }
     126
     127        return null;
     128    }
     129
     130    /**
    115131     * @param WC_Order $order
    116132     *
     
    135151            return end( $subscriptions )->get_id();
    136152        }
     153
    137154        return null;
    138155    }
  • woocommerce-quickpay/trunk/helpers/transactions.php

    r3239254 r3250888  
    1616
    1717    // If the order is a subscription or an attempt of updating the payment method
    18     if ( ! WC_QuickPay_Subscription::cart_contains_switches() && ( WC_QuickPay_Order_Utils::contains_subscription( $order ) || WC_QuickPay_Requests_Utils::is_request_to_change_payment() ) ) {
    19         // Instantiate a subscription transaction instead of a payment transaction
    20         $api_transaction = new WC_QuickPay_API_Subscription();
     18    if ( WC_QuickPay_Order_Utils::contains_subscription( $order ) || WC_QuickPay_Requests_Utils::is_request_to_change_payment() ) {
     19        if ( WC_QuickPay_Subscription::cart_contains_switches() ) {
     20            $subscription   = WC_QuickPay_Subscription::get_last_subscription_for_order( $order );
     21            $transaction_id = $subscription ? WC_QuickPay_Order_Utils::get_transaction_id( $subscription ) : null;
     22
     23            if ( ! $transaction_id && $order->needs_payment() ) {
     24                // Instantiate a subscription transaction instead of a payment transaction
     25                $api_transaction = new WC_QuickPay_API_Subscription();
     26            }
     27        } else {
     28            // Instantiate a subscription transaction instead of a payment transaction
     29            $api_transaction = new WC_QuickPay_API_Subscription();
     30        }
    2131    }
    2232
  • woocommerce-quickpay/trunk/woocommerce-quickpay.php

    r3239254 r3250888  
    44 * Plugin URI: http://wordpress.org/plugins/woocommerce-quickpay/
    55 * Description: Integrates your Quickpay payment gateway into your WooCommerce installation.
    6  * Version: 7.3.5
     6 * Version: 7.4.0
    77 * Author: Perfect Solution
    88 * Text Domain: woo-quickpay
     
    2020}
    2121
    22 define( 'WCQP_VERSION', '7.3.5' );
     22define( 'WCQP_VERSION', '7.4.0' );
    2323define( 'WCQP_URL', plugins_url( __FILE__ ) );
    2424define( 'WCQP_PATH', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.