2016-01-13 39 views
0

我正在嘗試使用條紋,雲代碼和swift向客戶收費。我可以使用所有元數據成功創建客戶,但是我在爲該卡充電時失敗。我得到這些錯誤。 enter image description here爲什麼客戶不收費?

雲代碼

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

plz post也雲代碼不是圖像。 –

+0

看看Parse示例項目[「Parse Store」](https://github.com/ParsePlatform/ParseStore),特別是[main.js文件](https://github.com/ParsePlatform/ParseStore/ blob/master/CloudTest/cloud/main.js) – shim

+0

我想出了什麼是錯誤的,但我不知道如何解決它。在createCharge函數中,我試圖向已創建的客戶收費,但我沒有使用正確的客戶ID,而是使用對象ID,其中條紋客戶ID是http://puu.sh/mtUae/5caca1fc81巴紐。我如何解決它? – coolmac

回答

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"); 

}); 
+0

這似乎會創建客戶,我已經完成了,現在我正試圖收費。 – coolmac

+0

@coolmac。你有2次返回錯誤信息。因爲這會引發錯誤。 plz只寫入'response.error(httpResponse)'或'response.error(「呃哦,出錯了」);' –

+0

http://puu.sh/mtUl7/c8d9428133.png – coolmac

相關問題