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.
- 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.plistfor redirect callbacks
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")
]pod 'RoktPaymentExtension'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 |
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
}
}
)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"
]
)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.
-
Declare the URL scheme in your host app's
Info.plistunderCFBundleURLTypes(e.g.myapp). -
Pass the matching
returnURLwhen creating the extension (e.g."myapp://stripe-redirect"). Omit it and the extension stays Apple-Pay-only. -
Forward redirect URLs to the Rokt SDK from your
SceneDelegate/AppDelegate. The SDK dispatches the URL to every registeredPaymentExtensionvia the optionalhandleURLCallback(with:)hook, which this extension implements by callingStripeAPI.handleURLCallback(with:).// SceneDelegate func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { for ctx in URLContexts { Rokt.handleURLCallback(with: ctx.url) } }
| 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(...) |
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
PaymentExtensionprotocol from RoktContracts; routes eachPaymentMethodTypeto the matching internal manager.supportedMethodsis computed from the configured managers. - StripeApplePayManager: Manages Apple Pay / card flows via Stripe's
STPApplePayContext. - StripeAfterpayManager: Manages redirect-based Afterpay / Clearpay flows via
STPPaymentHandler; validatesPaymentContext.billingAddressand confirms the PaymentIntent with the configuredreturnURL. - ContactAddressMapping: Converts Apple Pay
PKContacttoContactAddress. - BillingDetailsMapping: Converts
ContactAddresstoSTPPaymentMethodBillingDetailsandSTPPaymentIntentShippingDetailsParams.
Version 1.0 renames the package and class. To migrate:
- Replace
import RoktStripePaymentExtensionwithimport RoktPaymentExtension. - Replace the class name
RoktStripePaymentExtensionwithRoktPaymentExtension. - Update your
Package.swiftURL tohttps://github.com/ROKT/rokt-payment-extension-ios.git(old URL auto-redirects via GitHub). - Update your Podfile:
pod 'RoktPaymentExtension'. - Optional: the initializer now accepts an optional
applePayMerchantId. To support only Afterpay, drop it and passreturnURLinstead.
Copyright 2024 Rokt Pte Ltd. Licensed under the Rokt SDK Terms of Use 2.0.
Please report vulnerabilities via our disclosure form. Do not use GitHub issues.