示例#1
0
        public static PaymentRequestResult CreateRequestResult(Invoice invoice, IHttpContextAccessor httpContextAccessor, PasargadGatewayAccount account)
        {
            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 = SignData(account.PrivateKey, dataToSign);

            var transporter = new GatewayPost(
                httpContextAccessor,
                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 }
            });

            var result = PaymentRequestResult.Succeed(transporter, account.Name);

            result.DatabaseAdditionalData.Add("timeStamp", timeStamp);

            return(result);
        }
示例#2
0
        public static IEnumerable <KeyValuePair <string, string> > CreateVerifyData(InvoiceContext context, PasargadGatewayAccount account, 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 = SignData(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)
            });
        }
示例#3
0
        public static IEnumerable <KeyValuePair <string, string> > CreateRefundData(InvoiceContext context, Money amount, 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 = SignData(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)
            });
        }
示例#4
0
        public static PasargadCheckCallbackResult CreateCheckCallbackResult(string webServiceResponse, PasargadGatewayAccount account, PasargadCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var compareReferenceId  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "invoiceNumber");
            var compareAction       = XmlHelper.GetNodeValueFromXml(webServiceResponse, "action");
            var compareMerchantCode = XmlHelper.GetNodeValueFromXml(webServiceResponse, "merchantCode");
            var compareTerminalCode = XmlHelper.GetNodeValueFromXml(webServiceResponse, "terminalCode");

            bool isSucceed;
            PaymentVerifyResult verifyResult = null;

            if (compareReferenceId.IsNullOrWhiteSpace() ||
                compareAction.IsNullOrWhiteSpace() ||
                compareMerchantCode.IsNullOrWhiteSpace() ||
                compareTerminalCode.IsNullOrWhiteSpace())
            {
                isSucceed = false;

                verifyResult = PaymentVerifyResult.Failed(messagesOptions.InvalidDataReceivedFromGateway);
            }
            else
            {
                var responseResult = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result");

                isSucceed = responseResult.Equals("true", StringComparison.OrdinalIgnoreCase) &&
                            compareReferenceId == callbackResult.InvoiceNumber &&
                            compareAction == ActionNumber &&
                            compareMerchantCode == account.MerchantCode &&
                            compareTerminalCode == account.TerminalCode;

                if (!isSucceed)
                {
                    verifyResult = PaymentVerifyResult.Failed("پرداخت موفقيت آميز نبود و يا توسط خريدار کنسل شده است");
                }
            }

            return(new PasargadCheckCallbackResult
            {
                IsSucceed = isSucceed,
                Result = verifyResult
            });
        }