我不知道将哪些参数传递到此云代码函数(parse.com)
Parse.Cloud.define('stripe_card_create', function(req, res) {
Parse.Cloud.httpRequest({
method: 'POST',
headers: stripe_headers,
url: environment.stripe.api_url + '/customers/' + req.params.customer_id + '/sources',
params: {
source: req.params.token_id
},
success: function(card) {
res.success(card.data);
},
error: function(err) {
res.error(err.text);
}
})
});
这些应该被称为
req.customer_id(必填)客户 ID
req.token_id(必填) token 化卡
但是当我使用此函数调用时收到错误
PFCloud.callFunctionInBackground("stripe_card_create", withParameters: ["req.params.customer_id":"req.params.token_id"])
这是错误
[Error]: {
"error": {
"type": "invalid_request_error",
"message": "No such customer: undefined",
"param": "customer"
}
}
(Code: 141, Version: 1.7.5)
最佳答案
在云函数中,req.params.customer_id
的英文意思是这样的:
从function(req, res)
中的req
中,获取params
。从 params
属性中,获取名为 customer_id
的键。当您从 Swift 代码调用该函数时,您传递的字典键将是 params
的属性。
您的云代码需要键 customer_id
,而不是 req.params.customer_id
。您想要执行此操作:
PFCloud.callFunctionInBackground("stripe_card_create", withParameters: ["customer_id": "\(whatever the id is you need to pass)"], block: nil)
您在字典中传递的键值的命名也非常奇怪。要么这是一个同样的错误,要么你真的应该将其重命名为更好的名称。
关于ios - 如何在我的 iOS 应用程序中调用 Cloud Code Function(Parse)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415413/