receiptTotal method

Future<void> receiptTotal({
  1. required int paidMode,
  2. required double amountToPay,
  3. int? paymentType,
  4. int? changeCurrency,
})

Implementation

Future<void> receiptTotal({
  required int paidMode,
  required double amountToPay,
  int? paymentType,
  int? changeCurrency,
}) async {
  assert(
    paidMode >= 0 && paidMode <= 6 || paidMode == 12,
    'paidMode must be in range 0..5 (0=cash, 1=credit card, 2=debit card, 3=other #3, 4=other #4, 5=other #5, 6=foreign currency, 12=payment with pinpad)',
  );
  assert(amountToPay >= 0, 'amountToPay must be greater than or equal to 0');
  assert(
    paymentType == null ||
        (paymentType == 1 && paymentType == 12 && paidMode != 6),
    'paymentType must be 1 or 12 (1=with money, 12=with loyalty points)',
  );
  assert(
    changeCurrency == null ||
        (changeCurrency >= 0 && changeCurrency <= 1 && paidMode == 6),
    'changeCurrency must be 0 or 1 (0=current currency, 1=foreign currency)',
  );
  final message = await execute(
    Commands.paymentAndTotalSum.code,
    data: [
      paidMode,
      amountToPay.cleanDouble(),
      if (paymentType != null) paymentType,
      if (changeCurrency != null) changeCurrency,
    ].toCommand(),
  );
  final [$e, ...rest] = message.data.response;
  final error = int.tryParse($e) ?? 0;

  if (error != 0) {
    throw FiscalCodeException('Error payment and calculating totals', error);
  }
}