Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i am using Stripe for payment. 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?

-(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];
}
like image 547
Vvk Avatar asked Mar 12 '23 21:03

Vvk


1 Answers

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.

Once the token has been created, it must be sent to an external server where you can use it in API requests, e.g. to create a charge.

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.

like image 76
Ywain Avatar answered Mar 15 '23 23:03

Ywain