Example #1
0
        public override async Task <RequestResult> RequestAsync(Invoice invoice)
        {
            string webServiceXml = CreateRequestWebServiceXml(
                pin: ParsianConfiguration.Pin,
                orderId: invoice.OrderNumber,
                amount: invoice.Amount,
                callBackUrl: invoice.CallbackUrl);

            var result = await WebHelper.SendXmlWebRequestAsync(WebServiceUrl, webServiceXml);

            long authority = Convert.ToInt64(XmlHelper.GetNodeValueFromXml(result, "authority", "http://tempuri.org/"));

            byte status = Convert.ToByte(XmlHelper.GetNodeValueFromXml(result, "status", "http://tempuri.org/"));

            var isSucceed = status == 0;

            IGatewayResultTranslator gatewayResultTranslator = new ParsianStatusTranslator();

            var translatedResult = gatewayResultTranslator.Translate(status);

            if (!isSucceed)
            {
                return(new RequestResult(RequestResultStatus.Failed, translatedResult, authority.ToString()));
            }

            var paymentPageUrl = CreatePaymentPageUrl(PaymentPageUrl, authority);

            return(new RequestResult(RequestResultStatus.Success, translatedResult, authority.ToString())
            {
                BehaviorMode = GatewayRequestBehaviorMode.Redirect,
                Content = paymentPageUrl
            });
        }
Example #2
0
        public override VerifyResult Verify(GatewayVerifyPaymentContext verifyPaymentContext)
        {
            //  Callback

            var referenceId = verifyPaymentContext.RequestParameters.GetAs <string>("au");

            var response = verifyPaymentContext.RequestParameters.GetAs <string>("rs");

            if (referenceId.IsNullOrWhiteSpace() || response.IsNullOrWhiteSpace())
            {
                return(new VerifyResult(Gateway.Parsian, referenceId, string.Empty, VerifyResultStatus.Failed, "Invalid data is received from the gateway."));
            }

            IGatewayResultTranslator gatewayResultTranslator = new ParsianStatusTranslator();

            var isSuccess = response != "0";

            if (!isSuccess)
            {
                var callbackTranslatedMessage = gatewayResultTranslator.Translate(Convert.ToByte(response));

                return(new VerifyResult(Gateway.Parsian, referenceId, string.Empty, VerifyResultStatus.Failed, callbackTranslatedMessage));
            }

            //  Now verify

            string verifyWebServiceXml = CreateVerifyWebServiceXml(
                pin: ParsianConfiguration.Pin,
                authority: Convert.ToInt64(referenceId));

            var verifyResult = WebHelper.SendXmlWebRequest(WebServiceUrl, verifyWebServiceXml);

            byte status = Convert.ToByte(XmlHelper.GetNodeValueFromXml(verifyResult, "status", "http://tempuri.org/"));

            //  invoiceNumber is TransactionId
            var transactionId = XmlHelper.GetNodeValueFromXml(verifyResult, "invoiceNumber", "http://tempuri.org/");

            var translatedMessage = gatewayResultTranslator.Translate(status);

            isSuccess = status == 0;

            var verifyResultStatus = isSuccess ? VerifyResultStatus.Success : VerifyResultStatus.Failed;

            return(new VerifyResult(Gateway.Parsian, referenceId, transactionId, verifyResultStatus, translatedMessage));
        }
Example #3
0
        public override async Task <RefundResult> RefundAsync(GatewayRefundPaymentContext refundPaymentContext)
        {
            string webServiceXml = CreateReverseWebServiceXml(ParsianConfiguration.Pin,
                                                              refundPaymentContext.OrderNumber,
                                                              refundPaymentContext.Amount);

            var result = await WebHelper.SendXmlWebRequestAsync(WebServiceUrl, webServiceXml);

            byte status = Convert.ToByte(XmlHelper.GetNodeValueFromXml(result, "status", "http://tempuri.org/"));

            IGatewayResultTranslator gatewayResultTranslator = new ParsianStatusTranslator();

            var translatedMessage = gatewayResultTranslator.Translate(status);

            var isSuccess = status == 0;

            var reverseResultStatus = isSuccess ? RefundResultStatus.Success : RefundResultStatus.Failed;

            return(new RefundResult(Gateway.Parsian, refundPaymentContext.Amount, reverseResultStatus, translatedMessage));
        }