Skip to content

Commit

Permalink
fix: handle VAT properly in gw change, also do not cancel our own agr…
Browse files Browse the repository at this point in the history
…eement on gw change
  • Loading branch information
Marcuzz committed Dec 23, 2024
1 parent a2a0c8b commit 61bcfa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ 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.
* Fixed: VAT is now properly shown when a subscription is switched to Vipps MobilePay.
* Fixed: If an agreement is cancelled we don't want to listen for webhooks when the actor is the merchant, i.e. ourselves. This prevents us from cancelling our subscription when changing payment gateway from Vipps MobilePay to Vipps MobilePay.

= 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
16 changes: 11 additions & 5 deletions includes/wc-gateway-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ public function create_vipps_agreement_from_order( $order, $subscription = null,
$redirect_url = WC_Vipps_Recurring_Helper::get_payment_redirect_url( $order, $is_gateway_change );

// total no longer returns the order amount when gateway is being changed
$agreement_total = $is_gateway_change ? $subscription->get_subtotal() : $subscription->get_total( 'code' );
$agreement_total = $subscription->get_total( 'code' );

// when we're performing a variation switch we need some special logic in Vipps
$is_subscription_switch = wcs_order_contains_switch( $order );
Expand Down Expand Up @@ -1668,11 +1668,11 @@ public function process_payment( $order_id, bool $retry = true, bool $previous_e

WC_Vipps_Recurring_Helper::update_meta_data( $order, WC_Vipps_Recurring_Helper::META_AGREEMENT_ID, $response['agreementId'] );
WC_Vipps_Recurring_Helper::update_meta_data( $order, WC_Vipps_Recurring_Helper::META_CHARGE_PENDING, true );
}

/* translators: Vipps/MobilePay Agreement ID */
$message = sprintf( __( 'Agreement created: %s. Customer sent to Vipps/MobilePay for confirmation.', 'vipps-recurring-payments-gateway-for-woocommerce' ), $response['agreementId'] );
$order->add_order_note( $message );
/* translators: Vipps/MobilePay Agreement ID */
$message = sprintf( __( 'Agreement created: %s. Customer sent to Vipps/MobilePay for confirmation.', 'vipps-recurring-payments-gateway-for-woocommerce' ), $response['agreementId'] );
$order->add_order_note( $message );
}

$debug_msg .= sprintf( 'Created agreement with agreement ID: %s', $response['agreementId'] ) . "\n";

Expand Down Expand Up @@ -2499,6 +2499,12 @@ public function handle_webhook_callback( array $webhook_data ): void {

// Customers can now cancel their agreements directly from the app.
if ( $event_type === 'recurring.agreement-stopped.v1' ) {
// If the initiator of this webhook is ourselves, we must discard it.
// Otherwise, we risk cancelling payment gateway changes etc.
if ( $webhook_data['actor'] === 'MERCHANT' ) {
return;
}

$subscription_id = $this->maybe_get_subscription_id_from_agreement_webhook( $webhook_data );
if ( empty( $subscription_id ) ) {
return;
Expand Down

0 comments on commit 61bcfa1

Please sign in to comment.