Embedded Experience
Setupβ
Generate a Sessionβ
- From the Merchant's backend, make a call to
/POST sessions
to generatesession
and pass it to the web app. - Widget's capabilities can be customized using
config
property insession
request object - Refer Generate a Session for details
/POST session (request/response)
## /POST sessions request
curl --location --request POST 'https://api.uhg.com/api/financial/commerce/nonprodcheckout/v1/sessions' \
--header 'X-Merchant-Id: <x-merchant-id>' \
--header 'X-Upstream-Env: <x-upstream-env>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <authorization-token>' \
--data-raw '{
"customer": {
"firstName": "foo",
"lastName": "bar",
"email": "foo.bar@email.com",
"ssnLastFour": "1234",
"dateOfBirth": "1970-31-12",
"phoneNumber": {
"number": "9876543210",
"countryCode": "1"
},
"zip5": "54321",
"hsid": "120c5730-e796-4448-8da9-081fde4e3e79",
"metadata": {}
},
"payment": {
"merchantTransactionId": "f32736c8-266a-4da1-af16-293fa02a351a",
"amount": 1200,
"authorizeCard": false,
},
"config": {
"modes": [
"PAYMENT_METHOD_ENTRY"
]
}
}'
// /POST sessions reponse
{
"url": "/sessions/<CHECKOUT_SESSION_ID>",
"data": {
"sessionId": "<CHECKOUT_SESSION_ID>",
"hostedUrl": "<CCG_DOMAIN>/checkout-sessions/<CHECKOUT_SESSION_ID>"
}
}
Load the widgetβ
<script src="https://<DOMAIN>.healthsafepay.com/wallet/<VERSION>/<FILE_NAME>.js"></script>
- Integrate by adding
<script>
tag.optumCCG
object is added to the globalwindow
object
To reduce the load time for widget refer to
Placeholder values
DOMAIN: walletstage
| walletprod
VERSION: v2 see Version History for more details
FILE_NAME: ccg-widget.js
| ccg-widget.min.js
Example:
https://walletstage.healthsafepay.com/wallet/v2/ccg-widget.min.js
https://walletstage.healthsafepay.com/wallet/v2/ccg-widget.js
Access the widget initializerβ
const OptumCCGWidgetInitializer = window.optumCCG.OptumCCGWidgetInitializer;
Initializeβ
const options = {...};
const ccgWidget = OptumCCGWidgetInitializer(options);
OptumCCGWidgetInitializer
function is used to setup and manage the widget. This sets up the widget, attaches to DOM and returns the instance
Renderβ
ccgWidget.render();
Makes the embedded payment modal window visible on screen. By default, the widget is not visible when attached to DOM
Full Exampleβ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CCG Widget Integration</title>
</head>
<body>
<h1>CCG Widget Integration</h1>
<button id="payRemainingBalance">Pay Remaining Balance</button>
<div id="ccg-widget-container"></div>
<!-- 1. Load the widget -->
<script src="https://walletprod.healthsafepay.com/wallet/v2/ccg-widget.min.js"></script>
<script>
let ccgWidget;
document
.querySelector("#payRemainingBalance")
.addEventListener("click", () => {
// 2. Initialize widget once
if (!ccgWiget) {
// 3. Access the widget initializer
const OptumCCGWidgetInitializer =
window.optumCCG.OptumCCGWidgetInitializer;
const options = {
rootElement: document.querySelector("#ccg-widget-container"),
checkoutSessionId: "REPLACE_WITH_CHECKOUT_SESSION_ID",
appEnv: "prod",
onSuccess: (data) => {},
onError: (data) => {},
onEvent: (data) => {},
};
// 4. Initialize
ccgWidget = OptumCCGWidgetInitializer(options);
}
// 5. Render
ccgWidget.render();
});
</script>
</body>
</html>
Removing the widgetβ
ccgWidget.unmount();
ccgWidget = null;
This unmounts the widget from the DOM
Additional Detailsβ
OptumCCGWidgetInitializer method optionsβ
Option | Values | Description |
---|---|---|
rootElement required Element | Valid DOM node | CCG Widget will be injected into this DOM node |
checkoutSessionId required string | - | Valid checkout session id |
appEnv required string | stage prod | Widget's environment variable |
appearanceAppearance | default: Optum Theme | Brand/styling configuration see Theming and Styling deprecated >= 2.1.0 Refer /POST sessions on how to pass appearance as part of session creation |
containerConfig object Container Config | default: { type: 'modal' } | |
onSuccessFunction param type | (data) => void | Called when payment is successful |
onErrorFunction param type | (data) => void | Called when there is an error with the checkout session or a payment failure |
onEventFunction param type | (data) => void | Called for all other events (i.e., widget loaded , open , closed , PAYMENT_METHOD_SELECTION ) |