public static IEnumerable <KeyValuePair <string, string> > CreateVerifyData( InvoiceContext context, PasargadGatewayAccount account, IPasargadCrypto crypto, PasargadCallbackResult callbackResult) { var timeStamp = GetTimeStamp(DateTime.Now); var dataToSign = string.Format("#{0}#{1}#{2}#{3}#{4}#{5}#", account.MerchantCode, account.TerminalCode, context.Payment.TrackingNumber, callbackResult.InvoiceDate, (long)context.Payment.Amount, timeStamp); var signData = crypto.Encrypt(account.PrivateKey, dataToSign); return(new[] { new KeyValuePair <string, string>("InvoiceNumber", context.Payment.TrackingNumber.ToString()), new KeyValuePair <string, string>("InvoiceDate", callbackResult.InvoiceDate), new KeyValuePair <string, string>("MerchantCode", account.MerchantCode), new KeyValuePair <string, string>("TerminalCode", account.TerminalCode), new KeyValuePair <string, string>("Amount", ((long)context.Payment.Amount).ToString()), new KeyValuePair <string, string>("TimeStamp", timeStamp), new KeyValuePair <string, string>("Sign", signData) }); }
public void Setup() { var mockCrypto = new Mock <IPasargadCrypto>(); mockCrypto .Setup(crypto => crypto.Encrypt(It.IsAny <string>(), It.IsAny <string>())) .Returns(ExpectedSignedValue); _crypto = mockCrypto.Object; }
public PasargadGateway( IHttpContextAccessor httpContextAccessor, IHttpClientFactory httpClientFactory, IGatewayAccountProvider <PasargadGatewayAccount> accountProvider, IPasargadCrypto crypto, IOptions <PasargadGatewayOptions> gatewayOptions, IOptions <MessagesOptions> messageOptions) : base(accountProvider) { _httpContextAccessor = httpContextAccessor; _httpClient = httpClientFactory.CreateClient(this); _crypto = crypto; _gatewayOptions = gatewayOptions.Value; _messageOptions = messageOptions; }
public static PaymentRequestResult CreateRequestResult( Invoice invoice, HttpContext httpContext, PasargadGatewayAccount account, IPasargadCrypto crypto, PasargadGatewayOptions gatewayOptions) { var invoiceDate = GetTimeStamp(DateTime.Now); var timeStamp = invoiceDate; var dataToSign = string.Format("#{0}#{1}#{2}#{3}#{4}#{5}#{6}#{7}#", account.MerchantCode, account.TerminalCode, invoice.TrackingNumber, invoiceDate, (long)invoice.Amount, invoice.CallbackUrl, ActionNumber, timeStamp); var signedData = crypto.Encrypt(account.PrivateKey, dataToSign); var result = PaymentRequestResult.SucceedWithPost( account.Name, httpContext, gatewayOptions.PaymentPageUrl, new Dictionary <string, string> { { "merchantCode", account.MerchantCode }, { "terminalCode", account.TerminalCode }, { "invoiceNumber", invoice.TrackingNumber.ToString() }, { "invoiceDate", invoiceDate }, { "amount", invoice.Amount.ToLongString() }, { "redirectAddress", invoice.CallbackUrl }, { "action", ActionNumber }, { "timeStamp", timeStamp }, { "sign", signedData } }); result.DatabaseAdditionalData.Add("timeStamp", timeStamp); return(result); }
public static IEnumerable <KeyValuePair <string, string> > CreateRefundData( InvoiceContext context, Money amount, IPasargadCrypto crypto, PasargadGatewayAccount account) { var transactionRecord = context.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Request); if (transactionRecord == null) { throw new Exception($"Cannot find transaction record for Payment-{context.Payment.TrackingNumber}"); } if (!AdditionalDataConverter.ToDictionary(transactionRecord).TryGetValue("invoiceDate", out var invoiceDate)) { throw new Exception("Cannot get the invoiceDate from database."); } var timeStamp = GetTimeStamp(DateTime.Now); var dataToSign = string.Format("#{0}#{1}#{2}#{3}#{4}#{5}#{6}#", account.MerchantCode, account.TerminalCode, context.Payment.TrackingNumber, invoiceDate, (long)amount, RefundNumber, timeStamp); var signedData = crypto.Encrypt(account.PrivateKey, dataToSign); return(new[] { new KeyValuePair <string, string>("InvoiceNumber", context.Payment.TrackingNumber.ToString()), new KeyValuePair <string, string>("InvoiceDate", invoiceDate), new KeyValuePair <string, string>("MerchantCode", account.MerchantCode), new KeyValuePair <string, string>("TerminalCode", account.TerminalCode), new KeyValuePair <string, string>("Amount", amount.ToLongString()), new KeyValuePair <string, string>("action", RefundNumber), new KeyValuePair <string, string>("TimeStamp", timeStamp), new KeyValuePair <string, string>("Sign", signedData) }); }