Skip to main content

Overview

The Novac iOS SDK allows you to easily collect payments within your iOS apps using Novac’s secure checkout experience. It provides APIs for payment initialization and verification, along with a built-in UI that handles the full checkout flow for you.

Prerequisites

See details

Before you begin, ensure that you’ve completed the following steps:
  • Obtain your API keys: required for making authenticated API calls.
  • Xcode project with Swift Package Manager support
  • A Novac account with dashboard access

Installation

1

Step 1 - Add the Package in Xcode

In Xcode, navigate to File → Add Packages…, select Add Local…, and choose your SDK folder (Novac/). Then add Novac to your app target’s dependencies.If your SDK is hosted on GitHub, you can add it directly via URL instead of a local folder:
    .package(url: "https://github.com/yourusername/Novac.git", from: "1.0.0")

Initialize the SDK

Before launching any payment, you need to set up two things: an APIClient (which authenticates your requests using your API key) and a PaymentCoordinator (which manages the entire checkout flow). Both are configured inside your ViewController. You’ll need your apiKey from the Novac dashboard. The optional CustomTheme lets you style the checkout UI to match your brand.
import UIKit
import Novac

class ViewController: UIViewController, PaymentDelegate {

    var coordinator: PaymentCoordinator!

    override func viewDidLoad() {
        super.viewDidLoad()

        let apiClient = APIClient(apiKey: "YOUR_TEST_API_KEY")
        let theme = CustomTheme(primaryColor: .systemBlue, buttonTextColor: .white)

        coordinator = PaymentCoordinator(
            apiClient: apiClient,
            theme: theme,
            delegate: self
        )
    }
}

Launch the Checkout Flow

Once the coordinator is set up, you can trigger a payment from any user action — in this case, a button tap. You create a PaymentRequest with the transaction details and pass it to the coordinator, which handles the rest.
@IBAction func startPayment(_ sender: UIButton) {
    let payment = PaymentRequest(
        amount: 5000,
        currency: "NGN",
        email: "test@example.com",
        reference: UUID().uuidString
    )
    coordinator.start(presentingViewController: self, request: payment)
}

Handle Payment Outcomes

The PaymentDelegate protocol defines three callback methods that the SDK calls depending on what happens during checkout. Implement all three in your ViewController to handle every possible outcome.
func paymentDidSucceed(transactionId: String) {
    print("Payment succeeded with ID: \(transactionId)")
    // Update your UI, confirm the order, etc.
}

func paymentDidFail(error: Error) {
    print("Payment failed: \(error.localizedDescription)")
    // Show error message, offer retry option, etc.
}

func paymentDidCancel() {
    print("Payment cancelled by user.")
    // Handle cancellation gracefully
}

Configure Redirect URL

After a user completes checkout in the SDK’s webview, the payment gateway redirects them back to your app using a URL scheme. You need to register this scheme in your Info.plist so iOS knows to route that redirect back to your app.
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>exampleapp</string>
    </array>
  </dict>
</array>
Replace exampleapp with your own unique scheme. This value must match whatever redirect URL is configured in your Novac dashboard.

Advanced Usage

Ensure you use your Novac test key during development.
Keep the following in mind when testing:
  • Always use a unique reference value for each transaction, duplicate references will be rejected.
  • Start with small test amounts (₦100) to validate your integration before going live.
  • Check your sandbox dashboard to confirm transaction results and inspect any errors.