简体   繁体   English

有没有办法从我的服务器没有后端费用从iOS应用程序收取卡。(条纹 - iOS)

[英]Is there any way to charge card from iOS App without backend charge from our server.(Stripe - iOS)

i am using Stripe for payment. 我正在使用Stripe付款。 i want to charge card from my App. 我想从我的应用程序收取卡。 currently i am using below code to charge card but the process is done from server side. 目前我使用下面的代码来收费卡,但过程是从服务器端完成的。 is there any way to charge card from app instead of sending the stripeToken to a server? 有没有办法从应用程序收取卡而不是发送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];
}

No, this is not possible. 不,这是不可能的。 Stripe's iOS and Android bindings are only used to collect card information and create tokens, much like Stripe.js and Checkout do in a web application. Stripe的iOSAndroid绑定仅用于收集卡信息和创建令牌,就像Web应用程序中的Stripe.jsCheckout一样。

Once the token has been created, it must be sent to an external server where you can use it in API requests, eg to create a charge . 创建令牌后,必须将其发送到外部服务器,您可以在API服务器中使用它,例如创建费用

The reason an external server must be used is that all API requests besides token creation must be issued using your secret API key, which must not be used directly into your application, otherwise malicious users will be able to retrieve it and use it to access your account. 必须使用外部服务器的原因是除了令牌创建之外的所有API请求都必须使用您的秘密API密钥发布,该密钥不能直接用于您的应用程序,否则恶意用户将能够检索它并使用它来访问您的帐户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM