checkoutCompleteWithTokenizedPaymentV3 method
Complete Checkout with a tokenized payment.
Returns the ID of the payment
checkoutId
is the ID of the Checkout that you want to complete.
token
is the payment token generated by the payment provider.
test
is a boolean that indicates if the payment is a test payment. Test mode isn't supported in production stores. Defaults to false
NOTE: if you have products in your checkout that require shipping, you will get error message "Shipping rate can't be blank". So you either have to set a free shipping line, or mark these products/variants to not require shipping.
Implementation
Future<TokanizedCheckout> checkoutCompleteWithTokenizedPaymentV3(
String checkoutId, {
required Checkout checkout,
required String token,
required PaymentTokenType paymentTokenType,
required String idempotencyKey,
required String amount,
required String currencyCode,
Address? billingAddress,
bool test = false,
}) async {
final MutationOptions _options = MutationOptions(
document: gql(completeCheckoutWithTokenV3),
variables: {
'checkoutId': checkoutId,
'payment': {
'paymentAmount': {'amount': amount, 'currencyCode': currencyCode},
'idempotencyKey': idempotencyKey,
'paymentData': token,
'type': paymentTokenType.name,
'test': test,
'billingAddress': {
'address1': billingAddress?.address1 ?? '',
'address2': billingAddress?.address2 ?? '',
'city': billingAddress?.city ?? '',
'company': billingAddress?.company ?? '',
'country': billingAddress?.country ?? '',
'firstName': billingAddress?.firstName ?? '',
'lastName': billingAddress?.lastName ?? '',
'phone': billingAddress?.phone ?? '',
'province': billingAddress?.province ?? '',
'zip': billingAddress?.zip ?? '',
},
},
},
);
final QueryResult result = await _graphQLClient!.mutate(_options);
checkForError(
result,
key: 'checkoutCompleteWithTokenizedPaymentV3',
errorKey: 'checkoutUserErrors',
);
return TokanizedCheckout.fromJson(
((result.data!['checkoutCompleteWithTokenizedPaymentV3'] ??
const {})['payment'] ??
const {}));
}