Esempio n. 1
0
        public static PaymentRequestResult CreateRequestResult(
            string webServiceResponse,
            Invoice invoice,
            IranKishGatewayOptions options,
            IHttpContextAccessor httpContextAccessor,
            MessagesOptions messagesOptions)
        {
            var result  = XmlHelper.GetNodeValueFromXml(webServiceResponse, "result", "http://schemas.datacontract.org/2004/07/Token");
            var message = XmlHelper.GetNodeValueFromXml(webServiceResponse, "message", "http://schemas.datacontract.org/2004/07/Token");
            var token   = XmlHelper.GetNodeValueFromXml(webServiceResponse, "token", "http://schemas.datacontract.org/2004/07/Token");

            var isSucceed = result.Equals("true", StringComparison.OrdinalIgnoreCase) && !token.IsNullOrEmpty();

            if (!isSucceed)
            {
                if (message.IsNullOrEmpty())
                {
                    message = messagesOptions.InvalidDataReceivedFromGateway;
                }

                return(PaymentRequestResult.Failed(message));
            }

            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "merchantid", options.MerchantId },
                { "token", token }
            });

            return(PaymentRequestResult.Succeed(transporter));
        }
Esempio n. 2
0
        public static IranKishCallbackResult CreateCallbackResult(
            Payment payment,
            IranKishGatewayOptions options,
            HttpRequest httpRequest,
            MessagesOptions messagesOptions)
        {
            httpRequest.TryGetParam("ResultCode", out var resultCode);
            httpRequest.Form.TryGetValue("Token", out var token);
            httpRequest.TryGetParam("MerchantId", out var merchantId);

            // Equals to TrackingNumber in Parbad system.
            httpRequest.TryGetParamAs <long>("InvoiceNumber", out var invoiceNumber);

            // Equals to TransactionCode in Parbad system.
            httpRequest.TryGetParam("ReferenceId", out var referenceId);

            var isSucceed = false;
            PaymentVerifyResult verifyResult = null;

            if (merchantId != options.MerchantId ||
                invoiceNumber != payment.TrackingNumber ||
                token.IsNullOrEmpty())
            {
                verifyResult = new PaymentVerifyResult
                {
                    TrackingNumber  = invoiceNumber,
                    TransactionCode = referenceId,
                    IsSucceed       = false,
                    Message         = messagesOptions.InvalidDataReceivedFromGateway
                };
            }
            else
            {
                var translatedMessage = IranKishGatewayResultTranslator.Translate(resultCode, messagesOptions);

                isSucceed = resultCode == OkResult;

                if (!isSucceed)
                {
                    verifyResult = new PaymentVerifyResult
                    {
                        TrackingNumber  = invoiceNumber,
                        TransactionCode = referenceId,
                        IsSucceed       = false,
                        Message         = translatedMessage
                    };
                }
            }

            return(new IranKishCallbackResult
            {
                IsSucceed = isSucceed,
                Token = token,
                InvoiceNumber = invoiceNumber,
                ReferenceId = referenceId,
                Result = verifyResult
            });
        }
Esempio n. 3
0
 public static string CreateVerifyData(IranKishCallbackResult callbackResult, IranKishGatewayOptions options)
 {
     return
         ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">" +
          "<soapenv:Header/>" +
          "<soapenv:Body>" +
          "<tem:KicccPaymentsVerification>" +
          $"<tem:token>{callbackResult.Token}</tem:token>" +
          $"<tem:merchantId>{options.MerchantId}</tem:merchantId>" +
          $"<tem:referenceNumber>{callbackResult.ReferenceId}</tem:referenceNumber>" +
          "<tem:sha1Key></tem:sha1Key>" +
          "</tem:KicccPaymentsVerification>" +
          "</soapenv:Body>" +
          "</soapenv:Envelope>");
 }
Esempio n. 4
0
 public static string CreateRequestData(Invoice invoice, IranKishGatewayOptions options)
 {
     return
         ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">" +
          "<soapenv:Header/>" +
          "<soapenv:Body>" +
          "<tem:MakeToken>" +
          $"<tem:amount>{(long)invoice.Amount}</tem:amount>" +
          $"<tem:merchantId>{options.MerchantId}</tem:merchantId>" +
          $"<tem:invoiceNo>{invoice.TrackingNumber}</tem:invoiceNo>" +
          "<tem:paymentId></tem:paymentId>" +
          "<tem:specialPaymentId></tem:specialPaymentId>" +
          $"<tem:revertURL>{invoice.CallbackUrl}</tem:revertURL>" +
          "<tem:description></tem:description>" +
          "</tem:MakeToken>" +
          "</soapenv:Body>" +
          "</soapenv:Envelope>");
 }