Colfah
Colfah

Reputation: 358

Saving a card to charge a connected stripe account later in EU (using SCA). React & Node

My code is working to save a customer's card and charge them later on my stripe account. However, when I amend the code to charge the card on a connected stripe account, it will not work.

Please note, I am in EU so I must use strong customer authentication - I cannot use tokens.

The relevant frontend code is:

        const cardElement = this.props.elements.getElement('card');

    axios.post(`${process.env.REACT_APP_API}/saveCardDetails`, {stripeAccountID: this.props.stripeAccountID}).then(res => {


    this.props.stripe.confirmCardSetup(res.data.client_secret, {
        payment_method: {
    card: cardElement,
  },
    },{
    stripe_account: this.props.stripeAccountID,
    }
).then( confirmCardSetupRes => {..})

The relevant backend code is:

    //saveCardDetails controller

module.exports = (req, res) => {

    stripe.setupIntents.create().then(intent => {
        console.log('intent.client_secret', intent.client_secret)
        res.send({client_secret: intent.client_secret})
    })
}

//code to charge the saved card
const chargeSavedCard = (customerStripeID, price, currency, eventTitle, applicationFee, organiserstripeAccountID) => {


    stripe.paymentMethods.list({
        customer: customerStripeID,
        type: 'card',
    }).then(paymentMethods => {
        stripe.paymentIntents.create({
            amount: Math.round(price * 100),
            currency: currency,
            customer: customerStripeID,
            payment_method: paymentMethods.data[0].id,
            off_session: true,
            confirm: true,
            application_fee_amount: Math.round(applicationFee)
        }
        ,{
        stripe_account: organiserstripeAccountID,
        }

    ).then(stripeRes => {.......})

which is throwing the following error:

{ Error: No such PaymentMethod: pm_1G4YYVCFzSpFw85fXVcZj0hX; OAuth key or Stripe-Account header was used but API request was provided with a platform-owned payment method ID. Please ensure that the provided payment method matches the specified account.

I don't understand why my code isn't setting up the payment method on the connected account. Where am I going wrong?

Upvotes: 2

Views: 1255

Answers (1)

hmunoz
hmunoz

Reputation: 3351

Looks like the PaymentMethod is created on the Platform account, not on the Connect account.

On your frontend, you should initialize Stripe.js and authenticate as the Connect account: https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application The way you have right now (by passing {stripe_account: "acct_123"} as options to confirmCardSetup) won't work.

You should also create the SetupIntent on the Connect account, by passing the Stripe-Account header server-side, like you are doing when creating the PaymentIntent: https://stripe.com/docs/connect/authentication#stripe-account-header

Upvotes: 1

Related Questions