您需要确保您的 Stripe 帐户已设置为允许连接帐户。通过添加 var Buffer = require('buffer').Buffer; 要在请求范围之外条带化云代码,您可以使用以下代码创建一个帐户:
var Buffer = require('buffer').Buffer;
var bankAccountNumber = request.params['bankAccountNumber']
Parse.Cloud.httpRequest({
method:"POST",
url: "https://" +"api.stripe.com/v1" + "/accounts",
headers: {
'Authorization': 'Basic ' + new Buffer('YOUR_STRIPE_SECRET_KEY' + ':' + '').toString('base64')
},
body:{
"managed": false,
"country": "US",
"email": "example@mailinator.com"
},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code: ' + httpResponse.status);
}
如果您创建独立帐户,您将在创建时收到一封电子邮件。Mailinator 是一项服务,允许您使用任何名称创建工作电子邮件地址,但没有隐私。编辑:我正在使用连接的帐户。我注意到,在测试时,如果您成功创建了一个帐户,那么随后尝试使用相同的电子邮件创建一个帐户将会失败。要转移资金,Stripe 需要您可以在平台仪表板的已连接帐户下查看的某些属性。我找到了其中几个的语法(除了银行账户)。Edit2:要完成 Stripe 的必填字段以验证您的帐户,您需要包含一个银行帐户字段。我的项目在 Swift 中运行,传递给我的云代码的参数是在我的应用程序中使用 STPAPIClient.sharedClient() 创建的令牌。https://stripe.com/docs/testing#how-do-i-test-sending-transfers。
body:{
"managed": true,
"country": "US",
"email": "yourUniqueemail@mailinator.com",
"legal_entity[first_name]": "AnyName",
"legal_entity[last_name]": "AnyName",
"legal_entity[dob[day]]": "20",
"legal_entity[dob[month]]": "11",
"legal_entity[dob[year]]": "1993",
"legal_entity[type]": "individual",
"tos_acceptance[date]": "1438198036",
"tos_acceptance[ip]": "123.34.56.789",
"bank_account": bankAccountNumber,
},
编辑 3:我的代码的工作方式是创建客户并收取费用。收费金额与申请费一起发送到平台。然后从平台支付连接的帐户。(我不完全确定这是使用 Stripe 的正确方法;但是,这种方法似乎在测试模式下工作,并允许我们存储有关客户和我们支付的人的信息.) 好在 Parse 的 api 中存在 charge 方法,所以我们不必发出 POST 请求。这是执行此功能的收费方法。
Parse.Cloud.define("chargeAccount", function(request, response) {
var amount2 = request.params['amount']*100;
Stripe.Charges.create({
amount: amount2,
currency: request.params["currency"],
customer: request.params['customerId'],
description: request.params['description'],
application_fee: amount2/5,
destination: request.params['destinationAccountId']
},{
success: function(charge) {
response.success("There was a charge of $" + amount2/100 + " The application fee is: $" +amount2/500 +".");
},
error: function(error) {
response.error("\nThis is the error:\n" +error);
}
})
});