5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Stripe ConnectのCustomアカウントで、子アカウントへの入金情報などを取得する方法(アカウントヘッダー)

Last updated at Posted at 2019-04-17

Stripe Connectでの子アカウントに関する情報をAPIで取得したい

ドキュメントが少しわかりづらかったので記事を書きました。
プラットフォーム上で子アカウントの情報(例:決済情報、入金情報)を取得し、マイページなどで表示する方法です。
Stripe APIにはアカウントヘッダーという機能があり、APIを呼び出す上で、どのAccountに紐づいた情報を取得するのかを指定できます。このアカウントヘッダーを使用しない場合は、デフォルトで親アカウントが指定されるようです。

  # 例) 子アカウント(ID: acct_xxxxxxxxxx)に対して行われた最新の入金を3件取得する
    Stripe::Payout.list(
      {limit: 3},
      {stripe_account: "acct_xxxxxxxxxx"}
    )

このように、第一引数にパラメータ、第二引数にacct_idを指定することで、特定のアカウントに基づいた情報を取得できるようになります。

例) ある月の売上の入金額を取得する

私が開発しているCtoCサービスでは、子アカウントの売上の入金スケジュールを月末締め、翌月末払いにしています。そこで欲しい情報は、毎月の入金情報です。
例えば2019年3月に作成された入金情報を取得したい場合は、以下のようにします。

    beginning_of_month = Date.new(2019, 3).to_time.to_i
    end_of_month = Date.new(2019, 3).end_of_month.to_time.to_i

    payout = Stripe::Payout.list(
      {created: {gte: beginning_of_month, lte: end_of_month}}, #gteが以上、lteが以下。日時の範囲指定が独特w
      {stripe_account: "acct_xxxxxxxxxx"}
    )

    # 入金額
    payout.data[0].amount
    # 入金予定日
    Time.at(payout.data[0].arrival_date).strftime("%Y/%m/%d")

間違いなどあればご指摘頂けると嬉しいです。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?