createCheckout method
creates a new Checkout with the given lineItems
, shippingAddress
and email
.
Implementation
Future<Checkout> createCheckout({
List<LineItem>? lineItems,
Address? shippingAddress,
String? email,
}) async {
final MutationOptions _options =
MutationOptions(document: gql(createCheckoutMutation), variables: {
'input': {
'allowPartialAddresses': true,
if (lineItems != null)
'lineItems': [
for (var lineItem in lineItems)
{
'variantId': lineItem.variantId,
'quantity': lineItem.quantity,
'customAttributes': lineItem.customAttributes
.map((e) => {
'key': e.key,
'value': e.value,
})
.toList(),
}
],
if (email != null) 'email': email,
if (shippingAddress != null)
'shippingAddress': {
'address1': shippingAddress.address1,
'address2': shippingAddress.address2,
'city': shippingAddress.city,
'company': shippingAddress.company,
'country': shippingAddress.country,
'firstName': shippingAddress.firstName,
'lastName': shippingAddress.lastName,
'phone': shippingAddress.phone,
'province': shippingAddress.province,
'zip': shippingAddress.zip
}
}
});
final QueryResult result = await _graphQLClient!.mutate(_options);
checkForError(
result,
key: 'checkoutCreate',
errorKey: 'checkoutUserErrors',
);
return Checkout.fromJson(
((result.data!['checkoutCreate'] ?? const {})['checkout'] ?? const {}));
}