getHash method
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 = "",
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;
}