Skip to main content

Blog

Stripeから送信されるメールをユーザーに合わせた言語にする

Posted over 2 years ago
この記事をシェア:

いつから可能なったのか不明ですが、Stripeでカスタマー情報を更新することで自動送信するメールの言語を変更できるようすです。

言語を変えた状態。
「詳細情報の更新」から変更できる

日本語に設定すると、請求・領収メールの文面などが日本語化されます。

Node.jsで実行する

customers.createpreferred_localesを指定すればOKです。

stripe.customers.create({
  source: 'tok_visa',
  description: 'Customer for locale test',
  preferred_locales: ['ja']
})
.then(data => console.log(data))
.catch(e => console.log(e))

ちなみに複数指定できますが、先頭に指定した言語で配信される様子です。将来的な拡張を見据えた実装とかでしょうか。

// 英語
stripe.customers.create({
  source: 'tok_visa',
  description: 'Customer for locale test',
  preferred_locales: ['en','ja']
})
.then(data => console.log(data)
.catch(e => console.log(e))

// 日本語
stripe.customers.create({
  source: 'tok_visa',
  description: 'Customer for locale test',
  preferred_locales: ['ja', 'en']
})
.then(data => console.log(data)
.catch(e => console.log(e))

customers.updateの引数でも使えますので、既存にも対応できます。

stripe.customers.update('cus_xxxx', {
  preferred_locales: ['ja']
})
.then(data => console.log(data))
.catch(e => console.log(e))

ちなみに

言語のリストはざっと見た範囲でどこにも載ってませんでした。

今回のデモは、一旦Dashboardで操作して、APIリクエストの中身を見るという力技を使っています。

あと、現時点(2019/08)では@types/stripeの型定義に反映されていませんので、TypeScriptだと型エラーがでます。

Tools to Support Stripe Development

We provide helpful tools to extend the Stripe Dashboard and streamline development and testing.

View All Tools

Support This Project

If you find this content helpful, consider supporting the project through GitHub Sponsors. Your support helps maintain and improve these tools.