Paytm console giving 404 error in Swift 4

折月煮酒 提交于 2019-12-13 03:15:54

问题


I'm implementing Paytm in iOS using Swift 4. I'm sending requested data to paytm console, but it is showing "404 Not Found" error. I'm sending the following data to paytm:

let merchantConfig = PGMerchantConfiguration.default()
merchantConfig?.checksumGenerationURL = "https://pguat.paytm.com/paytmchecksum/paytmCheckSumGenerator.jsp" 
merchantConfig?.checksumValidationURL = "https://pguat.paytm.com/paytmchecksum/paytmCheckSumVerify.jsp" 

let odrDict = NSMutableDictionary()

odrDict["CALLBACK_URL"] = "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp",
odrDict["CHANNEL_ID"] = "WAP",
odrDict["CUST_ID"] =  "30244",
odrDict["INDUSTRY_TYPE_ID"] = "Software",
odrDict["MID"] = self.MID
odrDict["ORDER_ID"] = "29",
odrDict["REQUEST_TYPE"] = "DEFAULT",
odrDict["TXN_AMOUNT"] = "200",
odrDict["WEBSITE"] = "WEB_STAGING"
odrDict["CHECKSUMHASH"] = "a/4w+QPWAEZXlNXg48Nr9OQoBYGDjj1lVbY4VPhAqi4pkadfcUFoY6UToaHNnND8pNoDCJRxYlFEirdsnowwMACKAXgTB3ScBBYorzipqQ=",
odrDict["MOBILE_NO"] = "7777777777"
odrDict["EMAIL"] = "demo@gmail.com"

print("odrDict",odrDict)

let order: PGOrder = PGOrder(params: odrDict as? [AnyHashable : Any])
let transactionController = PGTransactionViewController(transactionFor: order)
transactionController?.serverType = eServerTypeStaging
transactionController?.merchant = merchantConfig
transactionController?.delegate = self
self.showController(controller: transactionController!)

I don't know, what I'm doing wrong. Every time I request to open the paytm console, it is giving 404 not found.


