我正在尝试使用条带,云代码和swift向客户收费。我可以使用所有元数据成功创建客户,但是当我对卡充电时它会失败。我收到这些错误。
云代码
var Stripe = require('stripe');
Stripe.initialize('sk_test_xxx');
Parse.Cloud.define("createCustomer", function(request, response) {
Stripe.Customers.create({
card: request.params.coin,
account_balance: 25*100,
metadata: {
name: request.params.name,
customer: request.params.customer, // e.g PFUser object ID
}
}, {
success: function(customer) {
response.success(customer.id);
},
error: function(error) {
response.error("Error:" +error);
}
})
});
Parse.Cloud.define("createCharge", function(request, response) {
Stripe.Charges.create({
amount: 100 * 25,
currency: "usd",
card: request.params.coin,
customer: request.params.customerId
},{
success: function(httpResponse) {
response.success("Purchase made!");
},
error: function(httpResponse) {
response.error(httpResponse)
response.error("Uh oh, something went wrong");
}
});
});
ios代码:
PFCloud.callFunctionInBackground("createCustomer", withParameters: ["coin" : coin, "name": name, "customer": customer], block: { (success: AnyObject?, error: NSError?) -> Void in
if error != nil {
print("create customer not working")
print(error)
}
})
var customerId = customer!
PFCloud.callFunctionInBackground("createCharge", withParameters: ["customerId" : customerId], block: { (success: AnyObject?, error: NSError?) -> Void in
if error != nil {
print("not working")
}
})
答案 0 :(得分:0)
编写如下的云代码。可能会帮助它。
Stripe.Customers.create({
//your key - value pair here which you want to pass.
}).then(function(httpResponse){
console.log(httpResponse);
response.success("success");
}, function(httpResponse){
console.error(httpResponse);
response.success("error");
});