DaudiHell DaudiHell - 2 months ago 28
Ruby Question

Braintree checkout gives error `Braintree::ConfigurationError` after deploy

Hi I deployed an App to a VPS yesterday using Passenger/Capistrano and Nginx server.

All is running smoothly except when I enter the

checkout
button on the order page.

Then the app crashes and in the
production.log
there is this error line
Braintree::ConfigurationError (Braintree::Configuration.merchant_id needs to be set):
app/controllers/orders_controller.rb:22:in 'new'


The thing is that the
Merchiant_id
is set and I'm totally lost.

before the deploy I changed the
Sandbox
API keys to
Production
API keys in
application.yml
. I'm using
figaro
to hide the
API keys
.

When I ran this on the
localhost
before deploy everything worked fine.

I've went through the Braintree guides again and again. I can't find anything wrong.

Am I missing something here?

here is the
orders_controller.rb
were the error is coming from.

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

Answer

I had a similar problem once, basically it was the same Error.

What I did to solve this in my case was to add config/application.yml to set :linked_files in the `deploy.rb``

so the line would look something like this set :linked_files, %w{ config/application.yml}

then before you deploy again you must create the application.yml on the server. Most likely it is in ~/YOURAPP/shared/config$

And you copy/paste the code from the application.yml on your machine to the ~/YOURAPP/shared/config/application.yml

I can almost bet that adding this will fix your problem