Jack tileman
Jack tileman

Reputation: 871

Saving credit card of a Custom Account's customer in Stripe

We are building a Platform. In our Platform we create Custom Connect Accounts in Stripe. For these Custom Connect Account we create customer accounts. Essentially the customer accounts are end-customers of our Custom Connect (Company)accounts in the Platform. Now we would like to store credit card information of the customer accounts (for a particular custom connect account).

We followed the instructions here to create a setupIntent. The code is as below, here the stripe_account is the account_id of the custom connect (Company) account and customer['id'] is the id of the customer account -

    intent = stripe.SetupIntent.create(
      customer=customer['id'],
      stripe_account = stripe_account
    )

We pass this intent.client_secret to our front end. In the Javascript we are calling this -

setupForm.addEventListener('submit', function(ev) {
  ev.preventDefault();
  stripe.confirmCardSetup(
    clientSecret,
    {stripe_account : stripe_account},
    {
      payment_method: {
        card: cardElement,
        billing_details: {
          name: cardholderName.value,
        },
      },
    }
  ).then(function(result) {
    if (result.error) {
      // Display error.message in your UI.
    } else {
      // The setup has succeeded. Display a success message.
    }
  });
});

But we are getting the error, No such setupintent: 'seti_1IBkyZ4ZQzThevDR3MR433aI'. Clearly the setupintent that was generated from Stripe is not being accepted here. What are we doing wrong?

Upvotes: 0

Views: 168

Answers (1)

Justin Michael
Justin Michael

Reputation: 6475

The likely cause of this error is that you're not initializing Stripe.js with the stripeAccount the Setup Intent exists on. Your Stripe.js initialization code should look something like this:

var stripe = Stripe('pk_test_YOUR_PUBLISHABLE_KEY', {
    stripeAccount: 'acct_CONNECTED_ACCOUNT_ID'
});

That will allow Stripe.js to make requests on behalf of the connected account (which is where the Setup Intent exists).

Upvotes: 2

Related Questions