Transparent Redirect
Creating Customers
The integration method outlined below is deprecated. Learn more about upgrading to the Braintree SDKs.
To create customers using Transparent Redirect, you’ll need to build an HTML form that submits directly to Braintree.
Form action URL
- HTML
<form method="POST" action="<?php echo Braintree_TransparentRedirect::url(); ?>">
TR data
The form needs to include a hidden field named tr_data
. It needs to include the URL that Braintree will redirect the user to after storing the form params. You should also include any parameter that you want to send to Braintree that you’re not asking your users to enter. For example, if you are specifying the customer ID rather than letting the gateway generate one, it should be included in tr_data
.
Generating the TR data:
- PHP
$trData = Braintree_TransparentRedirect::transactionData(
array(
'transaction' => array(
'type' => Braintree_Transaction::SALE,
'amount' => '100.00'
),
'redirectUrl' => 'http://www.example.com/url_to_redirect_to'
)
);
Then use a hidden field to add to your form:
- HTML
<input type="hidden" name="tr_data" value="<?php echo htmlentities($trData) ?>" />
TR form fields
Create text fields for data parameters that you want to have your users enter. If you’re just creating a customer without credit card, nothing is required, so it’s up to you what you collect. But you’re probably using the TR API because you will be creating a credit card along with the customer. In that case, the credit card number and expiration date are required.
- HTML
<input type="text" name="customer[credit_card][number]" />
<input type="text" name="customer[credit_card][expiration_date]" />
You can also include other customer, credit card, and billing address fields. For example:
- HTML
<input type="text" name="customer[email]" />
<input type="text" name="customer[credit_card][cardholder_name]" />
<input type="text" name="customer[credit_card][billing_address][street_address]" />
<input type="text" name="customer[credit_card][billing_address][postal_code]" />
See the full list of TR HTML fields.
TR confirmation
Before the customer is actually created, you will need to confirm the TR request. For the confirmation, you will need to use the query string from the URL on the Redirect. Braintree will add parameters to the query string that identify the request, so the redirect URL will look something like:
http://example.com/path?http_status=200&id=vgqssrhqhxfhgrwz&hash=0c3c641f1de3ed1c732c54cab367355350603b28
Use the query string to confirm. You’ll receive a result object just like if you created a customer using a client library.
- HTML
$result = Braintree_TransparentRedirect::confirm($queryString);