Upsell lifecycle

Events: upsell.*, with order.updated after an accept and payment.failed for a decline.

Upsell lifecycle On one upsell page, opened with the order’s ref_id. The page loads the order (order.loaded): an order that takes upsells shows the offer, next-available, and upsell.viewed comes once per offer, when half of it is on screen; one that does not, or cannot load (sdk.error), keeps it next-hidden. Accepting sends the offer to the order: next-processing. Added, next-success (upsell.accepted, then order.updated) and the next page opens after a tenth of a second. Declined (upsell.declined, payment.failed), refused, or no answer and the order loaded again does not have it (sdk.error, upsell.failed): next-error, and the next page opens after a second. With no answer and the order loaded again having the offer, it was added. Skipping is next-skipped (upsell.skipped) and opens the next page at once. The next page loads the order again. the page loads the order takes upsells order.loaded does not take upsells or cannot load order.loaded, or sdk.error accept skip upsell.skipped added, or no answer and the order has it declined upsell.declined payment.failed refused, or not on the order sdk.error, upsell.failed after a tenth of a second after a second at once the next page loads the order next-available upsell.viewed once half of it is on screen next-processing the offer is sent next-success upsell.accepted order.updated next-hidden the offer stays hidden next-skipped upsell.skipped next-error not added

The lifecycle is one offer's on one page after the checkout, opened with the order's ref_id. Its state is the class on the offer; while it is added, the order's status is accepting.

StateMeans
next-hiddenThe order does not take upsells, or did not load: the offer stays hidden
next-availableThe order takes upsells: the offer is shown
next-processingThe offer is being added to the order
next-successAdded, or already added on this page; the next page opens after a tenth of a second
next-errorNot added; the next page opens after a second
next-skippedThe shopper went on without it; the next page opens at once
FromWhat happensToEvents, in order
noneThe page loads the order, and it takes upsellsnext-availableorder.loaded, then order.paid the first time this browser has it paid
noneThe order does not take upsells, or cannot loadnext-hiddenorder.loaded; or sdk.error (order.load) when it cannot load
next-availableHalf of the offer is on screen, and its selector, if any, is pricednext-availableupsell.viewed, once per offer
next-availableThe shopper acceptsnext-processingnone; upsell.viewed first, if it has not come yet
next-processingThe order takes the offernext-successupsell.accepted, order.updated
next-processingNo answer (network, timeout or server): the order is loaded again, and it has the offer's linesnext-successupsell.accepted, order.updated
next-processingNo answer, and the order loaded again does not have them, or cannot loadnext-errorsdk.error (upsell.add), upsell.failed (with error)
next-processingRefusednext-errorsdk.error (upsell.add), upsell.failed (with error)
next-processingDeclinednext-errorupsell.declined, payment.failed (method, ref_id, error with code: 'declined')
next-availableThe shopper accepts, but an offer was already added on this page for this ordernext-successnone
next-availableThe shopper accepts, but the offer has nothing to add: no package id, nothing picked in its selectornext-errornone; a warning is logged
next-hiddenThe shopper acceptsnext-errornone
next-available, next-hiddenThe shopper skipsnext-skippedupsell.skipped; upsell.viewed first, if it has not come yet

Viewed once

  • upsell.viewed comes once per offer: when half of it is on screen, after the order has loaded and the offer's selector, if any, is priced.
  • An accept or a skip counts as a view: upsell.viewed comes first if it has not come yet, on a next-hidden offer too once the order has loaded.
  • An offer the order cannot load sends no upsell.viewed, on screen or clicked.
  • upsell.shown, internal, marks the offer shown; the 0.4.x upsell:viewed comes from it, before the offer is on screen.

Added once

  • One add per order and page: once an offer is added, an accept on that page, after a reload or a back included, goes to next-success without a second add.
  • While the order loads, or another offer on the page is being added, an accept does nothing: next-processing comes off at once. A skip still goes on, with upsell.skipped once the URL has a ref_id.
  • Once the offer is leaving, every further click does nothing.

The next page

  • The button's data-next-url, else next-upsell-accept-url after an accept or a failed add and next-upsell-decline-url after a skip; without one the shopper stays.
  • The URL gets the order's ref_id and the visit's URL parameters.
  • next-success leaves after a tenth of a second, next-skipped at once, next-error after a second.
  • The next page sends order.loaded with the order, its added lines marked upsell: true.

Classes

  • Before the order loads the offer has no class; next-available or next-hidden comes once it has loaded, or failed to.
  • next-success is on for three seconds and next-error for five; next-processing stays on after a success.
  • The buttons are next-disabled while any offer on the page is being added, or this one is leaving.

What each event carries

  • upsell.*: the same Upsell: the order's ref_id, the page, selector_id and option_id for an offer with a selector, its lines and currency, and total once the offer has a price.
  • upsell.failed adds the error; upsell.declined, internal, the error and its message.
  • payment.failed: the order's payment method, its ref_id, and the error with code: 'declined' and the gateway's decline_code when it gave one.
  • order.updated: the Order with the added lines, marked upsell: true.

Errors

Each sends sdk.error with this action. The SDK lifecycle lists every action and code.

actionWhenWhat the SDK does next
upsell.addThe offer cannot be added: refused, or no answer and the order loaded again does not have itupsell.failed; next-error, and the next page after a second. A decline sends payment.failed without sdk.error
order.loadThe page cannot load the orderThe offer is next-hidden: no upsell.viewed; an accept goes to next-error, a skip to next-skipped