如何在我的Xcode项目中集成Razorpay付款网关?

时间:2019-11-08 06:14:14

标签: ios swift swift5 razorpay

我第一次尝试在我的项目中实现支付网关。

strong text

我从Razorpay官方链接https://razorpay.com/docs/payment-gateway/ios-integration/standard/

正确地执行了所有步骤。

但是,我想在我的目的地即RPViewController.swift而不是RootVC上打开razorpay付款网关。

请帮助我解决这个问题。

我的Xcode版本是11.1

//
//  RPViewController.swift

import UIKit
import Razorpay
class RPViewController: UIViewController  , RazorpayPaymentCompletionProtocol {
   var razorpay : Razorpay!
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    internal func showPaymentForm(){
        let options: [String:Any] = [
                    "amount": "100", //This is in currency subunits. 100 = 100 paise= INR 1.
                    "currency": "INR",//We support more that 92 international currencies.
                    "description": "purchase description",
                    "order_id": "order_4xbQrmEoA5WJ0G",
                    "image": "https://image.flaticon.com/icons/svg/124/124010.svg",
                    "name": "business or product name" ,
                    "prefill": [
                        "contact": "9797979797",
                        "email": "foo@bar.com"
                    ],
                    "theme": [
                        "color": "#F37254"
                    ]
                ]


        print(options)
        razorpay.open(options)
    }

    func onPaymentError(_ code: Int32, description str: String) {
           let alertController = UIAlertController(title: "FAILURE", message: str, preferredStyle: UIAlertController.Style.alert)
           let cancelAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil)
           alertController.addAction(cancelAction)
           print("code",code)
           self.view.window?.rootViewController?.present(alertController, animated: true, completion: nil)
       }

       func onPaymentSuccess(_ payment_id: String) {
           let alertController = UIAlertController(title: "SUCCESS", message: "Payment Id \(payment_id)", preferredStyle: UIAlertController.Style.alert)

           let cancelAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil)
              alertController.addAction(cancelAction)
              self.view.window?.rootViewController?.present(alertController, animated: true, completion: nil)
       }

 @IBAction func paybuttonTapped(_ sender: Any) {
           razorPay = Razorpay.initWithKey("rzp_test_oaXFcpSvVQ9Ry9", andDelegate: self)
                 showPaymentSummary()
       }


}

// I'm getting this warning 

Warning: Attempt to present <UINavigationController: 0x7fadd200e200>  on <TestingDemo.ViewController: 0x7fadd1f15f80> which is already presenting <UIViewController: 0x7fadd1f33c70> 


1 个答案:

答案 0 :(得分:0)

我得到了答案。 错误是我正在传递不需要的参数orderId