yikegaya’s blog

仕事関連(Webエンジニア)と資産運用について書いてます

StripeでSDKからExternalAccount登録する時にハマったことメモ

StripeでRubysdkからExternalAccount作る機能実装した時にハマったことメモ。

individualの登録

個人事業主(individual)のアカウントを登録するときに以下だとStripe::Accountのインスタンスからindividualを呼び出す時にmethod_missingになってしまう。

stripe_account = Stripe::Account.create({
  type: 'custom',
  country: 'JP',
  business_type: "individual",
  email: "hoge@gmail.com",
  capabilities: {
    card_payments: {requested: true},
    transfers: {requested: true},
  },
})
stripe_account.individual.last_name_kanji = "hoge"

インスタンスを作るタイミングでなんでもいいからindividualの属性を入れてからだとうまくいくらしい。謎。

stripe_account = Stripe::Account.create({
  type: 'custom',
  country: 'JP',
  business_type: "individual",
  individual: {last_name_kanji: "hoge"},
  email: "hoge@gmail.com",
  capabilities: {
    card_payments: {requested: true},
    transfers: {requested: true},
  },
})
stripe_account.individual.last_name_kanji = "hoge"

APIのversion指定による実装方法の違い

最初特にAPIのバージョン指定せずに実装進めていたが途中で指定しないと古いAPIを叩いていることに気づいて以下指定したら動かなくなった。

Stripe.api_version = '2022-08-01'

途中からAPIの引数があちこち変わったので新しい引数に書き直す必要があった。これもしばらく気づかず。

stripe.com