conform method
void
conform({})
Confirms a payment intent.
id
- The ID of the payment intent to confirm.
apiKey
- The API key for authentication.
testMode
- Flag indicating if the test mode is enabled.
onDone
- Callback function to be executed on successful confirmation.
onError
- Callback function to be executed on an error.
Implementation
void conform({
required String id,
required String apiKey,
required bool testMode,
required void Function(ConformPaymentModel data) onDone,
required void Function(Map<String, dynamic> data) onError}) {
// Define the URL based on the test mode.
String url = testMode
? "https://uatcheckout.thawani.om/api/v1/payment_intents/$id/confirm"
: 'https://checkout.thawani.om/api/v1/payment_intents/$id/confirm';
// Send a POST request to confirm the payment intent.
Request.post(url: url, data: {}, headers: {
'Content-Type': "application/json",
'thawani-api-key': apiKey
}).then((value) {
if (value['status'] == 200) {
// Parse the response data into a ConformPaymentModel.
ConformPaymentModel model = ConformPaymentModel.fromJson(value['data']);
onDone(model);
} else {
// Handle errors by calling the onError callback.
onError(value['data']);
}
});
}