-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send an email when the invoice is failed to charge
We automate the process of sending emails when an invoice fails to charge, including error details from the Stripe API. We also add the support email as a CC, allowing the entire team to follow up with the customer if needed.
- Loading branch information
Showing
2 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ def charge | |
|
||
if !success | ||
Clog.emit("Invoice couldn't charged with any payment method.") { {invoice_not_charged: {ubid: ubid}} } | ||
send_failure_email(errors) | ||
false | ||
else | ||
send_success_email | ||
|
@@ -99,6 +100,21 @@ def send_success_email(below_threshold: false) | |
button_title: "View Invoice", | ||
button_link: "#{Config.base_url}#{project.path}/billing#{ser[:path]}") | ||
end | ||
|
||
def send_failure_email(errors) | ||
ser = Serializers::Web::Invoice.new(:detailed).serialize(self) | ||
Util.send_email(ser[:billing_email], "Urgent: Action Required to Prevent Service Disruption", | ||
cc: Config.mail_from, | ||
greeting: "Dear #{ser[:billing_name]},", | ||
body: ["We hope this message finds you well.", | ||
"We've noticed that your credit card on file has been declined with the following errors:", | ||
*errors.map { "- #{_1}" }, | ||
"The invoice amount of #{ser[:total]} tried be debited from your credit card on file.", | ||
"To prevent service disruption, please update your payment information within the next two days.", | ||
"If you have any questions, please send us a support request via [email protected]."], | ||
button_title: "Update Payment Method", | ||
button_link: "#{Config.base_url}#{project.path}/billing") | ||
end | ||
end | ||
|
||
Invoice.unrestrict_primary_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters