Stripe和Parse SDK存储信用卡

时间:2015-02-27 04:30:15

标签: ios objective-c parse-platform stripe-payments cloud-code

我正在尝试将用户信用卡存储到条带中。我有一个使用付款套件PTKView设置的表单。然后,当用户点按保存按钮后,我会创建STPToken Stripe所需的Stripe。创建令牌后,我尝试将用户objectId的令牌保存为STPCard作为客户。我确信问题出在服务器代码中。

有点背景,我使用Parse SDK的云代码作为我的服务器,所以我正在处理javascript :(。

在这里,我从表单中获取信息,创建一个PTKCard* card = self.cardView.card; // self.cardView is the PTKView STPCard *stpcard = [[STPCard alloc] init]; stpcard.number = card.number; stpcard.expMonth = card.expMonth; stpcard.expYear = card.expYear; stpcard.cvc = card.cvc; [[STPAPIClient sharedClient] createTokenWithCard:stpcard completion:^(STPToken *token, NSError *error) { if (error) { NSLog(@"error"); } else { [self createBackendChargeWithToken:token]; } }]; ,然后生成一个令牌。

- (void)createBackendChargeWithToken:(STPToken *)token
{

    NSDictionary *productInfo = @{@"cardToken": [NSString stringWithFormat:@"%@",token],
                                  @"objectId": [[PFUser currentUser] objectId]};


    [PFCloud callFunctionInBackground:@"saveCardInformation"
                       withParameters:productInfo
                                block:^(id object, NSError *error) {
                                    if (error) {
                                        NSLog(@"error");
                                        return ;
                                    }

                                    [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Success", @"Success")
                                                                message:nil
                                                               delegate:nil
                                                      cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
                                                      otherButtonTitles:nil] show];

                                }];
}

创建令牌后,我将其发送到Parse,在那里我实现了服务器端代码,以处理创建客户并将其保存到Stripe。

var Stripe = require('stripe');
Stripe.initialize(my_key);


Parse.Cloud.define("saveCardInformation", function(request, response) {

    Stripe.Customers.create({
      source: request.params.cardToken,
    },{
      success: function(httpResponse) {
        response.success("Customer created!");
      },
      error: function(httpResponse) {
        response.error(httpResponse.message);
      }
    });

});

现在我处理在云代码中传递的令牌:

Error: There is no token with ID tok_15afWSDOYfVZdgZvh6qSvmmm (test mode). (Code: 141, Version: 1.6.0)
然后我回复说:

{{1}}

为什么这么说?据我所知,我只是创建一个用户,所以当然没有指定id的令牌。我理解它主要是在javascript云代码中,但我不确定如何处理这个...任何人都有任何想法?

1 个答案:

答案 0 :(得分:2)

好的......我犯了一个小错误......显然我需要访问STPTokens tokenId属性....

NSDictionary *productInfo = @{@"cardToken": token.tokenId,
                              @"objectId": [[PFUser currentUser] objectId]};

需要彻底阅读我的代码。