status method

Future<String> status (
  1. {@required String transactionCode,
  2. @required String id,
  3. @required String secret}
)

Implementation

Future<String> status({
  @required String transactionCode,
  @required String id,
  @required String secret,
}) async {
  if (transactionCode != null && transactionCode.isEmpty) {
    throw ArgumentError.value(
        transactionCode, 'transactionCode cannot be empty or null');
  }

  if (id != null && id.isEmpty) {
    throw ArgumentError.value(id, 'id cannot be empty or null');
  }

  if (secret != null && secret.isEmpty) {
    throw ArgumentError.value(secret, 'secret cannot be empty or null');
  }

  String method = "GET";
  String url = "https://khipu.com/api/2.0/payments/" + transactionCode;

  var toSign = new StringBuffer(
      method.toUpperCase() + "&" + _encryptData.percentEncode(url));

  String sign = _encryptData.hmacSHA256(secret, toSign.toString());
  String authorization = '$id' + ':' + sign;

  var response = await http.get(
    url,
    headers: {
      'Authorization': authorization,
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  );

  if (response.statusCode == 200 || response.statusCode == 201) {
    final Map responseMap = json.decode(response.body);
    print("responseMap.status: " + responseMap['status']);
    return responseMap['status'];
  } else {
    print("response.body: " + response.body);
    return '';
  }
}