payOrder method
Future<Order>
payOrder({
- required int orderId,
- required PayOrderRequest request,
- String? authToken,
Pay for an order using one or more approved payments or settle an order with a total of 0.
The total of the payment_ids listed in the request must be equal to the order total. Orders with a total amount of 0 can be marked as paid by specifying an empty array of payment_ids in the request.
Implementation
Future<Order> payOrder({
required int orderId,
required PayOrderRequest request,
String? authToken,
}) async {
authToken ??= authenticationService.getCachedToken()?.accessToken;
Map<String, String> headers = {
"Authorization": "Bearer ${authToken ?? ""}",
'Content-Type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
};
Uri endpoint = Uri.https(
baseUrl, "/v2/orders/$orderId/pay");
//print (endpoint.toString());
var response = await
http.post(endpoint, body: jsonEncode(request.toJson()), headers: headers);
if (response.statusCode == 200) {
print (jsonDecode(response.body));
return OrderResponse.fromJson(jsonDecode(response.body)).order!;
}
else {
print (response.body);
throw OrderException(statusCode: response.statusCode, message: TerminalCheckoutResponse.fromJson(jsonDecode(response.body)).errors?[0].detail?.toString());
}
}