Wonder

iOS SDK

The iOS SDK lets you embed Wonder Payment Gateway's payment flow into your iOS application.

Workflow

Initiate the iOS SDK

To initiate the SDK, you need to know:

  1. Set up the Payment Configurations. Retrieve appID as a first step when initiating the SDK when you onboard on Wonder, in order to get access to our Payment Gateway configurations.
  2. For iOS SDK, Wechat Pay, Googl Pay and Apple Pay, you will be required to apply directly with the schemes to obtain the unique identifier, for the activation of those methods.
  3. To set up a method for future payments, you must generate a customer UUID for the Tokenisation process.
  4. Customer can opt to customise the UI of the payment elements, or follow the default UI settings.

Podfile

Add the SDK dependency via CocoaPods.

  1. Add the SDK dependency:
text
pod 'WonderPaymentSDK'
  1. Or pin a specific version:
text
pod 'WonderPaymentSDK', 'x.x.x'
INFO

Replace x.x.x with the latest SDK version, then run pod install to install the SDK.

Info.plist

The following Info.plist entries handle two directions of app-to-app communication: URL types let payment apps return to your app, whitelist lets your app open payment apps, and AppDelegate receives the returned result. WeChat Pay requires an additional whitelist entry.

  1. Add URL types

Register a custom URL scheme so third-party payment apps can redirect back to your app after payment.

text
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string>payment_sdk_demo</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>paydemo</string>
    </array>
  </dict>
</array>
INFO

paydemo here must match fromscheme in your payment config.

  1. Add whitelist

Declare which external apps your app is allowed to query and launch, so payment apps like WeChat Pay, Alipay, and Octopus can be opened.

text
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>weixin</string>
    <string>weixinULAPI</string>
    <string>weixinURLParamsAPI</string>
    <string>uppaysdk</string>
    <string>uppaywallet</string>
    <string>uppayx1</string>
    <string>uppayx2</string>
    <string>uppayx3</string>
    <string>octopus</string>
    <string>alipayhk</string>
    <string>alipays</string>
</array>
INFO

This is the opposite direction from URL types: whitelist lets your app open other apps, while URL types lets other apps return to yours.

  1. WeChatPay dependency

Required only if you use WeChat Pay. Without these three schemes, WeChat Pay cannot redirect back to your app.

text
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>weixin</string>
  <string>weixinULAPI</string>
  <string>weixinURLParamsAPI</string>
</array>
  1. Handle redirect in AppDelegate.swift

Receive the redirect from third-party payment apps and pass it to the SDK.

text
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return WonderPayment.handleOpenURL(url: url)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return WonderPayment.handleOpenURL(url: url)
}
INFO

Without this, the SDK cannot receive the payment result when the user returns from WeChat or Alipay or other payment methods.

iOS SDK configuration

The iOS SDK takes 2 configuration objects:

ObjectControlsExample
PaymentConfigHow the payment behaves — merchant identity, environment, payment methods.appId,environment,applePay.
UICOnfigHow the checkout looks — colors, radius, interaction stylebackground,borderRadius.
text
WonderPayment.initSDK(
  paymentConfig: PaymentConfig(
      appId: "f3615c8b-e402-48ac-bcd9-5af7a473ebdc",
      customerId: "87d8f5a5-e745-456d-938e-065bb77cedc7",
      fromscheme: "paydemo",
      // staging, alpha, production
      environment: .staging,
      /*
        public enum Locale: String {
          case zh_CN = "zh-CN", zh_HK = "zh-HK", en_US = "en-US"
        }
      */
      locale: .zh_HK,
      wechat: WechatConfig(
          appId: "wx5ac0eb5676b32e80",
          universalLink: "https://heypark.gobindo.com/"
      ),
      applePay: ApplePayConfig(
          merchantIdentifier: "merchant.app.wonder.hq.staging",
          merchantName: "Jek",
          countryCode: "HK"
      )
  ),
  uiConfig: UIConfig(
      displayStyle: .confirm
  )
)
  1. PaymentConfig
FieldRequiredDescription
appIdYesThe APP ID generated on Wonder Dashboard.
customerIdNoNeeded for tokenisation. Create via create customerAPI.
fromschemeYesUsed to redirect back to your app after app-to-app payment.
environmentNoAvailable parameter:.staging, .alpha,.production.
localeNoAvailable parameter:.zh_CN, .zh_HK,.en_US.
wechatNoEnable WeChat Pay.
WechatConfig.appIdYesThe appId applied on WeChat Pay.
WechatConfig.universalLinkYesThe official website of the merchant's app.
applePayNoEnable Apple Pay.
ApplePayConfig.merchantIdentifierYesApple merchant identifier.
ApplePayConfig.merchantNameYesMerchant display name for Apple Pay.
ApplePayConfig.countryCodeYesTwo-letter ISO 3166 country code.
  1. UIConfig
FieldRequiredDescription
backgroundNoDefault: #FFFFFF
secondaryBackgroundNoDefault: #F7F8F9
primaryTextColorNoDefault: #000000
secondaryTextColorNoDefault: #8E8E93
primaryButtonColorNoDefault: #FFFFFF
primaryButtonBackgroundNoDefault: #000000
textFieldBackgroundNoDefault: #F5F5F5
linkColorNoDefault: #0094FF
errorColorNoDefault: #FC2E01
successColorNoDefault: #4CD964
borderColorNoDefault: #565656
dividerColorNoDefault: #EBEFF2
borderRadiusNoDefault: 12
displayStyleNoconfirm,oneClick. Default:oneClick.
showResultNoWhether to show Wonder's pre-built result page. Default: true.

Payment

Wonder support 2 ways to make payment.

FieldRequiredDescription
amountYesOrder amount.
currencyYesOrder currency.
orderNumberYesOrder number.
paymentMethodNoNot needed when calling present; required when calling pay.
supportedPaymentModesNoSupported payment modes. Available parameter: preAuth, autoDebit, sale.
lineItemsNoOrder line item details.
statusOutputAvailable parameter: completed, cancelled, failed.
codeOutputIf the payment goes wrong, an error code is returned.
messageOutputIf the payment goes wrong, an error message is returned.
  1. Present - Complete payment flow

Initialize a Payment Intent and complete payment immediately in one flow:

text
let paymentIntent = PaymentIntent(
  amount: 0.1, currency: "HKD", orderNumber: "202403081229292766405205"
)
WonderPayment.present(intent: paymentIntent) { result in
  print(result.status)
}
  1. Select + pay — Alternative payment flow

2 steps for this flow are needed:

Step 1 - Select a payment method (no charge yet):

text
let paymentIntent = PaymentIntent(
    amount: 0.1,
    currency: "HKD",
    orderNumber: "202404181750209612110734"
)
let newIntent = paymentIntent.copy()
 WonderPayment.select(intent: paymentIntent) {
    method in
    newIntent.paymentMethod = method
}

Step 2 - Start the payment:

text
WonderPayment.pay(intent: newIntent) { result in
    print(result.status)
}
  1. Preview — Preview payment method

View current payment methods and add a verified credit card.

text

WonderPayment.preview()