Skip to content
Last updated

iOS SDK Reference

The Banxa iOS SDK (BanxaPaymentSDK) is a headless Swift interface to Banxa Hosted Checkout for native iOS apps. You configure it once and start a payment with a single call. The SDK checks eligibility, creates the order, presents checkout, and reports the outcome on a delegate.

For the end-to-end walkthrough, see the iOS SDK Integration Guide.


Requirements

RequirementVersion
iOS13.1 and above
Xcode16 and above
Swift6.0 and above

The public surface is @MainActor isolated and built on Swift concurrency.


Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/BanxaOfficial/ios-payment-sdk", from: "1.0.0")
]
.target(
    name: "YourApp",
    dependencies: [
        .product(name: "BanxaPaymentSDK", package: "ios-payment-sdk")
    ]
)

Through Xcode

  1. Select File, Add Package Dependencies.
  2. Enter the repository URL.
  3. Select BanxaPaymentSDK and add it to your app target.

The SDK transitively pulls in the payment provider SDK. You do not import or reference it directly.


Configuration

import BanxaPaymentSDK

let config = BanxaConfig(
    apiKey: "YOUR_API_KEY",
    partnerID: "your-partner-id",
    environment: .sandbox
)

BanxaPaymentSDK.shared.configure(config: config)
BanxaPaymentSDK.shared.delegate = self

BanxaConfig

FieldTypeRequiredDescription
apiKeyStringYesYour v2 API key from the merchant dashboard.
partnerIDStringYesYour partner identifier.
environmentEnvironmentYes.sandbox or .production.

Requests use x-api-key authentication.

Environments

EnvironmentHost
.sandboxhttps://api.banxa-sandbox.com
.productionhttps://api.banxa.com

The effective base URL is <host>/{partnerID}/v2. Sandbox and production credentials are separate and are not interchangeable.


startPayment

BanxaPaymentSDK.shared.startPayment(request: request, controller: self)
ParameterDescription
requestA CreateOrderRequest.
controllerThe UIViewController that hosts the checkout presentation.

startPayment creates the order and presents checkout in a single call. It returns nothing: results arrive on the delegate. Call it when the customer confirms, not in advance, because Banxa checkout must be loaded within one minute of order creation.

Requires a prior configure(config:) call. Otherwise it fails with APIError.sdkNotConfigured.


BanxaPaymentSDKDelegate

Three methods, each with a default no-op implementation. All callbacks are delivered on the main actor. All callback types are Banxa-owned: you never import or reference the underlying payment provider SDK.

extension MyViewController: BanxaPaymentSDKDelegate {

    func banxaDidCompleteCheckout(_ result: BanxaCheckoutResult) { }

    func banxaDidFail(error: Error) { }

    func banxaDidDismiss() { }
}
MethodFires when
banxaDidCompleteCheckout(_:)The customer completed payment.
banxaDidFail(error:)Any Banxa, network, validation, or checkout failure. Banxa-originated failures are APIError.
banxaDidDismiss()The customer closed checkout without completing.

BanxaCheckoutResult

FieldPopulated when
paymentIdThe native payment sheet was used.
orderIdThe native payment sheet was used.
statusThe native payment sheet was used.
rawQueryBanxa checkout was used. Contains the terminal success URL query string.

The success callback is a UI signal, not the authoritative order state. Confirm the final state from webhooks or Order Lookup before you credit a customer.


Models

CreateOrderRequest

FieldTypeRequiredDescription
cryptoStringYesCrypto asset symbol, for example ETH.
fiatStringYesFiat currency code, for example EUR.
fiatAmountStringYesFiat amount as a string.
paymentMethodIDString?YesBanxa payment method id, for example debit-credit-card.
walletAddressStringYesDestination wallet address.
emailStringYesCustomer email address.
redirectURLStringYesURL Banxa redirects to after checkout.
idString?NoYour order id.
blockchainString?NoExplicit blockchain network.
cryptoAmountString?NoCrypto amount when ordering by crypto value.
walletAddressTagString?NoTag or memo for chains that require it.
subPartnerIDString?NoSub-partner identifier.
metadataString?NoOpaque metadata string.
externalCustomerIDString?NoYour stable customer identifier.
externalOrderIDString?NoYour order reference.
discountCodeString?NoPromotion or discount code.
paymentMethodID is optional in the type, required in practice

paymentMethodID is declared as an optional in the Swift signature, but Banxa requires a value. Omitting it fails at payment execution rather than at compile time, so the compiler will not catch it for you. Always pass an id returned by fetchPaymentMethods.

A missing memo can permanently lose funds

XRP, XLM, EOS, and ATOM require a memo or tag. Pass it as walletAddressTag. An order to one of these chains without the memo can be unrecoverable.


Configuration endpoints

All configuration calls are async throws and require a configured SDK with non-blank credentials.

Countries

GET /{partnerID}/v2/countries. The list is the same for buy and sell.

let countries = try await BanxaPaymentSDK.shared.fetchCountries()
TypeFields
Countryid, description, states: [CountryState]?
CountryStateid, description

Fiats

GET /{partnerID}/v2/fiats/{orderType}.

let fiats = try await BanxaPaymentSDK.shared.fetchFiats(orderType: .buy)
TypeFields
OrderType.buy, .sell
Fiatid, description?, symbol?, supportedPaymentMethods: [FiatPaymentMethod]?
FiatPaymentMethodid, name?, minimum?, maximum?

Crypto

GET /{partnerID}/v2/crypto/{orderType}.

