I need to integrate PayUMoney payment gateway in my iOS application. They do not have an SDK for iOS. So I have to upload some web url in webview for payment. My parameters
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]];
I need to use the POST method with my test URL ( https://test.payu.in/_payment ) and you need to pass parameters. I have all the parameters with the key and value in the dictionary ("parameters"). So I tried the following code
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; }
But when I run this, he says: "The required tnxid parameter is missing." But I passed tnxid, which you can see in the parameter dictionary. If I pass everything correctly, the result will be a web page on which the user can select bank details, etc., which I have to upload in my web view.
Please help me find what I did wrong, or what I have to do to get the right result.