我正在嘗試使用條紋,雲代碼和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")
}
})
plz post也雲代碼不是圖像。 –
看看Parse示例項目[「Parse Store」](https://github.com/ParsePlatform/ParseStore),特別是[main.js文件](https://github.com/ParsePlatform/ParseStore/ blob/master/CloudTest/cloud/main.js) – shim
我想出了什麼是錯誤的,但我不知道如何解決它。在createCharge函數中,我試圖向已創建的客戶收費,但我沒有使用正確的客戶ID,而是使用對象ID,其中條紋客戶ID是http://puu.sh/mtUae/5caca1fc81巴紐。我如何解決它? – coolmac