checkPaymentStatus method
Implementation
Future<bool> checkPaymentStatus(
{required String paymentIntentId, required String secretKey}) async {
try {
final url = Uri.parse(
"https://api.stripe.com/v1/payment_intents/$paymentIntentId");
final response = await http.get(
url,
headers: {
'Authorization': 'Bearer $secretKey',
'Content-Type': 'application/x-www-form-urlencoded',
},
);
if (response.statusCode == 200) {
Map<String, dynamic> result = jsonDecode(response.body);
if (result['status'] == 'succeeded') {
log("Payment succeeded!");
return true;
} else {
log("Payment status: ${result['status']}");
return false;
}
} else {
log("Failed: ${response.body}");
throw Exception("Failed to check payment status");
}
} catch (e) {
log("Error: $e");
rethrow;
}
}