嗨, 我开发了一个需要支付网关的应用程序。我已经开始研究“Paypal”了。它是成功的,现在我需要整合另一个支付网关,即“ccavenue”。任何人都可以帮助我如何整合那个? 谢谢。
我正在搜索SDK,因为他们已经提到了IOS / Android / Windows SDK可用的here。但没有找到任何东西。最后,我给CCAvenue tech起草了一封电子邮件。支持团队。
然后打电话给他们,这就是他们所说的:
由于CCAvenue显示服务器端选项,我们需要连接到Web视图并加载可与iphone屏幕兼容的ccavenue网关。在我们的应用程序中,我们需要做如下的小事
首先创建与您的ccavenue网关相关的html文件和参数
<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>
之后加载屏幕上的Web视图
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];
首先查看此链接“https://www.ccavenue.com/inapp_payments.jsp”进行集成,CCAvenue提供的内容。
请按照以下步骤通过非无缝方法在您的移动应用程序上实施支付网关:
1.请确保您的公共/传出IP已在CCAvenue端列入白名单。
2.将GetRSA和ccavResponseHandler文件放在您的服务器上。
3.在您的应用程序中,提及服务器上保留的GetRSA文件的路径
4.从您的应用程序中调用GetRSA,该应用程序保留在您的服务器上以获取RSA公钥。
5.使用获取的公钥商家将加密参数(金额,货币)。要加密RSA密钥,请执行以下步骤(从步骤1到步骤8)。
步骤1:您必须从CCAvenue网站下载CCAvenue SDK并下载您必须使用商家帐户凭证登录。
第二步:登录后,下载SDK进入资源 - >移动集成套件。请参见以下屏幕截图。
步骤3:要下载,请单击下载屏幕截图中的下载集成套件。下载前选择无缝或非无缝。 (在CCAvenue提供的文件中查看有关此内容的详细信息)
无缝:如果商家配置为无缝,则在商家页面上接受包括付款选项在内的所有结算/运送详细信息。
非无缝:如果商家配置为非无缝,则会在CCAvenue的移动页面上接受包含付款选项的结算/送货详细信息。
Step4:下载SDK工具包后,你必须将文件夹“OpenSSL”复制到你的项目中,否则你也可以使用pod安装“openssl”。
步骤5:您将在Openssl / openssl-1.0.1i-iOS文件夹下找到2个文件夹include和lib。同样在项目的Build Settings下搜索路径 - >库,搜索路径,删除提供的内容Users / test / desktop / ....并拖放include /和lib /这两个文件夹。你也必须为Paths-> User Header Search Paths做同样的事情。
Stop6:将这两个文件(您下载的SDK中可用的文件)复制到项目“CCTOOL&BASE64”。
Step7:使用桥接头导入“CCTool.h”。
步骤8:最后使用“CCTool”文件中的方法加密您的RSA密钥。
6.加密参数后,您将通过浏览器(嵌入式webview)帖子将加密值以及其他计费运送详细信息(如果有)发布到CCAvenue服务器。 (如果你不能将所有代码从objective-c转换为swift,请使用objective-c文件CCWEBVIEWCONTROLER)
7.用户将被重定向到CCAvenue的账单发货页面,在那里他将填写所需的详细信息,包括付款选项。
8.填写完所需的详细信息后,他将被重定向到他将授权自己的银行页面。
9.授权后,他将被重定向到CCAvenue并且响应,即成功或失败将被发送到商家页面,该商家页面在注册期间被配置为返回URL。
10.然后,您应该解密响应,然后可以解析该响应以获取事务状态。
注意 :
CCAvenue's integration page仅显示服务器端选项。
所以,你必须自己实现这一点。您可以在服务器上集成CCAvenue的支付网关,并在设备的Web视图中打开支付页面。由于服务器端实施在您的控制范围内,您可以通过Cookie以OAuth中的方式发送付款确认详细信息。
我已经按照Sagar Sukode的所有步骤进行了整合并成功整合了CCAvenue。
如果有人在swift 2.3中需要CCWEBVIEWCONTROLER: -
在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)
方法获取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方法读取响应:
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 {
}
}
}
只需检查后端开发人员的响应字符串,即可在webViewDidFinishLoad中添加条件。
对于需要Swift 3.2答案的人来说,这里是代码。花了一段时间才转换成它。但是你走吧。在此之前让我解释一下事情仍然不清楚。
(1)将GetRSA文件放在服务器上,然后将该链接复制并粘贴到应用程序中作为“rsaKeyUrl”。
(2)“getRsaKeyForCCAvenue()”函数调用放在服务器上的文件,其IP必须事先列入白名单。
(3)“getRSA”文件向已经在其中的链接向CCavenue发出请求。(这很重要,因为CCAvenue只接受来自白名单IP的请求,这使得所有请求都可以从一个IP路由。
(4)CCAvenue检查详细信息并处理请求并发送响应,并在所有检查都重定向到付款页面。
(5)重定向URL应为“ccavResponseHandler”文件的链接,该文件具有您的访问代码并转换响应。
SWIFT中的代码3.2
1)获取RSA密钥
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)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)最后是webViewDidFinishLoad()实现
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...")
}
}