Skip to content

Commit

Permalink
fix: capture payment button now displays only when it has to, fix aut…
Browse files Browse the repository at this point in the history
…o capturing mobilepay payments
  • Loading branch information
Marcuzz committed Oct 24, 2024
1 parent 4790fd3 commit bde95ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
15 changes: 11 additions & 4 deletions includes/wc-gateway-vipps-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
}

Expand Down Expand Up @@ -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 );

Expand All @@ -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';
Expand Down Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion includes/wc-vipps-recurring-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit bde95ab

Please sign in to comment.