diff --git a/website/api/controllers/customers/save-billing-info-and-subscribe.js b/website/api/controllers/customers/save-billing-info-and-subscribe.js index 543d049b42..2794131294 100644 --- a/website/api/controllers/customers/save-billing-info-and-subscribe.js +++ b/website/api/controllers/customers/save-billing-info-and-subscribe.js @@ -60,6 +60,11 @@ module.exports = { responseType: 'badRequest' }, + cardVerificationRequired: { + description: 'The billing card provided requires additional verfication before it can be used.', + responseType: 'badRequest' + }, + }, @@ -103,6 +108,7 @@ module.exports = { }); // Create the subscription for this order in Stripe + // [?]: https://stripe.com/docs/api/subscriptions/create?lang=node const subscription = await stripe.subscriptions.create({ customer: this.req.me.stripeCustomerId, items: [ @@ -113,6 +119,18 @@ module.exports = { ], }); + // Get the Stripe ID of the invoice for this subscription. + let latestInvoiceIdForThisSubscription = subscription.latest_invoice; + + // Get the invoice from Stripe. + const invoice = await stripe.invoices.retrieve(latestInvoiceIdForThisSubscription);// [?]: https://stripe.com/docs/api/invoices/retrieve?lang=node + + if(!invoice.paid) { + // If the invoice is not paid, we will throw an error, and ask the customer to contact support. + // FUTURE: Send an invoice to the customer and update the recieve-from-stripe webhook to handle off-website invoice payments. + throw 'cardVerificationRequired'; + } + // Generate the license key for this subscription let licenseKey = await sails.helpers.createLicenseKey.with({ numberOfHosts: quoteRecord.numberOfHosts, diff --git a/website/views/pages/customers/new-license.ejs b/website/views/pages/customers/new-license.ejs index eed3e63e01..c80abb217d 100644 --- a/website/views/pages/customers/new-license.ejs +++ b/website/views/pages/customers/new-license.ejs @@ -41,7 +41,7 @@

Billing information

- +
-

The billing card provided could not be used. Please use another card or contact support

+

The billing card provided could not be used. Please use another card or contact support.

+
+ +

The billing card provided could not be used without additional verification. Please use another card or contact support to complete your order.

Get license key