Hi,
I have developed an application which needs payment gateway. I have already worked on "Paypal". It was successful and now i need to integrate another payment gateway that is "ccavenue". Can anybody help me how to integrate that one?
Thanks.
I was searching for the SDK as they have mentioned here that IOS/Android/Windows SDKs are available. But did not find anything. Finally I drafted an email to CCAvenue tech. support team.
Then had call with them and this is what they said:
- We need to have actual merchant account to get the login credentials to download the SDKs.
- They do not provide any sandbox testing environment.
- The process is, they will verify the merchant account by merchant's website and other entered details.
- Once they are done with verification, they send an activation email to merchant's registered email address.
- Once merchant activates his account, he will get the login credentials to download the SDK.
- There are two types of subscription: Free and privileged.(Refer their website to know more)
- With SDK, if merchant has free plan then only INR and USD currencies are supported. If merchant wants to add support for any other currency then he will have to request CCAvenue for the same. CCAvenue team will verify with the concerned banks for it, if banks allow the transactions then new currency can be activated by paying Rs. 5000 for each.
- If merchant has privileged plan, then along with INR, merchant can select any 4 currencies from the supported 27 currencies. If merchant wants more, then he can purchase currency by paying Rs. 5000 for each.
Since the CCAvenue shows server side options we need to connect to web view and load the ccavenue gateway which is compatable with iphone screens. Here in Our application we need to do small things as follows
First create the html file and parameters related to your ccavenue gateway
<html>
<body>
<form name='form2' method='post' action='UR URL HERE'>
<input type="text" name='Merchant_Id'><br>
<input type="text" name='Amount'><br>
<input type="text" name='Order_Id'><br>
<input type="text" name='Redirect_Url'><br>
<input type="text" name='Checksum'><br>
<input type="text" name='billing_cust_name'><br>
<input type="text" name='billing_cust_address'><br>
<input type="text" name='billing_cust_address'><br>
<input type="text" name='billing_cust_tel'><br>
<input type="text" name='billing_cust_email'><br>
<input type="text" name='delivery_cust_name'><br>
<input type="text" name='delivery_cust_address'><br>
<input type="text" name='delivery_cust_tel'><br>
<input type="text" name='delivery_cust_notes'><br>
<input type="text" name='Merchant_Param'><br>
</form>
</body>
After that load the web view on your screen
NSURL *url = [NSURL URLWithString: @"https://www.ccavenue.com/shopzone/cc_details.jsp"];
webView.delegate = self;
webView.scalesPageToFit = YES;
NSString *strUsername = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *body = [NSString stringWithFormat: @"Merchant_Id=%@&Amount=%@&Order_Id=%@&Redirect_Url=%@&Checksum=%@&billing_cust_name=%@&billing_cust_address=%@&billing_cust_country=%@&billing_cust_tel=%@&billing_cust_email=%@&delivery_cust_name=%@&delivery_cust_address=%@&delivery_cust_tel=%@&delivery_cust_notes=%@&Merchant_Param=%@",@"XXXXX",@"10",@"123456",@"http://us2guntur.com/us2guntur/CCAvenueredirecturl.jsp",@"1234567890",@"Test",@"Hyderabad",@"India",@"1357896437",@"Test1000",@"Guntur",@"234567896",@"",@""];
NSLog(@"%@",body);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[webView loadRequest: request];
CCAvenue Payment Gateway Integration in Swift 3
First check this link "https://www.ccavenue.com/inapp_payments.jsp" for integration, what CCAvenue provides.
Kindly follow the below steps for implementing the Payment Gateway on your Mobile Application by Non Seamless Method :
1. Kindly make sure that your Public/Outgoing IP has been whitlisted on CCAvenue's end.
2. Place GetRSA and ccavResponseHandler files on your server.
3. In your App, mention the path of GetRSA file kept on your server
4. Call GetRSA from your app which is kept on your server for fetching the RSA public key.
5. Using the fetched public key merchant will encrypt parameters(amount,currency). To encrypt the RSA key, do following steps (From Step1 to Step8).
Step1: You have to download CCAvenue SDK from CCAvenue website and to download you must have to login using merchant account credential.
Step2: After login, to download SDK go to Resources->Mobile Integration Kit. See following screen shot.
Step3: To download, click on Download Integration Kits as shown in following screen shot. Before downloading choose Seamless or Non-Seamless. (Check details about this in document provided by CCAvenue)
Seamless: If a merchant is configured as seamless, then all the billing/shipping details including the payment options are accepted on the merchant page.
Non-Seamless: If a merchant is configured as non-seamless, then the Billing/Shipping details including the payment options are accepted on the CCAvenue's mobile page.
Step4: After downloading SDK kit, you have to copy folder "OpenSSL" to your project or else you can install "openssl" using pods also.
Step5: You will find 2 folders include and lib under Openssl/openssl-1.0.1i-iOS folder. Also under Build Settings of project go for Search Paths->Library, Search Paths, remove what is provided Users/test/desktop/.... and drag & drop include/ and lib/ this two folder. Also you have to do same thing for Paths->User Header Search Paths.
Stop6: Copy this two files (Files available in you downloaded SDK`s) to you project "CCTOOL & BASE64.
Step7: Using bridging header import "CCTool.h".
Step8: Finally encrypt your RSA key using the method which is present in "CCTool" file.
6. After encrypting the parameters you will post the encrypted value along with the other billing shipping details(if any) to the CCAvenue server via a browser(embedded webview) post. (If you didn`t able to convert all code from objective-c to swift, use objective-c file CCWEBVIEWCONTROLER)
7. The user will be redirected to the CCAvenue's billing shipping page where he will fill in the required details including the payment option.
8. After filling the required details he will be redirected to the bank page wherein he will authorize himself.
9. After authorization he will be redirected to CCAvenue and a response i.e. Success or failure will be sent to the merchant page which was configured as return url during registration.
10. You should then decrypt the response, which can then be parsed to get transaction status.
Note :
Access code and order ID should be the same as passed during the RSA call.
Order ID should always be unique
The transaction should hit the CCAvenue server within 60 seconds after receiving the RSA key.
Working key posted in ccavResponseHandler file should be corresponding to the Accesscode being posted to CCAvenue.
CCAvenue's integration page shows only server side options.
So, you will have to implement this yourself. You can integrate CCAvenue's payment gateway on your server and open the payment page in a web view on the device. Since the server side implementation is in your control, you can send payment confirmation details via cookies the ways its done in OAuth.
I have followed all the steps of Sagar Sukode and integrated CCAvenue SUCCESSFULLY.
If anyone need CCWEBVIEWCONTROLER in swift 2.3 :-
In ViewDidLoad :
let rsaKey = getRsaKeyForCCAvenue()
//Encrypting Card Details
let myRequestString = "amount=\(AMOUNT)¤cy=\(CURRENCY)"
let ccTool = CCTool()
var encVal = ccTool .encryptRSA(myRequestString, key: rsaKey)
let charset = NSCharacterSet(charactersInString: "!*'();:@&=+$,/?%#[]").invertedSet
encVal = encVal.stringByAddingPercentEncodingWithAllowedCharacters(charset)
//Preparing for a webview call
let urlAsString = TRANS_URL
let encryptedStr = "\(KEY_MERCHANT_ID)=\(MERCHANT_ID)&\(KEY_ORDER_ID)=\(ORDER_ID)&\(KEY_REDIRECT_URL)=\(REDIRECT_URL)&\(KEY_CANCEL_URL)=\(CANCEL_URL)&\(KEY_ENC_VAL)=\(encVal)&\(KEY_CC_ACCESS_CODE)=\(CC_ACCESS_CODE)&\(KEY_BILLING_NAME)=""&\(KEY_BILLING_ADDRESS)=""&\(KEY_BILLING_ZIP)=""&\(KEY_BILLING_CITY)=""&\(KEY_BILLING_STATE)=""&\(KEY_BILLING_COUNTRY)=""&\(KEY_BILLING_TEL)=""&\(KEY_BILLING_EMAIL)="""
let myRequestData = encryptedStr.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let request = NSMutableURLRequest(URL: NSURL(string: urlAsString)!)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request.setValue("https://secure.ccavenue.com/", forHTTPHeaderField: "Referer")
request.HTTPMethod = "POST"
request.HTTPBody = myRequestData
ccWebView .loadRequest(request)
Method To get rsaKey :
func getRsaKeyForCCAvenue() -> String {
//Getting RSA Key
let rsaKeyDataStr = "\(KEY_CC_ACCESS_CODE)=\(CC_ACCESS_CODE)&\(KEY_ORDER_ID)=\(ORDER_ID)"
let requestData = rsaKeyDataStr.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let rsaRequest = NSMutableURLRequest(URL: NSURL(string: RSA_KEY_URL)!)
rsaRequest .setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
rsaRequest.HTTPMethod = "POST"
rsaRequest.HTTPBody = requestData
let rsaKeyData: NSData? = try? NSURLConnection.sendSynchronousRequest(rsaRequest, returningResponse: nil)
var rsaKey = NSString(data: rsaKeyData!, encoding: NSASCIIStringEncoding)
let strNewRSA = rsaKey as! String
let range: Range<String.Index> = strNewRSA.rangeOfString("<")!
let index: Int = strNewRSA.startIndex.distanceTo(range.startIndex)
rsaKey = strNewRSA.substringToIndex(range.startIndex)
rsaKey = rsaKey?.stringByTrimmingCharactersInSet(NSCharacterSet.newlineCharacterSet())
rsaKey = "-----BEGIN PUBLIC KEY-----\n\(rsaKey!)\n-----END PUBLIC KEY-----\n"
return rsaKey as! String
}
Web View Delegate method to read the response :
func webViewDidFinishLoad(webView: UIWebView) {
let webString = webView.request?.URL?.absoluteString
if (webString! as NSString).containsString("PaymentCCAvenue/ReturnAPI") {
let html = webView .stringByEvaluatingJavaScriptFromString("document.documentElement.outerHTML")
if (html! as NSString).containsString("Success") {
}
else if (html! as NSString).containsString("Failure") {
}
else {
}
}
}
Just check for the response strings from the back end developers to add conditions in webViewDidFinishLoad.
For anyone who needs an answer for Swift 3.2 here is the code. Took me a while to convert to it. But here you go. Before that let me explain in case things are still unclear.
(1) you place your GetRSA file on the server and then copy and paste that link in your app as "rsaKeyUrl".
(2) The "getRsaKeyForCCAvenue()" function makes a call to that file placed on the server, the IP of which has to be whitelisted beforehand.
(3) The "getRSA" file makes a request to CCavenue on the link that is already in it.(This is important as CCAvenue only accepts requests from whitelisted IP's and this enables all the requests to be routed from just one IP.
(4) CCAvenue checks the details and processes the request and sends the response and redirects to the payment page if everything checks.
(5) The redirection URL shall be the link of the "ccavResponseHandler" file which has your access code and translates the response.
THE CODE IN SWIFT 3.2
1) Get RSA Key
func getRsaKeyForCCAvenue() -> String {
//Getting RSA Key
let rsaKeyDataStr = "access_code=\(accessCode)&order_id=\(orderId)"
let requestData = rsaKeyDataStr.data(using: String.Encoding.utf8, allowLossyConversion: false)
var request = URLRequest(url: URL(string: rsaKeyUrl)!)
let rsaRequest = NSMutableURLRequest(url: URL(string: rsaKeyUrl)!)
rsaRequest .setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
rsaRequest.httpMethod = "POST"
rsaRequest.httpBody = requestData
let rsaKeyData: NSData? = try? NSURLConnection.sendSynchronousRequest(rsaRequest as URLRequest, returning: nil) as NSData
var rsaKey = NSString(data: rsaKeyData! as Data, encoding: String.Encoding.ascii.rawValue)
rsaKey = rsaKey?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) as NSString?
// rsaKey = rsaKey?.trimmingCharacters(in: NSCharacterSet.newlines) as? NSString
rsaKey = "-----BEGIN PUBLIC KEY-----\n\(rsaKey!)\n-----END PUBLIC KEY-----\n" as NSString
print(rsaKey)
return rsaKey! as String
}
2) Code after super.viewDidLoad()
let rsaKey = getRsaKeyForCCAvenue()
//Encrypting Card Details
let myRequestString = "amount=\(VQ_MOUNT)¤cy=\(currency)"
let ccTool = CCTool()
var encVal :NSString = ccTool.encryptRSA(myRequestString, key: (rsaKey as NSString) as String!) as NSString
let charset : String = "!*'();:@&=+$,/?%#[]"
encVal = CFURLCreateStringByAddingPercentEscapes(nil, encVal as CFString, nil, (charset as CFString), CFStringBuiltInEncodings.UTF8.rawValue) as String as NSString
//Preparing for a webview call
let urlAsString = TRANS_URL
var encryptedStr = "merchant_id=\(merchantId)&order_id=\(orderId)&redirect_url=\(redirectUrl)&cancel_url=\(cancelUrl)&enc_val=\(encVal)&access_code=\(accessCode)"
let myRequestData = NSData.init(bytes: encryptedStr.cString(using: .utf8), length: encryptedStr.characters.count) as Data
let request = NSMutableURLRequest(url: URL(string: urlAsString)!)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request.setValue(TRANS_URL, forHTTPHeaderField: "Referer")
request.httpMethod = "POST"
request.httpBody = myRequestData
viewWeb.loadRequest(request as URLRequest)
3) Finally the webViewDidFinishLoad() implementation
func webViewDidFinishLoad(_ webView: UIWebView) {
let webString = webView.request?.url?.absoluteString
if ((webString as NSString?)?.range(of: "/ccavResponseHandler.jsp"))?.location != NSNotFound {
let html: String? = webView.stringByEvaluatingJavaScript(from: "document.documentElement.outerHTML")
var transStatus = "Not Known"
if (((html as NSString?)?.range(of: "Aborted"))?.location != NSNotFound) || (((html as NSString?)?.range(of: "Cancel"))?.location != NSNotFound) {
transStatus = "Transaction Cancelled"
}
else if (((html as NSString?)?.range(of: "Success"))?.location != NSNotFound) {
transStatus = "Transaction Successful"
}
else if (((html as NSString?)?.range(of: "Fail"))?.location != NSNotFound) {
transStatus = "Transaction Failed"
}
var controller = storyboard?.instantiateViewController(withIdentifier: "CCResultViewController") as? CCResultViewController
controller?.transStatus = transStatus
controller?.modalTransitionStyle = .crossDissolve
present(controller ?? UIViewController(), animated: true)
}else {
print("Something went wrong...")
}
}
来源:https://stackoverflow.com/questions/23777006/ccavenue-gateway-integration-kit-for-ios-application