For the complete documentation index, see llms.txt. This page is also available as Markdown.

Function: resolveAdyenCheckoutEntry()

function resolveAdyenCheckoutEntry(params): AdyenCheckoutEntry;

Determines how the checkout page was entered.

Parameters

params

AdyenCheckoutQueryParams

Query parameters of the checkout page

Returns

AdyenCheckoutEntry

Whether the page was mounted fresh or entered from a redirect

Remarks

Adyen returns the customer to the returnUrl of the checkout with a sessionId and a redirectResult after payment methods such as iDEAL, Bancontact or a 3D Secure challenge. Re-initialise Drop-in with the returned session id and submit the result instead of creating a new session, otherwise the customer starts paying all over again. On a redirect return the payment is already with Adyen, so read the outcome before doing anything else. A session cannot be created for a payment that has been paid, and the webhook that pays it often lands before the customer is back.

Example

const entry = resolveAdyenCheckoutEntry(new URLSearchParams(window.location.search));
// The token of the payment returned by `client.carts.createSubscription`, stored
// before Drop-in was mounted so that it survives the redirect.
let paymentToken = sessionStorage.getItem('paymentToken');

if (entry.mode === 'redirect' && paymentToken) {
  const status = await client.payments.waitForCheckoutStatus(subscriptionToken, paymentToken);
  if (status.paymentStatus === 'PAID' && status.successUrl) {
    window.location.assign(status.successUrl);
    return;
  }
}

if (!paymentToken) {
  const { payment } = await client.carts.createSubscription(subscriptionToken, checkoutUrl, returnUrl);
  if (!payment) return;
  paymentToken = payment.token;
  sessionStorage.setItem('paymentToken', paymentToken);
}

// A fresh checkout, or a retry after the customer came back from a refused payment.
const session = await client.payments.createAdyenSession(subscriptionToken, paymentToken);
const checkout = await AdyenCheckout(buildAdyenCheckoutOptions(session));
new Dropin(checkout, buildAdyenDropinOptions(session)).mount('#dropin-container');

Last updated

Was this helpful?