Search code examples
androidstripe-paymentspaymentstripe-payment-intent

Android Stripe Saved card missing from payment sheet


After fetching the customerId, ephemeralKey and clientSecret, I initialize the PaymentSheet with a Configuration object (which includes the app name, customerConfiguration(customerId, ephemeralKey and GooglePayConfiguration.

I then call presentWithPaymentIntent(clientSecrent, customerConfiguration), where the customerConfiguration is the object created at the first step.

The documentation says that if you pass the customer configuration and the user checks the "Save for future payments" checkbox, on the next payment the PaymentSheet will show the saved card, but for some reason, for me it doesn't.

I've checked and the customerId it's always the same for the current customer, only the ephemeralKey changes for new payments, which seems right.

Any idea what I might be doing wrong? The iOS client works as expected, so server side is configured ok.

Thanks!

Code sample:

PaymentSheet.GooglePayConfiguration googlePayConfiguration = new PaymentSheet.GooglePayConfiguration(getGooglePayEnvironment(), countryCode);
        PaymentSheet.CustomerConfiguration customerConfiguration = new PaymentSheet.CustomerConfiguration(mViewModel.getCustomerId(), mViewModel.getEphemeralKey());

        PaymentSheet.Configuration configuration = new PaymentSheet.Configuration(getString(R.string.app_name),
                customerConfiguration,
                googlePayConfiguration,
                null,
                null);

mPaymentSheet.presentWithPaymentIntent(mViewModel.getClientSecret(), configuration);

Solution

  • Your question does not show the code that is executed in the View Model, so I will give a working example of saving/loading card data:

    • getting an ephemeral key - to get a key from the server, you need to send a POST request, to which you must attach a custom ID. The request may differ depending on the implementations on your server. In the response from the server, we receive an ephemeral key. Stripe sends it to a server called "secret". Important! If you do not use own server to protect your secret key, then you neet to get exactly field named "secret" from https://api.stripe.com/v1/ephemeral_keys

    • send payment intent. Most likely, this implementation will also be transferred to your server and will be replaced by a reflection to your server, which will generate a payment intent and send you the necessary data back, however, the default body implementation will look like this:

    https://api.stripe.com/v1/payment_intents BODY PARAMS
    
     customer=$customerId
     amount=$amount
     currency=usd
    
    

    This request will return the secret key intent, which we will use during the initialization of our payment sheet.

    Next step is setting up the sheet. Use the following code:

    val customerConf = PaymentSheet.CustomerConfiguration(viewModel.customerId, ephemeralKey)
    val sheetConf = PaymentSheet.Configuration(
            merchantDisplayName = "Some product name",
            customer = customerConf,
            allowsDelayedPaymentMethods = false
    )
    paymentSheet.presentWithPaymentIntent(intentSecret, sheetConf)
    

    As the result, you will receive the preservation of your cards after re-payment.

    Payment by saved card. Image

    I also advise you to create a test user for the android application and check on the dashboard whether the card data is saved after clicking on the checkbox and paying