#bazylh-connect-accounts

1 messages · Page 1 of 1 (latest)

tawny osprey
#

Can you give some more detail? What specifically are you trying to do, and what doc are you following?

south gyro
#
def create_payment_data(
    customer_id,
    intent: StripeIntent,
    stripe_account_id: str,
) -> StripePaymentData:
    stripe_settings = get_stripe_settings()
    ephemeral_key = stripe.EphemeralKey.create(
        stripe_account=stripe_account_id,
        customer=customer_id,
        stripe_version="2020-08-27",
        api_key=stripe_settings.api_key,
    )

    return StripePaymentData(
        customer_data=StripeCustomerData(
            customer_id=customer_id,
            ephemeral_key=ephemeral_key,
        ),
        client_secret=intent.client_secret,
        publishable_key=stripe_settings.pub_key,
    )```
#

When we try to lookup the setup intent for initializing a future payment we get not founds. Although I can visibly see the customers and setup intent inside the connect account as expected.

#

Yet I am passing in the stripe_account field in the ephemeral key create method.

tawny osprey
#

Can you share the request ID that's showing the error so I can look at it on my end?

south gyro
#

req_pGD56g96hi4vpk

#

req_SiQO8xADcpoAv4

#

First one is session, second one is intent request using the ephemeral.

tawny osprey
#

When you creat the Setup Intent are you also setting the Stripe-Account header?

south gyro
#

yes.

#
    transaction_id: KSUID,
    partner_id: PartnerId,
    stripe_account_id: str,
    customer_id: str,
) -> StripeSetupIntent:
    setup_intent = stripe.SetupIntent.create(
        customer=customer_id,
        metadata=dict(
            org_id=partner_id,
            transaction_id=transaction_id,
        ),
        stripe_account=stripe_account_id,
    )
    # get the info needed to fulfill the intent and get the card info.
    return StripeSetupIntent(
        id=setup_intent["id"],
        client_secret=setup_intent["client_secret"],
        status=setup_intent["status"],
    )
#

req_UIoiw6kBhlorUB

#

Interestingly enough I don't see it in the post body although I'm supplying it.

#

If you look at my images above you can see in the connect account there is a setup intent indeed

tawny osprey
#

AH - I think I see what the issue is. I don't htink you're actually using the ephemeral key in those two requests you sent over (req_pGD56g96hi4vpk and req_SiQO8xADcpoAv4). You're accidentally using the publishable key isntead

south gyro
#

Oh is this on the client or the backend?

tawny osprey
#

This is your frontend making these calls

south gyro
#

Right on.

#

Okay.

south gyro
#
        print("Keys Dict: ", dict)
        let customerId = dict["customer_id"] as? String ?? ""
        let customerEphemeralKeySecret = dict["ephemeralKey"] as? String ?? ""
        let setupIntentClientSecret = dict["setupIntent"] as? String ?? ""
        let publishableKey = dict["publishableKey"] as? String ?? ""
        
        STPAPIClient.shared.publishableKey = publishableKey
        var configuration = PaymentSheet.Configuration()
        configuration.returnURL = "com.koloni.lockers.app://stripe-redirect"
        configuration.merchantDisplayName = "Lockrs"
        configuration.customer = .init(id: customerId, ephemeralKeySecret: customerEphemeralKeySecret)
        configuration.allowsDelayedPaymentMethods = true
        self.paymentSheet = PaymentSheet(setupIntentClientSecret: setupIntentClientSecret, configuration: configuration)```
#

So this is already in our active application.

tawny osprey
#

Thanks for sharing that - that also helps clear up some more things. So the issue isn't with your ephemeral keys at all. The issue is the stripe-ios uses both ephemeral and publishable keys to make requests. The requests that are using the publishable key don't have the Stripe-Account header set, so they're looking at the wrong account. You need to set STPAPIClient.shared.stripeAccount as well (https://stripe.dev/stripe-ios/docs/Classes/STPAPIClient.html#/s:10StripeCore12STPAPIClientC13stripeAccountSSSgvp)

south gyro
#

Wow interesting. I'd request there be a lot more documentation and examples for fully connect use cases.

#

Also if ephemeral and public keys are both set, I feel like the SDK should be able to either keep track of both keys or override to the ephemeral if its given.

#

So we need to provide the connect account id string to stripeAccount in the SDK?

tawny osprey
#

Yes, you need to also set the stripeAccount header in the SDk