PayUMoney 支付网关问题

Posted

技术标签:

【中文标题】PayUMoney 支付网关问题【英文标题】:PayUMoney payment gateway issue 【发布时间】:2015-03-10 00:06:28 【问题描述】:

我必须在我的 ios 应用程序中集成 PayUMoney 支付网关。他们没有适用于 iOS 的 SDK。所以我必须在 webview 中加载一些 web URL 以进行付款。我的参数是

int i = arc4random() % 9999999999;
NSString *strHash = [self createSHA512:[NSString stringWithFormat:@"%d%@",i,[NSDate date]]];// Generatehash512(rnd.ToString() + DateTime.Now);
NSString *txnid1 = [strHash substringToIndex:20];
NSLog(@"tnx1 id %@",txnid1);
NSString *key = @"JBZaLc";
NSString *amount = @"1000";
NSString *productInfo = @"Nice product";
NSString *firstname = @"Mani";
NSString *email = @"mani.ingenius@gmail.com";
NSString *phone = @"1234566";
NSString *surl = @"www.google.com";
NSString *furl = @"www.google.com";
NSString *serviceprovider = @"payu_paisa";
NSString *action = @"https://test.payu.in/_payment";
NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|udf1|udf2|udf3|udf4|udf5||||||salt",key,txnid1,amount,productInfo,firstname,email];
NSString *hash = [self createSHA512:hashValue];
NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:txnid1,key,amount,productInfo,firstname,email,phone,surl,furl,hash,serviceprovider,action, nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",@"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash",@"service_provider",@"action", nil]];

我必须对我的测试 URL (https://test.payu.in/_payment) 使用 POST 方法并且需要传递参数。我在字典(“参数”)中有所有带有键和值的参数。所以我尝试了以下代码

 NSData *dataValue = [self getPropertiesAsData:parameters];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://test.payu.in/_payment"]];
    // Create a mutable copy of the immutable request and add more headers
    NSMutableURLRequest *mutableRequest = [request mutableCopy];
    [mutableRequest setHTTPMethod: @"POST"];
    [mutableRequest setHTTPBody: dataValue];
    request = [mutableRequest copy];
    [_webviewSample loadRequest:request];


-(NSData *)getPropertiesAsData :(NSDictionary *)dict
    NSMutableData *body = [NSMutableData postData];
    [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) 
            [body addValue:[obj stringByReplacingOccurrencesOfString:@" " withString:@"%20"] forKey:key];
            ];
    return body;


-(NSString *)createSHA512:(NSString *)string

    const char *cstr = [string cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *data = [NSData dataWithBytes:cstr length:string.length];
    uint8_t digest[CC_SHA512_DIGEST_LENGTH];
    CC_SHA512(data.bytes, data.length, digest);
    NSMutableString* output = [NSMutableString  stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_SHA512_DIGEST_LENGTH; i++)
        [output appendFormat:@"%02x", digest[i]];
    return output;

但是当我运行它时,它显示“缺少强制参数 tnxid”。但是我已经传递了您可以在参数字典中看到的 tnxid。如果我正确传递了所有内容,那么结果将是用户可以选择银行详细信息等的网页,我必须将其加载到我的网络视图中。

请帮助我找出我做错了什么或应该做些什么来获得正确的结果。

【问题讨论】:

您好,我在使用我的商户密钥和盐密钥通过测试 url 发送数据时出错...抱歉,出现了一些问题。如何解决?我确实首先在 SHA256 中转换了 tnx1,然后根据需要将 postData 转换为 Base64 编码......它在 android 版本中工作正常吗?有什么解决办法吗? 请查看我的更新答案 你好 Mani,我已经检查过了,它再次给了我同样的错误..发生错误,对不起一些问题......即使我已经更改了我的 Merchant_key 和 SALT。你知道如何使用它吗?如果可能的话,请帮助您将示例代码发送给我 dsrawat4u@gmail.com 吗? 感谢它现在可以正常工作 (y) 请移除您的测试盐密钥,以免有人使用它 您是否使用 Payumoney 的真实凭证进行测试?您在 Payumoney 有账户吗? 【参考方案1】:

快速版本

1) 导入桥接头

** 导入 CommonCrypto/CommonDigest.h **

2) 之后

