【问题标题】:Is there any way to charge card from iOS App without backend charge from our server.(Stripe - iOS)有什么方法可以从 iOS 应用程序中收取卡,而无需从我们的服务器收取后端费用。(条纹 - iOS)
【发布时间】:2016-07-03 09:33:51
【问题描述】:

我正在使用 Stripe 进行付款。我想从我的应用程序中充值卡。目前我正在使用以下代码对卡进行收费,但该过程是从服务器端完成的。有没有办法从应用程序收取卡而不是将stripeToken发送到服务器?

-(void)createBackendChargeWithToken:(STPToken *)token completion:(void (^)(PKPaymentAuthorizationStatus))completion {
    NSURL *url = [NSURL URLWithString:@"https://example.com/token"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    request.HTTPMethod = @"POST";
    NSString *body     = [NSString stringWithFormat:@"stripeToken=%@&amount=%@", token.tokenId,_txtAmount.text];
    request.HTTPBody   = [body dataUsingEncoding:NSUTF8StringEncoding];
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
    NSURLSessionDataTask *task =
    [session dataTaskWithRequest:request
               completionHandler:^(NSData *data,
                                   NSURLResponse *response,
                                   NSError *error) {
                   if (error) {
                       completion(PKPaymentAuthorizationStatusFailure);
                       // [self customeAlertView:@"Payment not successful" message:@"Please try again later."];
                       NSLog(@"Payment not successful. Please try again later.");
                   } else {
                       completion(PKPaymentAuthorizationStatusSuccess);
                       // [self customeAlertView:@"Success" message:@"Please enjoy your new purchase."];
                       NSLog(@"Payment Success. Please enjoy your new purchase.");
                   }
               }];
    [task resume];
}

【问题讨论】:

  • 看一次可能对你有帮助stripe.com/docs/mobile/ios
  • @Anbu.Karthik 我也检查过了,但所有代码都是来自服务器的后端费用。

标签: ios objective-c stripe-payments


【解决方案1】:

不,这是不可能的。 Stripe 的 iOSAndroid 绑定仅用于收集卡片信息和创建令牌,就像在 Web 应用程序中的 Stripe.jsCheckout 一样。

创建令牌后,必须将其发送到外部服务器,以便在 API 请求中使用它,例如到create a charge

必须使用外部服务器的原因是除了创建令牌之外的所有 API 请求都必须使用您的秘密 API 密钥发出,该密钥不能直接用于您的应用程序,否则恶意用户将能够检索并使用它访问您的帐户。

【讨论】:

    猜你喜欢
    • 2015-07-09
    • 2015-06-03
    • 1970-01-01
    • 2017-06-26
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多