将条纹cURL代码转换为Parse.Cloud.httpRequests
问题描述:
如何将以下代码转换为Parse REST http请求?将条纹cURL代码转换为Parse.Cloud.httpRequests
curl https://api.stripe.com/v1/charges \
-u {PLATFORM_SECRET_KEY}: \
-H "Stripe-Account: {CONNECTED_STRIPE_ACCOUNT_ID}" \
-d amount=1000 \
-d currency=aud \
-d source={TOKEN}
我已经尝试以下,但我接收401授权错误:
Parse.Cloud.define("payMerchantDirect", function(request, response){
Parse.Cloud.httpRequest({
method: "POST",
url: "https://" + {PLATFORM_SECRET_KEY} + ':@' + "api.stripe.com/v1" + "/charges/",
headers: {
"Stripe-Account": request.params.{CONNECTED_STRIPE_ACCOUNT_ID}
},
body: {
'amount': 1000,
'currency': "aud",
'source': request.params.{TOKEN}
},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code ' + httpResponse.status);
}
});
});
我三重检查使用的带区按键和标识,但可惜仍然没有工作。将-u cURL变量放在url中是否正确?
干杯, 埃里克
答
解决了它。
另一个问题是,通过向URL添加参数导致404错误。
此问题的解决方案(Parse.com create stripe card token in cloud code (main.js))对我的问题有所帮助。
基本上你可以在httpRequest'headers'中调用-u和-H cURL参数。确保您将“承载者”前缀添加到{PLATFORM_SECRET_KEY}。
Parse.Cloud.define("payMerchantDirect", function(request, response){
Parse.Cloud.httpRequest({
method: "POST",
url: "https://api.stripe.com/v1/charges",
headers : {
'Authorization' : 'Bearer {PLATFORM_SECRET_KEY}',
'Stripe-Account' : request.params.{CONNECTED_STRIPE_ACCOUNT_ID}
},
body: {
'amount': request.params.amount,
'currency': "aud",
'source': request.params.sharedCustomerToken
},
success: function(httpResponse) {
response.success(httpResponse.data.id);
},
error: function(httpResponse) {
response.error('Request failed with response code ' + httpResponse.status);
}
});
});
答
这里就是我翻了一个卷曲的请求到HttpRequest的一个例子:
卷曲:
curl https://api.stripe.com/v1/transfers \
-u [secret api key]: \
-d amount=400 \
-d destination=[account id]\
-d currency=usd
的HttpRequest:
Parse.Cloud.httpRequest
(
{
method:"POST",
url: "https://" + STRIPE_SECRET_KEY + ':@' + STRIPE_API_BASE_URL + "/transfers?currency=usd&amount=" + amountOwedProvider.toString() + "&destination=" + recipient_id
}
)
这不是性感可能有更好的方法使用标题/正文,但basica我建立了URL,然后呢?在所有参数之前,以及参数之间的&符号(&)。
但是,它看起来像你刚刚创建收费。你可以使用Parse的Stripe模块。
此外,通过连接的帐户,您应该将帐户设置为收费目的地,或者只有极少数情况下一次性从您的条形帐户转移到他们的帐户,而不是使用费用。这是为了税务目的。
谢谢杰克, 是的这是用于关联帐户的费用。我想要完成的是第一种方法,如下所述:[链接](https://stripe.com/docs/connect/payments-fees#charging-directly) 我已设法向客户收费并转让资金到达目的地。然而,付款仍然通过平台帐户处理,我希望关联帐户管理所有这些。 因此,我的示例curl代码中的-H变量。 –