Adyen / adyen-react-native

Adyen React Native
https://docs.adyen.com/checkout
MIT License
43 stars 32 forks source link

storedPaymentMethods in case of single paymentMethod #172

Closed gkueny closed 4 months ago

gkueny commented 1 year ago

Contexte

In our app, we show paiements methods in custom UI

In case of card paiement, we want to show stored Payement method if any.

Issue

For now, it's just possible to show:

In our case, we do not want to show all available paiement in NativeModule because our user already choose CreditCard paiement

Workaround

For now, we patch this library to have this code in src/AdyenCheckoutContext.tsx

diff --git a/src/AdyenCheckoutContext.tsx b/src/AdyenCheckoutContext.tsx
index 1fcd523..2e0b063 100644
--- a/src/AdyenCheckoutContext.tsx
+++ b/src/AdyenCheckoutContext.tsx
@@ -134,7 +134,10 @@ const AdyenCheckout: React.FC<AdyenCheckoutProps> = ({
       startEventListeners(config, nativeComponent);

       if (paymentMethod) {
-        const singlePaymentMethods = { paymentMethods: [paymentMethod] };
+        const singlePaymentMethods = { 
+          paymentMethods: [paymentMethod],
+          storedPaymentMethods: paymentMethods.storedPaymentMethods,
+        };
         const singlePaymentConfig = {
           ...config,
           dropin: { skipListWhenSinglePaymentMethod: true },

Proposition

Is it possible to add a config to show stored paiement that match paymentMethod to show ?

descorp commented 1 year ago

Hey @gkueny

Thank you for reaching out! 💚

This is indeed not possible with current AdyenCheckoutContext. Drop-In on iOS and Android are not design to work with single stored payment method.

We have this on our backlog, and in next versions we will add way to initiate stored payment by its' ID:

start('HW9LL9ML73M84H82')

Potential workaround:

Instantiate this payment "API-Only" way without use of AdyenCheckoutContext; only problem - you wouldn't be able to handle native 3DS challenges (only web-redirect 3DS).

You might need encrypted CVV - you can use AdyenCSE module for this.

gkueny commented 1 year ago

thanks for your response !

gkueny commented 1 year ago

Hi @descorp ,

On this subject, to avoid using "API-Only" way or payment by ID,

Is it possible to show related stored payment on single payment method ? (with config optin ?)

I can imagine this API:

// config API
const configuration = {
   // ....
   showStoredPaymentForSinglePaymentMethod: true
}
// In AdyenContext

if (paymentMethod) {
        const storedPaymentMethods = config.showStoredPaymentForSinglePaymentMethod && paymentMethods.storedPaymentMethods 
          ? paymentMethods.storedPaymentMethods.filter(storedPaymentMethod => {
              return storedPaymentMethod.type === paymentMethod.type
            }) 
          : []
        const singlePaymentMethods = { 
          paymentMethods: [paymentMethod],
          storedPaymentMethods: storedPaymentMethods,
        };
        const singlePaymentConfig = {
          ...config,
          dropin: { skipListWhenSinglePaymentMethod: true },
        };
        nativeComponent.open(singlePaymentMethods, singlePaymentConfig);
      } else {
        nativeComponent.open(paymentMethods, config);
      }

With this API, we will be able to show storedPayments for single payment.

Here is the flow it would unlock:

gkueny commented 1 year ago

Hello @descorp !

do you think this feature could land in this module ?

for now we patch this lib to implement this feature and have used it in production succesfully (rc-2)

If you approve the API I can submit an PR

descorp commented 1 year ago

Hey @gkueny

Sorry for the long reply and not getting back to you.

Main issues with approach:

We currently have showPreselectedStoredPaymentMethod: true, that will show:

Screenshot 2023-06-21 at 13 14 14

However if you send only a single stored payment Method, UI looks odd:

Screenshot 2023-06-21 at 13 25 06


One suggestion I could make - better search for StoredPaymentMethod.id rather then type - shopper might have several stored cards. I would encourage you to make PR - it will allow us to test and asses the idea faster.


showStoredPaymentForSinglePaymentMethod

This is great idea: we are looking to enable standalone stored payment methods, but it will require more work from Android side. Currently we are postponing all major work till upcoming Android v5 release, since it will effect multiple public APIs.

gkueny commented 1 year ago

thanks for your response @descorp .

I will make a PR, it will be easier to discuss / test the proposal indeed.

descorp commented 5 months ago

Hey @gkueny

Stored payment method could be performed via CSE + Standalone Action handling on v2. Feel free to check BETA version.

camil-adyen commented 4 months ago

Closing this issue as it's fixed on v2.0.0-BETA.