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")
}
}
}