回答1:


     extension ABViewController: UIViewController {

        var custID = ""
        override func viewDidLoad() {

        super.viewDidLoad()

        self.setMerchant()


        custID =  custID.randomString(length: 20)
        print(custID)
      }

        func setMerchant() {


            merchant  = PGMerchantConfiguration.default()
            //user your checksum urls here or connect to paytm developer team for this or use default urls of paytm


            merchant.checksumGenerationURL = "http://test/Admin/paytm/generateChecksum.php";
            merchant.checksumValidationURL = "http://test/Admin/paytm/verifyChecksum.php";
        merchant.merchantID = "testI93673659336118";//paste here your merchant id  //mandatory
            merchant.website = "APPPROD";//mandatory
            merchant.industryID = "Retail109";//mandatory
            merchant.channelID = "WAP"; //provided by PG WAP //mandatory

            merchant.clientSSLCertPath = nil; //[[NSBundle mainBundle]pathForResource:@"Certificate" ofType:@"p12"];
            merchant.clientSSLCertPassword = nil; //@"password";
        }

        //MARK:- Create Payment
        func createPayment(checksumHash : String, orderID : String) {

            var orderDict = [AnyHashable : Any]()

            let txnAmt = self.amountTextField.text!
            print(txnAmt)

            orderDict["MID"] = "RentSe98692194807190"
            orderDict["CHANNEL_ID"] = "WAP"
            orderDict["INDUSTRY_TYPE_ID"] = "Retail109"
            orderDict["WEBSITE"] = "APPPROD"
            orderDict["TXN_AMOUNT"] = "50" as AnyObject
            orderDict["ORDER_ID"] = orderID
            orderDict["CHECKSUMHASH"] = checksumHash
            orderDict["CUST_ID"] = custID
            orderDict["EMAIL"] = "kj@gmail.com" as AnyObject
            orderDict["MOBILE_NO"] = "7777777777" as AnyObject
            orderDict["REQUEST_TYPE"] = "DEFAULT" as AnyObject
            orderDict["THEME"] = "merchant" as AnyObject
            orderDict["CALLBACK_URL"] = "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp" as AnyObject

            print(custID)
            let pgOrder = PGOrder(params: orderDict)

            let transaction = PGTransactionViewController.init(transactionFor: pgOrder)

            if eServerTypeStaging != eServerTypeNone {
                transaction!.serverType = eServerTypeProduction
                transaction!.merchant = merchant
                transaction!.delegate = self
                self.navigationController?.pushViewController(transaction!, animated: true)
            }
        }

        func validatePaytm(checksumHash : String, orderID: String) {

            var orderDict = [String : AnyObject]()

            orderDict["CHECKSUMHASH"] = checksumHash as AnyObject
            orderDict["ORDER_ID"] = orderID as AnyObject
        }

        //MARK:- Generate Checksum from our Server
        func paytmAPI() {

            let url = "http://mstoo.co.in/Admin/paytm/generateChecksum.php"

            let orderID = "".randomString(length: 20)
            print(orderID)

            let txnAmt = self.amountTextField.text!
            print(txnAmt)

            var orderDict = [String : AnyObject]()

            orderDict["MID"] = "RentSe98692194807190" as AnyObject
            orderDict["CHANNEL_ID"] = "WAP" as AnyObject
            orderDict["INDUSTRY_TYPE_ID"] = "Retail109" as AnyObject
            orderDict["WEBSITE"] = "APPPROD" as AnyObject
            orderDict["TXN_AMOUNT"] = txnAmt as AnyObject
            orderDict["ORDER_ID"] = orderID as AnyObject
            orderDict["CUST_ID"] = custID as AnyObject
            orderDict["EMAIL"] = "kj@gmail.com" as AnyObject
            orderDict["MOBILE_NO"] = "7777777777" as AnyObject
            orderDict["REQUEST_TYPE"] = "DEFAULT" as AnyObject
            orderDict["THEME"] = "merchant" as AnyObject
            orderDict["CALLBACK_URL"] = "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp" as AnyObject

            let imageArray = [UIImage]()

            Methods.sharedInstance.showLoader(object: self.view)

            WebServiceClass.uploadeImageToServer(urlName: url, params: orderDict, uploadedImage: imageArray, imageName: "") { (isTrue, response, errorMessage) in

                Methods.sharedInstance.hideLoader(object: self.view)

                if let jsonResult = response as? Dictionary<String, AnyObject> {

                    print(jsonResult)

                    self.paytmValidate(checksumhash: jsonResult["CHECKSUMHASH"] as? String ?? "", orderID: jsonResult["ORDER_ID"] as? String ?? "")
                } else {

                    self.showAlertWithoutCallBack(messageTitle: "MessageWhatHappen")
                }
            }
        }

        func paytmValidate(checksumhash: String,orderID: String) {

            let url = "http://test/Admin/paytm/verifyChecksum.php"

            var orderDict = [String : AnyObject]()

            orderDict["CHECKSUMHASH"] = checksumhash as AnyObject
            orderDict["ORDER_ID"] = orderID as AnyObject

            let imageArray = [UIImage]()

            WebServiceClass.uploadeImageToServer(urlName: url, params: orderDict, uploadedImage: imageArray, imageName: "") { (isTrue, response, errorMessage) in

                if let jsonResult = response as? Dictionary<String, AnyObject> {

                    print(jsonResult)

                    self.createPayment(checksumHash:checksumhash, orderID:orderID)
                } else {

                     print("MessageWhatHappen")
                }
            }
        }
    }

   extension ABViewController:  PGTransactionDelegate {

        func didFinishedResponse(_ controller: PGTransactionViewController!, response responseString: String!) {

            print("Transaction Finished")
            print(responseString)
            let Str = responseString
            let finalDictResponse = convertToDictionary(text: Str ?? "")
            print(finalDictResponse)
            if let myDict = finalDictResponse as Dictionary<String,AnyObject>? {
                self.addMoneyAPI(transectionID : myDict["TXNID"] as? String ?? "")
                self.removeController(controller: controller)
                showToast(message: "Finish Response")

            }
        }

        func didCancelTrasaction(_ controller: PGTransactionViewController!) {
            self.navigationController?.popViewController(animated: true)
            self.showToast(message: "Transaction Cancelled")
        }

        func errorMisssingParameter(_ controller: PGTransactionViewController!, error: Error!) {

            self.removeController(controller: controller)
            showToast(message: "Missing Parameters")
            DispatchQueue.main.async {
                self.removeController(controller: controller)
                self.navigationController?.popViewController(animated: true)
            }
            showAlert(title: "didCancelTrasaction", message: error.localizedDescription)
        }

        func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {

            print(response)
            self.showToast(message: "Transaction Successful")

        }

        func didFailTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {

            print(error)
            self.navigationController?.popToViewController(controller, animated: true)
            self.showToast(message: "Transaction Failed")
        }

        func didFinishCASTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {

            print(response)
        }

        func showController(controller: PGTransactionViewController) {

            if self.navigationController != nil {
                self.navigationController?.pushViewController(controller, animated: true)
            } else {
                self.navigationController?.pushViewController(controller, animated: true)
            }
        }

        func removeController(controller: PGTransactionViewController) {

            if self.navigationController != nil {
                print("Transcation Successful")

            } else {
                print("Transcation Successful")
            }
        }
    }


来源:https://stackoverflow.com/questions/55804117/paytm-console-giving-404-error-in-swift-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!