captureCharge method
Capture charge funds
Implementation
Future<Charge> captureCharge({
required String requestId,
required String chargeId,
required String amount,
String? description,
PaymentContext? context,
String? realmId,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.access_token;
realmId ??= authenticationService.getCachedRealmId();
Map<String, String> headers = {
"Request-ID": requestId,
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json',
//'Accept': 'application/json',
};
Uri endpoint =
Uri.https(baseUrl, "/quickbooks/v4/payments/charges/$chargeId/capture");
//print(endpoint.toString());
var charge = Charge(
amount: amount,
context: context,
description: description);
var response = await http.post(endpoint,
headers: headers, body: jsonEncode(charge.toJson()));
if (response.statusCode == 200 || response.statusCode == 201) {
//print (response.body);
return Charge.fromJson(jsonDecode(response.body));
} else {
throw ChargeException(
statusCode: response.statusCode, message: response.body);
}
}