无法更新带有URI错误的Stripe帐户

时间:2019-04-04 00:26:05

标签: ruby-on-rails ruby stripe-payments

尝试更新Stripe Connect帐户时收到以下错误:

bad URI(is not URI?): /v1/accounts/{ "id": "acct_xxxxxxxxxxxxxxxxxx", "object": "account", "business_profile": { "mcc": null, "name": null, "product_description": 
....
....

我能够创建帐户,但更新它们似乎无效。我在控制器中使用相同的形式和相似的代码。这是我在控制器中的更新方法:

def update

    unless (current_user || current_affiliate).stripe_account
      redirect_to new_user_stripe_account_path and return
    end

  begin
    @stripe_account_retrieve = Stripe::Account.retrieve((current_user || current_affiliate).stripe_account.acct_id)

    stripe_account_params.each do |key, value|
      if value.empty?
        flash.now[:alert] = "Please complete all fields."
        render 'edit' and return
      end
    end

    if @stripe_account.account_type == "individual"
       Stripe::Account.update(
        @stripe_account_retrieve,
        {
      :country => stripe_account_params[:country],
      :type => "custom",
      :business_type => stripe_account_params[:account_type],
      requested_capabilities: ['platform_payments'],
        individual: {
          address: stripe_account_params[:address_line1],
          first_name: stripe_account_params[:first_name],
          last_name: stripe_account_params[:last_name],
          ssn_last_4: stripe_account_params[:ssn_last_4],
          # phone: stripe_account_params[:business_tax_id],
            dob: {
              day: stripe_account_params[:dob_day],
              month: stripe_account_params[:dob_month],
              year: stripe_account_params[:dob_year]
            },
            address: {
              line1: stripe_account_params[:address_line1],
              city: stripe_account_params[:address_city],
              state: stripe_account_params[:address_state],
              postal_code: stripe_account_params[:address_postal]
            },
          },
        tos_acceptance: {
          date: Time.now.to_i,
          ip: request.remote_ip
        }

    })
....
....
respond_to do |format|
      @stripe_account = StripeAccount.find(params[:id])
      if @stripe_account.update(stripe_account_params)
        format.html { redirect_to @stripe_account, notice: 'Stripe account was successfully updated.' }
        format.json { render :show, status: :ok, location: @stripe_account }
      else
        format.html { render :edit }
        format.json { render json: @stripe_account.errors, status: :unprocessable_entity }
      end
    end
  end 
end

根据文档,我没有发现我做错了什么... https://stripe.com/docs/api/accounts/update

我在控制器中所做的编辑:

def edit
    @stripe_account_retrieve = Stripe::Account.retrieve((current_user || current_affiliate).stripe_account.acct_id)
    @stripe_account = StripeAccount.find(params[:id])
end

当我提交更新表格时(这是错误之前的内容:)

Started PATCH "/stripe_accounts/27" for 127.0.0.1 at 2019-04-03 20:16:38 -0400
Processing by StripeAccountsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"3//b+Exxxf9xxxtagFbsdzMxxxW+wxxxx899FDLfMb/RxxxxQA==", "stripe_account"=>{"first_name"=>"seller21114", "last_name"=>"last2124", "ssn_last_4"=>"2222", "dob_month"=>"1", "dob_day"=>"10", "dob_year"=>"1912", "address_line1"=>"111 st", "address_city"=>"san fran", "country"=>"US", "address_state"=>"IL", "address_postal"=>"90210", "tos"=>"1"}, "2"=>"", "button"=>"", "id"=>"27"}

在这里我的代码有什么地方做错了吗?

1 个答案:

答案 0 :(得分:1)

Stripe::Account.update(
        @stripe_account_retrieve,... )

应该是

Stripe::Account.update(
        @stripe_account_retrieve[:id], ...)

,即传递您检索到的Account对象的ID,而不是完整对象本身的ID。

或者直接将(current_user || current_affiliate).stripe_account.acct_id的值传递给Stripe::Account.update,因为您当前似乎还没有将检索到的帐户用于其他任何用途,因此您最好自己保存一个GET请求:) < / p>