diff --git a/dartdoc_options.yaml b/dartdoc_options.yaml index 64c25f0..7585a7b 100644 --- a/dartdoc_options.yaml +++ b/dartdoc_options.yaml @@ -1,4 +1,4 @@ dartdoc: linkToSource: root: '.' - uriTemplate: 'https://github.com/airwallex/airwallex-payment-flutter/tree/main/%f%#L%l%' + uriTemplate: 'https://github.com/airwallex/airwallex-payment-flutter/tree/%v%/%f%#L%l%' diff --git a/lib/airwallex.dart b/lib/airwallex.dart index d4c8d73..fdfc176 100644 --- a/lib/airwallex.dart +++ b/lib/airwallex.dart @@ -1,3 +1,10 @@ +/// Public API for the Airwallex Flutter payment plugin. +/// +/// Import this library to initialize the SDK and present payment flows +/// (full checkout sheet, card-only flow, Google Pay, Apple Pay) from your +/// Flutter app. See [Airwallex] for the entry-point class. +library; + import 'dart:ui'; import 'package:airwallex_payment_flutter/types/environment.dart'; @@ -12,18 +19,28 @@ import '/types/payment_sheet_configuration.dart'; import 'airwallex_payment_flutter_platform_interface.dart'; +/// Entry point for the Airwallex payment SDK. +/// +/// Call [Airwallex.initialize] once at app startup, then use instance +/// methods such as [presentEntirePaymentFlow], [presentCardPaymentFlow], +/// [payWithCardDetails], [startGooglePay], or [startApplePay] to drive +/// individual payments. class Airwallex { /// Initializes the Airwallex SDK. Call this once at app startup before invoking any other payment method. /// /// @param environment - The Airwallex environment to connect to. Defaults to `Environment.production`. /// @param enableLogging - When `true`, the SDK emits logs to the console. Android only. Defaults to `true`. /// @param saveLogToLocal - When `true`, logs are also persisted to a local file for debugging. Defaults to `false`. - static void initialize({ - Environment environment = Environment.production, bool enableLogging = true, bool saveLogToLocal = false}) { + static void initialize( + {Environment environment = Environment.production, + bool enableLogging = true, + bool saveLogToLocal = false}) { if (enableLogging && kDebugMode) { - debugPrint('[AirwallexSdk] Current connected environment: ${environment.name}'); + debugPrint( + '[AirwallexSdk] Current connected environment: ${environment.name}'); } - AirwallexPaymentFlutterPlatform.instance.initialize(environment, enableLogging, saveLogToLocal); + AirwallexPaymentFlutterPlatform.instance + .initialize(environment, enableLogging, saveLogToLocal); } /// Presents the full Airwallex payment sheet, letting the customer pick any supported payment method @@ -61,7 +78,8 @@ class Airwallex { /// @param card - The card details to charge. /// @param saveCard - When `true`, the card is saved as a payment consent for future use. /// @returns The result of the payment attempt. - Future payWithCardDetails(BaseSession session, Card card, bool saveCard) { + Future payWithCardDetails( + BaseSession session, Card card, bool saveCard) { return AirwallexPaymentFlutterPlatform.instance .payWithCardDetails(session, card, saveCard); } @@ -71,7 +89,8 @@ class Airwallex { /// @param session - The payment session describing the intent, amount, currency, and customer. /// @param consent - The payment consent to charge. /// @returns The result of the payment attempt. - Future payWithConsent(BaseSession session, PaymentConsent consent) { + Future payWithConsent( + BaseSession session, PaymentConsent consent) { return AirwallexPaymentFlutterPlatform.instance .payWithConsent(session, consent); } diff --git a/lib/airwallex_payment_flutter_method_channel.dart b/lib/airwallex_payment_flutter_method_channel.dart index 04c602a..08c3d8c 100644 --- a/lib/airwallex_payment_flutter_method_channel.dart +++ b/lib/airwallex_payment_flutter_method_channel.dart @@ -35,8 +35,8 @@ class MethodChannelAirwallexPaymentFlutter BaseSession session, { PaymentSheetConfiguration? configuration, }) async { - final result = await methodChannel.invokeMethod( - 'presentEntirePaymentFlow', { + final result = + await methodChannel.invokeMethod('presentEntirePaymentFlow', { 'session': session.toJson(), if (configuration != null) 'configuration': configuration.toJson(), }); @@ -104,7 +104,7 @@ class MethodChannelAirwallexPaymentFlutter } } - PaymentResult parsePaymentResult(result) { + PaymentResult parsePaymentResult(Map? result) { if (result == null) { throw Exception('Result is null'); } diff --git a/lib/airwallex_payment_flutter_platform_interface.dart b/lib/airwallex_payment_flutter_platform_interface.dart index 60303cc..cbefa83 100644 --- a/lib/airwallex_payment_flutter_platform_interface.dart +++ b/lib/airwallex_payment_flutter_platform_interface.dart @@ -17,7 +17,8 @@ abstract class AirwallexPaymentFlutterPlatform extends PlatformInterface { static final Object _token = Object(); - static AirwallexPaymentFlutterPlatform _instance = MethodChannelAirwallexPaymentFlutter(); + static AirwallexPaymentFlutterPlatform _instance = + MethodChannelAirwallexPaymentFlutter(); /// The default instance of [AirwallexPaymentFlutterPlatform] to use. /// @@ -41,21 +42,25 @@ abstract class AirwallexPaymentFlutterPlatform extends PlatformInterface { BaseSession session, { PaymentSheetConfiguration? configuration, }) { - throw UnimplementedError('presentEntirePaymentFlow() has not been implemented.'); + throw UnimplementedError( + 'presentEntirePaymentFlow() has not been implemented.'); } Future presentCardPaymentFlow( BaseSession session, { List? supportedBrands, }) { - throw UnimplementedError('presentCardPaymentFlow() has not been implemented.'); + throw UnimplementedError( + 'presentCardPaymentFlow() has not been implemented.'); } - Future payWithCardDetails(BaseSession session, Card card, bool saveCard) { + Future payWithCardDetails( + BaseSession session, Card card, bool saveCard) { throw UnimplementedError('payWithCardDetails() has not been implemented.'); } - Future payWithConsent(BaseSession session, PaymentConsent consent) { + Future payWithConsent( + BaseSession session, PaymentConsent consent) { throw UnimplementedError('payWithConsent() has not been implemented.'); } diff --git a/lib/types/apple_pay_options.dart b/lib/types/apple_pay_options.dart index 637b2e8..678e162 100644 --- a/lib/types/apple_pay_options.dart +++ b/lib/types/apple_pay_options.dart @@ -26,7 +26,8 @@ class ApplePayOptions { this.totalPriceLabel, }); - factory ApplePayOptions.fromJson(Map json) => _$ApplePayOptionsFromJson(json); + factory ApplePayOptions.fromJson(Map json) => + _$ApplePayOptionsFromJson(json); Map toJson() => _$ApplePayOptionsToJson(this); } @@ -73,7 +74,8 @@ class CartSummaryItem { this.type, }); - factory CartSummaryItem.fromJson(Map json) => _$CartSummaryItemFromJson(json); + factory CartSummaryItem.fromJson(Map json) => + _$CartSummaryItemFromJson(json); Map toJson() => _$CartSummaryItemToJson(this); } @@ -83,4 +85,4 @@ class CartSummaryItem { enum CartSummaryItemType { finalType, pendingType, -} \ No newline at end of file +} diff --git a/lib/types/billing.dart b/lib/types/billing.dart index 69aa4ec..44966f8 100644 --- a/lib/types/billing.dart +++ b/lib/types/billing.dart @@ -2,7 +2,8 @@ import 'package:json_annotation/json_annotation.dart'; part 'billing.g.dart'; -@JsonSerializable(explicitToJson: true, fieldRename: FieldRename.snake, includeIfNull: false) +@JsonSerializable( + explicitToJson: true, fieldRename: FieldRename.snake, includeIfNull: false) class Billing { String? firstName; String? lastName; @@ -22,7 +23,8 @@ class Billing { this.address, }); - factory Billing.fromJson(Map json) => _$BillingFromJson(json); + factory Billing.fromJson(Map json) => + _$BillingFromJson(json); Map toJson() => _$BillingToJson(this); } @@ -35,9 +37,11 @@ class BillingAddress { String? postcode; String? state; - BillingAddress({this.city, this.countryCode, this.street, this.postcode, this.state}); - - factory BillingAddress.fromJson(Map json) => _$BillingAddressFromJson(json); + BillingAddress( + {this.city, this.countryCode, this.street, this.postcode, this.state}); + + factory BillingAddress.fromJson(Map json) => + _$BillingAddressFromJson(json); Map toJson() => _$BillingAddressToJson(this); -} \ No newline at end of file +} diff --git a/lib/types/google_pay_options.dart b/lib/types/google_pay_options.dart index 14469c1..be8f4e4 100644 --- a/lib/types/google_pay_options.dart +++ b/lib/types/google_pay_options.dart @@ -41,7 +41,8 @@ class GooglePayOptions { }) : allowedCardNetworks = allowedCardNetworks ?? googlePaySupportedNetworks(); - factory GooglePayOptions.fromJson(Map json) => _$GooglePayOptionsFromJson(json); + factory GooglePayOptions.fromJson(Map json) => + _$GooglePayOptionsFromJson(json); Map toJson() => _$GooglePayOptionsToJson(this); } @@ -57,7 +58,8 @@ class BillingAddressParameters { this.phoneNumberRequired = false, }); - factory BillingAddressParameters.fromJson(Map json) => _$BillingAddressParametersFromJson(json); + factory BillingAddressParameters.fromJson(Map json) => + _$BillingAddressParametersFromJson(json); Map toJson() => _$BillingAddressParametersToJson(this); } @@ -82,7 +84,8 @@ class ShippingAddressParameters { this.phoneNumberRequired = false, }); - factory ShippingAddressParameters.fromJson(Map json) => _$ShippingAddressParametersFromJson(json); + factory ShippingAddressParameters.fromJson(Map json) => + _$ShippingAddressParametersFromJson(json); Map toJson() => _$ShippingAddressParametersToJson(this); } diff --git a/lib/types/merchant_trigger_reason.dart b/lib/types/merchant_trigger_reason.dart index fbeb047..1c9acbe 100644 --- a/lib/types/merchant_trigger_reason.dart +++ b/lib/types/merchant_trigger_reason.dart @@ -6,4 +6,4 @@ enum MerchantTriggerReason { unscheduled, scheduled, -} \ No newline at end of file +} diff --git a/lib/types/next_triggered_by.dart b/lib/types/next_triggered_by.dart index 78c9e0d..623315b 100644 --- a/lib/types/next_triggered_by.dart +++ b/lib/types/next_triggered_by.dart @@ -2,4 +2,4 @@ enum NextTriggeredBy { merchant, customer, -} \ No newline at end of file +} diff --git a/lib/types/payment_consent.dart b/lib/types/payment_consent.dart index 1a2bdb9..dcb789d 100644 --- a/lib/types/payment_consent.dart +++ b/lib/types/payment_consent.dart @@ -9,7 +9,8 @@ part 'payment_consent.g.dart'; /// A reusable payment authorization tied to a customer and a payment method. /// Created during a `RecurringSession` / `RecurringWithIntentSession` flow, /// and later passed to `payWithConsent` to charge without re-prompting the customer. -@JsonSerializable(explicitToJson: true, fieldRename: FieldRename.snake, includeIfNull: false) +@JsonSerializable( + explicitToJson: true, fieldRename: FieldRename.snake, includeIfNull: false) class PaymentConsent { String? id; String? requestId; @@ -42,15 +43,17 @@ class PaymentConsent { this.updatedAt, this.clientSecret, }); - - factory PaymentConsent.fromJson(Map json) => _$PaymentConsentFromJson(json); + + factory PaymentConsent.fromJson(Map json) => + _$PaymentConsentFromJson(json); Map toJson() => _$PaymentConsentToJson(this); } /// The payment instrument attached to a `PaymentConsent` — typically a saved card, /// along with its billing details. -@JsonSerializable(explicitToJson: true, fieldRename: FieldRename.snake, includeIfNull: false) +@JsonSerializable( + explicitToJson: true, fieldRename: FieldRename.snake, includeIfNull: false) class PaymentMethod { String? id; String? type; @@ -66,7 +69,8 @@ class PaymentMethod { this.customerId, }); - factory PaymentMethod.fromJson(Map json) => _$PaymentMethodFromJson(json); + factory PaymentMethod.fromJson(Map json) => + _$PaymentMethodFromJson(json); Map toJson() => _$PaymentMethodToJson(this); -} \ No newline at end of file +} diff --git a/lib/types/payment_result.dart b/lib/types/payment_result.dart index 2158c44..abc56ac 100644 --- a/lib/types/payment_result.dart +++ b/lib/types/payment_result.dart @@ -12,8 +12,7 @@ abstract class PaymentResult { class PaymentSuccessResult extends PaymentResult { final String? paymentConsentId; - PaymentSuccessResult({this.paymentConsentId}) - : super('success'); + PaymentSuccessResult({this.paymentConsentId}) : super('success'); } /// The payment has been submitted but its final outcome is not yet known. @@ -25,4 +24,4 @@ class PaymentInProgressResult extends PaymentResult { /// The customer cancelled the payment flow before it completed. class PaymentCancelledResult extends PaymentResult { PaymentCancelledResult() : super('cancelled'); -} \ No newline at end of file +} diff --git a/lib/types/payment_session.dart b/lib/types/payment_session.dart index 1c07ac9..31c67fe 100644 --- a/lib/types/payment_session.dart +++ b/lib/types/payment_session.dart @@ -51,7 +51,7 @@ abstract class BaseSession { } /// A one-off payment against a payment intent. -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, createFactory: false) class OneOffSession extends BaseSession { String paymentIntentId; bool? autoCapture; @@ -81,7 +81,7 @@ class OneOffSession extends BaseSession { /// A session that sets up a payment consent for future recurring charges /// without charging the customer right now. -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, createFactory: false) class RecurringSession extends BaseSession { NextTriggeredBy nextTriggeredBy; MerchantTriggerReason merchantTriggerReason; @@ -109,7 +109,7 @@ class RecurringSession extends BaseSession { /// A session that charges a payment intent now and sets up a payment consent /// for future recurring charges in a single step. -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, createFactory: false) class RecurringWithIntentSession extends BaseSession { String paymentIntentId; bool? autoCapture; diff --git a/lib/types/payment_session.g.dart b/lib/types/payment_session.g.dart index 5870237..383043e 100644 --- a/lib/types/payment_session.g.dart +++ b/lib/types/payment_session.g.dart @@ -6,35 +6,6 @@ part of 'payment_session.dart'; // JsonSerializableGenerator // ************************************************************************** -OneOffSession _$OneOffSessionFromJson(Map json) => - OneOffSession( - customerId: json['customerId'] as String?, - clientSecret: json['clientSecret'] as String, - shipping: json['shipping'] == null - ? null - : Shipping.fromJson(json['shipping'] as Map), - isBillingRequired: json['isBillingRequired'] as bool?, - isEmailRequired: json['isEmailRequired'] as bool?, - currency: json['currency'] as String, - countryCode: json['countryCode'] as String, - amount: (json['amount'] as num).toDouble(), - returnUrl: json['returnUrl'] as String?, - googlePayOptions: json['googlePayOptions'] == null - ? null - : GooglePayOptions.fromJson( - json['googlePayOptions'] as Map), - applePayOptions: json['applePayOptions'] == null - ? null - : ApplePayOptions.fromJson( - json['applePayOptions'] as Map), - paymentMethods: (json['paymentMethods'] as List?) - ?.map((e) => e as String) - .toList(), - paymentIntentId: json['paymentIntentId'] as String, - autoCapture: json['autoCapture'] as bool?, - hidePaymentConsents: json['hidePaymentConsents'] as bool?, - )..type = json['type'] as String; - Map _$OneOffSessionToJson(OneOffSession instance) => { 'type': instance.type, @@ -55,36 +26,6 @@ Map _$OneOffSessionToJson(OneOffSession instance) => 'hidePaymentConsents': instance.hidePaymentConsents, }; -RecurringSession _$RecurringSessionFromJson(Map json) => - RecurringSession( - customerId: json['customerId'] as String?, - clientSecret: json['clientSecret'] as String, - shipping: json['shipping'] == null - ? null - : Shipping.fromJson(json['shipping'] as Map), - isBillingRequired: json['isBillingRequired'] as bool?, - isEmailRequired: json['isEmailRequired'] as bool?, - currency: json['currency'] as String, - countryCode: json['countryCode'] as String, - amount: (json['amount'] as num).toDouble(), - returnUrl: json['returnUrl'] as String?, - googlePayOptions: json['googlePayOptions'] == null - ? null - : GooglePayOptions.fromJson( - json['googlePayOptions'] as Map), - applePayOptions: json['applePayOptions'] == null - ? null - : ApplePayOptions.fromJson( - json['applePayOptions'] as Map), - paymentMethods: (json['paymentMethods'] as List?) - ?.map((e) => e as String) - .toList(), - nextTriggeredBy: - $enumDecode(_$NextTriggeredByEnumMap, json['nextTriggeredBy']), - merchantTriggerReason: $enumDecode( - _$MerchantTriggerReasonEnumMap, json['merchantTriggerReason']), - )..type = json['type'] as String; - Map _$RecurringSessionToJson(RecurringSession instance) => { 'type': instance.type, @@ -115,39 +56,6 @@ const _$MerchantTriggerReasonEnumMap = { MerchantTriggerReason.scheduled: 'scheduled', }; -RecurringWithIntentSession _$RecurringWithIntentSessionFromJson( - Map json) => - RecurringWithIntentSession( - customerId: json['customerId'] as String?, - clientSecret: json['clientSecret'] as String, - shipping: json['shipping'] == null - ? null - : Shipping.fromJson(json['shipping'] as Map), - isBillingRequired: json['isBillingRequired'] as bool?, - isEmailRequired: json['isEmailRequired'] as bool?, - currency: json['currency'] as String, - countryCode: json['countryCode'] as String, - amount: (json['amount'] as num).toDouble(), - returnUrl: json['returnUrl'] as String?, - googlePayOptions: json['googlePayOptions'] == null - ? null - : GooglePayOptions.fromJson( - json['googlePayOptions'] as Map), - applePayOptions: json['applePayOptions'] == null - ? null - : ApplePayOptions.fromJson( - json['applePayOptions'] as Map), - paymentMethods: (json['paymentMethods'] as List?) - ?.map((e) => e as String) - .toList(), - paymentIntentId: json['paymentIntentId'] as String, - autoCapture: json['autoCapture'] as bool?, - nextTriggeredBy: - $enumDecode(_$NextTriggeredByEnumMap, json['nextTriggeredBy']), - merchantTriggerReason: $enumDecode( - _$MerchantTriggerReasonEnumMap, json['merchantTriggerReason']), - )..type = json['type'] as String; - Map _$RecurringWithIntentSessionToJson( RecurringWithIntentSession instance) => { diff --git a/lib/types/shipping.dart b/lib/types/shipping.dart index 57434fe..dc92e13 100644 --- a/lib/types/shipping.dart +++ b/lib/types/shipping.dart @@ -24,7 +24,8 @@ class Shipping { this.address, }); - factory Shipping.fromJson(Map json) => _$ShippingFromJson(json); + factory Shipping.fromJson(Map json) => + _$ShippingFromJson(json); Map toJson() => _$ShippingToJson(this); } @@ -37,9 +38,11 @@ class ShippingAddress { String? postcode; String? state; - ShippingAddress({this.city, this.countryCode, this.street, this.postcode, this.state}); - - factory ShippingAddress.fromJson(Map json) => _$ShippingAddressFromJson(json); + ShippingAddress( + {this.city, this.countryCode, this.street, this.postcode, this.state}); + + factory ShippingAddress.fromJson(Map json) => + _$ShippingAddressFromJson(json); Map toJson() => _$ShippingAddressToJson(this); -} \ No newline at end of file +} diff --git a/pubspec.yaml b/pubspec.yaml index c8ae694..4af40d6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: airwallex_payment_flutter -description: "A payment Flutter plugin project." +description: "Official Airwallex Flutter plugin for accepting payments on Android and iOS. Supports cards, Apple Pay, Google Pay, and major e-wallets." version: 0.3.0 homepage: "https://www.airwallex.com/"