Class: UpsellStore

UpsellStore(flow, optionsopt)

new UpsellStore(flow, optionsopt)

Ingests flow data from the backend and makes it easily accessible to the front-end. This class will manage the state for the front-end Upsell App. It should be wrapped in a reactive and provided to the root Vue app.
Parameters:
Name Type Attributes Description
flow Object A recursive tree structure that defines the sequence of post-purchase offers. This data will be fetched from the /upsell API endpoint
options UpsellStoreOptions <optional>
Additional config options
Source:

Members

acceptedOffers :Array.<Array.<UpsellConfig>>

When the user accepts an offer, the option they selected is stored in this Array. Each object in the Array contains the upsell configuration data that was sent to ReCharge.
Type:
  • Array.<Array.<UpsellConfig>>
Source:

(readonly) allViewsLoaded :Boolean

Completion status of loading the UI component files. true = all loaded, false = not all loaded. If true, it is safe to mount the UI app.
Type:
  • Boolean
Source:

(readonly) cartItems :Array.<CartItem>

An array of cart items included in the original order. This is either passed as an option to the constructor, or it is an empty array.
Type:
  • Array.<CartItem>
Source:

(readonly) completeFlow :Flow

The initial state of the upsell flow, including id, name, and all offers.
Type:
  • Flow
Source:

declinedOffers :Array.<Array.<UpsellConfig>>

Same as acceptedOffers, but this Array contains the options the user declined.
Type:
  • Array.<Array.<UpsellConfig>>
Source:

flow :Flow

The current state of the upsell flow. This is updated each time an offer is accepted or declined.
Type:
  • Flow
Source:

(readonly) orderTotal :Number

A number representing the total price of the original order. This is either passed as an option to the constructor, or it is 0.
Type:
  • Number
Source:

(readonly) views :Array.<String>

List of UI component files that need to be loaded.
Type:
  • Array.<String>
Source:

Methods

(async) acceptOffer(option) → {Promise.<Object>}

Action method that handles the user accepting an offer. The state of the store is updated and a request is made to the ReCharge Upsell Service containing the offer option data. If no option is specified, the default option will be used -- the first option of the current offer. Error messages are returned if the request fails.
Parameters:
Name Type Description
option Array.<UpsellConfig> The offer option that the user accepted
Source:
Returns:
- An object with a `success` boolean and an array of `errors`
Type
Promise.<Object>

(async) createSnapshot() → {String}

Encodes the internal state of the UpsellStore into a string. The return value can be used to restore the UpsellStore via the static fromSnapshot method. This is asynchronous because it must wait for all accepted offers to resolve.
Source:
Returns:
- a string representing the internal state
Type
String

(async) declineOffer(option) → {void}

Action method that handles the user declining an offer. The state of the store is updated to reflect the user's decision.
Parameters:
Name Type Description
option Array.<UpsellConfig> The offer option that the user declined
Source:
Returns:
Type
void

loadView(viewName) → {void}

Marks a UI component as loaded. This method should be called each time a component is registered in the UI app.
Parameters:
Name Type Description
viewName String The name of the view to be marked as loaded
Source:
Returns:
Type
void

(static) exitFlowOnTimeout(timeoutSeconds) → {void}

Sets a timeout to exit the flow after a specified number of seconds. This allows us to automatically show the Thank You page after the upsell window closes.
Parameters:
Name Type Default Description
timeoutSeconds Number 300 The number of seconds to wait before exiting the flow
Source:
Returns:
Type
void

(static) fromSnapshot(snapshot) → {UpsellStore}

Creates a new UpsellStore instance and restores its internal state using a snapshot. The snapshot should be a string created by the createSnapshot method. This allows us to save and resume upsell flows across page reloads.
Parameters:
Name Type Description
snapshot String the stringified internal state to be restored
Source:
Returns:
Type
UpsellStore

Type Definitions

UpsellStoreOptions

Type:
  • Object
Properties:
Name Type Attributes Description
assetHostingURL String <optional>
The base URL where the assets are hosted. Defaults to the current domain
rechargeUpsellServiceURL String <optional>
The URL of the ReCharge Upsell Service. Defaults to the current domain
csrfToken String <optional>
The CSRF token to be sent with each request to the ReCharge Upsell Service. Defaults to an empty string
orderTotal number <optional>
Total price of the order. Used to calculate analytics event values.
cartItems Array.<Object> <optional>
Array of cart items.
Source: