stripe / stripe-java

Java library for the Stripe API.
https://stripe.com
MIT License
795 stars 358 forks source link

'No such customer' error when using Pre-built single Step + Connected Standard Account. #1240

Closed igmartell closed 3 years ago

igmartell commented 3 years ago

I created this issue in stripe/stripe-iOS project also, since I'm not sure if this is a backend or client error:

https://github.com/stripe/stripe-ios/issues/1849#issue-951183506

Summary

I have set up the Prebuilt UI (Single-Step). When I'm using it without a Connected Stripe Account, it works perfectly fine. When I add --in the server-- the RequestOptions requestOptions = RequestOptions.builder() .setStripeAccount(account.getId()) .setStripeVersionOverride(Stripe.API_VERSION) .setIdempotencyKey(orderId) .build(); , using a valid Connected Account Id, I immediately receive this error:

No such customer: 'cus_xxxxxxxxxx'; code: resource_missing; request-id: req_xxxxxxxxxxxxx

Code to reproduce

1) Create a Connected Account to receive an ID 2) Setup this ID while creating the PaymentIntent object in the Server (using JAVA)

EphemeralKeyCreateParams ephemeralKeyParams =
                                EphemeralKeyCreateParams.builder()
                                        .setCustomer(customer.getId())
                                        .build();

                        RequestOptions requestOptions = RequestOptions.builder()
                                .setStripeAccount("acct_xxxxxxxxxxx") // I hide it for security reasons
                                .setStripeVersionOverride(Stripe.API_VERSION)
                                .setIdempotencyKey(orderId)
                                .build();

                        EphemeralKey ephemeralKey = EphemeralKey.create(
                                ephemeralKeyParams,
                                requestOptions);

                         PaymentIntentCreateParams paymentIntentParams =
                                    PaymentIntentCreateParams.builder()
                                            .setAmount(stripeAmount.longValue())
                                            .setCurrency("mxn")
                                            .setCustomer(customer.getId())
                                            .setReceiptEmail(customer.getEmail())
                                            .setApplicationFeeAmount(fee)
                                            .build();

                            paymentIntent = PaymentIntent.create(paymentIntentParams, requestOptions);

3) Receive the information in iOS to create the Payment Sheet:

var configuration = PaymentSheet.Configuration()
configuration.customer = .init(id: customerId, ephemeralKeySecret: ephemeralKey)
self.paymentSheet = PaymentSheet(paymentIntentClientSecret: paymentIntentIdClientSecret, configuration: configuration)

4) Error appears.

No such customer: 'cus_xxxxxxxxxx'; code: resource_missing; request-id: req_xxxxxxxxxxxxx

NOTE: With the same parameters (commenting out the .setCustomer() and .setApplicationFeeAmount() while creating the PaymentIntent in the backend, it works as expected, but that is not the business model I need. I need to make direct payments using Connected Accounts.

iOS version

iOS 14.5

Installation method

Cocoa Pods

SDK version

JAVA VERSION:

20.62.0

Other information

remi-stripe commented 3 years ago

@igmartell Github issues should be limited to bugs with the library itself. Your question is an integration question and should be asked to our support team directly on https://support.stripe.com/contact or https://stripe.com/go/developer-chat

To unblock you though, the customer should be created on the connected account directly, it can not be the customer id of the platform.

igmartell commented 3 years ago

Big thank you. I think this was not so obvious for me. This could be a good observation to add in the documentation.