Checkout with Vault

Checkout with Vault is a one-time PayPal Checkout experience that includes vaulting capabilities. It automatically creates a PayPal Billing Agreement and stores a customer's PayPal account in the Braintree Vault. You can then charge the account in the future without requiring your customer to re-authenticate with PayPal or choose a payment method again within their wallet.

Checkout with Vault supports the following features:

  • Select or add shipping addresses to the PayPal account
  • Select or add funding instruments to the PayPal account
  • Support two-factor authentication, currently available only in the US, UK, CA, DE, AT, and AU
  • Get the customer's authorization to store the PayPal wallet in the Vault

Typical use cases for the Checkout with Vault flow are similar to those of One-time Payments, with the added benefit of storing the PayPal wallet to reduce friction when the customer returns for a repeat purchase. Common use cases include:

  • Checkout from cart or product pages
  • Checkout page replacement
  • As a payment source

Invoke the Checkout with Vault flowAnchorIcon

To request a Checkout with Vault payment, create a session with createCheckoutWithVaultSession and include the amount, currency, and billingAgreementDetails.description options. If you use intent, set it on the session (the default is capture).

Include these additional options:

  • billingAgreementDetails.description: a description of the billing agreement to show the customer

  • Call session.start() from your PayPal button's click handler to open the PayPal flow.

  • Use the onShippingAddressChange and onShippingOptionsChange session options to listen for shipping changes within the PayPal flow, and return updatePayment with the modified line items or shipping options. Alternatively, use shippingCallbackUrl to handle shipping changes on your server. It can't be combined with the two callbacks.

  • Use the PayPal Checkout v6 instance in the onApprove callback to tokenize the PayPal account with tokenizePayment({ orderID: data.orderId, payerID: data.payerId }). After the customer completes the consent flow and the PayPal pop-up closes, successful tokenization returns a payment method single-use token.

  • Send the single-use token to your server and use a Braintree server SDK to call Transaction.sale to create a transaction. When you create a Transaction.sale using a single-use token from the Checkout with Vault flow, the result contains a PayPal details object with an implicitlyVaultedPaymentMethodToken property. You can then associate this payment method token with your customer for future transactions.

  1. JavaScript
async function setupCheckoutWithVault() {
  try {
    const client = await braintree.client.create({
      authorization: "CLIENT-TOKEN",
    });
    const paypal = await braintree.paypalCheckoutV6.create({ client: client });
    await paypal.loadPayPalSDK();

    const session = paypal.createCheckoutWithVaultSession({
      amount: "10.00",
      currency: "USD",
      intent: "capture",
      billingAgreementDetails: {
        description: "Monthly subscription to Totally Real Products!",
      },
      onApprove: async function (data) {
        const payload = await paypal.tokenizePayment({
          orderID: data.orderId,
          payerID: data.payerId,
        });
        // Submit payload.nonce to your server
      },
      onCancel: function () {
        console.log("Payment canceled");
      },
      onError: function (err) {
        console.error("Payment error:", err);
      },
    });

    document
      .getElementById("paypal-checkout-with-vault-button")
      .addEventListener("click", function () {
        session.start();
      });
  } catch (err) {
    // Handle error
  }
}

Returning customerAnchorIcon

Returning customers who have already stored the PayPal wallet in the Vault can change the payment method they previously selected within the PayPal wallet.

Customers can change their payment method by selecting the saved payment method element, which opens the PayPal flow.

For vaulted customers, you can add a <paypal-saved-payment-methods> element. It shows the buyer's current PayPal payment method, and clicking it opens PayPal so they can change it.

  1. Use a client token generated with a customer ID and a preferredPaymentMethodToken for the vaulted PayPal Billing Agreement when you initialize the Braintree client instance.
  2. Add a <paypal-saved-payment-methods> element to your page before you call loadPayPalSDK().
  3. Create the session with createEditSavedPaymentSession, passing amount, currency, and onApprove, and call session.start() when the buyer clicks the element.

Country supportAnchorIcon

PayPal is available to merchants in all supported countries and to customers in more than 140 countries. Make sure you use a locale code as described in the JavaScript PayPalCheckoutV6 reference.

Currency presentmentAnchorIcon

Checkout with Vault shows the transaction currency to the customer. Braintree supports all currencies that the PayPal REST APIs support.

For details on charging a transaction in a specific currency, see the Currency support section of the server-side guide.