public IActionResult GenerateSignature([FromQuery] GenerateSignatureRequest request) { var hmacValidator = new HmacValidator(); var stringToSign = hmacValidator.BuildSigningString(GetDictonaryFromRequest(request)); var signature = hmacValidator.CalculateSignature(stringToSign, request.SigningKey); return(Ok(signature)); }
public Dictionary <string, string> GetPostParametersFromDlRequest(DirectoryLookupRequest request) { var config = this.Client.Config; var postParameters = new Dictionary <string, string> { { Fields.CurrencyCode, request.CurrencyCode }, { Fields.MerchantReference, request.MerchantReference }, { Fields.SessionValidity, request.SessionValidity }, { Fields.CountryCode, request.CountryCode } }; if (!string.IsNullOrEmpty(request.MerchantAccount)) { postParameters.Add(Fields.MerchantAccount, request.MerchantAccount); } else { postParameters.Add(Fields.MerchantAccount, config.MerchantAccount); } postParameters.Add(Fields.PaymentAmount, request.PaymentAmount); if (!string.IsNullOrEmpty(request.SkinCode)) { postParameters.Add(Fields.SkinCode, request.SkinCode); } else { postParameters.Add(Fields.SkinCode, config.SkinCode); } var hmacValidator = new HmacValidator(); var dataToSign = hmacValidator.BuildSigningString(postParameters); string hmacKey; if (!string.IsNullOrEmpty(request.HmacKey)) { hmacKey = request.HmacKey; } else { hmacKey = config.HmacKey; } var merchantSig = hmacValidator.CalculateHmac(dataToSign, hmacKey); postParameters.Add(Fields.MerchantSig, merchantSig); return(postParameters); }
public void TestDataSign() { var postParameters = new Dictionary <string, string> { { Constants.HPPConstants.Fields.MerchantAccount, "ACC" }, { Constants.HPPConstants.Fields.CurrencyCode, "EUR" } }; var hmacValidator = new HmacValidator(); var buildSigningString = hmacValidator.BuildSigningString(postParameters); Assert.IsTrue(string.Equals("currencyCode:merchantAccount:EUR:ACC", buildSigningString)); postParameters = new Dictionary <string, string> { { Constants.HPPConstants.Fields.CurrencyCode, "EUR" }, { Constants.HPPConstants.Fields.MerchantAccount, "ACC:\\" } }; buildSigningString = hmacValidator.BuildSigningString(postParameters); Assert.IsTrue(string.Equals("currencyCode:merchantAccount:EUR:ACC\\:\\\\", buildSigningString)); }
private string CalculateSignature(ProcessPaymentRequest request) { var parametrs = new Dictionary <string, string> { { nameof(request.MerchantTransactionId), request.MerchantTransactionId }, { nameof(request.Amount), request.Amount.ToString("F", CultureInfo.InvariantCulture) }, { nameof(request.CardNumber), request.CardNumber }, { nameof(request.ExpiryMonth), request.ExpiryMonth.ToString() }, { nameof(request.ExpiryYear), request.ExpiryYear.ToString() }, { nameof(request.Cvv), request.Cvv }, { nameof(request.Currency), request.Currency } }; var hmacGenerator = new HmacValidator(); return(hmacGenerator.CalculateSignature(hmacGenerator.BuildSigningString(parametrs), _testMerchant.SigningKey)); }