mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Website: Update stripe webhook to send confirmation emails. (#24378)
Closes: #24345 Changes: - Updated the receive-from-stripe webhook to send confirmation emails to users who purchase a Fleet Premium license subscription.
This commit is contained in:
parent
6039708e59
commit
f67ff80e4d
1 changed files with 31 additions and 2 deletions
|
|
@ -95,7 +95,7 @@ module.exports = {
|
|||
|
||||
let userForThisSubscription = await User.findOne({stripeCustomerId: stripeEventData.customer});
|
||||
if(!userForThisSubscription){
|
||||
throw new Error(`The stripe subscription events webhook received a tpye ${type} event for a user with stripeCustomerId: ${stripeEventData.customer}, but no matching user was found in the databse. Stripe event ID: ${id}`);
|
||||
throw new Error(`The stripe subscription events webhook received a type ${type} event for a user with stripeCustomerId: ${stripeEventData.customer}, but no matching user was found in the databse. Stripe event ID: ${id}`);
|
||||
}
|
||||
// ┬ ┬┌─┐┌─┐┌─┐┌┬┐┬┌┐┌┌─┐ ┬─┐┌─┐┌┐┌┌─┐┬ ┬┌─┐┬
|
||||
// │ │├─┘│ │ │││││││││ ┬ ├┬┘├┤ │││├┤ │││├─┤│
|
||||
|
|
@ -221,7 +221,7 @@ module.exports = {
|
|||
// Generate a new license key.
|
||||
let newLicenseKey = await sails.helpers.createLicenseKey.with({
|
||||
numberOfHosts,
|
||||
organization: userForThisSubscription.organization,
|
||||
organization: userForThisSubscription.organization ? userForThisSubscription.organization : 'Unknown',
|
||||
expiresAt: nextBillingAt,
|
||||
});
|
||||
// Create the database record for this subscription.
|
||||
|
|
@ -233,6 +233,35 @@ module.exports = {
|
|||
fleetLicenseKey: newLicenseKey,
|
||||
user: userForThisSubscription.id,
|
||||
});
|
||||
|
||||
await sails.helpers.sendTemplateEmail.with({
|
||||
to: userForThisSubscription.emailAddress,
|
||||
from: sails.config.custom.fromEmail,
|
||||
fromName: sails.config.custom.fromName,
|
||||
subject: 'Your Fleet Premium order',
|
||||
template: 'email-order-confirmation',
|
||||
templateData: {
|
||||
firstName: userForThisSubscription.firstName ? userForThisSubscription.firstName : '',
|
||||
lastName: userForThisSubscription.lastName ? userForThisSubscription.lastName : '',
|
||||
}
|
||||
});
|
||||
|
||||
let todayOn = new Date();
|
||||
let isoTimestampForDescription = todayOn.toISOString();
|
||||
sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
|
||||
emailAddress: userForThisSubscription.emailAddress,
|
||||
firstName: userForThisSubscription.firstName,
|
||||
lastName: userForThisSubscription.lastName,
|
||||
organization: userForThisSubscription.organization,
|
||||
contactSource: 'Website - Sign up',// Note: this is only set on new contacts.
|
||||
description: `Purchased a self-service Fleet Premium license on ${isoTimestampForDescription.split('T')[0]} for ${numberOfHosts} host${numberOfHosts > 1 ? 's' : ''}.`
|
||||
}).exec((err)=>{
|
||||
if(err){
|
||||
sails.log.warn(`Background task failed: When a user (email: ${userForThisSubscription.emailAddress} purchased a self-service Fleet premium subscription, a Contact and Account record could not be created/updated in the CRM.`, err);
|
||||
}
|
||||
return;
|
||||
});
|
||||
|
||||
}
|
||||
// FUTURE: send emails about failed payments. (type === 'invoice.payment_failed' && stripeEventData.billing_reason === 'subscription_cycle')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue