簡體   English   中英

如何獲取當前的用戶關聯帳戶,以便在對不同的關聯帳戶進行條紋API調用時使用該帳戶

[英]How do I get the current user connected account so that I use it when making stripe api calls for different connected accounts

 def stripe_charges_not_paid
    if Rails.env.production?
      Stripe.api_key = ENV['STRIPE_SECRET_KEY_PRO']
    else
      Stripe.api_key = ENV['STRIPE_SECRET_KEY']
    end
    Stripe::Charge.list(limit: 100, paid: false ,stripe_account: CONNECTED_STRIPE_ACCOUNT_ID)
  end

現在,它在終端上給我一個錯誤的未初始化常量User :: CONNECTED_STRIPE_ACCOUNT_ID。

創建用戶的Stripe帳戶時,返回的數據包括id (它將以“ acct _...”開頭)。 您應該將ID存儲在用戶記錄中的字段中……您可以根據自己的:stripe_account_id進行選擇,但:stripe_account_id是一個不錯的選擇。 另外,請確保在創建帳戶時將帳戶電子郵件設置為current_user電子郵件。

您可以在用戶模型中獲取具有以下內容的關聯帳戶列表...

  require "stripe"
  def stripe_user_account
    return @stripe_user_account if defined? @stripe_user_account
    if Rails.env.production?
      Stripe.api_key = ENV['STRIPE_SECRET_KEY_PRO']
    else
      Stripe.api_key = ENV['STRIPE_SECRET_KEY']
    end

    Stripe::Account.list(limit: 99).each do |account|
      if account.email == self.email
        @stripe_user_account = account.id 
        break
      end
    end
    @stripe_user_account
  end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM