I'm new to CCAvenue integration and i want to pass all customer data to webview but i dont know how to pass it. can anyone help me to solve?
Try below code in viewDidLoad of CCAvenue webview Controller, here you can also pass billing address if you needed in your app.
//Getting RSA Key
NSString *rsaKeyDataStr = [NSString stringWithFormat:#"access_code=%#&order_id=%#",accessCode,orderId];
NSData *requestData = [NSData dataWithBytes: [rsaKeyDataStr UTF8String] length: [rsaKeyDataStr length]];
NSMutableURLRequest *rsaRequest = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: rsaKeyUrl]];
[rsaRequest setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
[rsaRequest setHTTPMethod: #"POST"];
[rsaRequest setHTTPBody: requestData];
NSData *rsaKeyData = [NSURLConnection sendSynchronousRequest: rsaRequest returningResponse: nil error: nil];
NSString *rsaKey = [[NSString alloc] initWithData:rsaKeyData encoding:NSASCIIStringEncoding];
rsaKey = [rsaKey stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
rsaKey = [NSString stringWithFormat:#"-----BEGIN PUBLIC KEY-----\n%#\n-----END PUBLIC KEY-----\n",rsaKey];
NSLog(#"%#",rsaKey);
//Encrypting Card Details
NSString *myRequestString = [NSString stringWithFormat:#"amount=%#¤cy=%#",amount,currency];
CCTool *ccTool = [[CCTool alloc] init];
NSString *encVal = [ccTool encryptRSA:myRequestString key:rsaKey];
encVal = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)encVal,
NULL,
(CFStringRef)#"!*'();:#&=+$,/?%#[]",
kCFStringEncodingUTF8 ));
//Preparing for a webview call
NSString *urlAsString = [NSString stringWithFormat:#"https://secure.ccavenue.com/transaction/initTrans"];
NSString *Name=[NSString stringWithFormat:#"%# %#",billing_Fname,billing_Lname];
NSString *encryptedStr = [NSString stringWithFormat:#"merchant_id=%#&order_id=%#&redirect_url=%#&cancel_url=%#&enc_val=%#&access_code=%#&billing_name=%#&billing_address=%#&billing_city=%#&billing_state=%#&billing_zip=%#&billing_country=India&billing_tel=%#&billing_email=%#&delivery_name=%#&delivery_address=%#&delivery_city=%#&delivery_state=%#&delivery_zip=%#&delivery_country=India&delivery_tel=%#",merchantId,orderId,redirectUrl,cancelUrl,encVal,accessCode,Name,billing_address,billing_city,billing_state,billing_zip,billing_tel,billing_email,Name,billing_address,billing_city,billing_state,billing_zip,billing_tel];
NSData *myRequestData = [NSData dataWithBytes: [encryptedStr UTF8String] length: [encryptedStr length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: urlAsString]];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"content-type"];
[request setValue:urlAsString forHTTPHeaderField:#"Referer"];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: myRequestData];
[_viewWeb loadRequest:request];
Related
NSString *phone = [NSString stringWithFormat:#"phone=%#",[paymentServerData valueForKey:#"phone"]];
NSString *key = [NSString stringWithFormat:#"key=%#",[paymentServerData valueForKey:#"key"]];
NSString *furl = [NSString stringWithFormat:#"furl=%#",[paymentServerData valueForKey:#"furl"]];
NSString *txnid = [NSString stringWithFormat:#"txnid=%#",[paymentServerData valueForKey:#"txnid"]];
NSString *productinfo =[NSString stringWithFormat:#"productinfo=%#",[paymentServerData valueForKey:#"txnid"]];
NSArray *arrayString = [[NSArray alloc] initWithObjects phone, key,furl,txnid,productinfoEncode,nil];
NSString *postString = [arrayString componentsJoinedByString:#"&"];
NSString *address = #"https://secure.payu.in/_payment";
NSURL *url = [NSURL URLWithString: address];
NSString *body = [NSString stringWithFormat: #"%#", postString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: body];
[_paymentWebView loadRequest: request];
i have 5 parameters to pass the body string but i want encode only one parameter how to encode one parameter and send the body method.
help me to encode this productionfo string.
// this line for encoding your data .
NSData *postData = [productinfo dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:#"URL"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:postData];
I am using two links.First link i created nsaaray for "id".This "id" i need to pass as parameter in nsurlconnection using POST method by second link.i tried lots but i stuck in while passing parameter "id".
nsaaray for id:
- (IBAction)button_drop:(id)sender {
NSString *parseURL =#"first_link";
NSString *encodeurl =[parseURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:encodeurl];
NSData *data = [NSData dataWithContentsOfURL:url];
if(data){
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options: kNilOptions error:&error];
arrMsg = [json valueForKeyPath:#"Branches.branch_name"];
arrmsg1 =[json valueForKeyPath:#"Branches.id"];
[_picker2 reloadAllComponents];
}
}
POST method using nsurlconnection:
NSString *Branchid=#"3";
NSURL *url = nil;
NSMutableURLRequest *request = nil;
if([method isEqualToString:#"GET"]){
NSString *getURL = [NSString stringWithFormat:#"%#?branch_id=%#\n", URL, Branchid];
url = [NSURL URLWithString: getURL];
request = [NSMutableURLRequest requestWithURL:url];
NSLog(#"%#",getURL);
}else{ // POST
NSString *parameter = [NSString stringWithFormat:#"branch_id=%#",Branchid];
NSData *parameterData = [parameter dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
url = [NSURL URLWithString: URL];
NSLog(#"%#", parameterData);
request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPBody:parameterData];
arr= [NSMutableString stringWithUTF8String:[parameterData bytes]];
}
[request setHTTPMethod:method];
[request addValue: #"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if( connection )
{
mutableData = [NSMutableData new];
}
Try to create a "POST" method like this:-
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
Branchid, #"branch_id", nil];
NSString *newRequest = [dict JSONRepresentation];
NSData *requestData = [newRequest dataUsingEncoding:NSUTF8StringEncoding];
//If you are not using SBJsonParser Library then try the following:
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *urlString = #"YOUR URL String";
NSURL *requestURL = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"%lu", (unsigned long) [requestData length]] forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:requestData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection) {
mutableData = [NSMutableData new];
}
Also, You can follow this link if you don't find out the answer working properly:-
Data in POST or GET methods
Send data in POST methods
I am trying to post some values to my web service which is working for android version nicely and for iOS it works for about 12 requests then it stops sending. What am i doing wrong?
I am sending about 1 per second.
-(void) PostDataToServer:(NSMutableArray*) value
{
NSString *xValue = [NSString stringWithFormat:#"%#", [value objectAtIndex:0]];
NSString *yValue = [NSString stringWithFormat:#"%#", [value objectAtIndex:1]];
NSString *jsonRequest = [NSString stringWithFormat:#"{\"person\":\"%#\",\"x\":\"%#\",\"y\":\"%#\",\"z\":\"%#\"}",#"1",xValue ,yValue ,#"0.0"];
NSLog(#"Request: %#", jsonRequest);
NSURL *url = [NSURL URLWithString:#"mywebserviceURL"];
request = [[NSMutableURLRequest alloc] initWithURL:url];
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"%d", [requestData length]] forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody: requestData];
NSData *urlData= connection= [NSURLConnection connectionWithRequest:request delegate:self];
NSLog(urlData);
I am trying to post data to WCF service from iPhone Application but somehow service doesn't seems to be call through the iPhone. I received a Status Code = 999.
NSString *urlString = #"http://192.168.1.192/MSservice/SecureRegistration";
NSURL *URL = [NSURL URLWithString:
[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *postData = [bodyData stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:#"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setValue:#"gzip" forHTTPHeaderField:#"Accept-Encoding"];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Current-Type"];
[request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
NSError *errorReturned = nil;
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
if (errorReturned)
{
NSLog(#"Error %#", errorReturned.localizedDescription);
}
else
{
NSLog(#"Data %#", data);
NSString *responseString=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(#"Response %#", responseString);
}
In calling apexrest webservice for uploading attachment to specific record by calling method. So for this I hardcoded Json.
-(void)uploadToSalesforce
{
NSData *imagedata = UIImageJPEGRepresentation(imagePreview.image, 1.0);
int datalength = [imagedata length];
NSString *filename = [NSString stringWithFormat:#"Supload_iPhone_%d.jpg",datalength];
NSString *req = [NSString stringWithFormat:#"{\n\"name\":\"%#\",\n\"Body\": \"%#\"\n,\"ParenId\":%#\"\n}",filename,imagedata,receivedrecordid];
const char *utfString = [req UTF8String];
NSData *postData = [NSData dataWithBytes:utfString length:strlen(utfString)];
NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
NSMutableURLRequest *requestUrl = [[NSMutableURLRequest alloc] init ];
[requestUrl setURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#/services/apexrest/Account/",receivedinstanceurl]]];
[requestUrl setHTTPMethod:#"POST"];
[requestUrl setValue:postLength forHTTPHeaderField:#"Content-length"];
[requestUrl setValue:[NSString stringWithFormat:#"Bearer %#",receivedaccesstoken] forHTTPHeaderField:#"Authorization"];
[requestUrl setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[requestUrl setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *reponseData = [NSURLConnection sendSynchronousRequest:requestUrl returningResponse:&response error:&err];
NSString *res = [[NSString alloc] initWithData:reponseData encoding:NSASCIIStringEncoding];
}
In response it says there is
[{"message":"Unexpected parameter encountered during deserialization: Name at [line:2, column:9]","errorCode":"JSON_PARSER_ERROR"}]
In console JSON seems correct but cannot parse parameter "Name".I think this is not by IOS code. Or is there some different format.
In the line
NSString *req = [NSString stringWithFormat:#"{\n\"name\":\"%#\",\n\"Body\": \"%#\"\n,\"ParenId\":%#\"\n}",filename,imagedata,receivedrecordid];
JSON is missing " character for ParentId key value. It should be:
NSString *req = [NSString stringWithFormat:#"{\n\"name\":\"%#\",\n\"Body\": \"%#\"\n,\"ParenId\":\"%#\"\n}",filename,imagedata,receivedrecordid];
Therefore Salesforce webservice deserialization was throwing exception.