我正在使用条纹解析云代码模块尝试从我的iOS应用程序中收集信息的卡片。我正在使用解析网站上的指南: http://parse.com/docs/cloud_modules_guide#stripe
这是我在cloud / main.js中的版本:
var Stripe = require('stripe');
Stripe.initialize('MY_STRIPE_TEST_SECRET_KEY');
Parse.Cloud.define("purchase", function(request, response) {
Stripe.Charges.create({
amount: 100,
currency: "usd",
card: request.params.cardToken
},{
success: function(httpResponse)
{
response.success("Purchase made!");
},
error: function(httpResponse)
{
response.error(httpResponse);
}
});
});
通过查看云代码错误日志,我可以看到云功能购买是使用条带用户和" cardToken"作为输入。
错误是:
Failed with: {"name" : "card_error"}
但我认为这对我没什么帮助,因为这是条纹文档中最常见的错误类型。
我尝试解决此问题的另一种方法是通过搞乱" parseVersion"在config / global.json文件中,因为我引用了一个解析问题文章,我认为是一个相同的问题: http://www.parse.com/questions/stripe-integration-not-working
他们说要改变" parseVersion"到" 1.2.5"是关键,它是有效的。虽然它对我有用了一段时间,但我仍然会得到相同的错误代码:
Error: {"name" : "card_error"} (Code: 141, Version: 1.2.20)
我尝试将其更改为1.2.20(在我的错误代码中)和1.3.3(这是Parse Javascript SDK的最新版本)和1.6.1(这是最新版本)解析iOS SDK)
现在我得到了一些我不太懂的疯狂Python错误:
Traceback (most recent call last):
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/bin/parse/__main__.py", line 6, in <module>
File "/usr/local/bin/parse/main.py", line 682, in main
File "/usr/local/bin/parse/main.py", line 170, in handle_deploy
File "/usr/local/bin/parse/parse.py", line 156, in __init__
File "/usr/local/bin/parse/parse.py", line 164, in load_state
File "/usr/local/bin/parse/config_handler.py", line 125, in get_keys_for_app
File "/usr/local/bin/parse/config_handler.py", line 100, in get_info_for_apps
File "/usr/local/bin/parse/config_handler.py", line 112, in get_app_info_for_file
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load
**kw)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 12 column 20 (char 312)
现在即使我将版本更改回&#34; 1.2.5&#34;我得到了相同的Python错误,甚至无法部署其他版本以继续进行故障排除。我真的感到困惑,非常感谢你的帮助。
这是我在用户首次将数据输入解析时调用的保存功能,并希望第一次购买也是如此:
- (IBAction)save:(id)sender
{
PTKCard* card = self.paymentView.card;
STPCard* stpcard = [[STPCard alloc] init];
stpcard.number = card.number;
stpcard.expMonth = card.expMonth;
stpcard.expYear = card.expYear;
stpcard.cvc = card.cvc;
[Stripe createTokenWithCard:stpcard completion:^(STPToken *token, NSError *error)
{
if (error)
{
NSLog(@"creating token error: %@", error);
} else
{
NSArray *objectsArray = [NSArray arrayWithObjects:token.tokenId, nil];
NSArray *keysArray = [NSArray arrayWithObjects:@"cardToken", nil];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:objectsArray forKeys:keysArray];
// create a PFObject called "Order" for my own records
PFObject *order = [PFObject objectWithClassName:@"Order"];
order[@"itemName"] = self.restaurant[@"name"];
order[@"name"] = self.currentUser.username;
order[@"email"] = self.currentUser.email;
order[@"address"] = self.currentUser[@"address"];
order[@"price"] = self.total;
// save the order to Parse
[order saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
NSLog(@"saved Order");
// call cloud function
[PFCloud callFunctionInBackground:@"purchase" withParameters:dictionary block:^(id object, NSError *error)
{
// if there is no errors
if(error == nil)
{
[[[UIAlertView alloc] initWithTitle:@"It Worked!"
message:@"It charged the card with no error!"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] show];
NSLog(@"%@", object);
} else [[[UIAlertView alloc] initWithTitle:@"Error"
message:@"The purchase did not work, your card will not be charged"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] show];
}];
}];
}
}];
}
答案 0 :(得分:0)
我不确定这是否重要,但我首先创建了一个客户,然后使用卡片令牌:
Parse.Cloud.define("charge", function(request, response) {
Stripe.Customers.create({
card: request.params.token,
description: request.params.description
},{
success: function(results) {
response.success(results);
},
error: function(httpResponse) {
response.error(httpResponse);
}
}).then(function(customer){
return Stripe.Charges.create({
amount: request.params.amount, // in cents
currency: request.params.currency,
customer: customer.id
},{
success: function(results) {
response.success(results);
},
error: function(httpResponse) {
response.error(httpResponse);
}
});
});
});
此外,令牌可能有问题吗?你能粘贴调用云代码的代码吗?
答案 1 :(得分:-1)
我不确定这是否有帮助,但您可以通过在响应中发送错误消息来查看错误消息。
var Stripe = require('stripe');
Stripe.initialize('MY_STRIPE_TEST_SECRET_KEY');
Parse.Cloud.define("purchase", function(request, response) {
Stripe.Charges.create({
amount: 100,
currency: "usd",
card: request.params.cardToken
},{
success: function(httpResponse)
{
response.success("Purchase made!");
},
error: function(httpResponse)
{
response.error(httpResponse.message);
}
});
});
示例httpResponse.message:'您的卡已过期。'等