# Install Checkout SDK yarn add `@medipass/checkout-sdk` Or npm install `@medipass/checkout-sdk` # Create Checkout A payment request URL is passed to the createCheckout function, which opens a secure pop-up window to Tyro Health Online to take the payment. ## Basic Usage You will need to make a network request to `https://stg-api-au.medipass.io/v3/transactions/invoices` and pass your `app id` as part of the headers under `x-appid` and the `API key` also as part of the headers under `Authorization`.Please see the example below: ```js import medipassCheckoutSDK from'@medipass/checkout-sdk'; // or: const medipassCheckoutSDK = require('@medipass/checkout-sdk'); medipassCheckoutSDK.init({ env: 'stg', onSuccess: ({ transactionId }) =\> { // handle success }, onFailure: ({ transactionId }) =\> { // handle failure }, onCancel: ({ transactionId }) =\> { // handle cancel }, onClose: () =\> { // handle close } }); const data = await fetch(`https://${API_ENVS[env]}-api-au.medipass.io/v3/transactions/invoices`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-appid': 'your-app-id', Authorization: `Bearer ${apiKey}` }, body: { callbackOrigin: window.location.origin, sendReceipt: true, ...otherPayloadAttributes }, }); const checkout = await data?.json(); const url = checkout?.paymentRequestUrl; medipassCheckoutSDK.createCheckout({ paymentRequestUrl: data.paymentRequestUrl, }); ``` Please note this is just demo code to make a network request. You can implement this in whichever way you prefer. ## With a ``` Please note this is just demo code to make a network request. You can implement this in whichever way you prefer. # Request To Update Patient Card Details Partners can update a patient's payment details using the `requestUpdatePaymentDetails` function. ## Example ```js import medipassCheckoutSDK from '@medipass/checkout-sdk'; // or: const medipassCheckoutSDK = require('@medipass/checkout-sdk'); await medipassCheckoutSDK.requestUpdatePaymentDetails({ apiKey, // apiKey | undefined token, // token | undefined patientRefId, // patientRefId env, // 'stg' | 'prod' onSuccess, // Invoked when the payment method update has been successful onFailure, // Invoked when the payment method update has failed onCancel, // Invoked when the payment method update has been rejected onClose, // Invoked when the pop-up window has been closed by the user callbackOrigin // The origin of the window invoking the checkout SDK }); ``` ## With a ``` > Take note of the following: 1. **`medipassCheckoutSDK.int()` should not be called when using `requestUpdatePaymentDetails`** 2. **It is required that you pass either an apiKey or a token** # API ## **sdk.init(config)** ### **config** **Object** **| required** ```js { env: 'stg' | 'prod', onSuccess: function({ transactionId }) {}, // Invoked when the payment has been successful onFailure: function({ transactionId }) {}, // Invoked when the payment has failed onCancel: function({ transactionId }) {}, // Invoked when the payment has been rejected onClose: function() {} // Invoked when the pop-up window has been closed by the user before approving or rejecting the payment } ``` ## **sdk.createCheckout(config)** ### **config** ```js { paymentRequestUrl: string, } ```