execute method

Future<StandardResponse> execute(
  1. Client client
)

Implementation

Future<StandardResponse> execute(Client client) async {
  final url = Utils.getBaseUrl(isTestMode) + Utils.standardPayment;
  final uri = Uri.parse(url);
  try {
    final response = await client.post(uri,
        headers: {
          HttpHeaders.authorizationHeader: publicKey,
          HttpHeaders.contentTypeHeader: 'application/json'
        },
        body: json.encode(_toJson()));
    final responseBody = json.decode(response.body);
    if (responseBody["status"] == "error") {
      throw TransactionError(responseBody["message"] ??
          "An unexpected error occurred. Please try again.");
    }
    return StandardResponse.fromJson(responseBody);
  } catch (error) {
    rethrow;
  }
}