Braintree checkout在部署后出现错误`Braintree :: ConfigurationError`

时间:2016-09-29 16:38:31

标签: ruby-on-rails ruby nginx e-commerce braintree

您好我昨天使用Passenger / Capistrano和Nginx服务器将应用程序部署到了VPS。

除非我在订单页面上输入checkout按钮,否则一切都在顺利进行。

然后应用程序崩溃,production.log出现此错误行Braintree::ConfigurationError (Braintree::Configuration.merchant_id needs to be set): app/controllers/orders_controller.rb:22:in 'new'

问题是Merchiant_id已经确定,我完全迷失了。

在部署之前,我将Sandbox API密钥更改为Production中的application.yml API密钥。我正在使用figaro隐藏API keys

当我在部署之前在localhost上运行它时,一切正常。

我一次又一次地浏览了Braintree指南。我找不到任何错误。

我在这里错过了什么吗?

这里是错误来自的orders_controller.rb

class OrdersController < ApplicationController

include CurrentCart
before_action :set_cart, only: [:new, :create]
before_action :set_order, only: [:show, :edit, :destroy]

def index
    @orders = Order.all? 
end

def new
    @images  = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"]
 @random_no = rand(5)
 @random_image = @images[@random_no]

    if @cart.product_items.empty?
        redirect_to root_url, notice: 'Your Cart is Empty'
        return

    end
    @order = Order.new
    @client_token = Braintree::ClientToken.generate #this is line 22 were the error is
end

def create
    @order = Order.new(order_params)
    if @order.save
        charge
        if @result.success?
            @order.add_product_items_from_cart(@cart)
        Cart.destroy(session[:cart_id])
        session[:cart_id] = nil
        OrderNotifier.received(@order).deliver 
        redirect_to root_url, notice: 'Thank You for Your Order'
        else
            flash[:error] = 'Please Check Your Cart'
            redirect_to root_url, alert: @result.message
            @order.destroy
        end
    else
        @client_token = Braintree::ClientToken.generate
        render :new
    end
end


def show

end


def destroy
    @order.destroy
    redirect_to root_url, notice: 'Order deleted'
end

private

def set_order
    @order = Order.find(params[:id])
end

def order_params
    params.require(:order).permit(:name, :email, :address, :city, :country)
end

def charge
    @result = Braintree::Transaction.sale(
        amount: @cart.total_price_usd,
        payment_method_nonce: params[:payment_method_nonce] )
end

end

1 个答案:

答案 0 :(得分:1)

我曾经遇到过类似的问题,基本上它是相同的错误。

在我的案例中,我所做的就是在`deploy.rb``中将config/application.yml添加到set :linked_files

因此该行看起来像set :linked_files, %w{ config/application.yml}

然后再次部署之前,您必须在服务器上创建application.yml。最有可能是~/YOURAPP/shared/config$

您将代码从计算机上的application.yml复制/粘贴到~/YOURAPP/shared/config/application.yml

我几乎可以打赌,添加此功能可以解决您的问题