【发布时间】:2015-08-01 01:40:21
【问题描述】:
我正在尝试将用户信用卡存储到条带中。生成令牌后,我尝试将令牌与用户一起保存到 Stripe 作为客户。但是我没有找到任何问题的答案,我只需要存储一张卡给一个已经存在的用户。
我尝试使用 Stripe.Customers.update 方法,但如果用户有一张“默认”卡,它会存储新卡。并使用 Stripe.Customers.create 方法使用新卡创建一个新客户,但我需要存储在特定用户中。
云代码:
Parse.Cloud.define("stripeCreateCard", function(request,response)
{
Stripe.initialize(STRIPE_SECRET_KEY);
Stripe.Customers.create
(
request.params,
{
success:function(results)
{
response.success(results);
},
error:function(error)
{
response.error("Error:" +error);
}
}
);
});
Parse.Cloud.define("stripeUpdateCustomer", function(request, response)
{
Stripe.initialize(STRIPE_SECRET_KEY);
Stripe.Customers.update
(
request.params["customerId"],
request.params["data"],
{
success:function(results)
{
console.log(results["id"]);
response.success(results);
},
error:function(error)
{
response.error("Error:" +error);
}
}
);
});
iOS 代码:
class func getParamsForAddingCardToCustomer(custormerId: String, cardToken: String) -> NSDictionary {
let params = NSMutableDictionary()
params.setObject(["card" : cardToken], forKey: "data")
params.setObject(custormerId, forKey: "customerId")
return params
}
var params = ParamsHelper.getParamsForAddingCardToCustomer(stripeId, cardToken: token)
PFCloud.callFunctionInBackground("stripeCreateCard", withParameters: params as [NSObject : AnyObject]) {
(response: AnyObject?, error: NSError?) -> Void in
let responseString = response as? String
if (error === nil) {
println("Response: \(responseString) ")
}
else if (error != nil) {
println("Error: \(error) \(error!.userInfo)")
}
}
我根据需要尝试了几个参数来存储卡,但我总是收到错误'收到未知参数'
有人知道如何在不删除或创建新客户的情况下存储卡片吗?
【问题讨论】:
-
查看 stripe 的文档,这是更新卡片字段时的意图。或者他们现在称之为源。 Parse 的条带 Api 并不适用于所有条带功能。我会在早上添加一个答案,以便使用 http 请求为您提供解决方法。
标签: ios swift parse-platform stripe-payments parse-cloud-code