delete method
Deletes a saved card.
cardId
- The ID of the card to be deleted.
onDelete
- Callback function to be executed on successful deletion.
onError
- Callback function to be executed on an error.
Implementation
void delete({
required String cardId,
required void Function() onDelete,
required void Function() onError,
}) {
String url = keysViewModel.isTestMode
? "https://uatcheckout.thawani.om/api/v1/payment_methods/$cardId"
: "https://checkout.thawani.om/api/v1/payment_methods/$cardId";
Request.delete(url: url, data: {}, headers: {
'Content-Type': "application/json",
'thawani-api-key': keysViewModel.userApiKey
}).then((value) {
if (value['data']['code'] == 2003) {
// Call onDelete callback on successful deletion.
onDelete();
} else {
print(value);
// Handle errors if necessary.
}
});
}