CocoaPods trunk is moving to be read-only. Read more on the blog, there are 8 months to go.

RoktPaymentExtension 2.0.1

RoktPaymentExtension 2.0.1

Maintained by ROKT DEV.



 
Depends on:
RoktContracts~> 2.0
StripeApplePay~> 25.0
StripePayments~> 25.0
 

  • By
  • ROKT DEV

Rokt Payment Extension (iOS)

Optional payment integration for the Rokt iOS SDK ecosystem. Currently provides Apple Pay, card, and Afterpay/Clearpay support via Stripe for Shoppable Ads placements. Designed to host additional providers (e.g. PayPal, Klarna) over time.

This package depends only on RoktContracts — not the full Rokt SDK — keeping payment-provider SDKs isolated and the integration lightweight.

Requirements

  • iOS 15.0+
  • Swift 5.9+
  • Xcode 15.0+
  • Stripe account with Apple Pay enabled (for Apple Pay / card)
  • For Afterpay / Clearpay: a Stripe account with the method enabled and a custom URL scheme registered in the host app's Info.plist for redirect callbacks

Installation

Swift Package Manager

In Xcode: File > Add Packages, enter:

https://github.com/ROKT/rokt-payment-extension-ios.git

Or add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/ROKT/rokt-payment-extension-ios.git", from: "1.0.0")
]

CocoaPods

pod 'RoktPaymentExtension'

Usage

The extension accepts optional init params — you enable only the methods you want to support. At least one of applePayMerchantId or returnURL must be provided; otherwise the initializer returns nil.

Init parameters Enables
applePayMerchantId only Apple Pay, card
returnURL only Afterpay / Clearpay
Both Apple Pay, card, Afterpay

Direct Rokt SDK Integration

When using the Rokt SDK directly, the partner provides the Stripe publishable key explicitly at registration time:

import Rokt_Widget
import RoktPaymentExtension

// 1. Initialize Rokt
Rokt.initWith(roktTagId: "your-tag-id")

// 2. Create the payment extension.
//    Supply `applePayMerchantId` for Apple Pay, `returnURL` for Afterpay, or both.
guard let paymentExtension = RoktPaymentExtension(
    applePayMerchantId: "merchant.com.example",
    returnURL: "myapp://stripe-redirect" // omit to keep the extension Apple-Pay-only
) else { return }

// 3. Register with the Rokt SDK — pass your Stripe publishable key
Rokt.registerPaymentExtension(paymentExtension, config: [
    "stripeKey": "pk_live_abc123"
])

// 4. Show Shoppable Ads (always overlay)
Rokt.selectShoppableAds(
    identifier: "ConfirmationPage",
    attributes: [
        "email": "[email protected]",
        "firstname": "John",
        "lastname": "Doe",
        "confirmationref": "ORDER-12345"
    ],
    onEvent: { event in
        switch event {
        case let e as RoktEvent.CartItemInstantPurchase:
            print("Purchase: \(e.catalogItemId)")
        case let e as RoktEvent.CartItemInstantPurchaseFailure:
            print("Failed: \(e.error ?? "unknown")")
        default:
            break
        }
    }
)

SDK+ Integration

When using the mParticle SDK, the Stripe publishable key is automatically provided from the mParticle dashboard configuration. The partner only needs to create the extension and register it — the Kit injects the stripeKey before forwarding to the Rokt SDK:

import mParticle_Apple_SDK
import RoktPaymentExtension

// 1. mParticle init handles Rokt.initialize via Kit (tagId from dashboard)

// 2. Create and register the payment extension — no stripeKey needed.
guard let paymentExtension = RoktPaymentExtension(
    applePayMerchantId: "merchant.com.example",
    returnURL: "myapp://stripe-redirect" // omit to keep the extension Apple-Pay-only
) else { return }
MParticle.sharedInstance().rokt.registerPaymentExtension(paymentExtension)
// Kit automatically injects stripeKey from dashboard config

