Skip to content

How it works

Learn about how card components work on iOS.

Card components allow you to easily integrate a highly secure and customisable payment solution into your iOS app. By offering full control over layout, styling, and field visibility, card components ensure a seamless and branded payment experience, while maintaining top-tier security with PXP's Token Vault service and 3DS service.

The iOS SDK is built for SwiftUI and uses Swift's modern async/await patterns. You configure your checkout once, create the components you need, and render them in your view hierarchy using buildContent().

Integration steps

A full integration involves the following steps:

  1. Set up the Unity Portal: To use the SDK, you first need to activate the Components and Card services in the Unity Portal. You also need to whitelist any iOS bundle identifiers that you'll be sending requests from.
  2. Install the SDK: Add PXPCheckoutSDK to your Xcode project using Swift Package Manager.
  3. Initialise checkout: Create a CheckoutConfig with your session data, transaction details, and merchant identifiers, then call PxpCheckout.initialize(config:).
  4. Create and configure components: Use pxpCheckout.create(_:componentConfig:) to create the components you need. Configure each component with labels, validation rules, and callbacks.
  5. Embed components: Add the components to your SwiftUI views by calling component.buildContent() in your view hierarchy.
  6. Handle results: Implement callbacks like onPostAuthorisation and onSubmitError to handle payment outcomes. Add analytics tracking to monitor your customers' payment journeys.
  7. Submit and view transactions: Call the submitAsync() method on your CardSubmitComponent instance. The SDK then validates all form data, tokenises the card (if needed), runs 3DS authentication when required, and sends the transaction request to PXP.
    After PXP processes the payment, the SDK receives the response and triggers an onPostAuthorisation callback that receives a result object containing the transaction identifiers and state. You can use these identifiers to retrieve the full transaction details from your backend via Unity APIs.

Component types

There are two types of card components:

  • Pre-built components: For convenience and speed. They offer ready-to-use user interfaces, pre-designed and responsive layouts, and a consistent experience.
  • Standalone components: For maximum flexibility and control. They offer individual field control, custom layouts, and fine-grained validation.

You can think of pre-built components as containers that manage multiple standalone components internally, while standalone components are individual building blocks you assemble yourself.

Use cases

Use pre-built components if:

  • You want a complete payment form with minimal setup.
  • You're happy with pre-designed, responsive payment forms.
  • You want to get up and running quickly, with minimal custom styling.
  • You want a proven user interface that follows payment best practices.

Use standalone components if:

  • You want to position and style each payment field (card number, expiry, CVC, etc.) separately in your own custom user interface.
  • You're building a completely custom payment form layout that doesn't fit standard patterns.
  • You need to handle validation for each field independently.
  • You're integrating with existing forms or complex UI frameworks.

Available components

ComponentDescription
Billing addressCollect a customer's billing address to use for AVS checks during authorisation.
Card-on-fileAllow customers to select previously tokenised cards for quick and easy payments.
Click-onceAllow customers to pay with just one click, using a tokenised card.
New cardSecurely capture full card details for first-time users.

Swift examples

import SwiftUI
import PXPCheckoutSDK

// Create checkout config with session and transaction data
let pxpCheckout = try PxpCheckout.initialize(config: checkoutConfig)

// Configure submit callbacks
var submitConfig = CardSubmitComponentConfig()
submitConfig.onPreAuthorisation = { _ async in TransactionInitiationData() }
submitConfig.onPostAuthorisation = { _ in /* handle success / decline */ }
submitConfig.onSubmitError = { _ in /* handle errors */ }

// Create new card component
let newCardConfig = NewCardComponentConfig(submit: submitConfig)
let newCard = try pxpCheckout.create(.newCard, componentConfig: newCardConfig) as! NewCardComponent

// In SwiftUI:
// newCard.buildContent()

Supported transaction intents

When you initiate a transaction, you have to provide key information about the transaction method, as well as the amount and currency.

The transaction method is made up of three elements:

  • The entry type, which describes the origin of the transaction and determines the supported payment methods and available features. For components, this is always ecom.
  • The funding type, which describes the method used to fund the transaction. In this case, card.
  • The intent, which describes the purpose of a transaction, indicating the intended money flow direction. Each intent dictates a specific transaction flow and affects how the transaction is handled by the system.

For card transactions, we support the following intents:

IntentDescription
.authorisationReserve funds on the customer's payment method.
.estimatedAuthorisationReserve funds on the customer's payment method, based on an estimated amount. This method is particularly useful in environments such as hotels, car rental agencies, and fuel stations, where the final charge may vary based on additional services or usage.
.purchaseCapture funds immediately after authorisation.
.payoutSend funds to a recipient.
.verificationVerify that a card is legitimate and active, without reserving any funds or completing a purchase. This method is particularly useful in environments such as hotels, car rental agencies, and other scenarios where it's important to validate the card upfront, but the final transaction amount may not be known or processed immediately.

We support recurring payments for subscription-based services where payments are automatically made on a regular schedule (e.g. monthly memberships, subscription services).