Skip to main content

Blog

Stripeで多通貨を扱うときの注意点(定期購入版)

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

1つのStripeアカウントで複数の通貨を扱えるので、subscribeするプランのIDを変えるだけで多通貨決済に対応できるのが便利です。

ただ、1つカスタマーに複数の通貨のsubscriptionを設定することはできない様子です。(2018/01/23時点)

サンプルコード

Stripeでは以下のように一度に複数のプランをsubscribeすることができます。

stripe.subscriptions.create({
  customer: "cus_XXXXX",
  items: [
    {
      plan: "usd_plan",
    },
    {
      plan: "jpy_plan"
    }
  ]
}, function(err, subscription) {
    console.log(err)
    console.log(subscription)
  }
);

ただし通貨またはinterval(年 / 月など)が揃っていないとエラーになります。

raw: { type: 'invalidrequesterror', message: 'Currency and interval fields must match across all plans on this subscription. Found mismatch in currency field.', statusCode: 400, requestId: 'req_XXXXX' },

対応

ですので実装する際はどの通貨で決済するかを事前に指定させるか、1度決済した通貨と同じプランしか出さないようにする実装にするなどの調整が必要となります。

どうしても毎回選べるようにしたい場合は、カスタマーを通貨分作るようにする or 別の通貨で決済されたときにsubscribe中のプランもその通貨での同じプランに変更するのような力技をやる必要がありそうです。

とはいえ

USD / JPY両方で決済したいユーザーなんてそういないと思いますので、「アカウントもう一個作って決済して」と連絡するのが一番平和でしょうが・・・

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.