Esempio n. 1
0
        public static PaymentRequestResult CreateRequestResult(Invoice invoice, IHttpContextAccessor httpContextAccessor, PasargadGatewayOptions options)
        {
            var invoiceDate = GetTimeStamp(DateTime.Now);

            var timeStamp = invoiceDate;

            var dataToSign = string.Format("#{0}#{1}#{2}#{3}#{4}#{5}#{6}#{7}#",
                                           options.MerchantCode,
                                           options.TerminalCode,
                                           invoice.TrackingNumber,
                                           invoiceDate,
                                           (long)invoice.Amount,
                                           invoice.CallbackUrl,
                                           ActionNumber,
                                           timeStamp);

            var signedData = SignData(options.PrivateKey, dataToSign);

            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "merchantCode", options.MerchantCode },
                { "terminalCode", options.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);

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

            return(result);
        }
Esempio n. 2
0
        public static IEnumerable <KeyValuePair <string, string> > CreateVerifyData(Payment payment, PasargadGatewayOptions options, PasargadCallbackResult callbackResult)
        {
            var timeStamp = GetTimeStamp(DateTime.Now);

            var dataToSign = string.Format("#{0}#{1}#{2}#{3}#{4}#{5}#",
                                           options.MerchantCode,
                                           options.TerminalCode,
                                           payment.TrackingNumber,
                                           callbackResult.InvoiceDate,
                                           (long)payment.Amount,
                                           timeStamp);

            var signData = SignData(options.PrivateKey, dataToSign);

            return(new[]
            {
                new KeyValuePair <string, string>("InvoiceNumber", payment.TrackingNumber.ToString()),
                new KeyValuePair <string, string>("InvoiceDate", callbackResult.InvoiceDate),
                new KeyValuePair <string, string>("MerchantCode", options.MerchantCode),
                new KeyValuePair <string, string>("TerminalCode", options.TerminalCode),
                new KeyValuePair <string, string>("Amount", ((long)payment.Amount).ToString()),
                new KeyValuePair <string, string>("TimeStamp", timeStamp),
                new KeyValuePair <string, string>("Sign", signData)
            });
        }
Esempio n. 3
0
        public static IEnumerable <KeyValuePair <string, string> > CreateRefundData(Payment payment, Money amount, PasargadGatewayOptions options)
        {
            var transactionRecord = payment.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Request);

            if (transactionRecord == null)
            {
                throw new Exception($"Cannot find transaction record for Payment-{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}#",
                                           options.MerchantCode,
                                           options.TerminalCode,
                                           payment.TrackingNumber,
                                           invoiceDate,
                                           (long)amount,
                                           RefundNumber,
                                           timeStamp);

            var signedData = SignData(options.PrivateKey, dataToSign);

            return(new[]
            {
                new KeyValuePair <string, string>("InvoiceNumber", payment.TrackingNumber.ToString()),
                new KeyValuePair <string, string>("InvoiceDate", invoiceDate),
                new KeyValuePair <string, string>("MerchantCode", options.MerchantCode),
                new KeyValuePair <string, string>("TerminalCode", options.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)
            });
        }
Esempio n. 4
0
        public static PasargadCheckCallbackResult CreateCheckCallbackResult(string webServiceResponse, PasargadGatewayOptions options, 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 == options.MerchantCode &&
                            compareTerminalCode == options.TerminalCode;

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

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