Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -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%'
31 changes: 25 additions & 6 deletions lib/airwallex.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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<PaymentResult> payWithCardDetails(BaseSession session, Card card, bool saveCard) {
Future<PaymentResult> payWithCardDetails(
BaseSession session, Card card, bool saveCard) {
return AirwallexPaymentFlutterPlatform.instance
.payWithCardDetails(session, card, saveCard);
}
Expand All @@ -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<PaymentResult> payWithConsent(BaseSession session, PaymentConsent consent) {
Future<PaymentResult> payWithConsent(
BaseSession session, PaymentConsent consent) {
return AirwallexPaymentFlutterPlatform.instance
.payWithConsent(session, consent);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/airwallex_payment_flutter_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down Expand Up @@ -104,7 +104,7 @@ class MethodChannelAirwallexPaymentFlutter
}
}

PaymentResult parsePaymentResult(result) {
PaymentResult parsePaymentResult(Map<String, dynamic>? result) {
if (result == null) {
throw Exception('Result is null');
}
Expand Down
15 changes: 10 additions & 5 deletions lib/airwallex_payment_flutter_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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<PaymentResult> presentCardPaymentFlow(
BaseSession session, {
List<CardBrand>? supportedBrands,
}) {
throw UnimplementedError('presentCardPaymentFlow() has not been implemented.');
throw UnimplementedError(
'presentCardPaymentFlow() has not been implemented.');
}

Future<PaymentResult> payWithCardDetails(BaseSession session, Card card, bool saveCard) {
Future<PaymentResult> payWithCardDetails(
BaseSession session, Card card, bool saveCard) {
throw UnimplementedError('payWithCardDetails() has not been implemented.');
}

Future<PaymentResult> payWithConsent(BaseSession session, PaymentConsent consent) {
Future<PaymentResult> payWithConsent(
BaseSession session, PaymentConsent consent) {
throw UnimplementedError('payWithConsent() has not been implemented.');
}

Expand Down
8 changes: 5 additions & 3 deletions lib/types/apple_pay_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ApplePayOptions {
this.totalPriceLabel,
});

factory ApplePayOptions.fromJson(Map<String, dynamic> json) => _$ApplePayOptionsFromJson(json);
factory ApplePayOptions.fromJson(Map<String, dynamic> json) =>
_$ApplePayOptionsFromJson(json);

Map<String, dynamic> toJson() => _$ApplePayOptionsToJson(this);
}
Expand Down Expand Up @@ -73,7 +74,8 @@ class CartSummaryItem {
this.type,
});

factory CartSummaryItem.fromJson(Map<String, dynamic> json) => _$CartSummaryItemFromJson(json);
factory CartSummaryItem.fromJson(Map<String, dynamic> json) =>
_$CartSummaryItemFromJson(json);

Map<String, dynamic> toJson() => _$CartSummaryItemToJson(this);
}
Expand All @@ -83,4 +85,4 @@ class CartSummaryItem {
enum CartSummaryItemType {
finalType,
pendingType,
}
}
16 changes: 10 additions & 6 deletions lib/types/billing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +23,8 @@ class Billing {
this.address,
});

factory Billing.fromJson(Map<String, dynamic> json) => _$BillingFromJson(json);
factory Billing.fromJson(Map<String, dynamic> json) =>
_$BillingFromJson(json);

Map<String, dynamic> toJson() => _$BillingToJson(this);
}
Expand All @@ -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<String, dynamic> json) => _$BillingAddressFromJson(json);
BillingAddress(
{this.city, this.countryCode, this.street, this.postcode, this.state});

factory BillingAddress.fromJson(Map<String, dynamic> json) =>
_$BillingAddressFromJson(json);

Map<String, dynamic> toJson() => _$BillingAddressToJson(this);
}
}
9 changes: 6 additions & 3 deletions lib/types/google_pay_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class GooglePayOptions {
}) : allowedCardNetworks =
allowedCardNetworks ?? googlePaySupportedNetworks();

factory GooglePayOptions.fromJson(Map<String, dynamic> json) => _$GooglePayOptionsFromJson(json);
factory GooglePayOptions.fromJson(Map<String, dynamic> json) =>
_$GooglePayOptionsFromJson(json);

Map<String, dynamic> toJson() => _$GooglePayOptionsToJson(this);
}
Expand All @@ -57,7 +58,8 @@ class BillingAddressParameters {
this.phoneNumberRequired = false,
});

factory BillingAddressParameters.fromJson(Map<String, dynamic> json) => _$BillingAddressParametersFromJson(json);
factory BillingAddressParameters.fromJson(Map<String, dynamic> json) =>
_$BillingAddressParametersFromJson(json);

Map<String, dynamic> toJson() => _$BillingAddressParametersToJson(this);
}
Expand All @@ -82,7 +84,8 @@ class ShippingAddressParameters {
this.phoneNumberRequired = false,
});

factory ShippingAddressParameters.fromJson(Map<String, dynamic> json) => _$ShippingAddressParametersFromJson(json);
factory ShippingAddressParameters.fromJson(Map<String, dynamic> json) =>
_$ShippingAddressParametersFromJson(json);

Map<String, dynamic> toJson() => _$ShippingAddressParametersToJson(this);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/types/merchant_trigger_reason.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
enum MerchantTriggerReason {
unscheduled,
scheduled,
}
}
2 changes: 1 addition & 1 deletion lib/types/next_triggered_by.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
enum NextTriggeredBy {
merchant,
customer,
}
}
16 changes: 10 additions & 6 deletions lib/types/payment_consent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,15 +43,17 @@ class PaymentConsent {
this.updatedAt,
this.clientSecret,
});

factory PaymentConsent.fromJson(Map<String, dynamic> json) => _$PaymentConsentFromJson(json);

factory PaymentConsent.fromJson(Map<String, dynamic> json) =>
_$PaymentConsentFromJson(json);

Map<String, dynamic> 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;
Expand All @@ -66,7 +69,8 @@ class PaymentMethod {
this.customerId,
});

factory PaymentMethod.fromJson(Map<String, dynamic> json) => _$PaymentMethodFromJson(json);
factory PaymentMethod.fromJson(Map<String, dynamic> json) =>
_$PaymentMethodFromJson(json);

Map<String, dynamic> toJson() => _$PaymentMethodToJson(this);
}
}
5 changes: 2 additions & 3 deletions lib/types/payment_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,4 +24,4 @@ class PaymentInProgressResult extends PaymentResult {
/// The customer cancelled the payment flow before it completed.
class PaymentCancelledResult extends PaymentResult {
PaymentCancelledResult() : super('cancelled');
}
}
6 changes: 3 additions & 3 deletions lib/types/payment_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading