3

While trying to generate a token for my connected account from my already created stripe customer, I keep on receiving an error saying that the customer id does not exist. That being said, I know for a fact that the customer is being created.

Here's the code:

var Stripe = StripeAPI('sk_test_key');

Stripe.customers.create({
  email: Meteor.user().emails[0].address,
  description: "SIDIM 2016",
  source: stripeToken
}).then(function(customer) {

  return Stripe.tokens.create({
    customer: customer.id
  }, {stripe_account: "acct_XXXYYYZZZ"});

}).then(function(token) {

  console.log(token);

  var charge = Stripe.customers.create({
    email: Meteor.user().emails[0].address,
    description: "SIDIM 2016",
    source: token.id
  }, {stripe_account: "acct_XXXYYYZZZ"});

  console.log(charge);

}).then(function(charge) {

  return Stripe.charges.create({
    amount: total,
    currency: 'usd',
    customer: charge.id
  }, {stripe_account: "acct_XXXYYYZZZ"});

}).catch(function(err) {
  // Deal with an error
});

I'm using API version 2016-03-07 (latest).

I've already spent 2 hours debugging and looked through stackoverflow. Thanks!

Nima Amin
  • 92
  • 2
  • 10
  • At first glance, your code looks correct (even though assigning a customer object to a variable named `charge` is confusing). Could you write to Stripe support using the form at https://support.stripe.com/email? This issue will be a lot easier to debug if we can see your requests' log entries. – Ywain Mar 09 '16 at 11:35

1 Answers1

4

If you wish to use customers across your "connected" accounts, you must take the extra step of generating a new "token", as described here.

This issue is elaborated on a bit more in this SO post, which includes some sample Ruby code.

Chris W.
  • 1,680
  • 16
  • 35
Alireza Balouch
  • 467
  • 4
  • 13