← All changes
|
app/Modules/PaymentMethods/StripeGateway/Stripe.php
+16
-16
1.7.0
→
1.7.1
View file →
| @@ -843,11 +843,13 @@ | ||
| 843 | 843 | // mode — a zero-amount payment mode is invalid — and consent becomes a |
| 844 | 844 | // required checkbox: without a saved card the trial can never bill. |
| 845 | 845 | $payableNow = \FluentCart\App\Services\OrderService::getItemsAmountTotal($cart->cart_data ?? [], false, false); |
| 846 | 846 | if ($payableNow <= 0) { |
| 847 | + // Match the SetupIntent usage even when the optional save-card flag is set. | |
| 847 | 848 | $intentData = [ |
| 848 | - 'mode' => 'setup', | |
| 849 | - 'currency' => strtolower($storeCurrency), | |
| 849 | + 'mode' => 'setup', | |
| 850 | + 'currency' => strtolower($storeCurrency), | |
| 851 | + 'setup_future_usage' => 'off_session', | |
| 850 | 852 | ]; |
| 851 | 853 | $consentRequired = true; |
| 852 | 854 | } |
| 853 | 855 | } |
| @@ -858,22 +860,20 @@ | ||
| 858 | 860 | } elseif (empty($intentData['setup_future_usage']) && Arr::get($data, 'save_payment_method') === 'yes') { |
| 859 | 861 | $intentData['setup_future_usage'] = 'on_session'; |
| 860 | 862 | } |
| 861 | 863 | |
| 862 | - // The browser cannot pass setup_future_usage per-request (this endpoint | |
| 863 | - // receives no body), so extensions that vault cards (e.g. saved payment | |
| 864 | - // methods) resolve it here, server-side. Must be matched on the actual | |
| 865 | - // PaymentIntent at place-order (fluent_cart/payments/stripe_onetime_intent_args) | |
| 866 | - // or Stripe rejects the confirmation for a setup_future_usage mismatch. | |
| 867 | - $setupFutureUsage = apply_filters( | |
| 868 | - 'fluent_cart/stripe/client_setup_future_usage', | |
| 869 | - Arr::get($intentData, 'setup_future_usage'), | |
| 870 | - ['data' => $data, 'has_subscription' => $hasSubscription] | |
| 871 | - ); | |
| 872 | - if ($setupFutureUsage) { | |
| 873 | - $intentData['setup_future_usage'] = $setupFutureUsage; | |
| 874 | - } else { | |
| 875 | - unset($intentData['setup_future_usage']); | |
| 864 | + // a one-time payment may be changed here. | |
| 865 | + if ($intentData['mode'] === 'payment') { | |
| 866 | + $setupFutureUsage = apply_filters( | |
| 867 | + 'fluent_cart/stripe/client_setup_future_usage', | |
| 868 | + Arr::get($intentData, 'setup_future_usage'), | |
| 869 | + ['data' => $data, 'has_subscription' => $hasSubscription] | |
| 870 | + ); | |
| 871 | + if ($setupFutureUsage) { | |
| 872 | + $intentData['setup_future_usage'] = $setupFutureUsage; | |
| 873 | + } else { | |
| 874 | + unset($intentData['setup_future_usage']); | |
| 875 | + } | |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | wp_send_json( |
| 879 | 879 | [ |