2
votes

I am saving customers and their sources on my platform, and trying to create charges for my connected accounts. I am able to successfully create destination charges, but I'm having trouble with creating direct charges.

I've tried creating a token per: https://stripe.com/docs/connect/shared-customers

If I create a token using just the customer the example, the error is:

'You provided a customer without specifying a source. The default source of the customer is a source and cannot be shared from existing customers.'

Even though the documentation says that you need "The card or bank account ID for that customer, if you want to charge a specific card or bank account rather than the default".

I cannot find a parameter that lets me specify a source as well or instead of a customer.

I've tried sharing the customer's chosen source with the connected account per: https://stripe.com/docs/sources/connect#shared-card-sources which results in the error:

'Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing.'

I tried attaching a test token (tok_visa) to my customer, and creating a charge with that, but that had the same result.

Every time I have some success I end up with the error about sending numbers being unsafe even though I'm only ever sending Stripe's provided token or source ID's.

I've tried this:

const newToken = await stripe.tokens.create({
        customer: customerId,
    }, {
        stripe_account: stripeAccountId,
    }).catch((e) => {
        console.log(e);
    });

and this:

const newToken = await stripe.sources.create({
        customer: customerId,
        usage: 'single_use',
        original_source: sourceId,
      }, {
        stripe_account: stripeAccountId,
      }).catch((e) => {
        console.log(e);            
    });

The only success I've had is creating the direct charge with a test token (tok_visa), completely bypassing the sharing of tokens/sources. No other combination seems to work. But that leaves me at a loss as to how to get a real shared token when I need it.

1

1 Answers

0
votes

I found out I should be using sources, not tokens. And it turns out I was accidentally using the whole newToken as the source for the charge. It's working now that I'm passing the newToken.id to the charge.