triniwiz / nativescript-plugins

Apache License 2.0
80 stars 50 forks source link

[android] EphemeralKeyProvider called 4 times #135

Open kefahB opened 2 years ago

kefahB commented 2 years ago

Hi @triniwiz @NathanWalker

Sorry for reporting 3 separated issues but I discover then as i go!

I've seen 4 call to get the Ephemeral key! the problem come from com.stripe.android.CustomerSession.initCustomerSession that accept a 3rd attribute to avoid sending other request when PaymentSession is initialized. see here

We can expose an attribute at the constructor as below but strangely enough setting shouldPrefetchCustomer to false this does prevent the prefetech call but doesn't resolve the problem !! I'll investigate that more, I yhink the problem come from the PaymentSession !

Also Application.android.contextis deprecated for Utils.android.getApplicationContext()

export class StripeStandardCustomerSession {
    constructor(shouldPrefetchEphemeralKey: boolean = false) {
        StripeStandardConfig.shared.initPaymentConfiguration();
        com.stripe.android.CustomerSession.initCustomerSession(StripeStandardCustomerSession.context, createKeyProvider(), shouldPrefetchEphemeralKey);
        this.native = com.stripe.android.CustomerSession.getInstance();
    }
    static get context() {
        return Utils.android.getApplicationContext();
    }
}
triniwiz commented 2 years ago

Thanks I'll check it out soon 😄

kefahB commented 1 year ago

Hi @triniwiz

This issue still on android even with the latest change to add shouldPrefetchEphemeralKey = false to com.stripe.android.CustomerSession.initCustomerSession(StripeStandardCustomerSession.context, createKeyProvider(), shouldPrefetchEphemeralKey); with this change it make 3 calls instead of 4!! and now I did a quick look to the SDK and it seems that we can reduce the number to 2 calls by setShouldPrefetchCustomer(false) to this line.

Now why still did 2 call I don't know but it is most likely from the Stripe SDK! I did explain this in new issue at the repo of Stripe android SDK

The problem is with all those call isReadyToCharge most of the time it return false, we should return backward and try again!!

Now setShouldPrefetchCustomer(false) does not request the auto filling the card info, the user should click show payment method to select the card!

kefahB commented 8 months ago

@triniwiz,

I was wondering if we can change StripeStandardCustomerSession to private and call it internally directly from here.

This issue come mainly from the 'createKeyProvider` because it is asynchrone, all the initialisations begin before the return of the ephemeral object .. but not only, we should ensure a synchronous calls on the initialisations.