let assets = try await BanxaPaymentSDK.shared.fetchCrypto(orderType: .buy)
TypeFields
Cryptocurrencyid, description?, blockchains: [CryptoBlockchain]?
CryptoBlockchainid, description?, isDefaultBlockchain?, address?, network?, minimum?, unsupportedCountries: [String: [String]]?

In unsupportedCountries, the key is a country code and the value is the restricted state codes. An empty list means the whole country is restricted.

Payment methods

GET /{partnerID}/v2/payment-methods/{orderType}. Optionally filter by fiat.

let methods = try await BanxaPaymentSDK.shared.fetchPaymentMethods(orderType: .buy)
let usdOnly = try await BanxaPaymentSDK.shared.fetchPaymentMethods(orderType: .buy, fiat: "USD")
TypeFields
PaymentMethodid, name?, description?, supportedFiats: [String]?

Quotes

GET /{partnerID}/v2/quotes/{orderType}. Do not cache: call immediately before showing a price.

let request = QuoteRequest(
    paymentMethodID: "debit-credit-card",
    crypto: "ETH",
    blockchain: "ETH",
    fiat: "USD",
    fiatAmount: "200"
)
let quotes = try await BanxaPaymentSDK.shared.fetchQuotes(orderType: .buy, request: request)
TypeFields
QuoteRequestpaymentMethodID, crypto, blockchain, fiat, fiatAmount?, cryptoAmount?, externalCustomerID?, ipAddress?, discountCode?
QuotepaymentMethodID?, cryptoAmount?, fiatAmount?, processingFee?, networkFee?, discount: QuoteDiscount?
QuoteDiscountoriginalQuote: QuoteOriginalAmounts?, discountCode?
QuoteOriginalAmountsoriginalCryptoAmount?, originalNetworkFee?, originalProcessingFee?, originalFiatAmount?

Provide either fiatAmount or cryptoAmount. If both are set, Banxa uses cryptoAmount. Banxa may return a single object or an array when discount codes apply, and fetchQuotes always returns [Quote].


Error handling

Failures are surfaced through banxaDidFail(error:) as APIError. Each case provides a human-readable errorDescription.

CaseMeaning
.invalidURLThe endpoint URL could not be built.
.serverError(Int)Non-2xx HTTP response.
.unauthorized401 from Banxa. Check apiKey.
.decodingFailed(String)The response payload failed to decode.
.networkUnavailableNo network connectivity.
.missingCredentials([String])apiKey or partnerID was blank in BanxaConfig.
.sdkNotConfiguredstartPayment was called before configure(config:).
.unknown(String)Any other unexpected error.

Show user-facing messages only from validated error fields. Do not expose raw error strings that may include internal detail.


URL scheme

Register a URL scheme in your Info.plist and use it for redirectURL on CreateOrderRequest. This covers 3D Secure returns and the checkout return.


Not available in the SDK

CapabilityReasonAlternative
Order lookup by id or customerNot exposedOrder Lookup via the API
Full order list across all customersNot exposedGET /{partnerRef}/v2/orders via API integration
KYC data sharing (Sumsub token share)Requires HMAC authentication, which the SDK does not useKYC Sharing
Off-ramp (sell) ordersThe SDK covers buy orders onlyCreate Sell Order
Payment sheet themingNot exposed on iOSAvailable on Android. See Android SDK Reference

Example

import SwiftUI
import BanxaPaymentSDK

@main
struct DemoApp: App {

    init() {
        let config = BanxaConfig(
            apiKey: ProcessInfo.processInfo.environment["BANXA_API_KEY"] ?? "",
            partnerID: "your-partner-id",
            environment: .sandbox
        )
        BanxaPaymentSDK.shared.configure(config: config)
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

final class CheckoutCoordinator: NSObject, BanxaPaymentSDKDelegate {

    override init() {
        super.init()
        BanxaPaymentSDK.shared.delegate = self
    }

    func buy(from controller: UIViewController) {
        let request = CreateOrderRequest(
            crypto: "ETH",
            fiat: "EUR",
            fiatAmount: "40",
            walletAddress: "0x0000000000000000000000000000000000000000",
            email: "[email protected]",
            redirectURL: "your-app-scheme://banxa-return",
            paymentMethodID: "debit-credit-card"
        )
        BanxaPaymentSDK.shared.startPayment(request: request, controller: controller)
    }

    func banxaDidCompleteCheckout(_ result: BanxaCheckoutResult) {
        print("Payment complete:", result.paymentId ?? result.rawQuery ?? "-")
    }

    func banxaDidFail(error: Error) {
        print("Payment failed:", error.localizedDescription)
    }

    func banxaDidDismiss() {
        print("Customer dismissed checkout")
    }
}

Payment methods and supported fiats

Availability varies by partner, region, and order type. Treat fetchPaymentMethods as the source of truth. The table below is a static reference.

Payment method idSupported fiats
debit-credit-cardAED, ARS, AUD, BRL, CAD, CHF, CZK, DKK, EUR, GBP, HKD, IDR, INR, JPY, KRW, MXN, MYR, NGN, NOK, NZD, PHP, PLN, QAR, RUB, SAR, SEK, SGD, THB, TRY, TWD, USD, VND, ZAR
apple-payAUD, EUR, GBP, USD
google-payAUD, EUR, USD
payid-bank-transferAUD
pixBRL
zar-bank-transferZAR
pseCOP
khipuCLP
interac-bank-transferCAD
klarna-paynowEUR
ideal-bank-transferAUD, EUR
sepa-bank-transferEUR
gbp-bank-transferGBP
speiMXN

For the full list, see Supported Payment Methods.


Next steps