func sha512Hex( string: String) -> String 
    var digest = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH))
    if let data = string.data(using: String.Encoding.utf8) 
        let value =  data as NSData
        CC_SHA512(value.bytes, CC_LONG(data.count), &digest)

    
    var digestHex = ""
    for index in 0..<Int(CC_SHA512_DIGEST_LENGTH) 
        digestHex += String(format: "%02x", digest[index])
    

    return digestHex

3) 安装 pod PlugNPlay

4) 按照步骤提供 PlugNPlay

【讨论】:

【参考方案2】:

我向 PayUMoney 技术团队发送了邮件并得到了答案,为什么我收到错误“抱歉,发生了一些问题。”

得到了技术团队的快速回复:

Recently, we have done some modifications in test environment due to which test key-JBZaLc and salt-GQs7yium will not work anymore.

In order to test the gateway using a test key and salt, kindly follow these steps:
1 - Go on https://test.payumoney.com
2 - Sign up as a merchant - use any of your valid email ids - kindly do not use a random email id.
3 - Complete the "Business Details"  - you may use PAN no. ABCDE1234F and DOB - 01/04/1990
4 - Complete "Bank Account Details" (You may use IFSC- ALLA0212632)
5 - Go to below mentioned location to get the Test Merchant Id :     
 Seller Dashboard -> Settings -> My account -> Profile Settings

Once you provide your test merchant id, we will approve it so that you can find your test key and salt at :
Seller Dashboard -> Settings -> My account -> Merchant Key - Salt

下载Github Repository

【讨论】:

嗨@Suraj Mirajkar 我使用了上面的代码,但我返回错误 404 页面未找到并使用此链接test.payu.in/_payment 请帮助。【参考方案3】:

最后我解决了关于 PayU India 的问题(not payU,payU 和 payUindia 略有不同)集成(上面的代码是为 payU Money 提供很多帮助) 下载github Repo here

你只需要去掉一个额外的参数service_provider,它的值为payu_paisa。

int i = arc4random() % 9999999999;
    NSString *strHash = [self createSHA512:[NSString stringWithFormat:@"%d%@",i,[NSDate date]]];// Generatehash512(rnd.ToString() + DateTime.Now);
    NSString *txnid1 = [strHash substringToIndex:20];
    NSLog(@"tnx1 id %@",txnid1);
    NSString *key = @"YOURKEY";
    NSString *salt = @"YOURSALTKEY";

    NSString *amount = @"100";
    NSString *productInfo = @"Niceproduct";
    NSString *firstname = @"Deepak";
    NSString *email = @"iphonemaclover@gmail.com";
    NSString *phone = @"9212138007";
    NSString *surl = @"www.google.com";
    NSString *furl = @"www.google.com";


    NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|||||||||||%@",key,txnid1,amount,productInfo,firstname,email,salt];
    NSString *hash = [self createSHA512:hashValue];
    NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:txnid1,key,amount,productInfo,firstname,email,phone,surl,furl,hash
                                                                    , nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",@"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash", nil]];
   __block NSString *post = @"";
    [parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) 
        if ([post isEqualToString:@""]) 
            post = [NSString stringWithFormat:@"%@=%@",key,obj];
        else
            post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
        

    ];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://test.payu.in/_payment"]]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:postData];

    [_webviewSample loadRequest:request];

编辑:如何处理 URL 支付是否成功

-(void)webViewDidFinishLoad:(UIWebView *)webView
        if (web_view_PayU.isLoading)
        return;
    NSURL *requestURL = [[web_view_PayU request] URL];

    NSLog(@"requestURL=%@",requestURL);

    NSString *getStringFromUrl=[NSString stringWithFormat:@"%@",requestURL];

    if ([getStringFromUrl isEqualToString:@"https://test.payu.in/yoursucessurladdedhere "]||[getStringFromUrl isEqualToString:@"https://secure.payu.in/yoursucessurladdedhere "])
    
       //SUCCESS ALERT
       //jump to place order API

    
   else if ([getStringFromUrl isEqualToString:@"https://test.payu.in/yourfailureurladdedhere "]||[getStringFromUrl isEqualToString:@"https://secure.payu.in/yourfailureurladdedhere"])
    
        // FAIL ALERT
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Sorry!" message:@"Your Order Not Successfull!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        alert.tag=2222;

        [alert show];
    


