2

如何在 iOS Objective C 中集成 instamojo 支付网关?可能没有直接的方法。那么通过WebView,如何在iOS中集成支付网关呢?已添加长 URL,但应该在重定向链接中放置什么以及发送标头和参数的键。

4

1 回答 1

2

为了将 Instamojo 与 ios 应用程序集成,唯一可能的方法是 webview。但是对于首先打开 webview,我们必须发送诸如支付金额和支付信息之类的数据。重定向 url 用于在成功交易后重定向到页面。我已将网站 Url 之一作为重定向 url 和来自委托方法webview 如果我得到相同的 url,我关闭 webview 作为成功付款的指示。参数 send_email 为 true 是发送电子邮件以通知。此键值对根据 instamojo 指南进行记录。Api 密钥和身份验证令牌是凭据当您在 instamojo 中创建帐户时,该帐户将在标头字段中传递以验证凭据。作为响应,我们得到长 url,并且在该 url 上应该打开 webview

On button 点击​​调用下面的函数

-(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 并且付款选项可以由 webview 处理。longurl 是加载 webview 的 url

于 2017-05-25T13:06:16.203 回答