Callbacks
Callbacks are functions that you can provide to a method in the SDK which will give you feedback when an event occurs.
They can be useful when you want to record data & attributes at a particular stage of a transaction.
sdk.renderCreateTransaction
You can provide a set of callback events to the second parameter of renderCreateTransaction
.
A list of the supported callbacks are as follows:
Callback | Description |
---|---|
onSuccess(transaction) |
Invoked when the transaction, claim (when applicable) & payment is successful. Warning: This callback will not be invoked if the user closes the modal before a successful transaction. |
onError(error) |
Invoked when an error occurs and the transaction cannot be completed. Warning: This callback will not be invoked if the user closes the modal and the transaction errors afterwards. |
onCancel() |
Invoked when the transaction has been cancelled. Warning: This callback will not be invoked if the user closes the modal and the transaction is cancelled afterwards. You can use the invoiceCancelled webhook to track the transaction outcome. |
onCloseModal({ transaction, error, status }) |
Invoked when the modal has been closed by the user and provides data at the current stage of the transaction. Example: it could be possible that the user closes the modal when a claim/payment is pending from the patient. |
Example:
import medipassSDK from '@medipass/partner-sdk';
medipassSDK.renderCreateTransaction(
{
// ... transaction attributes
},
{
onSuccess: function(transaction) {
console.log(transaction);
// -> { _id: '123', created: '2022-01-22T23:18:30.329', items: [...], claims: [...], ... }
},
onError: function(error) {
console.log(error);
// -> { message: 'An error occurred.' }
},
onCancel: function() {
console.log('Transaction cancelled.');
},
onCloseModal: function({ transaction, error, status }) {
if (status === 'success') {
console.log(transaction);
// -> { _id: '123', created: '2022-01-22T23:18:30.329', items: [...], claims: [...], ... }
} else if (status === 'error') {
console.log(error);
// -> { message: 'An error occurred.' }
} else if (status === 'cancelled') {
console.log('Transaction cancelled.');
}
},
onTransactionCreated: function(transaction) {
console.log('Transaction created', transaction);
},
onTransactionUpdated: function(transaction) {
console.log('Transaction updated', transaction);
},
}
);