setInstrumentToDefault method

Future<void> setInstrumentToDefault(
  1. Instrument instrument
)

switch a given instrument to default instrument for the customer

Implementation

Future<void> setInstrumentToDefault(Instrument instrument) async {
  final customer = state.value;

  final updatedInstrument = await checkout.updateInstrument(
    instrument: instrument,
    instrumentRequest: InstrumentRequest(
      id: instrument.id,
      isDefault: true,
      customer: customer!,
      expiryMonth: instrument.expiryMonth,
      expiryYear: instrument.expiryYear,
    ),
  );

  state = AsyncValue.data(
    customer.copyWith(defaultInstrument: updatedInstrument),
  );
}