2016-10-15 7 views
0

나는 Stripe Connect를 사용하여 피어 투 피어 마켓 플레이스를 구축하여 스트라이프 체크 아웃으로 신용 카드 결제를 처리하고 해당 청구를 은행 계좌 정보로 연결된 스트라이프 계좌로 이체하고 계좌에 위원회.Stripe Connect - Stripe :: AuthenticationError

내 코드는 이전에 개발 모드에서 작동했지만 heroku에 살짝 밀어 넣으면 충전이 스트라이프 체크 아웃을 통해 전송 된 후 오류가 발생합니다.

이 내가 실행 Heroku가 로그에서 잡기있어 현재의 에러입니다 ...

스트라이프 :: AuthenticationError (제공된 키 'sk_live _ ************** ****** 3yOZ '는'ca _ ***************** 1LR1 '계정에 대한 액세스 권한이 없거나 해당 계정이 존재하지 않습니다.) :

여기는 내 스파게티 코드입니다. (참고 : 저는 주말에 전사가 된 레일스입니다. 이전의 프로그래밍 경험이 없었기 때문에 이걸 가지고 놀랍습니다.)

,

주문 컨트롤러

class OrdersController < ApplicationController 
    before_action :set_order, only: [:show, :edit, :update, :destroy] 
    before_action :authenticate_user! 


    def sales 
    @orders = Order.all.where(seller: current_user).order("created_at DESC") 
    end 

    def purchases 
    @orders = Order.all.where(buyer: current_user).order("created_at DESC") 
    end 

    # GET /orders/new 
    def new 
    @order = Order.new 
    @item = Item.find(params[:item_id]) 
    end 

    # POST /orders 
    # POST /orders.json 
    def create 
    @order = Order.new(order_params) 
    @item = Item.find(params[:item_id]) 
    @seller = @item.user 

    @order.item_id = @item.id 
    @order.buyer_id = current_user.id 
    @order.seller_id = @seller.id 

    token = params[:stripeToken] 

    begin 

    customer = Stripe::Customer.create(
     :email => params[:stripeEmail], 
     :source => token 
    ) 

    require 'json' 

     charge = Stripe::Charge.create({ 
     :customer => customer.id, 
     :amount => (@item.price * 91.1).floor - 30, 
     :currency => "usd", 
     :description => @item.title, 
     :application_fee => ((@item.price * 100) * 0.089).floor + 30 
     }, 
     {:stripe_account => ENV["STRIPE_CONNECT_CLIENT_ID"] } 
    ) 
     @order.name = params[:stripeShippingName] 
     @order.address = params[:stripeShippingAddressLine1] 
     @order.city = params[:stripeShippingAddressCity] 
     @order.state = params[:stripeShippingAddressState] 
     @order.zip = params[:stripeShippingAddressZip] 
     @order.country = params[:stripeShippingAddressCountry] 

     flash[:notice] = "Thanks for ordering!" 
    rescue Stripe::CardError => e 
     flash[:danger] = e.message 
     redirect_to new_order_path 
    end 

    respond_to do |format| 
     if @order.save 
     format.html { redirect_to root_url } 
     format.json { render :show, status: :created, location: @order } 
     else 
     flash[:alert] = "Something went wrong :(" 
     # gon.client_token = generate_client_token 
     format.html { render :new } 
     format.json { render json: @order.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_order 
     @order = Order.find(params[:id]) 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
    def order_params 
     if params[:orders] && params[:orders][:stripe_card_token].present? 
     params.require(:orders).permit(:stripe_card_token) 
     end 
    end 

end 

OmniAuth 콜백 컨트롤러

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 

    def stripe_connect 
    @user = current_user 
    if @user.update_attributes({ 
     provider: request.env["omniauth.auth"].provider, 
     uid: request.env["omniauth.auth"].uid, 
     access_code: request.env["omniauth.auth"].credentials.token, 
     publishable_key: request.env["omniauth.auth"].info.stripe_publishable_key 
    }) 
     # anything else you need to do in response.. 
     sign_in_and_redirect @user, :event => :authentication 
     set_flash_message(:notice, :success, :kind => "Stripe") if is_navigational_format? 
    else 
     session["devise.stripe_connect_data"] = request.env["omniauth.auth"] 
     redirect_to new_user_registration_url 
    end 
    end 

end 

항목 커피 스크립트 (사용자가 나열하기 전에 스트라이프 Connect에서 은행 계좌 정보를 연결해야합니다) (

jQuery -> 
    Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')) 
    item.setupForm() 

item = 
    setupForm: -> 
    $('#new_item').submit -> 
     $('input[type=submit]').attr('disabled', true) 
     Stripe.bankAccount.createToken($('#new_item'), item.handleStripeResponse) 
     false 

    handleStripeResponse: (status, response) -> 
    if status == 200 
     $('#new_item').append($('<input type="hidden" name="stripeToken" />').val(response.id)) 
     $('#new_item')[0].submit() 
    else 
     $('#stripe_error').text(response.error.message).show() 
     $('input[type=submit]').attr('disabled', false) 

주문 커피 스크립트 스트라이프을 것이다 계산시 카드 정보 처리)

jQuery -> 
    Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')) 
    payment.setupForm() 

payment = 
    setupForm: -> 
    $('#new_order').submit -> 
     $('input[type=submit]').attr('disabled', true) 
     Stripe.card.createToken($('#new_order'), payment.handleStripeResponse) 
     false 

    handleStripeResponse: (status, response) -> 
    if status == 200 
     $('#new_order').append($('<input type="hidden" name="stripeToken" />').val(response.id)) 
     $('#new_order')[0].submit() 
    else 
     $('#stripe_error').text(response.error.message).show() 
     $('input[type=submit]').attr('disabled', false) 

devise.rb 이니셜

config.omniauth :stripe_connect, 
    ENV['STRIPE_CONNECT_CLIENT_ID'], 
    ENV['STRIPE_SECRET_KEY'], 
    :scope => 'read_write', 
    :stripe_landing => 'register' 

stripe.rb 이니셜

Rails.configuration.stripe = { 
    :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'], 
    :secret_key  => ENV['STRIPE_SECRET_KEY'] 
} 

Stripe.api_key = Rails.configuration.stripe[:secret_key] 

application.yml (피가로) (검열 키)

주문 _form.html.erb

production: 
    STRIPE_SECRET_KEY: "sk_live_****************3yOZ" 
    STRIPE_PUBLISHABLE_KEY: "pk_live_******************HhWi" 
    STRIPE_CONNECT_CLIENT_ID: "ca_**********************1LR1" 
    CONNECTED_STRIPE_ACCOUNT_ID: "acct_***********crNm" 
(스트라이프 스크립트 만)

<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" 
      data-key="<%= Rails.configuration.stripe[:publishable_key] %>" 
      data-description="<%= @item.title %>" 
      data-amount="<%= (@item.price * 100).floor %>" 
      data-email="<%= current_user.email %>" 
      data-shipping-address="true" 
      data-locale="auto"></script> 

답변

1

여기서 문제는 상수를 혼합한다는 것입니다. 연결된 계정 대신 API 요청을 할 때마다 연결된 계정의 ID 인 acct_XXXYYYZZZStripe-Accountheader에 전달하려고합니다.

여기서 문제는 대신 플랫폼의 클라이언트 ID ca_XXXX을 전달한다는 것입니다. 그런 다음 Stripe은 플랫폼에 연결된 ca_XXXX ID의 계정을 찾으려고 시도했지만 존재하지 않습니다.

당신은 정확한 일정하게 전달하여 충전 코드를 수정해야

:

charge = Stripe::Charge.create({ 
    :customer => customer.id, 
    :amount => (@item.price * 91.1).floor - 30, 
    :currency => "usd", 
    :description => @item.title, 
    :application_fee => ((@item.price * 100) * 0.089).floor + 30 
    }, 
    {:stripe_account => ENV["CONNECTED_STRIPE_ACCOUNT_ID"] } 
) 
+0

가 감사를! 문제 해결됨 –