Hyper Widget
In this Article:
- initWidget() Method
- onApprove() Method
- onValidPreference() Method
- onError() Method
API Methods
This method is used to specify an operation configuration for the Hyper widget.
| Field | Type | Required | Notes |
|---|
| config | Object | YES | Refer to widget config. |
Example
//payment gateways
var gateways = [
{type:"card",gatewayId:"<your-gateway-id>"},
{type:"zipPay",gatewayId:"<zipPay-gateway-id>"},
{type:"stripeGP",gatewayId:"<googlepay-gateway-id>"},
{type:"stripeAP",gatewayId:"<applepay-gateway-id>"},
]
//Hyper config
var config = {
//remove useSandbox declaration for production
publicKey:"<hyper-public-key>",
useSandbox: true,
gateways: gateways,
};
document.addEventListener("DOMContentLoaded", function (event) {
var widget = hyper.initWidget(config);
// continue widget configuration
// ....
});
onApprove()
This listener is called once the user has agreed to accept the Charge and corresponding a vaultToken is available for the use.
Response
| Field | Type | Required | Notes |
|---|
| vaultToken | String | YES | Used to create a Charge or Subscription linked to the user’s payment source |
| traceId | String | YES | If provided by Hyper API. Use it when requesting support about an issue related to Hyper. |
| userDetail | Object | YES | Refer to userDetail |
Example
document.addEventListener("DOMContentLoaded", function (event) {
var widget = hyper.initWidget(config);
// continue widget configuration
// ....
widget.onApprove = function(res) {
//replace this with code to handle successful pay authroization
console.log('Response:', res);
};
});
onValidPreference()
This method is called when any user preference information is available to personalise the checkout experience.
Response
| Field | Type | Required | Notes |
|---|
| sku | String | NO | If available, provides user preference information. For e.g. preferred product SKU |
Example
document.addEventListener("DOMContentLoaded", function (event) {
var widget = hyper.initWidget(config);
// continue widget configuration
// ....
//if a valid user profile is available, it can be used to optimize the checkout experience
widget.onValidPreference = function(data) {
//select the preferred product from the card
console.log('Preferred SKU:', data.sku);
};
});
onError()
This listener passes any error that occurs during widget operation.
Response
| Field | Type | Required | Notes |
|---|
| type | String | YES | Refer to Error Types. |
| reason | String | YES | Refer to Error Types. |
| traceId | String | YES | If provided by Hyper API. Use it when requesting support about an issue related to Hyper. |
Example
document.addEventListener("DOMContentLoaded", function (event) {
var widget = hyper.initWidget(config);
// continue widget configuration
// ....
//when an unrecoverable error occurs
widget.onError = function(err) {
//cutomize this section to take recovery action
console.log('Error occurred:', err);
};
});
Error Types
| Type | Reason | |
|---|
| CONFIG_GATEWAY_ID_INVALID | One or more gatewayId contains invalid value. | |
| CONFIG_GATEWAY_ID_REQUIRED | gatewayId is missing or empty on one or more of the gateway entries. | |
| CONFIG_GATEWAY_TYPE_REQUIRED | Gateway type is missing or empty on one or more of the gateway entries. | |
| CONFIG_INVALID_PUBLIC_KEY | Merchant publicKey is invalid. | |
| CONFIG_MISSING_GATEWAYS | gateways is missing from the configuration. | |
| CONFIG_MISSING_PUBLIC_KEY | publicKey is missing from the configuration. | |
| ORDER_NULL | The userOrder set with setOrder() method is null or undefined. | |
| ORDER_NO_ITEMS_FOUND | No items found in the order. | |
| ORDER_TOTAL_AMOUNT_UNDEFINED | Please check because the order total amount is zero or undefined. | |
| ORDER_ITEM_AMOUNT_UNDEFINED | One or more item amount is zero or undefined. | |
| ORDER_ITEM_QUANTITY_UNDEFINED | One or more item has a quantity of zero or undefined. | |
| ORDER_TOTAL_AMOUNT_NOT_EQUAL | Total amount is not equal to the total amount of items in the order. | |
API Objects
config
Hyper widget configuration
Fields
| Name | Type | Required | Notes |
|---|
| publicKey | String | YES | Your account’s public key, available from Hyper Merchant portal. |
| useSandbox | Boolean | YES | If true, Sandbox environment is used for operation. Default is false |
| gateways | Object | YES | Defines payment Gateways to use. At least one gateway is required. |
gateways
| Name | Type | Required | Notes |
|---|
| type | String | YES | See Gateway Types for Hyper supported gateways. |
| gatewayId | String | YES | Your the gateway’s ID, available from Hyper Merchant portal. |
gatewayType
| Value | Type | Required | Notes |
|---|
| card | String | YES | Use for all credit card processors like Stripe, eWay, etc. |
| zipPay | String | YES | Use for Zip payments. |
| stripeGP | String | YES | Support to be released in Q2 2021. |
| stripeAP | String | YES | Support to be released in Q2 2021. |
userDetail
Contains User’s details provided to Hyper. The checkout page can use these to complete the order process.
Fields
| Name | Type | Required | Notes |
|---|
| fullName | String | YES | E.g. John Stark |
| mobile | String | YES | E.g. +61400400400 |
| email | String | YES | E.g. john.stark@email.com |
userOrder
Hyper order details.
Fields
| Name | Type | Required | Notes |
|---|
| amount | Number | YES | Total order amount, for e.g. 10.00 |
| currency | String | YES | Order currency, for e.g. AUD |
| reference | String | YES | Order or quote reference, for e.g. Q-12345 |
| items | Object | YES | Refer to userOrderItems. |
userOrderItems
Hyper order item details.
Fields
| Name | Type | Required | Notes |
|---|
| name | String | YES | Item’s brief description, for e.g. its name Gadget ABC |
| amount | Number | YES | Item price, for e.g. 10.00 |
| quantity | Number | YES | Quantity being purchased, for e.g. AUD |
| reference | String | YES | Item reference, for e.g. SKU data A123 stealth drone |