Integrating a new payment provider can be daunting, and the official documentation unneccesarily complex. Here are four easy steps to a complete Braintree integration.

Note that you don’t technically need an SSL certificate to be compliant, as the form itself is secured by Braintree, but we would highly recommend the purchase of at least the basic certificate, if only for customer confidence.

Step 1

Download the SDK from here https://developers.braintreepayments.com/start/hello-server/php. You can deleted the “tests” folder as it’s not required.

Step 2

Create a config file to include Braintree, plus your API credentials (you’ll need to sign up to get these https://www.braintreepayments.com/get-started).

Step 3

Generate your Client Token then create a payment form along with the required Javascript.

All you need to do is make sure you have a div within the form with the same ID as the “container” in the Javascript. The Javascript will then generate the required form inputs for credit card information (plus a PayPal button if set up to do so within your Braintree account).

Step 4

The take-payment.php page (to which the form above posts) then needs to charge the card.

 

The above will charge £1 to the card. In a production environment you’d want to retrieve the customer’s order details here to get the correct amount.

 

This code is free to use at your own discretion. It comes without warranty. Please feel free to feedback any edits.

Discussion
Add a comment
Adam Mayhead

this isn’t complete surely?

you say make a config file. put it where? include it where?

where do we put the generate token code?

the file locatoin of the library, the version number has since changed, surely it’s best to show that this needs updating as numbers change?

the location of the library should be said surely so that we are referencing it correctly

    Chris Antcliff

    It’s a quick, simple guide to help; everything’s there to get Braintree payment up and running.

    The config file needs to be on your server where it can access the library and be included in any file that deals with Braintree.

    Step 3 deals with the Client Token. Please read it carefully.

    I hope this helps.

Add a comment