1 import { type PaymentsVersion } from '@proton/shared/lib/api/payments';
2 import { type Api } from '@proton/shared/lib/interfaces';
4 import { DEFAULT_TAX_BILLING_ADDRESS } from './billing-address';
5 import { type PaymentMethodStatusExtended } from './interface';
7 export const queryPaymentMethodStatus = (version: PaymentsVersion) => ({
8 url: `payments/${version}/status`,
12 export async function getPaymentMethodStatus(api: Api) {
13 const status = await api<PaymentMethodStatusExtended>(queryPaymentMethodStatus('v5'));
14 if (!status.CountryCode) {
15 status.CountryCode = DEFAULT_TAX_BILLING_ADDRESS.CountryCode;
18 if ('VendorStates' in status) {
19 const keys = Object.keys(status.VendorStates) as (keyof PaymentMethodStatusExtended['VendorStates'])[];
20 // Normalizing the boolean values, converting them from 0 or 1 to false or true
21 for (const key of keys) {
22 status.VendorStates[key] = !!status.VendorStates[key];
25 // The backend doesn't return the Cash key. We still use it in the frontend,
26 // so we synthetize it here.
27 if (!Object.hasOwn(status.VendorStates, 'Cash')) {
28 status.VendorStates.Cash = true;