0
1

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 1 year has passed since last update.

stripe(connect)においてプラットフォームで作成したcustomerと支払い情報を連結アカウントに複製・コピーする方法

Posted at

今回はプラットフォームで登録しているサブスクリプション情報をもとに、連結アカウントに顧客情報と支払い情報をコピーしていく。

controller.rb
# サブスクリプション情報を取得
@sub = Stripe::Subscription.retrieve(
    "sub_××××××××××", # サブスクリプションID
)

# 支払い情報の複製
@payment_method = Stripe::PaymentMethod.create({
    customer: @sub.customer, # カスタマーID
    payment_method: @sub.default_payment_method, # paymentMethodのID
}, {
    stripe_account: "attr_××××××××××", # 複製先の連結アカウントID
})

Stripe::Customer.create({
    email: "text@example.com", # 顧客のメールアドレス
    invoice_settings: {
        default_payment_method: @payment_method.id # paymentMethodのID
    },
    payment_method: payment_method.id # paymentMethodのID
},{
    stripe_account: "attr_××××××××××", # 複製先の連結アカウントID
})

【メモ】
invoice_settingsのdefault_payment_methodに「paymentMethodのID」を設定することで、一括販売・定期販売を作成するときにcustomerを設定するだけでデフォルトの支払い方法で支払いが行われる。

controlle.rb
Stripe::Subscription.create({
  customer: 'cus_×××××××', # デフォルトの支払い方法で支払いが行われる
  items: [
    {price: 'price_×××××××'},
  ],
})

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?