简体   繁体   English

适用于ios应用程序的CCAvenue Gateway集成工具包

[英]CCAvenue Gateway Integration kit for ios Application

Hi, 嗨,
I have developed an application which needs payment gateway. 我开发了一个需要支付网关的应用程序。 I have already worked on "Paypal". 我已经开始研究“Paypal”了。 It was successful and now i need to integrate another payment gateway that is "ccavenue". 它很成功,现在我需要整合另一个支付网关,即“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. 我正在搜索SDK,因为他们在这里提到 IOS / Android / Windows SDK可用。 But did not find anything. 但没有找到任何东西。 Finally I drafted an email to CCAvenue tech. 最后,我给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. 我们需要拥有实际的商家帐户才能获取登录凭据以下载SDK。
  • 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. 商家激活他的帐户后,他将获得登录凭据以下载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. 使用SDK,如果商家有免费计划,则仅支持INR和USD货币。 If merchant wants to add support for any other currency then he will have to request CCAvenue for the same. 如果商家想要添加对任何其他货币的支持,那么他将不得不同样请求CCAvenue。 CCAvenue team will verify with the concerned banks for it, if banks allow the transactions then new currency can be activated by paying Rs. CCAvenue团队将与相关银行核实,如果银行允许交易,则可以通过支付Rs来激活新货币。 5000 for each. 每个5000。
  • If merchant has privileged plan, then along with INR, merchant can select any 4 currencies from the supported 27 currencies. 如果商家有特权计划,那么随着INR,商家可以从支持的27种货币中选择任意4种货币。 If merchant wants more, then he can purchase currency by paying Rs. 如果商家想要更多,那么他可以通过支付Rs来购买货币。 5000 for each. 每个5000。

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. 由于CCAvenue显示服务器端选项,我们需要连接到Web视图并加载可与iphone屏幕兼容的ccavenue网关。 Here in Our application we need to do small things as follows 在我们的应用程序中,我们需要做如下的小事

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 之后加载屏幕上的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];

CCAvenue Payment Gateway Integration in Swift 3 Swift中的CCAvenue支付网关集成3


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). 5.使用获取的公钥商家将加密参数(金额,货币)。 To encrypt the RSA key, do following steps (From Step1 to Step8). 要加密RSA密钥,请执行以下步骤(从步骤1到步骤8)。

Step1: You have to download CCAvenue SDK from CCAvenue website and to download you must have to login using merchant account credential. 步骤1:您必须从CCAvenue网站下载CCAvenue SDK并下载您必须使用商家帐户凭证登录。

Step2: After login, to download SDK go to Resources->Mobile Integration Kit. 第二步:登录后,下载SDK进入资源 - >移动集成套件。 See following screen shot. 请参见以下屏幕截图。

在此输入图像描述

Step3: To download, click on Download Integration Kits as shown in following screen shot. 步骤3:要下载,请单击下载屏幕截图中的下载集成套件。 Before downloading choose Seamless or Non-Seamless. 下载前选择无缝或非无缝。 (Check details about this in document provided by CCAvenue) (在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. Step4:下载SDK工具包后,你必须将文件夹“OpenSSL”复制到你的项目中,否则你也可以使用pod安装“openssl”。

Step5: You will find 2 folders include and lib under Openssl/openssl-1.0.1i-iOS folder. 步骤5:您将在Openssl / openssl-1.0.1i-iOS文件夹下找到2个文件夹include和lib。 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. 同样在项目的Build Settings下搜索路径 - >库,搜索路径,删除提供的内容Users / test / desktop / ....并拖放include /和lib /这两个文件夹。 Also you have to do same thing for Paths->User Header Search Paths. 你也必须为Paths-> User Header Search Paths做同样的事情。

Stop6: Copy this two files (Files available in you downloaded SDK`s) to you project "CCTOOL & BASE64. Stop6:将这两个文件(您下载的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. 6.加密参数后,您将通过浏览器(嵌入式webview)帖子将加密值以及其他计费运送详细信息(如果有)发布到CCAvenue服务器。 (If you didn`t able to convert all code from objective-c to swift, use objective-c file CCWEBVIEWCONTROLER) (如果你不能将所有代码从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 ie 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. 访问代码和订单ID应与RSA调用期间传递的相同。

  • Order ID should always be unique 订单ID应始终是唯一的

  • The transaction should hit the CCAvenue server within 60 seconds after receiving the RSA key. 交易应在收到RSA密钥后60秒内到达CCAvenue服务器。

  • Working key posted in ccavResponseHandler file should be corresponding to the Accesscode being posted to CCAvenue. ccavResponseHandler文件中发布的工作密钥应与发布到CCAvenue的Accesscode相对应。

CCAvenue's integration page shows 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. 您可以在服务器上集成CCAvenue的支付网关,并在设备的Web视图中打开支付页面。 Since the server side implementation is in your control, you can send payment confirmation details via cookies the ways its done in OAuth. 由于服务器端实施在您的控制范围内,您可以通过Cookie以OAuth中的方式发送付款确认详细信息。

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)&currency=\(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 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 {
        }
    }

}

Just check for the response strings from the back end developers to add conditions in webViewDidFinishLoad. 只需检查后端开发人员的响应字符串,即可在webViewDidFinishLoad中添加条件。

For anyone who needs an answer for Swift 3.2 here is the code. 对于需要Swift 3.2答案的人来说,这里是代码。 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". (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)&currency=\(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...")
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM