Transparent Redirect

Updating Credit Cards

Note
The integration method outlined below is deprecated. Learn more about upgrading to the Braintree SDKs.
To update credit cards using Transparent Redirect, you’ll need to build an HTML form that submits directly to Braintree. You can:
  • Update a credit card
  • Update a credit card and billing address
  • Update a credit card and create a new billing address

Form action URLAnchorIcon

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:
  1. C#
ViewData["TransparentRedirectURL"] = gateway.TransparentRedirect.Url;
And then set the action on the form in your view.
  1. HTML
<form id="NewPaymentForm" action="<%= ViewData["TransparentRedirectURL"] %>" method="post" autocomplete="off">

TR dataAnchorIcon

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 token of the credit card to update. Generating the TR Data:
  1. C#
ViewData["TrData"] = gateway.TrData(
    new CreditCardRequest {
        PaymentMethodToken = "token_of_payment_method_to_update"
    },
    "http://example.com/url_to_redirect_to"
);
Then use a hidden field to add to your form:
  1. HTML
<input id="tr_data" name="tr_data" type="hidden" value="<%= ViewData["TrData"] %>" />
Use a hidden field to add tr_data to your form.

TR form fieldsAnchorIcon

Create text fields for data parameters that you want to have your users enter.
  1. HTML
<input type="text" name="credit_card[number]" />
<input type="text" name="credit_card[expiration_date]" />
You can also include other credit card and billing address fields. For example:
  1. HTML
<input type="text" name="credit_card[cardholder_name]" />
<input type="text" name="credit_card[billing_address][street_address]" />
<input type="text" name="credit_card[billing_address][postal_code]" />
See the full list of TR HTML fields.

Create new or update existingAnchorIcon

If you’re updating a billing address along with the credit card, you’ll need to set the update_existing option of the billing address in the TR data. If this is not set, a new address will be created instead of an existing one being updated.
  1. C#
var request = new CreditCardRequest {
    PaymentMethodToken = "token_of_payment_method_to_update",
    BillingAddress = new CreditCardAddressRequest {
        Options = new CreditCardAddressOptionsRequest {
            UpdateExisting = true
        }
    }
};

TR confirmationAnchorIcon

Before the credit card 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:
  1. HTML
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 credit card using a client library.
  1. C#
Result<transaction> result = gateway.TransparentRedirect.ConfirmCreditCard(Request.Url.Query);

See alsoAnchorIcon

We currently use cookies to improve and customize your experience on our site. If you accept, we’ll also use marketing cookies to show you personalized ads. Manage your cookies and learn more.