paypalCheckout.
Manage the link in the customer account
The page has two states, which are distinguished via the function wsAccount.hasPaymentVault(): if a link exists, a form for removing the link is displayed. If no link exists, the PayPal button is displayed. This creates the link in two steps: first,PaymentValueSetup fetches the setup token, and then the customer approves the link at PayPal. Finally, PaymentValueCreate saves it.
Because PaymentVaultCreate does not return a response body, the example reloads the page after creation. Only then does hasPaymentVault() return the new state.
The example is designed for testability, not for production readiness. The JavaScript part should be extended before going live:
onError only logs errors to the console, and a failure of PaymentVaultCreate stays hidden from the customer because the page is reloaded immediately afterwards, causing the action errors of the preceding POST to be lost.Offer the link during checkout
If a link already exists for the selected payment method, the order is paid directly through it and the PayPal button is omitted. If no link exists yet, you can offer the customer the option to create one with the current order. All that is needed for this is the form fieldinitPaymentValue — the link is then created automatically at order completion.
- The customer is logged in.
- It is not an express checkout.
- The selected payment method is pure PayPal payment, not PayPal SEPA or PayPal PayLater.
- No link exists yet.
If one of these conditions is not met, the order is completed normally and the link is simply not created; there is no error code for this. If you want to offer link creation to the customer reliably, use the approach via a dedicated page in the customer account, see Manage the link in the customer account.
