Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View braintree.rb
1 2 3 4 5 6 7 8 9 10 11
if Rails.env.production?
Braintree::Configuration.environment = Rails.env.staging? ? :sandbox : :production
Braintree::Configuration.merchant_id = ENV["braintree_merchant_id"]
Braintree::Configuration.public_key = ENV["braintree_public_key"]
Braintree::Configuration.private_key = ENV["braintree_private_key"]
else
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = "<super secret>"
Braintree::Configuration.public_key = "<super secret>"
Braintree::Configuration.private_key = "<super secret>"
end
View braintree.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 
<%= simple_form_for @braintree_customer,
:as => :customer,
:url => Braintree::TransparentRedirect.url,
:html => {:class => "form"} do |f| %>
 
<%= f.input :first_name, :required => true %>
<%= f.input :last_name, :required => true %>
<%= f.input :email, :required => true %>
 
<%= f.fields_for :credit_card, @braintree_customer.credit_card do |cc| -%>
<%= cc.input :number,
:input_html => {:autocomplete => "off" },
:wrapper_html => {:class => "credit_card_number"},
:hint => image_tag("/images/cards_accepted.png", :alt => "MasterCard, Visa") %>
<%= cc.input :expiration_month, :collection => 1..12,
:required => true,
:wrapper_html => {:class => "expiration_month"} %>
<%= cc.input :expiration_year,
:wrapper_html => {:class => "expiration_year"},
:collection => Time.zone.now.year..(Time.zone.now.year + 25) %>
 
<%= cc.input :cvv,
:input_html => {:autocomplete => "off" },
:required => true,
:wrapper_html => {:class => "cvv"} %>
<%- end -%>
<%= f.button :submit %>
<%- end -%>
View braintree.rb
1
add_column :accounts, :payment_processor_subscription_id, :integer

I think there is a mistake in your example:

if Rails.env.production?
  Braintree::Configuration.environment = Rails.env.staging? ? :sandbox : :production
  ...
else
  ...
end

Shouldn't that line just be

Braintree::Configuration.environment = :production

There can only be one active environment at any given time.

Owner

no that's a ternary operator basically if the equivalent of

  if Rails.env.staging?
    Braintree::Configuration.environment = :sandbox
  else
    Braintree::Configuration.environment = :production
  end

I'm well aware of the ternary operator. Maybe you didn't see this part of my comment:

There can only be one active environment at any given time.

If execution falls through the if Rails.env.production? branch, Rails.env.staging? will always return false, right? So in your gist, :production would always be the outcome. That's why I said you might as well just hard-code it to :production.

Sorry, made a typo in my previous comment. I've updated it.

hoverlover is correct, this would not actually work right. Saying "if not Rails.env.test?" in the first check would give the effect the author wants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.