iOS SDK

Nayax provides an iOS version of the eCom SDK. This guide shows you how to integrate it into your application. You will learn how to install, initialize, and prepare the SDK to facilitate payment creation.

Pre-requisites

To ensure compatibility and optimal performance, your iOS project must meet the following minimum requirements:

  • iOS 13.4 or later
  • Swift 5.0
  • Xcode Version 14.0 or later
  • A valid Sign Key (shared by Nayax, typically 16 characters).
  • The associated Sign Key ID.

Integrate eCom SDK

The integration of eCom SDK consists of three steps:

  1. Install the SDK.
  2. Initialize the SDK.
  3. Add Configuration Class.

The sections below provide a detailed description of each step.

Step 1: Install the SDK

To begin integrating the Nayax E-commerce functionality into your application, you'll first need to set up access to the GitLab repository and then install the SDK as shown below.

  1. The Nayax eCom SDK for iOS is hosted on Nayax's private GitLab repository. The Nayax Team will provide you with a read-only access token. Configure git to use this token for authentication:
    git config --global credential.helper store
    echo "https://gitlab-ci-token:<YOUR-PROVIDED-TOKEN>@gitlab.nayax-sdk.nayax.com" > ~/.git-credentials
    chmod 600 ~/.git-credentials # (Optional) Secure the credentials file
🚧

Sensitive Information

Do NOT commit the access token to your source control. The token should be treated as a sensitive credential.

  1. Set up your Podfile with the following code:
# Specify iOS platform version
platform :ios, '13.4'

# Add both the Nayax private Specs repo and the standard CocoaPods spec repo
source 'https://gitlab.nayax-sdk.nayax.com/nayax/ecom/ios/pods.git'
source 'https://github.com/CocoaPods/Specs.git'

target 'YourAppName' do
  # Use dynamic frameworks
  use_frameworks!

  # Add the NayaxEcomSDK
  pod 'NayaxEcomSDK', 'x.y.z'

  # Add any other dependencies your app needs
  ...
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
  end
end
  1. Before installing, remove any previous integrations:
pod deintegrate
  1. Now, install the pods.
    pod install --repo-update

Step 2: Initialize the SDK

Now initialize the SDK in your application, using the initialize method. Add the following code in your AppDelegate (or your main application entry point):

📘

Sign Key and ID

Nayax provides the signId , signKey, securityTokenId, and securityTokenValue values during your onboarding. Ensure you handle these values securely.

import NayaxEcomSDK
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> 
Bool {
                ...
        // Configure the SDK
        let config = NayaxEcomConfig(
            environment: NayaxEcomEnvironment.qa,
            signId: <sign_id>,
            signKey: <sign_key>,
                        securityTokenId: <security_token_id>,
                        securityTokenValue: <security_token_value>,
            enableLog: true
        )
        
        // Initialize the SDK and handle the result
        NayaxEcomSdk.shared.initialize(config: config) { result in
            switch result {
            case .success:
                // NayaxEcomSDK initialized
            case .failure(let error):
                // NayaxEcomSDK Initialization failed
            }
        }
        
        // Additional customization after application launch.
        return true
    }
}

Step 3: Add Configuration Class

Add the NayaxEcomConfig struct to set the essential properties of the SDK.

/// Configuration object for initializing the NayaxEcomSDK
public struct NayaxEcomConfig {
    public let environment: NayaxEcomEnvironment
    public let signId: Int
    public let signKey: String
    public let securityTokenId: Int
    public let securityTokenValue: String
    public let enableLog: Bool

    public init(
        environment: NayaxEcomEnvironment,
        signId: Int,
        signKey: String,
        securityTokenId: Int,
        securityTokenValue: String,
        enableLog: Bool = false
    ) {
        self.environment = environment
        self.signId = signId
        self.signKey = signKey
        self.securityTokenId = securityTokenId
        self.securityTokenValue = securityTokenValue
        self.enableLog = enableLog
    }
}
/// Enum representing the environments for the SDK
public enum NayaxEcomEnvironment: String {
    case qa
    case stable
    case production
}

This table describes the parameters required to initialize the NayaxEcomConfig object.

ParameterTypeDescription
environmentNayaxEcomEnvironmentThe target server environment. Possible values are .qa, .stable, or .production.
signIdIntThe ID used for signing API requests.
signKeyStringThe key used for signing API requests.
securityTokenIdIntThe security token ID used for merchant validation.
securityTokenValueStringThe security token value used for merchant validation.
enableLogBoolA flag to enable or disable SDK logging. Defaults to false.

Now the eCom SDK is integrated into your iOS application, and you can start creating payments through it. Refer to the Front-End Integration guide for more information on how this works.

See Also