Julien Attard
Julien Attard

Reputation: 83

Swift - Stripe Connect StripeAccount

I integrate Stripe Connect in my Android & iOS App. All is ok for my Android app.

For iOS, i'm stuck with this error :

Payment failed: Error Domain=com.stripe.lib Code=50 "There was an unexpected error -- try again in a few seconds" UserInfo={com.stripe.lib:StripeErrorCodeKey=resource_missing, NSLocalizedDescription=There was an unexpected error -- try again in a few seconds, com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:ErrorParameterKey=intent, com.stripe.lib:ErrorMessageKey=Ressource payment_intent inexistante : 'pi_3LNYx8QQGw6fEJWk06RcezpX'}

Here is my Swift code :

                    let customerId = json["customer"] as! String
                    let customerEphemeralKeySecret = json["ephemeralKey"] as! String
                    let paymentIntentClientSecret = json["paymentIntent"] as! String
                    let paymentIntentId = json["paymentIntent_id"] as! String
                    let publishableKey = json["publishableKey"] as! String
                    let stripe_account_connect = json["stripe_account_connect"] as! String

                    STPAPIClient.shared.publishableKey = publishableKey
                    StripeAPI.defaultPublishableKey = publishableKey
                
                    var configuration = PaymentSheet.Configuration()
                    configuration.merchantDisplayName = "Example"
                    configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
                    configuration.allowsDelayedPaymentMethods = false
                
                    print("connect : \(stripe_account_connect)")
                
                    if( stripe_account_connect != "" ) {
                        print("ok config account")
                        
                        STPPaymentConfiguration.shared.stripeAccount = stripe_account_connect
                        STPAPIClient.shared.stripeAccount = stripe_account_connect
                    }
                    
                    let paymentSheet = PaymentSheet(paymentIntentClientSecret: paymentIntentClientSecret, configuration: configuration)```

I think the difference with Android is this part :

if( !result.get("stripe_account_connect").getAsString().equals("") ) {
                                    Log.d("aaaaaa", "stripe_account_connect : "+result.get("stripe_account_connect").getAsString());
                                    PaymentConfiguration.init(getApplicationContext(), result.get("publishableKey").getAsString(), result.get("stripe_account_connect").getAsString());
                                } else {
                                    PaymentConfiguration.init(getApplicationContext(), result.get("publishableKey").getAsString());
                                }

Hope someone have a solution for this error, i found nothing on the documentation ...

Thanks!

Upvotes: 0

Views: 584

Answers (1)

Tarzan
Tarzan

Reputation: 1087

From what I understand of how the SDK works, when you create a PaymentSheet.Configuration() under the hood it will make a copy of the Global/Shared API Client and assign it to the Configuration’s API Client. So when you use STPAPIClient.shared.stripeAccount = stripe_account_connect to add the Stripe Account afterwards, it does not take effect on that PaymentSheet’s Configuration and it will try to get the PaymentIntent with only the Platform’s API key without the Connect StripeAccount Authentication Header. This results in the PaymentIntent not being found because it doesn’t really exist on the Platform’s Account (it’s technically a Direct Charge on the Connect Account).

Either put the if block before initializing your configuration or just create a new API Client and attribute that to the configuration.

Upvotes: 1

Related Questions