Skip to content

Commit

Permalink
fix: renewal orders that come from subscriptions made via Checkout co…
Browse files Browse the repository at this point in the history
…uld get stuck as "pending", even though a charge was actually created
  • Loading branch information
Marcuzz committed Nov 11, 2024
1 parent 4e20ff6 commit 5e2165b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions includes/wc-gateway-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}

Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions woo-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5e2165b

Please sign in to comment.