orderedMethodsForAlternatePaymentPicker function

List<AvailablePaymentMethod> orderedMethodsForAlternatePaymentPicker()

Methods to list in payment-option / retry flows.

Order: Apple PayGoogle Pay → other methods (API sequence) → Pay with Card (CARD) last. When customization is not loaded yet, uses checkoutPaymentMethodFallbackTypeOrder (wallets first, card last) filtered by checkoutPaymentMethodVisible.

Omits storedCard (handled as saved cards) and clickToPay until a host callback exists.

Implementation

List<AvailablePaymentMethod> orderedMethodsForAlternatePaymentPicker() {
  final fromApi = sortedVisibleCheckoutMethods();
  if (fromApi.isNotEmpty) {
    final filtered = fromApi.where((m) {
      final k = checkoutPaymentMethodKindFromType(m.type);
      return k != CheckoutPaymentMethodKind.storedCard &&
          k != CheckoutPaymentMethodKind.clickToPay &&
          k != CheckoutPaymentMethodKind.unknown;
    }).toList();

    final apple = <AvailablePaymentMethod>[];
    final google = <AvailablePaymentMethod>[];
    final middle = <AvailablePaymentMethod>[];
    final card = <AvailablePaymentMethod>[];
    for (final m in filtered) {
      switch (checkoutPaymentMethodKindFromType(m.type)) {
        case CheckoutPaymentMethodKind.applePay:
          apple.add(m);
        case CheckoutPaymentMethodKind.googlePay:
          google.add(m);
        case CheckoutPaymentMethodKind.newCard:
          card.add(m);
        default:
          middle.add(m);
      }
    }
    return [...apple, ...google, ...middle, ...card];
  }
  return [
    for (final t in checkoutPaymentMethodFallbackTypeOrder)
      if (checkoutPaymentMethodVisible(t, whenNoCustomizationData: true))
        AvailablePaymentMethod(type: t, show: 1),
  ];
}