diff --git a/README.txt b/README.txt index 99c0c77..3fc9241 100755 --- a/README.txt +++ b/README.txt @@ -167,6 +167,8 @@ Alternatively you could look into using WooCommerce "Early renewals": [https://d * Fixed: You are now informed that a Merchant Serial Number is required in order to enable Checkout. * Fixed: Your applied coupons are now given the proper respect when Checkout is enabled. * Fixed: The price is now set correctly when one off products are in a recurring cart when Checkout is enabled. +* Fixed: No longer show the "Capture payment" button when the charge is in a non-RESERVED state. +* Fixed: A scenario where the "auto capture payment" feature for MobilePay would not trigger correctly. * Added: We now cancel initial Checkout orders after two hours to avoid checking them in cron forever. * Added: You can now enable or disable deletion of changed or abandoned Checkout orders in the settings. diff --git a/includes/wc-gateway-vipps-recurring.php b/includes/wc-gateway-vipps-recurring.php index 5d03484..4aa1335 100755 --- a/includes/wc-gateway-vipps-recurring.php +++ b/includes/wc-gateway-vipps-recurring.php @@ -459,6 +459,7 @@ public function unlock_order( $order ): void { /** * @param $order_id + * @param bool $skip_lock * * @return string * @throws WC_Vipps_Recurring_Config_Exception @@ -506,7 +507,7 @@ public function check_charge_status( $order_id, $skip_lock = false ): string { if ( $order_initial && $order->get_payment_method() === $this->id ) { do_action( 'wc_vipps_recurring_check_charge_status_no_agreement', $order ); } - + return 'INVALID'; } @@ -561,11 +562,15 @@ public function check_charge_status( $order_id, $skip_lock = false ): string { $is_captured = ! in_array( $charge->status, [ WC_Vipps_Charge::STATUS_PENDING, WC_Vipps_Charge::STATUS_RESERVED - ], true ); + ], true ) && $agreement->status === WC_Vipps_Agreement::STATUS_ACTIVE; // If the brand is MobilePay, we should capture the payment now if it is not already captured. // This is because MobilePay auto-releases and refunds payments after 7 days. Vipps will keep a reservation for a lot longer. - if ( $this->brand === WC_Vipps_Recurring_Helper::BRAND_MOBILEPAY && ! $is_captured && $this->auto_capture_mobilepay ) { + if ( $this->brand === WC_Vipps_Recurring_Helper::BRAND_MOBILEPAY + && ! $is_captured + && $this->auto_capture_mobilepay ) { + $order->save(); + $order->add_order_note( __( 'MobilePay payments are automatically captured to prevent the payment reservation from automatically getting cancelled after 14 days.', 'vipps-recurring-payments-gateway-for-woocommerce' ) ); $this->maybe_capture_payment( $order_id ); @@ -574,6 +579,8 @@ public function check_charge_status( $order_id, $skip_lock = false ): string { $is_direct_capture = WC_Vipps_Recurring_Helper::get_meta( $order, WC_Vipps_Recurring_Helper::META_ORDER_DIRECT_CAPTURE ); if ( $is_direct_capture && ! $is_captured ) { + $order->save(); + $this->maybe_capture_payment( $order_id ); return 'SUCCESS'; @@ -1400,7 +1407,7 @@ public function create_vipps_agreement_from_order( $order, $subscription = null, $agreement_total = WC_Subscriptions_Product::get_regular_price( $product, 'code' ) * $quantity; } - $is_zero_amount = (int) $agreement_total === 0 || $is_gateway_change; + $is_zero_amount = (int) $agreement_total === 0 || (int) $order->get_total() === 0 || $is_gateway_change; $capture_immediately = $is_virtual || $direct_capture; $has_synced_product = WC_Subscriptions_Synchroniser::subscription_contains_synced_product( $subscription ); diff --git a/includes/wc-vipps-recurring-helper.php b/includes/wc-vipps-recurring-helper.php index 55b2c48..60b0ccd 100755 --- a/includes/wc-vipps-recurring-helper.php +++ b/includes/wc-vipps-recurring-helper.php @@ -278,7 +278,7 @@ public static function is_charge_captured_for_order( $order ) { public static function can_capture_charge_for_order( $order ): bool { return (int) self::get_meta( $order, self::META_CHARGE_PENDING ) === 1 && ! self::is_charge_captured_for_order( $order ) - && ! self::is_charge_failed_for_order( $order ) + && in_array( self::get_latest_api_status_from_order( $order ), [ WC_Vipps_Charge::STATUS_RESERVED, WC_Vipps_Charge::STATUS_PARTIALLY_CAPTURED ] ) && ! (int) WC_Vipps_Recurring_Helper::get_meta( $order, WC_Vipps_Recurring_Helper::META_ORDER_ZERO_AMOUNT ) && ! wcs_order_contains_renewal( $order ); }