コード例 #1
0
        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)
            });
        }
コード例 #2
0
        public static PaymentVerifyResult CreateVerifyResult(string webServiceResponse, PasargadCallbackResult callbackResult, MessagesOptions messagesOptions)
        {
            var result = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result");

            var isSucceed = result.Equals("true", StringComparison.OrdinalIgnoreCase);

            var message = isSucceed
                ? messagesOptions.PaymentSucceed
                : XmlHelper.GetNodeValueFromXml(webServiceResponse, "resultMessage");

            return(new PaymentVerifyResult
            {
                Status = isSucceed ? PaymentVerifyResultStatus.Succeed : PaymentVerifyResultStatus.Failed,
                TransactionCode = callbackResult.TransactionId,
                Message = message
            });
        }
コード例 #3
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
            });
        }
コード例 #4
0
ファイル: PasargadHelper.cs プロジェクト: Alibesharat/Parbad
        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)
            });
        }