问题
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