get method
Retrieves saved cards associated with a customer ID.
testMode
- Flag indicating if the test mode is enabled.
customerId
- The customer ID for whom the saved cards are retrieved.
apiKey
- The API key for authentication.
onError
- Callback function to be executed on an error.
onDone
- Callback function to be executed on successful retrieval.
Implementation
Future<void> get({
required bool testMode,
required String customerId,
required String apiKey,
required void Function(Map<String, dynamic>) onError,
required void Function(SavedCardsModel data) onDone,
}) async {
String url = testMode
? "https://uatcheckout.thawani.om/api/v1/payment_methods"
: "https://checkout.thawani.om/api/v1/payment_methods";
await Request.get(url: "$url?customer_id=$customerId", headers: {
'Content-Type': "application/json",
'thawani-api-key': apiKey
}).then((value) {
if (value['code'] == 2000 || value['code'] == 4003) {
// Parse the response data into a SavedCardsModel and call onDone callback.
onDone(SavedCardsModel.fromJson(value));
} else {
// Handle errors by calling the onError callback.
onError(value);
}
});
}