I have been working on ApplePay with stripe, all fine until taking stripe token with PKPayment Here Everyone mentioned send your stripe token to server and charge the amount. I don't have knowledge on creating web service and sending token to server. So I have planned to charge the card through iOS code.
Create-Charge Docs: Link
curl https://api.stripe.com/v1/charges \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
-d amount=999 \
-d currency=usd \
-d description="Example charge" \
-d source=tok_IPLStrXFSITtr78XW5SyDWL8
Here We don't know how to make the post data with secret key.
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
NSString *urlString = @"https://api.stripe.com/v1/charges";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
NSString *postBody = [NSString stringWithFormat:@"source=%@&amount=%@", sourceID, @1099];
NSData *data = [postBody dataUsingEncoding:NSUTF8StringEncoding];
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (!error && httpResponse.statusCode != 200) {
error = [NSError errorWithDomain:StripeDomain
code:STPInvalidRequestError
userInfo:@{NSLocalizedDescriptionKey: @"There was an error connecting to your payment backend."}];
}
if (error) {
completion(STPBackendChargeResultFailure, error);
} else {
completion(STPBackendChargeResultSuccess, nil);
}
}];
[uploadTask resume];
Error:
You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.
We have looked similar questions Apple Pay using Stripe send token to server and charge for purchase
Thanks in advance..