Stripe の description と metadata
Stripe のオブジェクトの中になんらかのデータを保存したい時がある。たとえば顧客の情報だったり、支払いの補足情報だったり。会社名などを保存しておくと、ダッシュボードから検索できて便利。そんな時にデータを保存するフィールドとして、 description と metadata の2つの選択肢がある。どれを使うべきか?
結論として
metadata を使ったほうがよさそう
それぞれの特徴を列挙すると
description
- 一部のオブジェクトだけ持っている (customer, invoice item, transfer など)
- customer.description はダッシュボードで閲覧できるだけだが、invoice item.description は請求書に表示されるなど、公開範囲がわかりづらい。
description についての細かい説明は API の create のところに書いてある。たとえば、incoiceitem の description は
Stripe API Reference
An arbitrary string which you can attach to the invoice item. The description is displayed in the invoice for easy tracking. This will be unset if you POST an empty value.
と、請求書に表示されることが書いてある。一方で、customer の説明では
Stripe API Reference
An arbitrary string that you can attach to a customer object. It is displayed alongside the customer in the dashboard. This will be unset if you POST an empty value.
と、ダッシュボードがに表示されることが書いてある。
metadata
- 更新可能な Stripe のオブジェクトはほとんど metadata を持つことができる (Account, Charge, Customer, Refund, Subscription, and Transfer)
- 各オブジェクトは20個のキーバリューペアを保存できる
- Stripe によって metadata が参照されることはないし、顧客に見られることもない
metadata は顧客に表示されないことが明確で、各オブジェクトによって使われ方が共通である。description はその点ちょっとわかりにくい。これなら何か追加データを保存するのであれば、metadata を使ったほうが良さそう。