如何在一个'中使用两个Stripe帐户?应用

时间:2015-11-06 19:06:48

标签: ios stripe-payments

我是iOS的新手,还有iOS的Stripe pay新手我想在iOS上支付Two Stripe帐户,就像我想要在One中支付一样,并且在尽快成功支付一个帐户之后我想支付在第二个帐户中,我编写了如下代码:

"Transaction Start"


-(void)startTransaction
{
 if ([self validateCustomerInfo])
 {
    [Stripe setDefaultPublishableKey:STRIPE_TEST_PUBLIC_KEY1];
    STPCardParams *card = [[STPCardParams alloc] init];
    card.number = txtCardNumber.text;
    card.expMonth =[btnMonth.titleLabel.text integerValue];
    card.expYear = [btnYear.titleLabel.text integerValue];
    card.cvc = txtCvv.text;
    [[STPAPIClient sharedClient] createTokenWithCard:card
                                          completion:^(STPToken *token, NSError *error) {
                                              if (error) {
                                                  [GlobalClass StopSpinner:self.view];
                                                  [AppDelegate ShowAlert:[NSString stringWithFormat:@"%@",[error localizedDescription]]];
                                              } else {
                                                  [self postStripeToken:token];
                                              }
                                          }];
}
}

#Generated First Token.


-(void)postStripeToken:(STPToken*)token
{
   [GlobalClass ActivateSpinner:self.view StringMSG:@"Please wait"];
   NSDictionary *parameter=@{@"secretkey":STRIPE_SECRET_KEY1,@"stripeToken":token.tokenId,@"amount":@"2",@"currency":@"usd",@"description":@"iOS Transaction"};
   AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
   manager.responseSerializer.acceptableContentTypes =          [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
   [manager POST:@"http://s570166064.onlinehome.us/seadealersWS/payment/payment.php" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"Responce Object %@",responseObject);
     if ([[responseObject valueForKey:@"status"]isEqualToString:@
         "Success"])
     {
     # Here i want to Pay in second account #

         [Stripe setDefaultPublishableKey:STRIPE_TEST_PUBLIC_KEY2];
         STPCardParams *card = [[STPCardParams alloc] init];
         card.number = txtCardNumber.text;
         card.expMonth =[btnMonth.titleLabel.text integerValue];
         card.expYear = [btnYear.titleLabel.text integerValue];
         card.cvc = txtCvv.text;
         [[STPAPIClient sharedClient] createTokenWithCard:card
                                               completion:^(STPToken *token, NSError *error) {
                                                   if (error) {
                                                       [GlobalClass StopSpinner:self.view];
                                                       [AppDelegate ShowAlert:[NSString stringWithFormat:@"%@",[error localizedDescription]]];
                                                   } else {
                                                       [GlobalClass StopSpinner:self.view];
                                        [GlobalClass ActivateSpinner:self.view StringMSG:@"Please wait"];

                                                       [self postStripeTokenTwo:token];
                                                   }
                                               }];
     }
 } failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     [GlobalClass StopSpinner:self.view];
     [AppDelegate ShowAlert:@"Please try again"];
     NSLog(@"Error %@",error);
 }];
 }
 -(void)postStripeTokenTwo:(STPToken*)token
 {
NSDictionary *parameter=@{@"secretkey":STRIPE_SECRET_KEY2,@"stripeToken":token.tokenId,@"amount":@"0.5",@"currency":@"usd",@"description":@"iOS Transaction"};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[manager POST:@"http://s570166064.onlinehome.us/seadealersWS/payment/payment.php" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"Responce Object %@",responseObject);
     if ([[responseObject valueForKey:@"status"]isEqualToString:@
          "Success"])
     {
         [GlobalClass StopSpinner:self.view];
     }
 } failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     [GlobalClass StopSpinner:self.view];
     [AppDelegate ShowAlert:@"Please try again"];
     NSLog(@"Error %@",error);
 }];

}

但对于First帐户,我获得了成功响应,但对于第二个帐户,它表示您的令牌无效我不想设置条带连接。 谢谢你,抱歉英语不好。

2 个答案:

答案 0 :(得分:1)

令牌只能使用一次,并且仅在创建它的帐户中有效。您必须使用两个令牌(每个帐户创建一个)

此外,您不应该在应用中发送Stripe secret API密钥。应用程序代码中的字符串很容易被发现,您不希望泄漏API密钥。标准方法是将令牌发送到您控制的服务器,并从您的服务器发送API调用。

此外,您可能需要查看Stripe Connect,这可能是解决您的问题的更好方法,然后存储多个帐户的api密钥。

答案 1 :(得分:0)

旧版本的Stripe SDK中存在此问题

为了解决此问题

1)将SDK升级到最新版本(13.2.0)

pod Stripe, '~>13.2.0'
pod install --repo-update

2)代替设置

STPPaymentConfiguration.shared().publishableKey = STRIPE_TEST_PUBLIC_KEY1

使用

STPAPIClient.shared().publishableKey = STRIPE_TEST_PUBLIC_KEY1 

3)清理并运行该项目,它将按预期工作。

Please refer this link for more information