Search code examples
iosxcodeccavenue

How to pass data to webview in CCAvenue integration in ios?


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?


Solution

  • 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=%@&currency=%@",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];