使用条带连接条带节点为共享客户充电

我正努力使用正确的语法来为使用Stripe Connect的连接用户的收益向客户收费。 我正在使用stripe-node api。 我已经尝试了几百个组合的参数来创造收费,没有人会为我工作。

我希望收取的客户已经作为客户添加到我的(连接应用程序的)Stripe账户中,并且我想要收取收费的用户已经连接到我的应用程序。 这很好。 随着这些步骤完成,我然后检索一个令牌为新的收费,这似乎也很好。 我打电话:

Stripe.tokens.create( { customer: myCustomer }, connectedUserAccessToken, function(error, token){ if (error){ return error; } else { return token; } } ); 

哪个返回:

 { id: 'tok_15L16gLFEmuXszazTaVUA0ty', livemode: false, created: 1421280206, used: false, object: 'token', type: 'card', card: { id: 'card_15L16gLFEmuXszaz7VAu2ciH', object: 'card', last4: '8210', brand: 'MasterCard', funding: 'debit', exp_month: 1, exp_year: 2020, fingerprint: 'ny39g9uj2lfhYA2H', country: 'US', name: null, address_line1: null, address_line2: null, address_city: 'New York', address_state: 'NY', address_zip: '10003', address_country: 'US', cvc_check: null, address_line1_check: null, address_zip_check: null, dynamic_last4: null, customer: null }, client_ip: '99.99.9.99' } 

(从条纹testing页面卡数据是假的)。

当我尝试使用新的令牌创build收费时出现问题。 我将上面的对象分配给var令牌并调用:

 Stripe.charges.create( { card: token.id }, function(error, result){ if (error){ return error; } else { return result; } } ); 

这返回:

 [ Error: There is no token with ID tok_15L16gLFEmuXszazTaVUA0ty. ] 

这个响应对我来说没有任何意义,因为正如你所看到的,令牌ID和刚才创build的ID是一致的。 (我也看到创build事件发布到我的条纹日志,所以他们正在创build)。

如果不是将{ card: token.id }传递给Stripe.charges.create()我会传递:

 Stripe.charges.create( token, function(error, result){} ); 

我收到:

 [Error: [Error: Missing required param: currency] 

这是有道理的,因为我没有通过它的收费货币或金额。 但是当我试图通过这些额外的参数作为选项,例如:

 Stripe.charges.create( { currency: user.currency, amount: transaction.amount }, token, function(error, result){} ); 

我收到:

 [Error: Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.] 

我收到相同的错误,如果我扭转的参数和调用:

 Stripe.charges.create( token, { currency: user.currency, amount: transaction.amount }, function(error, result){} ); 

实际上,我以任何格式传递的任何选项似乎都会被上面的同样的错误拒绝。

我试过了:

 Stripe.charges.create( { customer: token.id, currency: user.currency, amount: transaction.amount }, function(error. result){} ); 

这导致:

 [Error: No such customer: tok_15L16gLFEmuXszazTaVUA0ty] 

我尝试通过token.currency = user.currency ,然后调用Stripe.charges.create(token)直接将货币添加到令牌本身。 起初它似乎很喜欢,因为它返回了错误:

 [Error: Missing required param: amount] 

但是当我跟进并设置token.currency = user.currency; token.amount = transaction.amount; token.currency = user.currency; token.amount = transaction.amount; 那么它拒绝整个对象,返回:

 [Error: Received unknown parameters: id, livemode, created, used, object, type, client_ip] 

我想不出还有什么可以find的。

我读了几次以上的链接, https://github.com/stripe/stripe-node/wiki/Using-Stripe-Connect-with-node.js ,但是它并没有帮助我符合语法。 所以我暂时没有想法。 谢谢阅读。

一旦你使用他们的publishable_key为你的连接用户创build了一个卡令牌,那么你就需要使用他们的access_token代表他们的费用。 关于如何收费的文档中描述了这一点,代码如下所示:

 // Get the credit card details submitted by the form var token = request.body.stripeToken; // Create the charge on Stripe's servers - this will charge the user's card stripe.charges.create( { amount: 1000, // amount in cents currency: "eur", card: token, description: "payinguser@example.com", application_fee: 123 // amount in cents }, ACCESS_TOKEN, // user's access token from the Stripe Connect flow function(err, charge) { // check for `err` // do something with `charge` } );