Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe Connect Charge - Must authenticate as a connected account to be able to use customer parameter

I am trying to setup Stripe Connect and need to

  1. charge the buyer by creating a customer first,
  2. then generate a token and finally
  3. charge the customer with this token.

This works fine as long as the buyer and seller are not the owners of the Stripe Connect Platform.

I.e. let's assume the following email corresponds to the account holder:

[email protected]

Now, we have two sellers:

[email protected]
[email protected]

And we have one buyer:

[email protected]

My code works when buyer_1 buys from seller_1. All goes fine and an application fee is charged.

The problem however arises when buyer_1 wants to buy from [email protected]. Eventhough [email protected] is connected to the account platform (I go through the same process as for seller_1), I keep getting the error:

message: "Must authenticate as a connected account to be able to use customer parameter. See https://stripe.com/docs/api#create_card_token for more details."
param: "customer"
raw: Object
rawType: "invalid_request_error"
requestId: "req_8EtIue0F4JWFmQ"
stack: 400
type: "StripeInvalidRequestError"

I use the following tutorial to save a customer and charge customers:

// store
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("SECRETKEY");

// (Assuming you're using express - expressjs.com)
// Get the credit card details submitted by the form
var tokenID = request.body.stripeToken;

// Create a Customer
stripe.customers.create({
  source: tokenID,
  description: "Example customer"
}, function(err, customer) {

});

// Create token
// Create a Token from the existing customer on the platform's account
stripe.tokens.create(
  { customer: CUSTOMER_ID, card: CARD_ID },
  { stripe_account: CONNECTED_STRIPE_ACCOUNT_ID }, // id of the connected account
  function(err, token) {
    // callback
  }
);
like image 637
JohnAndrews Avatar asked Apr 09 '16 17:04

JohnAndrews


3 Answers

I know this question is not recent but I have come across this same problem several times in my development testing. The problem was fixed when I did a db:reset or removed the user(customer account) and reauthorized.

It turned out I had duplicate connect accounts for the same user, for old plans and the api_key was old.

Since I was in development and testing, I also found it useful to clear the test data from Stripe, on the dashboard >business settings >data > Delete all test data

Hope that helps.

like image 131
Laurie Avatar answered Nov 04 '22 01:11

Laurie


Same thing happened to me. It's somewhat deceiving because Stripe let's you connect your account directly to the same account in the Settings (where it says "test the OAuth flow"), like a single account is acting as both the platform and the connected account. However, when you attempt to actually create charges or customers on the connected account, you get the above error.

like image 23
toddg Avatar answered Nov 04 '22 01:11

toddg


I had this problem when testing charges using Stripe Connect. It turned out that when I went through the process of connecting a test business to my app (via the Connect To Stripe test page they provide) I was also already logged into my app's Stripe account in another browser window. This ended up saving my app's account data in the place of the new "test business" which kept causing charges to fail with that error.

When I went through the same process logged out of Stripe, it worked fine and charges were processed normally.

like image 36
Brendan O'Brien Avatar answered Nov 04 '22 02:11

Brendan O'Brien