2

How to integrate instamojo payment gateway in iOS Objective C? May be there is no direct method. Then through WebView, how to integrate payment gateway in iOS? long URL has been added, but what should be place in redirect link and on what key the header and params are sent.

Hasya
  • 9,792
  • 4
  • 31
  • 46
Aashi
  • 170
  • 2
  • 14
  • I think there is no iOS sdk available for that? – Ali Farhan Feb 23 '17 at 10:55
  • yep bt through webview we can and for that we have to send some key value pairs.i created json format for header and param bt for what key headers and params are to be sent – Aashi Feb 23 '17 at 11:05
  • Improved formatting and readability. – Hasya Feb 23 '17 at 11:44
  • Disclaimer: I work for Instamojo. The redirect URL could be any URL that you can control. After redirection you will be redirected to this URL with some payment data in query parameters, on this page you can call Javscript interface that can help you in closing the WebView and return back to your app. – Ashwini Chaudhary Feb 27 '17 at 07:41
  • Unfortunately I am not aware of any open-source or dummy projects that does something similar, but I hope you got the idea. – Ashwini Chaudhary Feb 27 '17 at 10:48
  • ay one can u help me out for instamojo integration including wallet,bank,credit and debitcard and also upi payment in ios swift 3.0 – ronak patel Oct 03 '17 at 03:30
  • @AsmaGodil : did you add instamojo successfully in objective c project? – Dhanunjay Kumar Nov 14 '17 at 11:37

1 Answers1

2

In order to integrate Instamojo with ios app,only possible way is webview. But for Opening webview first we have to send the data like amount for payment and information of payment.Redirect url is used to redirect to the page after the successful transaction.I have given one of the website Url as redirect url and from delegate method of webview if i get same url i closed down the webview as an indication to successful payment.one of the parameter send_email is true is to send email to notify.This key value pair is documented as per instamojo guidance.Api key And authentication token are credentials u get when creates account in instamojo that is to be passed in header field to validate credential.In response we get long url and on that url the webview should be opened up

On button Click Call the below Function

-(void)func_proceedCheckout
{
    NSError *error;
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
      NSString *post = [NSString stringWithFormat:@"amount=10&purpose=dummy&redirect_url=http://url to be redirected&buyer_name=Aashi&phone=123456789&email=demo@gmail.com&send_email=true&Name=Aashi"];
      NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];


    NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"https://www.instamojo.com/api/1.1/payment-requests/"]];//Url to be called 
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request setHTTPMethod:@"POST"];

    [request setHTTPBody:postData];

    [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"0" forHTTPHeaderField:@"Content-Length"];
    [request addValue:@"123456789" forHTTPHeaderField:@"X-Api-Key"];//Get from Instamojo Account
    [request addValue:@"123456789" forHTTPHeaderField:@"X-Auth-Token"];//Get from Instamojo Account

    if (!error) {

        NSURLSessionDataTask *downloadTask = [session dataTaskWithRequest:request  completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            if (!error) {
                NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
                if (httpResp.statusCode == 201) {
                    NSLog(@"%@",httpResp);

                    NSDictionary* json = [NSJSONSerialization
                                          JSONObjectWithData:data
                                          options:kNilOptions
                                          error:&error];
                     NSLog(@"%@",json);
            NSDictionary * dic =  [json objectForKey:@"payment_request"];
                     NSLog(@"%@",dic);
                    NSString * longurl = dic[@"longurl"];
                    NSURL *url = [NSURL URLWithString:longurl];


                    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
                        if (success) {
                            NSLog(@"Opened url");
                        }
                    }];



                }
            }

        }];
        [downloadTask resume];
    }
}

Long Url we get And the payment options can be handled by webview.longurl is a url on which webview is loaded

Aashi
  • 170
  • 2
  • 14