Transparent Redirect
Creating Transactions
Note
The integration method outlined below is to be sunset in early 2024. To prevent any disruptions to
your payment processing; we recommend upgrading to
Braintree’s Drop-in integration.
Form action URL
You should set the action attribute of your form to the URL for TransparentRedirect.
- Java
gateway.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, you will want to include the amount for the transaction in tr_data
unless
you’re asking the user to enter it, as in a donation site. Generating the TR Data:
- Java
TransactionRequest trParams = new TransactionRequest()
.type(Transaction.Type.SALE)
.amount(new BigDecimal("10.00"));
String trData = gateway.transparentRedirect().trData(trParams, "<a href=\"http://example.com/url_to_redirect_to\">http://example.com/url_to_redirect_to</a>");
- HTML
<input type="hidden" name="tr_data" value="<%= tr_data %>" />
TR form fields
Create text fields for data parameters that you want to have your users enter. At minimum you will
need to have the credit card number and expiration date.
- HTML
undefined
- HTML
undefined
TR confirmation
Before the transaction is actually processed, you will need to confirm it. 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:
- HTML
http://example.com/path?http_status=200&id=vgqssrhqhxfhgrwz&hash=0c3c641f1de3ed1c732c54cab367355350603b28
- Java
Result<transaction> result = gateway.transparentRedirect().confirmTransaction(queryString);
Error handling
While confirming a transparent redirect transaction, you may encounter a not found error. If you see
this error, then this is what is most likely happening:
- A user posts a form directly to Braintree
- Braintree creates a Transparent Redirect Request
- a token is generated to represent this request
- The user is redirected to the passed URL along with the generated token
- The code on the passed URL uses the token to ask Braintree for the response to the Transparent Redirect Request (this happens in the "confirm" method)
- Braintree consumes the token representing the Transparent Redirect request.
- Braintree sends you the response details.