Embedded component
The component renders the requirements a tenant can complete in a session. Load the script, create a session on your server, and mount the component with the session's client_secret.
<div id="tsg-guarantee"></div>
<script src="https://app.thestudentguarantor.com/embed/v1/guarantee.js"></script>
<script>
const guarantee = TSG.guarantee({
clientSecret: "sess_9Tg4HbN6mJ2kLp8Q_secret_x7Vq2ZcR5tYw8Ub1",
locale: "zh-CN",
appearance: { accentColor: "#FF5A5F" },
onComplete: (event) => { /* event.applicationId, event.outstanding */ },
onExit: (event) => { /* event.reason */ },
onError: (event) => { /* event.code */ }
});
guarantee.mount("#tsg-guarantee");
</script>
Methods
| Method | Description |
|---|---|
TSG.guarantee(options) | Creates a component instance for a session. |
guarantee.mount(selector) | Renders the component in the element matching selector. |
guarantee.unmount() | Removes the component from the DOM. It can be mounted again. |
guarantee.destroy() | Removes the component and discards the session on the client. |
Options
| Option | Type | Description |
|---|---|---|
clientSecretrequired | string | The session's client_secret. |
locale | string | en or zh-CN. Defaults to the session's locale. |
appearance.accentColor | string | Hex colour for buttons and links. |
appearance.borderRadius | string | CSS length for corners. |
appearance.fontFamily | string | System font stack. |
Events
| Callback | Payload | Description |
|---|---|---|
onReady | Called when the component has rendered. | |
onStepChange | step | Called when the tenant moves to another step. Steps appear in this order, and only when the tenant has something to complete in them: review, payment, documents, agreement, done. |
onComplete | applicationId, outstanding | Called when the tenant has completed every requirement available to them. outstanding lists the codes that remain for other parties. |
onExit | reason | Called when the tenant leaves before completing. reason is closed or expired. |
onError | code, message | Called when the component can't continue. Codes include session_invalid, session_expired, origin_not_allowed and payment_unavailable. |
The component only renders on the origins registered for your account. Don't rely on onComplete to update your records. Retrieve the application or listen for application.requirements_updated.
Redirect mode
To use the component where the script can't run, such as a native app or a WeChat mini program, create the session with mode: "redirect" and open its url in a web view. When the tenant finishes or leaves, they are redirected to your return_url with application_id and session_status appended. The return_url must be an HTTPS URL on one of the origins registered for your account.
Content Security Policy
script-src https://app.thestudentguarantor.com
frame-src https://app.thestudentguarantor.com