Storage
Since: 1.1.13
The storage API is a wrapper for defining key-value pairs within the hyva_checkout object.
setValue
Setting values for later usage can be very helpful in many situations. You can even group them into either existing groups or define your own by providing a group argument as a string. Both the payment and shipping groups will travel along to the Place Order Service PHP object when the order is being placed.
Parameters:
key(string, required)value(mixed, required)group(string, optional)
Returns:
void- No return value
<script>
(() => {
const group = 'payment';
const value = 123;
const key = 'pin';
// Wrapping it into an "after" when dispatched on page initialization. This doesn't need to be done
// when storage values are set based on user interactions since the API at that point in time is already fully initialized.
// But it is always good practice to ensure the API is fully available if you depend on any of our tools.
hyvaCheckout.api.after(() => {
hyvaCheckout.storage.setValue(key, value, group)
// Only available since v1.3.4
.then(v => {
if (v === value) {
console.log('Value was successfully set into the session storage.');
}
});
// Before v1.3.4
if (hyvaCheckout.storage.getValue(key, group) === value) {
console.log('Value was successfully set into the session storage.');
}
// Or get the full group and check if it sits in there
const groupData = hyvaCheckout.storage.getGroupData(group);
if (groupData && groupData[key] === value) {
console.log('Value found in group data.');
}
});
})();
</script>