Methods
(async) calculateFinalOrderValue(newState) → {number}
Calculates the final order value, which is used by the "complete" event.
It subtracts the value of any items removed from the cart, then adds the value of each accepted offer.
This temporarily necessary because we can't get the final order value from ReCharge.
Parameters:
| Name | Type | Description |
|---|---|---|
newState |
Object | the new state of the UpsellStore |
- Source:
Returns:
- the final order value
- Type
- number
createOfferView(name, component) → {void}
Registers a UI component with the app, marking it "loaded" in the UpsellStore state.
This ensures all components are registered with the app before it mounts.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
String | Name of the component |
component |
Component | Vue Component to be registered |
- Source:
Returns:
- Type
- void
createUpsellApp(store)
Creates a Vue app, providing the UpsellStore for state management.
Loads the UI component files asynchronously, then mounts the app.
Exposes the global createOfferView function
Parameters:
| Name | Type | Description |
|---|---|---|
store |
UpsellStore | store object provided to the app for state management |
- Source:
(async) createUpsellStore(config) → {Promise.<UpsellStore>}
Fetches the flow from the /upsell API and creates the UpsellStore.
The csrf token is also retrieved from the page, if it exists.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
UpsellAppConfig | Config object which may override the defaultConfig |
Returns:
- The upsell store
- Type
- Promise.<UpsellStore>
getCSRFToken() → {string}
Get the CSRF token from the hidden input on the page.
The CSRF token is required for the ReCharge Upsell Service endpoint.
If it is not found, an error will be thrown.
Throws:
-
- If the CSRF token is not found
- Type
- Error
Returns:
- CSRF token
- Type
- string
(async) getFlow(endpoint, cartItems) → {Object}
Fetch the upsell flow from the server.
This is what provides the data for the UpsellStore
Parameters:
| Name | Type | Description |
|---|---|---|
endpoint |
string | URL for the /upsell API endpoint |
cartItems |
Array.<Object> | Array of cart items |
Throws:
-
- If the response is not successful
- Type
- Error
Returns:
- Upsell flow
- Type
- Object
getSavedState() → {UpsellStore|null}
Checks for a saved store in sessionStorage. If it exists, it will be restored. Otherwise, returns null.
Returns:
- The saved store, or null if there is no saved store
- Type
- UpsellStore | null
(async) main(config) → {void}
Main entry point for the app.
This will be loaded directly onto the "Thank You" page.
It fetches the upsell flow from the server and creates the UpsellStore and Vue app.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
UpsellAppConfig | Config object which may override the defaultConfig |
Returns:
- Type
- void
(async) saveState(store)
Creates a snapshot of the store and saves it to sessionStorage.
Parameters:
| Name | Type | Description |
|---|---|---|
store |
UpsellStore | The store to save |
Type Definitions
UpsellAppConfig
A config object for the main function that is easy to override for local development.
Required to initialize the upsell system.
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
orderTotal |
number | Total price of the order. Used to calculate analytics event values. |
cartItems |
Array.<Object> | Array of cart items. |
assetHostingURL |
string | URL for the asset hosting service |
upsellEndpointURL |
string | URL for the upsell endpoint |
rechargeUpsellServiceURL |
string | URL for the Recharge Upsell Service |