Apple Pay using Stripe send token to server and charge for purchase

不想你离开。 提交于 2019-12-24 00:18:53

问题


I am using Apple Pay in my iPhone application with payment Provider Stripe.

I implemented Apple Pay using test_key and it returns token and getting PKPaymentAuthorizationStatusSuccess in simulator.

Actually, I don't know the real time payment when it will done from the real device.

I have a question is Do I need to send Token to server to charge for that payment or will charge itself withing iPhone application once get token?

As per below method they are sending token to server so It will charge only on server?

- (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=%@", token.tokenId];
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);
                   ;
               }
               else
               {
                   completion(PKPaymentAuthorizationStatusSuccess);
               }
           }];
[task resume];
}

Please suggest do we charge only from server?

Thanks


回答1:


You need to send the token to your server.

Creating a charge requires your secret API key which should never be accessible from your iPhone app.



来源:https://stackoverflow.com/questions/34810635/apple-pay-using-stripe-send-token-to-server-and-charge-for-purchase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!