createCheckout method
Future<CheckoutObject>
createCheckout({
- required String description,
- required String name,
- int? amount,
- required PricingType pricingType,
- required CurrencyType currency,
Checkouts make it possible to sell a single fixed price item or accept arbitrary amounts of cryptocurrency very easily. Checkouts can have many charges and each charge is automatically generated on a per customer basis. Creates a new checkout.
amount
amount to be charged.
name
name of what you are charging for
description
describe the good or service
pricingType
indicate if there is a fixed price or no fixed price
currency
optional value to use. only important when the priceType
is PriceType.fixed
Implementation
Future<CheckoutObject> createCheckout(
{required String description,
required String name,
int? amount,
required PricingType pricingType,
required CurrencyType currency}) async {
CheckoutObject coinbaseResponse;
Map data;
Map<String, dynamic> body = {
"name": name,
"description": description,
"pricing_type": getPricingType(pricingType),
"requested_info": ['email', 'name']
};
if (pricingType == PricingType.fixedPrice) {
assert(amount != null);
body["local_price"] = {
"amount": amount,
"currency": getCurrency(currency)
};
}
Map response = await postToDB(
api: 'https://api.commerce.coinbase.com/checkouts',
apiKey: _apiKey,
body: body);
if (response.containsKey('error')) {
data = response['error'];
} else {
data = response['data'];
}
coinbaseResponse = CheckoutObject.fromJson(data);
Logger(debug).displayLog(coinbaseResponse.toString());
return coinbaseResponse;
}