Skip to content

Commit

Permalink
chore(console): 3DS UI improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
poolsar42 committed Jul 24, 2023
1 parent 1886ab6 commit 1592ba0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
43 changes: 22 additions & 21 deletions apps/console/app/routes/__layout/billing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,29 +195,27 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
context.env.SECRET_STRIPE_API_KEY
)

const hasUnpaidInvoices = invoices.some((invoice) => {
if (invoice.status)
return ['uncollectible', 'open'].includes(invoice.status)
return false
})

const flashSession = await getFlashSession(request, context.env)

// We are not creating and/or updating subscriptions
// until we resolve our unpaid invoices
if (hasUnpaidInvoices) {
flashSession.flash(
'toast_notification',
JSON.stringify({
type: ToastType.Error,
message: 'Payment failed - check your card details',
})
)
return new Response(null, {
headers: {
'Set-Cookie': await commitFlashSession(flashSession, context.env),
},
})
for (const invoice of invoices) {
// We are not creating and/or updating subscriptions
// until we resolve our unpaid invoices
if (invoice.status) {
if (['open', 'uncollectible'].includes(invoice.status)) {
flashSession.flash(
'toast_notification',
JSON.stringify({
type: ToastType.Error,
message: 'Payment failed - check your card details',
})
)
return new Response(null, {
headers: {
'Set-Cookie': await commitFlashSession(flashSession, context.env),
},
})
}
}
}

const fd = await request.formData()
Expand Down Expand Up @@ -1011,6 +1009,9 @@ export default () => {
const stripeClient = await loadStripe(STRIPE_PUBLISHABLE_KEY)
const { status, client_secret, payment_method } = JSON.parse(actionData)
if (status === 'requires_action') {
toast(ToastType.Warning, {
message: 'Payment requires additional action',
})
await stripeClient?.confirmCardPayment(client_secret, {
payment_method: payment_method,
})
Expand Down
2 changes: 2 additions & 0 deletions apps/console/app/services/billing/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export const getInvoices = async (

const invoices = await stripeClient.invoices.list({
customer: customerID,
expand: ['data.payment_intent'],
})

return invoices
Expand All @@ -240,6 +241,7 @@ export const getUpcomingInvoices = async (

const upcomingInvoices = await stripeClient.invoices.retrieveUpcoming({
customer: customerID,
expand: ['data.payment_intent'],
})
return upcomingInvoices
}
Expand Down

0 comments on commit 1592ba0

Please sign in to comment.