Updating Customers using Transparent Redirect

To update customers using Transparent Redirect, you’ll need to build an HTML form that submits directly to Braintree. You can:

Form Action URL

You should set the action attribute of your form to the url for TransparentRedirect.

You’ll want to set the transparent redirect URL in your controller action. In ASP.NET MVC, for example:

  ViewData["TransparentRedirectURL"] = gateway.TransparentRedirect.Url;

And then set the action on the form in your view.

<form id="NewPaymentForm"
      action="<%= ViewData["TransparentRedirectURL"] %>"
      method="post" autocomplete="off">

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. It also needs to include the ID of the customer to update.

Generating the TR data:

ViewData["TrData"] = gateway.TrData(
    new CustomerRequest
    {
        CustomerId = "id_of_customer_to_update"
    },
    "http://example.com/url_to_redirect_to");

Then use a hidden field to add to your form:

<input id="tr_data" name="tr_data" type="hidden" value="<%= ViewData["TrData"] %>" />

TR Form Fields

Create text fields for data parameters that you want to have your users enter.

<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:

<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.

Create New or Update Existing

If you’re updating a credit card along with the customer, you’ll need to set the token of the credit card to update in the TR data. If this is not set, a new credit card will be created instead of an existing one updated.

ViewData["TrData"] = gateway.TrData(
    new CustomerRequest
    {
        CustomerId = "id_of_customer_to_update",
        CreditCard = new CreditCardRequest()
        {
            Options = new CreditCardOptionsRequest()
            {
                UpdateExistingToken = "token_of_credit_card_to_update"
            }
        }

    },
    "http://example.com/url_to_redirect_to");

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 updated a customer using the server-to-server API.

Result<Customer> result = gateway.TransparentRedirect.ConfirmCustomer(Request.Url.Query);

See Also