xcode ios应用程序的CCAvenue网关集成工具包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23777006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CCAvenue Gateway Integration kit for ios Application
提问by Madhu
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.
嗨,
我开发了一个需要支付网关的应用程序。我已经在“Paypal”上工作了。它成功了,现在我需要集成另一个“ccavenue”支付网关。有人可以帮我如何整合那个吗?
谢谢。
采纳答案by Madhu
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
由于 CCAvenue 显示服务器端选项,我们需要连接到 Web 视图并加载与 iphone 屏幕兼容的 ccavenue 网关。在我们的应用程序中,我们需要做如下的小事情
First create the html file and parameters related to your ccavenue gateway
首先创建你的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>
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];
回答by Bhumi Goklani
I was searching for the SDK as they have mentioned herethat IOS/Android/Windows SDKs are available. But did not find anything. Finally I drafted an email to CCAvenue tech. support team.
我正在寻找 SDK,因为他们在这里提到 IOS/Android/Windows SDK 可用。但没有发现任何东西。最后,我起草了一封电子邮件给 CCAvenue tech。支持团队。
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.
- 我们需要有实际的商家帐户才能获取登录凭据以下载 SDK。
- 他们不提供任何沙箱测试环境。
- 过程是,他们将通过商家的网站和其他输入的详细信息来验证商家帐户。
- 完成验证后,他们会向商家的注册电子邮件地址发送一封激活电子邮件。
- 一旦商家激活他的帐户,他将获得登录凭据以下载 SDK。
- 订阅有两种类型:免费和特权。(请参阅他们的网站了解更多信息)
- 使用 SDK,如果商家有免费计划,则仅支持印度卢比和美元货币。如果商家想要增加对任何其他货币的支持,那么他将不得不请求 CCAvenue 这样做。CCAvenue 团队将与相关银行核实,如果银行允许交易,则可以通过支付卢比来激活新货币。每个5000。
- 如果商户有特权计划,那么除了INR,商户可以从支持的27种货币中选择任意4种货币。如果商家想要更多,那么他可以通过支付卢比来购买货币。每个5000。
回答by Sagar Sukode
CCAvenue Payment Gateway Integration in Swift 3
Swift 3 中的 CCAvenue 支付网关集成
First check this link "https://www.ccavenue.com/inapp_payments.jsp" for integration, what CCAvenue provides.
首先检查此链接“ https://www.ccavenue.com/inapp_payments.jsp”以进行集成,CCAvenue 提供了什么。
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.
1.请确保您的公共/传出 IP 已在 CCAvenue 端列入白名单。
2.Place GetRSA and ccavResponseHandler files on your server.
2.将 GetRSA 和 ccavResponseHandler 文件放在您的服务器上。
3.In your App, mention the path of GetRSA file kept on your server
3.在您的应用程序中,提及您的服务器上保存的GetRSA文件的路径
4.Call GetRSA from your app which is kept on your server for fetching the RSA public key.
4.从您的应用程序中调用 GetRSA,该应用程序保存在您的服务器上以获取 RSA 公钥。
5.Using the fetched public key merchant will encrypt parameters(amount,currency). To encrypt the RSA key, do following steps (From Step1 to Step8).
5.商家使用获取的公钥对参数(金额、货币)进行加密。要加密 RSA 密钥,请执行以下步骤(从 Step1 到 Step8)。
Step1:You have to download CCAvenue SDK from CCAvenue website and to download you must have to login using merchant account credential.
第一步:您必须从 CCAvenue 网站下载 CCAvenue SDK,下载您必须使用商户帐户凭据登录。
Step2:After login, to download SDK go to Resources->Mobile Integration Kit. See following screen shot.
Step2:登录后,前往资源->移动集成工具包下载SDK。请参阅以下屏幕截图。
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)
步骤 3:要下载,请单击下载集成工具包,如下面的屏幕截图所示。下载前选择无缝或非无缝。(在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.
非无缝:如果商家配置为非无缝,则 CCAvenue 的移动页面上接受包括付款选项在内的账单/运输详细信息。
Step4:After downloading SDK kit, you have to copy folder "OpenSSL" to your project or else you can install "openssl" using pods also.
步骤4:下载SDK包后,您必须将文件夹“OpenSSL”复制到您的项目中,否则您也可以使用pods安装“openssl”。
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.
Step5:你会在Openssl/openssl-1.0.1i-iOS文件夹下找到2个文件夹include和lib。同样在项目的 Build Settings 下,转到 Search Paths->Library, Search Paths,删除提供的 Users/test/desktop/.... 并拖放 include/ 和 lib/ 这两个文件夹。您还必须对路径-> 用户标题搜索路径执行相同的操作。
Stop6:Copy this two files (Files available in you downloaded SDK`s) to you project "CCTOOL & BASE64.
停止 6:将这两个文件(在您下载的 SDK 中可用的文件)复制到您的项目“CCTOOL & BASE64.
Step7:Using bridging header import "CCTool.h".
Step7:使用桥接头导入“CCTool.h”。
Step8:Finally encrypt your RSA key using the method which is present in "CCTool" file.
步骤 8:最后使用“CCTool”文件中的方法加密您的 RSA 密钥。
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)
6.对参数进行加密后,您将通过浏览器(嵌入式 Web 视图)帖子将加密值与其他帐单运输详细信息(如果有)一起发布到 CCAvenue 服务器。(如果您无法将所有代码从objective-c 转换为swift,请使用objective-c 文件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.
7.用户将被重定向到 CCAvenue 的计费运输页面,他将在其中填写所需的详细信息,包括付款选项。
8.After filling the required details he will be redirected to the bank page wherein he will authorize himself.
8.填写所需的详细信息后,他将被重定向到银行页面,他将在其中授权自己。
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.
9.授权后,他将被重定向到 CCAvenue,并将响应即成功或失败发送到注册时配置为返回 url 的商家页面。
10.You should then decrypt the response, which can then be parsed to get transaction status.
10.然后您应该解密响应,然后可以对其进行解析以获取交易状态。
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.
访问代码和订单 ID 应与 RSA 调用期间传递的相同。
订单 ID 应始终唯一
交易应在收到 RSA 密钥后 60 秒内到达 CCAvenue 服务器。
ccavResponseHandler 文件中发布的工作密钥应与发布到 CCAvenue 的访问码相对应。
回答by Swapnil Luktuke
CCAvenue's integration pageshows only server side options.
CCAvenue 的集成页面仅显示服务器端选项。
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.
因此,您必须自己实现这一点。您可以在您的服务器上集成 CCAvenue 的支付网关,并在设备的网络视图中打开支付页面。由于服务器端的实现在您的控制之下,您可以通过 cookie 发送付款确认详细信息,就像它在 OAuth 中所做的那样。
回答by Amit
I have followed all the steps of Sagar Sukode and integrated CCAvenue SUCCESSFULLY.
我已经按照 Sagar Sukode 的所有步骤成功地集成了 CCAvenue。
If anyone need CCWEBVIEWCONTROLER in swift 2.3 :-
如果有人在 swift 2.3 中需要 CCWEBVIEWCONTROLER :-
In ViewDidLoad :
在 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 :
获取 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 :
读取响应的 Web 视图委托方法:
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.
只需检查后端开发人员的响应字符串即可在 webViewDidFinishLoad 中添加条件。
回答by The Doctor
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.
对于需要 Swift 3.2 答案的任何人,这里是代码。我花了一段时间才转换成它。但是你去吧。在此之前,让我解释一下,以防事情还不清楚。
(1) you place your GetRSA file on the server and then copy and paste that link in your app as "rsaKeyUrl".
(1) 您将 GetRSA 文件放在服务器上,然后将该链接作为“rsaKeyUrl”复制并粘贴到您的应用程序中。
(2) The "getRsaKeyForCCAvenue()" function makes a call to that file placed on the server, the IP of which has to be whitelisted beforehand.
(2) "getRsaKeyForCCAvenue()" 函数调用放置在服务器上的那个文件,其 IP 必须事先列入白名单。
(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.
(3) “getRSA”文件在已有的链接上向 CCavenue 发出请求。(这很重要,因为 CCAvenue 只接受来自白名单 IP 的请求,这使得所有请求都可以从一个 IP 路由。
(4) CCAvenue checks the details and processes the request and sends the response and redirects to the payment page if everything checks.
(4) CCAvenue 检查详细信息并处理请求,如果一切正常,则发送响应并重定向到支付页面。
(5) The redirection URL shall be the link of the "ccavResponseHandler" file which has your access code and translates the response.
(5) 重定向 URL 应是“ccavResponseHandler”文件的链接,该文件包含您的访问代码并翻译响应。
THE CODE IN SWIFT 3.2
Swift 3.2 中的代码
1) Get RSA Key
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) Code after super.viewDidLoad()
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) Finally the webViewDidFinishLoad() implementation
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...")
}
}