ruby-on-railsinternationalizationstripe-paymentscheckoutreceipt

Setting language of email after Stripe checkout


tl;dr: Using Stripe Checkout, new customers always get the first receipt email in English, even if the checkout process is in a different, customer-chosen language.

I'm struggling with an issue that should be simple to resolve, and I've been - without success - trying to get help from Stripe Support.

I'm using Checkout to take one-off payments (i.e. most people buy once, and I don't have a user / customer data base on my server). So far so good. My app is a simple Rails 6 app, and I am following this procedure: https://stripe.com/docs/payments/checkout/accept-a-payment

I have different languages on my website, and I am using standard Rails / I18n methods to do that - all good.

When the user goes to the Stripe checkout page, I send along the locale, as per the documentation, and the user does indeed see the page in the corresponding language - all good.

Example code:

# Set your secret key. Remember to switch to your live secret key in production!
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'

session = Stripe::Checkout::Session.create(
  payment_method_types: ['card'],
  line_items: [{
    price_data: {
      currency: 'eur',
      product_data: {
        name: 'T-shirt',
      },
      unit_amount: 2000,
    },
    quantity: 1,
  }],
  mode: 'payment',
  success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
  cancel_url: 'https://example.com/cancel',
  locale: 'de'
)

However - once the customer gets the confirmation / receipt email from Stripe, it is always in English. This puzzles me: in the absence of any other indication, I would expect Stripe to send the receipt email in the language of the checkout page. I mean, if Stripe is "interacting" with a customer in, say, German, I would expect that Stripe would also send the follow up (receipt) email in German. I'm puzzled that this is not the case.

Stripe has a preferred_locales in the customer object (see https://support.stripe.com/questions/language-options-for-customer-emails). My question is, how and when should I set this?

I tried using webhooks, and update the customer upon the checkout.session.completed event - as this is the only event where Stripe hands me the customer_id and the originally passed locale in one go (in the webhook event). Unfortunately, at this point, Stripe has already sent the email. The customer does get updated, but the email has already been sent.

Unfortunately, there seems to be no other event that is triggered during a checkout session that would have both pieces of information (which customer, which language); and thus there seems to be no other easy way to set the language of the customer before the receipt email is sent to the customer.

Before I go any deeper with this problem, and before I start begging the Stripe support team on my knees to finally let me talk to a technical person (whatever happened to "for devs, by devs"...), I am checking here to see if anyone has run into this problem and solved it.

This should be really simple, so I am almost certain I am stupidly overseeing something that should be totally obvious.

Any help would be much appreciated.


Solution

  • You can create a Customer beforehand and set their preferred locales, then pass its id as customer when creating the CheckoutSession.