Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Line Breaks in Stripe Email Description

I'm having trouble showing line breaks in Stripe's email receipts. The email description is generated via PHP and <br>, \r\n are displayed literally. enter image description here

I also tried nl2br but since that displays <br> I'm sure it won't work.

PHP

$detail = "$name\r\n";
$detail .= "Length: $length,";
$detail .= " Width: $width,";
$detail .= "Color: $color,";
$detail .= "Qty: $qty\r\n";
$detail .= "Price: $price\r\n";

echo nl2br($detail);

How can I display line breaks on my Stripe email receipt using PHP?

like image 474
Josan Iracheta Avatar asked Apr 09 '14 21:04

Josan Iracheta


People also ask

How do I customize my Stripe email?

Set up a custom email domain To start sending emails from your own domain, complete the following steps: Add your domain in the Dashboard. Verify your domain to allow sending. Set your sending domain as your domain.

Can you customize Stripe receipt?

Stripe allows you to customize (as well as preview) email receipts, hosted invoices, invoice PDFs, and more, in your Branding settings.

Does Stripe test mode send emails?

Receipts in test modeStripe can automatically send email receipts after a successful payment, or when you refund one. This is done by providing an email address when making the API request, using the email address of a Customer object, or updating a PaymentIntent with a customer's email address after checkout.

What is stripes API?

Stripe integrations handle complicated processes. The API uses a single object to track each process. You create the object at the start of the process, and after every step you can check its status to see what needs to happen next. For instance, while completing a payment, a customer might try several payment methods.


1 Answers

Edit: It looks like Stripe began supporting line breaks at some point over the past few years, see comments on this answer.


Previous answer:

I was trying to achieve the same thing and ended up talking with their support. In short:

  • HTML tags will always be converted to entities.
  • \n will be ignored.

As I see it, you have 3 options within these current constraints:

  1. Use commas (or whatever) for items on one long line:

    Shampoo - $5.00, Toothbrush - $2.00, Soap - $3.00 --------------- $10.00
    
  2. Send your own email.

  3. Create a customer in Stripe, then create as many invoice items as you need, then create an invoice, then pay the invoice.

This does give you an invoice + a receipt email like this:

 Shampoo ----- $5.00
 Toothbrush -- $2.00
 Soap -------- $3.00

 Total ------ $10.00

But there's 1 huge caveat to #3. Invoices are automatically created by Stripe for all outstanding invoice items and subscription plans that a customer might have. This occurs 1 hour before an invoice should be charged (this is according to the interval that you might have setup for a plan, or perhaps at the end of the month if you're only dealing with invoice items, I'm not sure in the latter case.). This means you could technically have a customer checking out that gets charged for more items within the current transaction then they were anticipating, which just smells of bad design and a bad solution to a simple problem.

So, I'm sticking with comma separated items on 1 line for a current project, and doing custom emails whenever a client has the budget for us to build them.

like image 151
Charlie Schliesser Avatar answered Oct 23 '22 14:10

Charlie Schliesser