From 5e2165bd0a1c2a2ffa459ea483c0bf17e660444c Mon Sep 17 00:00:00 2001 From: Marcus Dahl Date: Mon, 11 Nov 2024 18:59:05 +0100 Subject: [PATCH] fix: renewal orders that come from subscriptions made via Checkout could get stuck as "pending", even though a charge was actually created --- README.txt | 3 +++ includes/wc-gateway-vipps-recurring.php | 16 ++++++++++++++-- woo-vipps-recurring.php | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.txt b/README.txt index 9f806e7..b19751b 100755 --- a/README.txt +++ b/README.txt @@ -162,6 +162,9 @@ Alternatively you could look into using WooCommerce "Early renewals": [https://d == Changelog == += 2.0.7 = +* Fixed: Renewal orders that come from subscriptions made via Checkout could get stuck as "pending", even though a charge was actually created. Updating to this version fixes the affected orders and their statuses. + = 2.0.6 = * Fixed: Campaigns now display their "after" price correctly. * Fixed: Properly propagate recurring pricing to our manually created subscriptions in Checkout. diff --git a/includes/wc-gateway-vipps-recurring.php b/includes/wc-gateway-vipps-recurring.php index 7a36a2f..7b2bdf0 100755 --- a/includes/wc-gateway-vipps-recurring.php +++ b/includes/wc-gateway-vipps-recurring.php @@ -511,8 +511,10 @@ public function check_charge_status( $order_id, $skip_lock = false ): string { return 'INVALID'; } + $is_renewal = wcs_order_contains_renewal( $order ); + // logic for zero amounts when a charge does not exist - if ( WC_Vipps_Recurring_Helper::get_meta( $order, WC_Vipps_Recurring_Helper::META_ORDER_ZERO_AMOUNT ) && ! wcs_order_contains_renewal( $order ) ) { + if ( WC_Vipps_Recurring_Helper::get_meta( $order, WC_Vipps_Recurring_Helper::META_ORDER_ZERO_AMOUNT ) && ! $is_renewal ) { // if there's a campaign with a price of 0 we can complete the order immediately if ( $agreement->status === WC_Vipps_Agreement::STATUS_ACTIVE ) { $this->complete_order( $order, $agreement->id ); @@ -724,7 +726,8 @@ public function process_order_charge( $order, ?WC_Vipps_Charge $charge = null ): // status: DUE or PENDING // when DUE, we need to check that it becomes another status in a cron - $initial = WC_Vipps_Recurring_Helper::get_meta( $order, WC_Vipps_Recurring_Helper::META_ORDER_INITIAL ); + $initial = WC_Vipps_Recurring_Helper::get_meta( $order, WC_Vipps_Recurring_Helper::META_ORDER_INITIAL ) + && ! wcs_order_contains_renewal( $order ); if ( ! $initial && ! $transaction_id && ( $charge->status === WC_Vipps_Charge::STATUS_DUE || ( $charge->status === WC_Vipps_Charge::STATUS_PENDING @@ -2056,6 +2059,10 @@ public function delete_resubscribe_meta( $resubscribe_order ): void { WC_Vipps_Recurring_Helper::delete_meta_data( $resubscribe_order, WC_Vipps_Recurring_Helper::META_CHARGE_ID ); WC_Vipps_Recurring_Helper::delete_meta_data( $resubscribe_order, WC_Vipps_Recurring_Helper::META_CHARGE_CAPTURED ); + WC_Vipps_Recurring_Helper::delete_meta_data( $resubscribe_order, WC_Vipps_Recurring_Helper::META_ORDER_INITIAL ); + WC_Vipps_Recurring_Helper::delete_meta_data( $resubscribe_order, WC_Vipps_Recurring_Helper::META_ORDER_IS_EXPRESS ); + WC_Vipps_Recurring_Helper::delete_meta_data( $resubscribe_order, WC_Vipps_Recurring_Helper::META_ORDER_EXPRESS_AUTH_TOKEN ); + $this->delete_renewal_meta( $resubscribe_order ); } @@ -2072,6 +2079,11 @@ public function delete_renewal_meta( $renewal_order ) { WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_SUBSCRIPTION_UPDATE_IN_APP ); WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_SUBSCRIPTION_UPDATE_IN_APP_DESCRIPTION_PREFIX ); WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_ORDER_IDEMPOTENCY_KEY ); + WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_CHARGE_CAPTURED ); + + WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_ORDER_INITIAL ); + WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_ORDER_IS_EXPRESS ); + WC_Vipps_Recurring_Helper::delete_meta_data( $renewal_order, WC_Vipps_Recurring_Helper::META_ORDER_EXPRESS_AUTH_TOKEN ); $renewal_order->save(); diff --git a/woo-vipps-recurring.php b/woo-vipps-recurring.php index 75dfaa9..4e290cc 100755 --- a/woo-vipps-recurring.php +++ b/woo-vipps-recurring.php @@ -5,7 +5,7 @@ * Description: Offer recurring payments with Vipps MobilePay for WooCommerce Subscriptions * Author: Everyday AS * Author URI: https://everyday.no - * Version: 2.0.6 + * Version: 2.0.7 * Requires Plugins: woocommerce * Requires at least: 6.1 * Tested up to: 6.7 @@ -18,7 +18,7 @@ // phpcs:disable WordPress.Files.FileName -define( 'WC_VIPPS_RECURRING_VERSION', '2.0.6' ); +define( 'WC_VIPPS_RECURRING_VERSION', '2.0.7' ); /** * Polyfills