E-wallets with redirect

E-wallets with redirects, such as PayPal, Klarna and Skrill, redirect the user to the payment system website to authorize and confirm the payment, after which they return to the seller’‎s website. This method ensures payment security, as the seller doesn’‎t have access to the user payment data.

The instruction below describes the Headless checkout configuration to accept payments via e-wallets with redirects using PayPal as an example.

  1. Create a payment status page where the user will be redirected after PayPal payment. For example, https://example.com/return-page.html.

  2. Add the psdk-status component to the HTML markup of the payment UI to display a payment status.

Example:

Copy
Full screen
Small screen
@if (showStatus) {
  <psdk-status></psdk-status>
}
  1. Create a page to display the PayPal form. For example, https://example.com/form-page.html.

  2. Initialize the payment UI specifying the payment method ID and status page URL.

Example:

Copy
Full screen
Small screen
await headlessCheckout.form.init({
  paymentMethodId: 24, // PayPal payment ID
  returnUrl: 'https://example.com/return-page.html',
});
  1. Add the handling of the redirect event to redirect the user to an external page to make payment via PayPal. After completing the purchase, the user is redirected to the payment status page (https://example.com/return-page.html).

Example:

Copy
Full screen
Small screen
headlessCheckout.form.onNextAction((nextAction) => {
  switch (nextAction.type) {
    case 'redirect':
      this.handleRedirectAction(nextAction);
  }
});

private handleRedirectAction(redirectAction: RedirectAction): void {
  const url = this.buildRedirectUrl(redirectAction);
  window.location.href = url; // redirect to PayPal page
}

private buildRedirectUrl(redirectAction: RedirectAction): string {
  const url = new URL(redirectAction.data.redirect.redirectUrl);
  const params = Object.entries(redirectAction.data.redirect.data);
  params.forEach((entry) => {
    const [key, value] = entry;
    url.searchParams.append(key, value);
  });
  return url.toString();
}
Implementation sample
Refer to the detailed sample on GitHub.
Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Last updated: March 5, 2025

Found a typo or other text error? Select the text and press Ctrl+Enter.

Report a problem
We always review our content. Your feedback helps us improve it.
Provide an email so we can follow up
Thank you for your feedback!