If you haven't already, sign up for a free Braintree sandbox account:
Log in to obtain your sandbox API credentials. You'll need your:
- Sandbox Merchant ID
- Public Key
- Private Key
Use these credentials for your development and testing. When you go live, you will need to replace your sandbox API credentials with production API credentials.
braintree gem to your project's Gemfile:
bundle install to install it.
In your code, configure the environment and API credentials:
Braintree::Configuration.environment = :sandbox Braintree::Configuration.merchant_id = "use_your_merchant_id" Braintree::Configuration.public_key = "use_your_public_key" Braintree::Configuration.private_key = "use_your_private_key"
Your server is responsible for generating a client token, which contains all authorization and configuration information your client needs to initialize the client SDK to communicate with Braintree. Hello Client! covers the client side of the exchange.
Mobile clients need to make a request to your server to fetch a client token. Create a server endpoint to send client tokens to the device.
get "/client_token" do Braintree::ClientToken.generate( :customer_id => a_customer_id ) end
Once your client successfully obtains a customer payment method, it receives a
payment_method_nonce representing customer payment authorization, which it then sends to your server.
Your server implementation is then responsible for receiving the
payment_method_nonce and using it appropriately.
post "/purchases" do nonce = params[:payment_method_nonce] # Use payment method nonce here... end
You can create a transaction using a
payment_method_nonce and an
result = Braintree::Transaction.sale( :amount => "100.00", :payment_method_nonce => "nonce-from-the-client" )
To verify your integration, you can check in the Sandbox control panel, where transactions will immediately appear on success.
Develop and test your code against your sandbox account before processing live transactions against a production account.
Braintree's sandbox environment provides test values (card numbers, amounts, CVVs, and postal codes) for you to simulate transactions with validated cards.
In order to simplify testing your server side code, the Braintree library provides static
payment_method_nonce values for you to use in the Braintree sandbox.
||A valid nonce that can be used to create a transaction|
||A nonce that has already been consumed (this will return a validation error)|
||A nonce representing a Google Wallet request|
||A nonce representing an Apple Pay request for an AmEx card number|
||A nonce representing an Apple Pay request for an Visa card number|
||A nonce representing an Apple Pay request for an MasterCard card number|
||A nonce representing a Coinbase account|
||A nonce representing an unvaulted PayPal account that a user has authorized for the one time payment flow. You can use any email address and password you like when testing PayPal in Sandbox, but there are some restrictions to consider if doing end-to-end testing.|
||A nonce representing an unvaulted PayPal account that a user has authorized for the future payment flow. You can use any email address and password you like when testing PayPal in Sandbox, but there are some restrictions to consider if doing end-to-end testing.|
When writing integrations tests against the Braintree sandbox environment, you may use these nonces in place of the nonce that would normally be returned from the client side integration.
Braintree::Test::Nonce::Transactable Braintree::Test::Nonce::Consumed Braintree::Test::Nonce::PayPalOneTimePayment Braintree::Test::Nonce::PayPalFuturePayment
At this point, you should be able to accept a payment method nonce and create a transaction in our Sandbox. When you're ready to start charging real money, transition over to our Production environment. We'll explain that process next.
Was this page helpful? Give us some feedback.