open method
Opens checkout for orderId and completes with the final result once
checkout closes:
- CheckoutSuccess if a payment succeeded, even after failed attempts;
- CheckoutFailed if the last attempt failed, or checkout could not
open (code
CHECKOUT_OPEN_FAILED, e.g. while another checkout is open); - CheckoutDismissed if it closed without a payment attempt.
Throws ArgumentError if orderId is empty.
Implementation
Future<CheckoutResult> open({required String orderId}) {
if (orderId.trim().isEmpty) {
throw ArgumentError.value(orderId, 'orderId', 'orderId is required');
}
if (_active != null) {
final failed = CheckoutFailed(
orderId: orderId,
error: CheckoutFailureError(
code: 'CHECKOUT_OPEN_FAILED',
description: _active == this ? 'This checkout is already open' : 'Another checkout is already open',
),
);
_notify(CheckoutEvent.paymentFailed, failed);
return Future.value(failed);
}
return _open(orderId);
}