checkoutPaymentMethodVisible function
Whether a method should appear, using PayorcSdk.instance.checkoutCustomization.
When customization is missing or CheckoutCustomizationData.availableMethods
is empty (e.g. not loaded yet), returns whenNoCustomizationData so the UI
stays usable until the async customization request completes.
Implementation
bool checkoutPaymentMethodVisible(
String apiType, {
bool whenNoCustomizationData = true,
}) {
try {
final data = PayorcSdk.instance.checkoutCustomization;
final methods = data?.availableMethods;
if (data == null || methods == null || methods.isEmpty) {
return whenNoCustomizationData;
}
final key = normalizeCheckoutPaymentMethodType(apiType);
final googleNorm =
normalizeCheckoutPaymentMethodType(CheckoutPaymentMethodType.googlePay);
final treatAsGoogle = key == googleNorm;
for (final m in methods) {
final match = treatAsGoogle
? isGooglePayCheckoutMethodType(m.type)
: (normalizeCheckoutPaymentMethodType(m.type) == key);
if (match) {
return m.show != 0;
}
}
return false;
} catch (_) {
return whenNoCustomizationData;
}
}