• 1000 'не существует по типу' Клиент | DeletedCustomer '
export const attachSource = async(uid: string, source: string) => {
const customer = await getOrCreateCustomer(uid);
const existingSource = customer.sources.data.filter(s => s.id === source).pop();
if (existingSource) {
return existingSource;
}
else {
await stripe.customers.createSource(customer.id, { source: source });
// update default
return await stripe.customers.update(customer.id, { default_source: source });
}
}
ошибка customer.sources.
Вот функция getOrCreateCustomer ():
export const getOrCreateCustomer = async (uid: string) => {
const user = await getUser(uid);
const customerId = user && user.stripeCustomerId;
// If missing customerId, create it
if (!customerId) {
return createCustomer(uid);
} else {
return stripe.customers.retrieve(customerId);
}
}