【问题标题】:Parse Cloud Code Stripe Module Charges.Create Not Working and Now Deploy Not WorkingParse Cloud Code Stripe Module Charges.Create 不工作,现在部署不工作
【发布时间】:2015-03-20 18:52:49
【问题描述】:

我正在使用 Stripe Parse 云代码模块尝试对一张我在 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"}

但我认为这对我没有多大帮助,因为这是条带文档中最常见的错误类型。

我尝试解决此问题的另一种方法是弄乱 config/global.json 文件中的“parseVersion”,因为我引用了一篇解析问题文章,但我认为这是一个相同的问题: 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)

现在,即使我将版本改回“1.2.5”,我也会遇到相同的 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];
             }];

        }];
    }
}];
}

【问题讨论】:

    标签: ios json parse-platform stripe-payments parse-cloud-code


    【解决方案1】:

    我不确定这是否重要,但我先创建一个客户,然后使用卡令牌:

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

    另外,令牌可能有问题吗?能贴一下调用云代码的代码吗?

    【讨论】:

    • 好的,现在的主要问题是由于 python 错误,我无法部署任何新版本的云代码。我更改了代码,但无法部署。
    • 它说它更新到最新版本。然后我再次尝试解析部署,它给出了同样的错误。
    【解决方案2】:

    我不确定这是否有帮助,但您可以通过在响应中发送错误消息来查看错误消息。

    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:“您的卡已过期。”等等

    【讨论】:

    • 最好使用由 stripe 记录的代码,这并不能回答问题。对不起
    猜你喜欢
    • 2016-11-12
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多