Android 集成 Pay U check link--

【讨论】:

谁能告诉我如何知道我的付款是成功还是失败?上面的代码对我来说工作正常并显示支付屏幕,但是支付结果呢?请帮助我,因为我很想得到答案。我被困在这一点上。 你好pratik,请查看github repo,它包含处理失败支付成功的代码,快速点击,只需在webview委托方法中检查成功和失败的url加载,并根据它添加你的条件...希望它会有所帮助 非常感谢您对 iphonemaclover 的回复。我已经按照你的例子实现了。但我的主要观点是我如何知道在 -(void)webViewDidFinishLoad:(UIWebView *)webView 方法中支付成功与否?我已经用校验和和一切使用 webview 提出了请求,但这就是我坚持的一点。 现在检查我的编辑答案,类似地将加载 url 与 url 比较你得到它的东西 url/urlfail 或 url/urlsucess 只是检查 url 字符串是否包含它...... 非常感谢 iphonemaclover !!!让我试一试,如果有任何疑问,我会回来..【参考方案4】:

我成功找到了答案。下面列出了我的工作代码

int i = arc4random() % 9999999999;
    NSString *strHash = [self createSHA512:[NSString stringWithFormat:@"%d%@",i,[NSDate date]]];// Generatehash512(rnd.ToString() + DateTime.Now);
    NSString *txnid1 = [strHash substringToIndex:20];
    NSLog(@"tnx1 id %@",txnid1);
    NSString *key = @"JBZaLc";
    NSString *amount = @"1000";
    NSString *productInfo = @"Nice product";
    NSString *firstname = @"Mani";
    NSString *email = @"mani.ingenius@gmail.com";
    NSString *phone = @"1234566";
    NSString *surl = @"www.google.com";
    NSString *furl = @"www.google.com";
    NSString *serviceprovider = @"payu_paisa";


    NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|||||||||||GQs7yium",key,txnid1,amount,productInfo,firstname,email];
    NSString *hash = [self createSHA512:hashValue];
    NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:txnid1,key,amount,productInfo,firstname,email,phone,surl,furl,hash,serviceprovider
                                                                    , nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",@"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash",@"service_provider", nil]];
   __block NSString *post = @"";
    [parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) 
        if ([post isEqualToString:@""]) 
            post = [NSString stringWithFormat:@"%@=%@",key,obj];
        else
            post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
        

    ];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://test.payu.in/_payment"]]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:postData];

    [_webviewSample loadRequest:request];

然后是要使用的函数

-(NSString *)createSHA512:(NSString *)string

    const char *cstr = [string cStringUsingEncoding:NSUTF8StringEncoding];
    NSData *data = [NSData dataWithBytes:cstr length:string.length];
    uint8_t digest[CC_SHA512_DIGEST_LENGTH];
    CC_SHA512(data.bytes, (CC_LONG)data.length, digest);
    NSMutableString* output = [NSMutableString  stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_SHA512_DIGEST_LENGTH; i++)
        [output appendFormat:@"%02x", digest[i]];
    return output;

【讨论】:

你好,有什么想法吗?出现错误抱歉有些问题发生了 您好,您正在使用 payUmonkey SALT 和商家密钥。你用过payUmoney吗?因为我正在与 PayUindia 合作,但它不能通过他们提供的密钥工作。欢迎提供任何帮助 hello @iphonemaclover ,我使用的是相同的代码,在某些情况下它可以正常工作。意思是如果我使用这个 key = "gtKFFx" 和 salt = "eCwWELxi' ,它将不起作用。请告诉我这是什么原因。 @iphonemaclover , payUindia 和 payUmoney 不一样? 可以在这里找到测试凭证。 edugcet.in/franchisee_download/…

以上是关于PayUMoney 支付网关问题的主要内容,如果未能解决你的问题,请参考以下文章

如何将 PayUMoney BOLT 与 MVC4 c# 集成?

PHP 电子商务 API - 付款流程

如何在 Android 中集成 PayU 货币网关? [关闭]

使用 post 参数重定向到付款 URL

如何获取payumney支付的交易状态

Paypal 没有显示在我的 magento 1.9.2.3 商店中