1

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);
Anonymous
  • 835
  • 1
  • 5
  • 21
Gabriel Trifa
  • 173
  • 11
  • Could you share the code you are using when calling to present the payment sheet along with a sample of the data your back-end is providing? I assume you are roughly following this guide: https://stripe.com/docs/payments/accept-a-payment?platform=android. – RyanM Oct 25 '22 at 22:22
  • @RyanM thank you for you comment. Yes, I followed that link. I've edited my question with the code sample. – Gabriel Trifa Oct 26 '22 at 15:28
  • Can you log the value for the `customerConfiguration` and share that as a separate snippet? A common reason for the saved payment methods not appearing is a mismatch in expected vs. provided configuration values. – RyanM Oct 26 '22 at 20:14

2 Answers2

1

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

Pavel K
  • 46
  • 1
  • 10
  • Hi Pavel, thanks for the effort to answer this. Is interesting, something is missing from my side for sure, because i'm following all the steps. The customerId is always the same for each payment, and the ephemeralKey and clientSecret keys are different, which again is ok. The server side is configured fine, because the ios works as expected, and regarding the steps, im going trough the same process as you. 1) get client id, get ephemeral, get client secret. 2) init customer configuration with customer id and ephemral and then use it to presentWithPaymentIntent. Yet, i get a different result. – Gabriel Trifa Nov 09 '22 at 21:23
  • I see your replies on you question comments, and i seen what your ephimeral key looks wrong. My ephimeral key looks like this: ek_test_YWNjdF8xSdm2cDVBcVJaWHasdasdJBLFNvdWdiSnlPNVAweGVGZDdEVzVvS29HQTJUQWtqR0o_000RWoKz4S Your kei is ID of the the ephemeral key request. Its name in the response from the server is id. It is necessary to take a different value - secret. – Pavel K Nov 10 '22 at 07:31
  • 1
    @GabrielTrifa look on my current response from stripe when i call ephemeral key response. In this case you take the value from ID, but you need to take the value from SECRET `{ "id":"ephkey_HHK2LkAqRZKKFhBARtX5geSN", "object":"ephemeral_key", "associated_objects":[ { "id":"cus_SOMECUSTOMER", "type":"customer" } ], "created":1668065258, "expires":1668068858, "livemode":false, "secret":"ek_test_JUURw8xS3pRcDVBcVJaWKKGHEJBLFNvdWdiSnlPNVAweGVGZDdEVzVvS29HQTJUQWtqR0o_000RWoKz4S" }` – Pavel K Nov 10 '22 at 07:41
  • i will talk with the API team about this and I'll get back with the results. Thank you!! – Gabriel Trifa Nov 14 '22 at 09:27
  • Pavel, you were right! After switching the Ephemeral key from the one deserialized as "id" to the one deserialized as "secret", I can now see the saved cards. You rock man, thanks for putting time in understanding and answering this! – Gabriel Trifa Nov 20 '22 at 19:03
  • Glad it helped. If there are more questions, I will try to help in solving :) – Pavel K Nov 22 '22 at 14:50
0
lateinit var customerConfig: PaymentSheet.CustomerConfiguration
private lateinit var paymentSheet: PaymentSheet

customerConfig = PaymentSheet.CustomerConfiguration(id,ephemeral_key)

        paymentSheet.presentWithPaymentIntent(
            client_secret,
            PaymentSheet.Configuration(
                PrefManager.getFullName(),
                customer = customerConfig,
                // Set `allowsDelayedPaymentMethods` to true if your business
                // can handle payment methods that complete payment after a delay, like SEPA Debit and Sofort.
                allowsDelayedPaymentMethods = true
            )
        )

thanks a lot... form India