create method
Creates a new customer.
testMode
- Flag indicating if the test mode is enabled.
apiKey
- The API key for authentication.
customerId
- The customer's reference ID.
onError
- Callback function to be executed on an error.
onDone
- Callback function to be executed on successful customer creation.
Implementation
Future<void> create({
required bool testMode,
required String apiKey,
required String customerId,
required void Function(Map<String, dynamic>) onError,
required void Function(CreateCustomerModel data) onDone,
}) async {
// Define the URL based on the test mode.
final String url = testMode
? 'https://uatcheckout.thawani.om/api/v1/customers'
: 'https://checkout.thawani.om/api/v1/customers';
// Send a POST request to create a new customer.
await Request.post(url: url, data: {
'client_customer_id': customerId
}, headers: {
'Content-Type': "application/json",
'thawani-api-key': apiKey
}).then((value) {
if (value['status'] == 200) {
// Parse the response data into a CreateCustomerModel and call the onDone callback.
onDone(CreateCustomerModel.fromJson(value['data']));
} else {
// Handle errors by calling the onError callback.
onError(value);
}
});
}