Skip to content

Commit 4c32230

Browse files
authored
Generate mandates only for INR (#5442)
* Return empty mandate params for currencies other than INR * Prevent stale free subscription data to throw an error by amount < 0
1 parent 064229d commit 4c32230

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: update
3+
4+
Generate mandate only for orders using INR currency

includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,16 +858,32 @@ public function get_mandate_params_for_order( WC_Order $order ): array {
858858
return $result;
859859
}
860860

861+
// TEMP Fix – Stripe validates mandate params for cards not
862+
// issued by Indian banks. Apply them only for INR as Indian banks
863+
// only support it for now.
864+
$currency = $order->get_currency();
865+
if ( 'INR' !== $currency ) {
866+
return $result;
867+
}
868+
861869
// Get total by adding only subscriptions and get rid of any other product or fee.
862-
$subs_amount = 0;
870+
$subs_amount = 0.0;
863871
foreach ( $subscriptions as $sub ) {
864872
$subs_amount += $sub->get_total();
865873
}
866874

875+
$amount = WC_Payments_Utils::prepare_amount( $subs_amount, $order->get_currency() );
876+
877+
// TEMP Fix – Prevent stale free subscription data to throw
878+
// an error due amount < 1.
879+
if ( 0 === $amount ) {
880+
return $result;
881+
}
882+
867883
$result['setup_future_usage'] = 'off_session';
868884
$result['payment_method_options']['card']['mandate_options'] = [
869885
'reference' => $order->get_id(),
870-
'amount' => WC_Payments_Utils::prepare_amount( $subs_amount, $order->get_currency() ),
886+
'amount' => $amount,
871887
'amount_type' => 'fixed',
872888
'start_date' => $subscription->get_time( 'date_created' ),
873889
'interval' => $subscription->get_billing_period(),

0 commit comments

Comments
 (0)