getHash method

String getHash({
  1. required String reqTime,
  2. required String tranId,
  3. String amount = "",
  4. String items = "",
  5. String shipping = "",
  6. String ctid = "",
  7. String pwt = "",
  8. String? firstName = "",
  9. String? lastName = "",
  10. String? email = "",
  11. String? phone = "",
  12. String type = "",
  13. String paymentOption = "",
  14. String returnUrl = "",
  15. String cancelUrl = "",
  16. String continueSuccessUrl = "",
  17. String returnDeeplink = "",
  18. String currency = "",
  19. String customFields = "",
  20. String returnParams = "",
})

getHash

tranID: unique tran_id < 20 characters (number, character and (-) only)

amount: total amount

item: base64_encode (json_encode(array item))

shipping: shipping value

Example:

var merchant = ABAMerchant();
var helper = ABAClientHelper(merchant);
var tranID = DateTime.now().microsecondsSinceEpoch.toString();
var reqTime = DateTime.now().toUtc();
var amount = 0.00;
var hash = helper.getHash(tranID: tranID, amount: amount);
print(hash);

Implementation

String getHash({
  required String reqTime,
  required String tranId,
  String amount = "",
  String items = "",
  String shipping = "",
  String ctid = "",
  String pwt = "",
  String? firstName = "",
  String? lastName = "",
  String? email = "",
  String? phone = "",
  String type = "",
  String paymentOption = "",
  String returnUrl = "",
  String cancelUrl = "",
  String continueSuccessUrl = "",
  String returnDeeplink = "",
  String currency = "",
  String customFields = "",
  String returnParams = "",
}) {
  // String =
  // req_time + merchant_id +
  // tran_id + amount + items +
  // shipping + ctid + pwt +
  // firstname + lastname +
  // email + phone + type +
  // payment_option + return_url +
  // cancel_url + continue_success_url +
  // return_deeplink + currency + custom_fields + return_params with public_key.
  // assert(tranID != null);
  // assert(amount != null);
  var key = utf8.encode(merchant!.merchantApiKey!);
  var raw =
      "$reqTime ${merchant!.merchantID} $tranId $amount $items $shipping $ctid $pwt $firstName $lastName $email $phone $type $paymentOption $returnUrl $cancelUrl $continueSuccessUrl $returnDeeplink $currency $customFields $returnParams";
  var str =
      "$reqTime${merchant!.merchantID}$tranId$amount$items$shipping$ctid$pwt$firstName$lastName$email$phone$type$paymentOption$returnUrl$cancelUrl$continueSuccessUrl$returnDeeplink$currency$customFields$returnParams";

  var bytes = utf8.encode(str);
  var digest = crypto.Hmac(crypto.sha512, key).convert(bytes);
  var hash = base64Encode(digest.bytes);
  return hash;
}