Skip to content

Commit

Permalink
fix: agreements cancelled in app are now properly reflected in Woo
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcuzz committed Dec 23, 2024
1 parent 3a956dc commit a2a0c8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Alternatively you could look into using WooCommerce "Early renewals": [https://d

= 2.1.2 =
* Fixed: Cleaning up old cancelled orders that were initiated via Checkout now works as intended.
* Fixed: Old agreements that customers now cancelled in the Vipps or MobilePay apps are now cancelled properly in WooCommerce.

= 2.1.1 =
* Fixed: Added two new hosts to `allowed_redirect_hosts`: `pay.mobilepay.dk` and `pay.mobilepay.fi`. This fixes a bug where customers were not able to switch to MobilePay.
Expand Down
33 changes: 18 additions & 15 deletions includes/wc-gateway-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public function __construct() {
] );

add_action( 'woocommerce_order_status_pending_to_cancelled', [ $this, 'maybe_delete_order' ], 99999 );
add_action( 'woocommerce_new_order', [$this, 'maybe_delete_order_later'] );
add_action( 'woocommerce_vipps_recurring_delete_pending_order', [$this, 'maybe_delete_order'] );
add_action( 'woocommerce_new_order', [ $this, 'maybe_delete_order_later' ] );
add_action( 'woocommerce_vipps_recurring_delete_pending_order', [ $this, 'maybe_delete_order' ] );

add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [
$this,
Expand Down Expand Up @@ -2425,26 +2425,29 @@ private function maybe_get_subscription_id_from_agreement_webhook( array $webhoo
if ( empty( $order_id ) && isset( $webhook_data['agreementId'] ) ) {
$agreement_id = $webhook_data['agreementId'];

$options = [
'limit' => 1,
'type' => 'shop_subscription',
'meta_key' => WC_Vipps_Recurring_Helper::META_AGREEMENT_ID,
'meta_compare' => '=',
'meta_value' => $agreement_id,
'return' => 'ids',
'payment_method' => $this->id,
'order_by' => 'post_date'
];
$subscription_ids = get_posts( [
'limit' => 1,
'post_type' => 'shop_subscription',
'post_status' => [ 'wc-active', 'wc-pending', 'wc-on-hold' ],
'meta_key' => WC_Vipps_Recurring_Helper::META_AGREEMENT_ID,
'meta_compare' => '=',
'meta_value' => $agreement_id,
'fields' => 'ids',
] );

$order_ids = wc_get_orders( $options );
$order_id = array_pop( $order_ids );
if ( ! empty( $subscription_ids ) ) {
return array_pop( $subscription_ids );
}
}

// If the order id is not a subscription, we can get the subscription from the order
if ( ! empty( $order_id ) && ! wcs_is_subscription( $order_id ) ) {
$order = wc_get_order( $order_id );
$subscriptions = wcs_get_subscriptions_for_order( $order );
$order_id = array_pop( $subscriptions );

if ( ! empty( $subscriptions ) ) {
return array_pop( $subscriptions );
}
}

// Otherwise the order_id is either empty, or a subscription
Expand Down

0 comments on commit a2a0c8b

Please sign in to comment.