我建立了一个点对点市场,使用Stripe Connect处理信用卡付款,并使用条带结账并将该费用转移到连接的条带帐户及其银行帐户信息,我的帐户将收取佣金。
我的代码以前在开发模式下工作,但是一旦我将它推送到heroku,我就会在通过条带检查发送费用后收到错误。
这是我从运行heroku日志中捕获的当前错误...
Stripe :: AuthenticationError(提供的密钥' sk_live _ ******************** 3yOZ'无法访问帐户' ca _ ******************* 1LR1'(或该帐户不存在)。应用程序访问权限可能已被撤销。):
这是我的意大利面条代码......(注意:我只是Rails的一个周末战士......我很惊讶我没有任何先前的编程经验。 )
订单控制器
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
项目咖啡脚本(用户必须在列出之前使用Stripe 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)
订购咖啡脚本(Stripe将在结账时处理卡信息)
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(figaro)(密钥审查)
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"
订购_form.html.erb(只是条带脚本)
<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>
答案 0 :(得分:1)
这里的问题是你要混合你的常数。每当您代表已关联的帐户发出API请求时,您希望在acct_XXXYYYZZZ
header中传递已关联帐户的ID Stripe-Account
。
此处的问题是,您需要将平台的客户端ID ca_XXXX
传递到那里。然后,Stripe会尝试找到ID为ca_XXXX
的帐户,该帐户已连接到您的平台,并且它不存在。
你需要修改你的收费代码才能传递正确的常数:
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"] }
)