Redirect back to the application (ios and android) after payment success in paytm

after successful payment, Paytm redirects the user to a callback to mysite. How to redirect the user back to the application from the view returned by the callback URL to the application.

+4
source share
1 answer

Add these features

    func showController(controller: PGTransactionViewController) {

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

    }
    else {
        self.present(controller, animated: true, completion: {() -> Void in
        })
    }
}

func removeController(controller: PGTransactionViewController) {
    if self.navigationController != nil {
        self.navigationController!.popViewController(animated: true)
    }
    else {
        controller.dismiss(animated: true, completion: {() -> Void in
        })
    }
}
     func showError(title:String, message:String, controller: PGTransactionViewController) {
    let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert);

    let ok = UIAlertAction(title: "No", style: UIAlertActionStyle.default) { (alert) in

        alertController.dismiss(animated: true, completion: nil);
    };

    let goBack = UIAlertAction(title: attributedYesString.string, style: UIAlertActionStyle.default) { (alert) in
        self.removeController(controller: controller)
    };

    alertController.addAction(ok);
    alertController.addAction(goBack)
    self.parent?.present(alertController, animated: true, completion: nil)

}

And in Paytm functions, appropriately call these functions. I will give you an example of how I did this.

func didFinishedResponse(_ controller: PGTransactionViewController!, response responseString: String!) {
    print(responseString)
    print("didfinish")
    self.removeController(controller: controller)
}

func didCancelTrasaction(_ controller: PGTransactionViewController!) {
    print("cancelled", "didcancel")
    self.showError(title: "Your transaction will be cancelled", message: "Are you sure?", controller: controller)

}

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

func didSucceedTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
    print(response,"Transaction Successfull")
    self.removeController(controller: controller)

}


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

    self.removeController(controller: controller)
}
func didCancelTransaction(_ controller: PGTransactionViewController!, error: Error!, response: [AnyHashable : Any]!) {
    print(error, response , "Transaction Cancelled")
    self.removeController(controller: controller)

}

func didFinishCASTransaction(_ controller: PGTransactionViewController!, response: [AnyHashable : Any]!) {
    print(response , "Transaction")
}
0
source

Source: https://habr.com/ru/post/1682721/


All Articles