ios - instamojo 支付网关与 ios Objective C 集成

标签 ios objective-c instamojo

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

最佳答案

为了将 Instamojo 与 ios 应用程序集成,唯一可能的方法是 webview。但是为了首先打开 webview,我们必须发送付款金额和付款信息等数据。重定向 url 用于在交易成功后重定向到页面。我已经给出了网站 Url 之一作为重定向 url 并从委托(delegate)方法webview 如果我得到相同的 url,我会关闭 webview 作为成功付款的指示。send_email 参数之一为 true 是发送电子邮件以通知。此键值对按照 instamojo 指南进行记录。Api key 和身份验证 token 是凭据在 instamojo 中创建帐户时,您会得到该帐户将在 header 字段中传递以验证凭据。作为响应,我们会得到很长的 url,并且应该在该 url 上打开 Web View

在按钮上单击调用下面的函数

-(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&<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b2e262a2227762f2e26240b2c262a222765282426" rel="noreferrer noopener nofollow">[email protected]</a>&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];
    }
}

我们得到长网址并且支付选项可以由webview处理。longurl是加载webview的url

关于ios - instamojo 支付网关与 ios Objective C 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42413625/

相关文章:

ios - webview 加载 pdf 在 ios5 中损坏

ios - 如何检测 iOS View Controller 的当前方向?

objective-c - 将错误分配给错误指针时的潜在空引用

php - 如何使用来自支付网关的重定向链接更新 mysql 数据库?

ios - SKLabelNode 创建黑色矩形

ios - 如何测试toolBar中的item是否为FlexibleSpace item?

objective-c - UISplitViewController 以编程方式没有 nib/xib

ios - 无法根据 UIPickerview 中第一个组件的值重新加载第二个组件

ios - 无法解析 json 错误 instamojo

php - 使用 codeigniter 进行 instamojo 结帐