From cb8762f7566753334bdca7a5831b336b290d11da Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 18 Mar 2024 11:50:34 -0700 Subject: [PATCH] fix: Android StripeTerminal assign paymentIntentInstance for confirmPaymentIntent --- .../community/stripe/terminal/StripeTerminal.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/terminal/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java b/packages/terminal/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java index 41679fbe..086da958 100644 --- a/packages/terminal/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java +++ b/packages/terminal/android/src/main/java/com/getcapacitor/community/stripe/terminal/StripeTerminal.java @@ -57,8 +57,7 @@ public class StripeTerminal extends Executor { private final JSObject emptyObject = new JSObject(); private Boolean isTest; private TerminalConnectTypes terminalConnectType; - - private PaymentIntent paymentIntent; + private PaymentIntent paymentIntentInstance; public StripeTerminal( Supplier contextSupplier, @@ -339,6 +338,7 @@ public void onFailure(@NonNull TerminalException ex) { @Override public void onSuccess(PaymentIntent paymentIntent) { collectCancelable = null; + paymentIntentInstance = paymentIntent; notifyListeners(TerminalEnumEvent.CollectedPaymentIntent.getWebEventName(), emptyObject); PaymentMethod pm = paymentIntent.getPaymentMethod(); @@ -374,19 +374,20 @@ public void onFailure(@NonNull TerminalException ex) { }; public void confirmPaymentIntent(final PluginCall call) { - if (this.paymentIntent == null) { + if (this.paymentIntentInstance == null) { call.reject("PaymentIntent not found for confirmPaymentIntent. Use collect method first and try again."); return; } this.confirmPaymentIntentCall = call; - Terminal.getInstance().confirmPaymentIntent(this.paymentIntent, confirmPaymentMethodCallback); + Terminal.getInstance().confirmPaymentIntent(this.paymentIntentInstance, confirmPaymentMethodCallback); } private final PaymentIntentCallback confirmPaymentMethodCallback = new PaymentIntentCallback() { @Override public void onSuccess(PaymentIntent paymentIntent) { notifyListeners(TerminalEnumEvent.ConfirmedPaymentIntent.getWebEventName(), emptyObject); + paymentIntentInstance = null; confirmPaymentIntentCall.resolve(); }