// 3. Show Shoppable Ads
MParticle.sharedInstance().rokt.shoppableAds(
    "ConfirmationPage",
    attributes: [
        "email": "[email protected]",
        "firstname": "John",
        "lastname": "Doe"
    ]
)

Enabling Afterpay / Clearpay

Afterpay/Clearpay is a redirect-based payment method: Stripe opens a web page for authentication and redirects back to your app via a custom URL scheme.

  1. Declare the URL scheme in your host app's Info.plist under CFBundleURLTypes (e.g. myapp).

  2. Pass the matching returnURL when creating the extension (e.g. "myapp://stripe-redirect"). Omit it and the extension stays Apple-Pay-only.

  3. Forward redirect URLs to the Rokt SDK from your SceneDelegate / AppDelegate. The SDK dispatches the URL to every registered PaymentExtension via the optional handleURLCallback(with:) hook, which this extension implements by calling StripeAPI.handleURLCallback(with:).

    // SceneDelegate
    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
        for ctx in URLContexts {
            Rokt.handleURLCallback(with: ctx.url)
        }
    }

What Partners Need for Each Scenario

Scenario Packages Stripe Key Source Code
Standard placements (SDK+) mParticle SDK + Rokt Kit rokt.selectPlacements(...)
Shoppable Ads (SDK+) Above + RoktPaymentExtension Dashboard config (automatic) registerPaymentExtension(ext) + shoppableAds(...)
Standard placements (Direct) Rokt-Widget Rokt.selectPlacements(...)
Shoppable Ads (Direct) Rokt-Widget + RoktPaymentExtension Partner passes in config dict registerPaymentExtension(ext, config:) + selectShoppableAds(...)

Architecture

RoktPaymentExtension (public facade)
  ├── StripeApplePayManager (Apple Pay / card)       ← built if applePayMerchantId provided
  │    ├── STPApplePayContext (Stripe SDK)
  │    └── ContactAddressMapping (PKContact → ContactAddress)
  ├── StripeAfterpayManager (Afterpay / Clearpay)    ← built if returnURL provided
  │    ├── STPPaymentHandler (Stripe SDK)
  │    └── BillingDetailsMapping (ContactAddress → Stripe billing/shipping)
  └── handleURLCallback(with:) → StripeAPI.handleURLCallback
  • RoktPaymentExtension: Implements PaymentExtension protocol from RoktContracts; routes each PaymentMethodType to the matching internal manager. supportedMethods is computed from the configured managers.
  • StripeApplePayManager: Manages Apple Pay / card flows via Stripe's STPApplePayContext.
  • StripeAfterpayManager: Manages redirect-based Afterpay / Clearpay flows via STPPaymentHandler; validates PaymentContext.billingAddress and confirms the PaymentIntent with the configured returnURL.
  • ContactAddressMapping: Converts Apple Pay PKContact to ContactAddress.
  • BillingDetailsMapping: Converts ContactAddress to STPPaymentMethodBillingDetails and STPPaymentIntentShippingDetailsParams.

Migration from RoktStripePaymentExtension (0.x)

Version 1.0 renames the package and class. To migrate:

  1. Replace import RoktStripePaymentExtension with import RoktPaymentExtension.
  2. Replace the class name RoktStripePaymentExtension with RoktPaymentExtension.
  3. Update your Package.swift URL to https://github.com/ROKT/rokt-payment-extension-ios.git (old URL auto-redirects via GitHub).
  4. Update your Podfile: pod 'RoktPaymentExtension'.
  5. Optional: the initializer now accepts an optional applePayMerchantId. To support only Afterpay, drop it and pass returnURL instead.

License

Copyright 2024 Rokt Pte Ltd. Licensed under the Rokt SDK Terms of Use 2.0.

Security

Please report vulnerabilities via our disclosure form. Do not use GitHub issues.