Nuvei iOS SDK Installation

You need to follow the below steps to build an in-app payment flow fully functional using Nuvei SDK in your iOS app using Swift.

  1. Download the Smart2Pay.framework.
  2. Import the framework into your project by either dragging it into the project or go to File | Add files to “project name”.
  3. Add the framework to the Embedded Binaries. Select the Project icon in your file hierarchy – make sure you are in the General tabEmbedded Binaries.

    There are three scenarios possible do the one that applies to you:

    • If you don’t see it in “Embedded Binaries” and don’t see it in the “Linked Frameworks and Libraries”, just click the + on “Embedded Binaries” and select the Smart2Pay.framework.
    • If you see it in “Linked Frameworks and Libraries” but not in “Embedded Binaries”, you should first remove it from “Linked Frameworks and Libraries” and click the + on “Embedded Binaries” and select the Smart2Pay.framework. This will automatically add it to both.
    • If you see it in both “Embedded Binaries” and “Linked Frameworks and Libraries”, you don’t need to do anything.

Now that the SDK is in the app we can actually use it in the code. Continue with setting up the SDK: Nuvei iOS SDK Instructions (Swift).

Nuvei iOS SDK Instructions (Swift)

Now that you have imported the Smart2Pay.SDK package into your app, you need to follow the below steps in order to set up the Mobile SDK for iOS in Swift language.

  1. To get back to the app after doing a payment we need to set an URL Scheme.

    Select the Project icon again in your file hierarchy – make sure you are in the Info tab – URL Types.

    Fold it open and click the + button. You only need to set URL Schemes field. For example, you can use your bundle identifier. This ensures that there’s no other app that uses this URL Scheme.

    We’re all set to make a payment now!

  2. Create a payment from the data you’ve attained from the API.

    
    ```
    Let payment = Payment(id: id)
    payment.amount = 100 // This is in cents
    payment.currency = "CNY" // Use the three letter abbreviation
    payment.type = .ALIPAY // or .WECHAT 
    payment.delegate = this // The current view controller with PaymentManagerDelegate implementation
    let paymentManager = PaymentManager("urlscheme from step 4")
    paymentManager.pay(payment)
    ```
    
  3. Make sure the view controller uses the delegate implementation:

    PaymentManager.PaymentManagerDelegate

    For example, your view controller could look like this:

    
    `
    class ViewController: UIViewController, PaymentManagerDelegate {
    `
    

    To get the callbacks from the Payment Manager you need to add these two functions:

    
    ```
    func onPaymentSuccess(_ payment: Payment, _ body: [String: Any]) {
    }
        
    func onPaymentFailure(_ payment: Payment) {
    }
    ```
    

    The information needed is inside the payment. This is the structure of a Payment:

    
    ```
    class Payment {
       enum PaymentProvider: Int {
            case NONE = 0
            case ALIPAY = 24
            case WECHAT = 1066
        }
        var id: Int = 0
        var type = PaymentProvider.NONE
        var amount: Int = 0
        var currency: String = ""
        var instructions: String = "" 
        var delegate: PaymentManagerDelegate?
    }
    ```
    

SDK is now fully functional in your app!