3

I'm doing an IOS Application with Patym SDK, Transaction is happening successful but its not navigating back to app. Its showing an webview with " Redirect back to app ". anyone faced this issue before ?

Here is my code:

extension ShippingViewController : PGTransactionDelegate {


    func didCancelTrasaction(_ controller: PGTransactionViewController!) {
        let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
        self.present(vc, animated: true, completion: nil)
    }

    func didFinishedResponse(_ controller: PGTransactionViewController!, response responseString: String!) {
        let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
        self.present(vc, animated: true, completion: nil)
    }


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

        showAlert(title: "didCancelTrasaction", message: error.localizedDescription)
        let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "CSWhoopsView") as! CSAlertViewController
        self.present(vc, animated: true, completion: nil)
    }


    func didFailTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {
        print(error)
        showAlert(title: "Transaction Failed", message: error.localizedDescription)
        let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "CSWhoopsView") as! CSAlertViewController
        self.present(vc, animated: true, completion: nil)
    }
    func didCancelTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {

        showAlert(title: "Transaction Cancelled", message: error.localizedDescription)
        let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "CSWhoopsView") as! CSAlertViewController
        self.present(vc, animated: true, completion: nil)

    }

    func didFinishCASTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
         print("my response isis :" )
        print(response)
        showAlert(title: "cas", message: "")

    }

    func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
         print("my response is :" )
        print(response)
        showAlert(title: "Transaction Successfull", message: NSString.localizedStringWithFormat("Response- %@", response) as String)

        let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
        self.present(vc, animated: true, completion: nil)
    }
}
Krunal
  • 77,632
  • 48
  • 245
  • 261
  • you should be having a delegate method for knowing error/success of the transaction, right? – Saheb Roy Jan 12 '18 at 07:40
  • yea, I'm presenting my controller in didsuccessfulTransaction, but its not called . func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) { print(response) confirmViewController self.present(vc, animated: true, completion: nil) } – shree thaanu Jan 12 '18 at 07:42
  • is the `didSuccessTransaction` method invoking? – Saheb Roy Jan 12 '18 at 07:43

2 Answers2

0

According to this document: PayTM iOS SDK Integration Step, PGTransactionDelegate provides following methods to handle callback.

// On Successful Payment
func didSucceedTransaction(controller: PGTransactionViewController, response: [NSObject : AnyObject]) {              
    print(response)
    print("Response - \(response)")
    //removeController  - Close PayTM Controller here using dismiss or pop controller methods
}

// On Failure
func didFailTransaction(controller: PGTransactionViewController, error: NSError, response: [NSObject : AnyObject]) {
    print(response)
    if response.count == 0 {
        print(response.description)
    }
    else if error != 0 {
       print(error.localizedDescription)
    }
    //removeController  - Close PayTM Controller here using dismiss or pop controller methods
}


//On Cancellation
func didCancelTransaction(controller: PGTransactionViewController, error: NSError, response: [NSObject : AnyObject]) {
    print("Transaction has been Cancelled")
    //removeController  - Close PayTM Controller here using dismiss or pop controller methods     
}

func didFinishCASTransaction(controller: PGTransactionViewController, response: [NSObject : AnyObject]) {  
    print(response);    
}

Also one more importance point is: Paytm CALLBACK_URL - This url is provided by Paytm so app can read the data from paytm and return.

Note: Since recent updates in SDK here are PGTransactionDelegate methods (in Objective-C)

@protocol PGTransactionDelegate <NSObject>

@required
//Called when a transaction has completed. response dictionary will be having details about Transaction.

-(void)didFinishedResponse:(PGTransactionViewController *)controller response:(NSString *)responseString;

//Called when a user has been cancelled the transaction.

-(void)didCancelTrasaction:(PGTransactionViewController *)controller;

//Called when a required parameter is missing.

-(void)errorMisssingParameter:(PGTransactionViewController *)controller error:(NSError *) error;

@end

Edit:

Replace following delegate implementation in your code.

func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
 print("my response is :" )
print(response)
showAlert(title: "Transaction Successfull", message: NSString.localizedStringWithFormat("Response- %@", response) as String)


    controller.dismiss(animated: true) {
       let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
       self.present(vc, animated: true, completion: nil)
    }


}
Krunal
  • 77,632
  • 48
  • 245
  • 261
  • getting this error " Cannot subscript a value of type '[NSObject : AnyObject]' with an index of type 'String' " in print("Deducted amount :Rs. \(response["TXNAMOUNT"]!)") – shree thaanu Jan 12 '18 at 07:51
  • Remove other contents and use `print("Response - \(response)")` only. Also note, I used this code a year ago, so ensure all delegate methods are as it is at this time. – Krunal Jan 12 '18 at 07:55
  • I can get response from them, but cannot move out of that page, func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) { print("my response is :" ) print(response) showAlert(title: "Transaction Successfull", message: NSString.localizedStringWithFormat("Response- %@", response) as String) let vc = UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController self.present(vc, animated: true, completion: nil) } } – shree thaanu Jan 12 '18 at 08:04
  • Handle dismiss or pop controller operations in it. Please share your code, so that I can see what exactly you've missing – Krunal Jan 12 '18 at 08:05
0

extension ShippingViewController : PGTransactionDelegate {

func didCancelTrasaction(_ controller: PGTransactionViewController!) {
    let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
    self.present(vc, animated: true, completion: nil)
}

func didFinishedResponse(_ controller: PGTransactionViewController!, response responseString: String!) {
    let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
    self.present(vc, animated: true, completion: nil)
}


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

    showAlert(title: "didCancelTrasaction", message: error.localizedDescription)
    let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "CSWhoopsView") as! CSAlertViewController
    self.present(vc, animated: true, completion: nil)
}


func didFailTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {
    print(error)
    showAlert(title: "Transaction Failed", message: error.localizedDescription)
    let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "CSWhoopsView") as! CSAlertViewController
    self.present(vc, animated: true, completion: nil)
}
func didCancelTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {

    showAlert(title: "Transaction Cancelled", message: error.localizedDescription)
    let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "CSWhoopsView") as! CSAlertViewController
    self.present(vc, animated: true, completion: nil)

}

func didFinishCASTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
     print("my response isis :" )
    print(response)
    showAlert(title: "cas", message: "")

}

func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
     print("my response is :" )
    print(response)
    showAlert(title: "Transaction Successfull", message: NSString.localizedStringWithFormat("Response- %@", response) as String)

    let vc =  UIStoryboard(name: "account", bundle: nil).instantiateViewController(withIdentifier: "confirmViewController") as! confirmViewController
    self.present(vc, animated: true, completion: nil)
}

}