createInvoice method

Future<InvoiceObject> createInvoice({
  1. required String businessName,
  2. required String customerEmail,
  3. required String customerName,
  4. required CurrencyType currency,
  5. required int amount,
  6. String? memo,
})

To send an invoice in cryptocurrency, you need to create an invoice object and provide the user with the hosted url where they will be able to pay. Once an invoice is viewed at the hosted url, a charge will be generated on the invoice.

Implementation

Future<InvoiceObject> createInvoice(
    {required String businessName,
    required String customerEmail,
    required String customerName,
    required CurrencyType currency,
    required int amount,
    String? memo}) async {
  InvoiceObject coinbaseResponse;
  Map data;

  Map response = await postToDB(
      api: 'https://api.commerce.coinbase.com/invoices',
      apiKey: _apiKey,
      body: {
        'business_name': businessName,
        'customer_email': customerEmail,
        'customer_name': customerName,
        'local_price': {'amount': amount, 'currency': getCurrency(currency)}
      });
  if (response.containsKey('error')) {
    data = response['error'];
  } else {
    data = response['data'];
  }
  coinbaseResponse = InvoiceObject.fromJson(data);
  Logger(debug).displayLog(coinbaseResponse.toString());
  return coinbaseResponse;
}