addNewCard static method

Future<void> addNewCard(
  1. BuildContext context, {
  2. required PaymentRequest paymentRequest,
  3. required void onAddCard(
    1. BuildContext sheetContext,
    2. CardData card
    ),
  4. void onCancel(
    1. BuildContext sheetContext
    )?,
  5. CardData? initialCard,
  6. bool savedCardEditMode = false,
  7. String? recoveryErrorCode,
  8. String? recoveryErrorMessage,
})

Opens the add-card modal bottom sheet (AddCardForm) with SDK theme.

onAddCard receives the sheet BuildContext (e.g. to Navigator.pop) and the entered CardData.

Implementation

static Future<void> addNewCard(
  BuildContext context, {
  required PaymentRequest paymentRequest,
  required void Function(BuildContext sheetContext, CardData card) onAddCard,
  void Function(BuildContext sheetContext)? onCancel,
  CardData? initialCard,

  /// When true with [initialCard], use saved-card edit UI (read-only PAN). Otherwise [initialCard] only pre-fills the add-card flow.
  bool savedCardEditMode = false,

  /// When reopening the form after `/sdk/payment` errors `E0021` (mobile) or `43` (email).
  String? recoveryErrorCode,
  String? recoveryErrorMessage,
}) {
  return showModalBottomSheet<void>(
    context: context,
    isScrollControlled: true,
    backgroundColor: AppColors.transparent,
    shape: PayorcSdkUiConstants.bottomSheetModalShape,
    builder: (ctx) => wrapWithSdkTheme(
      context,
      AddCardForm(
        paymentRequest: paymentRequest,
        initialCard: initialCard,
        savedCardEditMode: savedCardEditMode,
        recoveryErrorCode: recoveryErrorCode,
        recoveryErrorMessage: recoveryErrorMessage,
        onAddCard: (card) => onAddCard(ctx, card.copyWith(cvv: '')),
        onCancel: () {
          if (onCancel != null) {
            onCancel(ctx);
          } else {
            Navigator.of(ctx).pop();
          }
        },
      ),
    ),
  );
}