Wonder

Flutter SDK

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

Workflow

Initiate the Flutter 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 Flutter SDK, Wechat Pay, Google 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.

pubspec.yaml

Add the SDK dependency via pub:

text
dependencies:
  wonder_payment_plugin: ^x.x.x

iOS Configuration files

The Flutter SDK wraps the native iOS SDK, so the same iOS configuration is required.

  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>YOUR_APP_SCHEME</string>
    </array>
  </dict>
</array>
INFO

YOUR_APP_SCHEME 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. This is the opposite direction from URL types: whitelist lets your app open other apps, while URL types lets other apps return to yours.

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>
  1. WeChatPay dependency

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

text
<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleTypeRole</key>
		<string>Editor</string>
		<key>CFBundleURLName</key>
		<string>wechat_pay</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>YOUR_WECHAT_APP_ID</string>
		</array>
	</dict>
</array>
INFO

YOUR_WECHAT_APP_ID must match WechatConfig.appId in your payment config.

  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.

Android Configuration files

The Flutter SDK wraps the native Android SDK, so the same Android configuration is required.

  1. Add the repository

Add the Wonder Maven repository in your project-level build.gradle:

text
dependencyResolutionManagement {
  repositories {
    mavenCentral()
    maven {
      url 'https://raw.githubusercontent.com/wonder-sources/WonderPayment-Android/master'
    }
  }
}
  1. Register result Activities

Register a result Activity for each third-party payment channel you use. Each channel redirects back to your app through its own Activity and URL scheme. Only add the ones you actually enable.

text
<!-- WeChat Pay: Create an empty Activity in the application package name directory -->
<activity-alias
    android:name=".wxapi.WXPayEntryActivity"
    android:exported="true"
    android:targetActivity="com.wonder.payment.sdk.wxapi.WXPayEntryResultActivity" />

<!-- Alipay Auto Debit -->
<activity
    android:name="com.wonder.payment.sdk.activity.AlipayResultActivity"
    android:exported="true"
    android:launchMode="singleTask"
    android:taskAffinity="${applicationId}"
    android:theme="@android:style/Theme.Translucent.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="alipay"
            android:scheme="paydemo" />
    </intent-filter>
</activity>

<!-- Payme -->
<activity
    android:name="com.wonder.payment.sdk.activity.PaymeResultActivity"
    android:exported="true"
    android:launchMode="singleTask"
    android:taskAffinity="${applicationId}"
    android:theme="@android:style/Theme.Translucent.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="payme"
            android:scheme="paydemo" />
    </intent-filter>
</activity>
INFO

paydemo here must match fromScheme in your payment config.

Flutter SDK configuration

The Flutter 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

WonderPaymentPlugin.init(
    paymentConfig: PaymentConfig(
      environment: PaymentEnvironment.staging, // [staging | alpha | production]
      appId: "YOUR_APP_ID",
      fromScheme: "YOUR_APP_SCHEME",
      wechat: WechatConfig(
        appId: "WECHAT_APP_ID",
        universalLink: "YOUR_APP_UNIVERSAL_LINK",
      ),
      applePay: ApplePayConfig(
        merchantIdentifier: 'YOUR_MERCHANT_IDENTIFIER',
        merchantName: 'YOUR_MERCHANT_NAME',
        countryCode: 'HK',
      ),
      googlePay: GooglePayConfig(
        merchantName: 'YOUR_MERCHANT_NAME',
        merchantId: 'YOUR_MERCHANT_IDENTIFIER',
        countryCode: 'HK',
        currencyCode: 'HKD',
      ),
    ),
    uiConfig: UIConfig(
      displayStyle: 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:PaymentEnvironment.staging, PaymentEnvironment.alpha,PaymentEnvironment.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.
googlePayNoEnable Google Pay.
GoogleConfig.countryCodeYesISO 3166-1 alpha-2 country code where the transaction is processed.
GoogleConfig.currencyCodeYesThe ISO 4217 alphabetic currency code.
GoogleConfig.merchantIdYesA Google merchant identifier issued after registration with the Google Pay & Wallet Console.
GoogleConfig.merchantNameYesMerchant name encoded as UTF-8. Merchant name is rendered in the payment sheet.
  1. UIConfig
FieldRequiredDescription
backgroundNoDefault: #FFFFFF
secondaryBackgroundNoDefault: #F7F8F9
primaryTextColorNoDefault: #000000
secondaryTextColorNoDefault: #8E8E93
primaryButtonColorNoDefault: #FFFFFF
primaryButtonBackgroundNoDefault: #000000
secondaryButtonColorNoDefault: #000000
secondaryButtonBackgroundNoDefault: #FFFFFF
textFieldBackgroundNoDefault: #F5F5F5
linkColorNoDefault: #0094FF
successColorNoDefault: #4CD964
borderColorNoDefault: #565656
dividerColorNoDefault: #EBEFF2
errorColorNoDefault: #FC2E01
borderRadiusNoDefault: 12.0
displayStyleNoconfirm,oneClick. Default:oneClick.
paymentRetriesEnabledNoIf payment fails, whether the user can try again or return a failed result.

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

final intent = PaymentIntent(
    amount: 0.1,
    currency: "HKD",
    orderNumber: "202403081229292766405205",
  );

final result = await WonderPaymentPlugin.present(intent);
  1. Select + pay — Alternative payment flow

2 steps for this flow are needed:

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

text
final intent = PaymentIntent(
    amount: 0.1,
    currency: "HKD",
    orderNumber: "202403081229292766405205",
  );

final method = await WonderPaymentPlugin.select(intent.transactionType);
intent.paymentMethod = method;

Step 2 - Start the payment:

final result = await WonderPaymentPlugin.pay(intent);
  1. Preview — Preview payment method

View current payment methods and add a verified credit card.

text
WonderPaymentPlugin.preview()