Airwallex logo

Embedded Payment Element integration

Copy for LLMView as Markdown

AWXPaymentElement provides a flexible way to embed payment UI directly into your own view hierarchy. Unlike AWXUIContext.launchPayment() which presents a full payment sheet as a view controller, AWXPaymentElement returns a UIView that you can place anywhere in your layout.

Make sure you add dependency for Airwallex or AirwallexPaymentSheet.

Keep in mind that:

  • The embedded view requires Auto Layout constraints for proper sizing.
  • The view's height updates automatically based on content.
  • Keyboard handling is the host app's responsibility.

How it works

The diagram below depicts the integration flow for a card payment.

iOS Card one-off

Prepare payment session

Before creating the embedded element, you need to create a payment session. See Prepare payment session for details on setting up the environment, creating a customer, payment intent, and payment session.

Display a list of available payment methods inside your own view hierarchy.

swift
1let configuration = AWXPaymentElement.Configuration()
2configuration.layout = .tab // or .accordion
3
4let element = try await AWXPaymentElement.create(
5 session: session,
6 delegate: self, // AWXPaymentElementDelegate
7 configuration: configuration
8)
9
10// Add the element's view to your view hierarchy
11let paymentView = element.view
12paymentView.translatesAutoresizingMaskIntoConstraints = false
13containerView.addSubview(paymentView)

Create embedded card element

Display only the card payment form for adding new cards.

swift
1let configuration = AWXPaymentElement.Configuration()
2configuration.elementType = .addCard
3configuration.supportedCardBrands = [.visa, .mastercard, .unionPay] // defaults to all available brands
4
5let element = try await AWXPaymentElement.create(
6 session: session,
7 delegate: self, // AWXPaymentElementDelegate
8 configuration: configuration
9)
10
11// Add the element's view to your view hierarchy
12let paymentView = element.view
13paymentView.translatesAutoresizingMaskIntoConstraints = false
14containerView.addSubview(paymentView)

Configuration options

We provide tab and accordion styles for our embedded payment sheet:

TabAccordion
Tab layoutAccordion layout

Other configuration options

PropertyDescriptionDefault
elementType.paymentSheet (all payment methods) or .addCard (card only).paymentSheet
layout.tab or .accordion (only applies to .paymentSheet).tab
supportedCardBrandsAccepted card brands (only applies to .addCard)All available brands
applePayButtonCustomize Apple Pay button appearance (for example, showsAsPrimaryButton, buttonType, disableCardArt)
checkoutButtonCustomize checkout button (for example, title)
appearance.tintColorPrimary brand color used throughout the payment elementSDK default

Handle payment element events

Implement AWXPaymentElementDelegate to receive payment lifecycle callbacks.

swift
1extension YourViewController: AWXPaymentElementDelegate {
2 // Required - called when payment completes
3 func paymentElement(
4 _ element: AWXPaymentElement,
5 didCompleteFor paymentMethod: String,
6 with status: AirwallexPaymentStatus,
7 error: Error?
8 ) {
9 // call back for status success / in progress / failure / cancel
10 }
11
12 // Optional - show/hide your own loading indicator
13 func paymentElement(
14 _ element: AWXPaymentElement,
15 onProcessingStateChangedFor paymentMethod: String,
16 isProcessing: Bool
17 ) {
18 // Show or hide loading indicator
19 }
20
21 // Optional - called when a payment consent is created
22 func paymentElement(
23 _ element: AWXPaymentElement,
24 didCompleteFor paymentMethod: String,
25 withPaymentConsentId paymentConsentId: String
26 ) {
27 // Store consent ID for future use
28 }
29
30 // Optional - scroll invalid input field into view
31 func paymentElement(
32 _ element: AWXPaymentElement,
33 validationFailedFor paymentMethod: String,
34 invalidInputView: UIView
35 ) {
36 let rect = invalidInputView.convert(invalidInputView.bounds, to: scrollView)
37 scrollView.scrollRectToVisible(rect, animated: true)
38 }
39}

Retrieve the payment result

For any actions subsequent to the payment such as shipping goods or sending email receipts, you can retrieve the payment result using the following options:

Was this page helpful?