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.
If you're integrating Pay Later offers, you'll need to render the Pay Later button in addition to the PayPal button.
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 flow
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 customerCall
session.start()from your PayPal button's click handler to open the PayPal flow.Use the
onShippingAddressChangeandonShippingOptionsChangesession options to listen for shipping changes within the PayPal flow, and returnupdatePaymentwith the modified line items or shipping options. Alternatively, useshippingCallbackUrlto handle shipping changes on your server. It can't be combined with the two callbacks.Use the PayPal Checkout v6 instance in the
onApprovecallback to tokenize the PayPal account withtokenizePayment({ 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.saleto create a transaction. When you create aTransaction.saleusing a single-use token from the Checkout with Vault flow, the result contains a PayPal details object with animplicitlyVaultedPaymentMethodTokenproperty. You can then associate this payment method token with your customer for future transactions.
- 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 customer
If you're integrating Pay Later offers, this step is mandatory. Returning customers can choose a Pay Later offer if they see PayPal Pay Later messaging in their shopping experience. Be sure to also render the Pay Later button in addition to the PayPal button for the returning customer experience.
To activate Pay Later offers in your Checkout with Vault integration, reach out to your PayPal account manager or contact us.
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.
- Use a client token generated with a customer ID and a
preferredPaymentMethodTokenfor the vaulted PayPal Billing Agreement when you initialize the Braintree client instance. - Add a
<paypal-saved-payment-methods>element to your page before you callloadPayPalSDK(). - Create the session with
createEditSavedPaymentSession, passingamount,currency, andonApprove, and callsession.start()when the buyer clicks the element.
Country support
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 presentment
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.