addInstrument method

Future<void> addInstrument({
  1. required CreditCard creditCard,
})

adds new instrument to the customer for future use

Implementation

Future<void> addInstrument({required CreditCard creditCard}) async {
  final customer = state.value;
  final token = await _requestToken(creditCard);
  final instrument = await _createInstrument(token, customer!);

  state = AsyncValue.data(
    customer.copyWith(
        instruments: [...customer.instruments, instrument],
        defaultInstrument: customer.instruments.isEmpty ? instrument : null),
  );
}