Ejemplo n.º 1
0
        public async override Task <PaymentResult> VerifyPayment(VerifyPaymentModel paymentModel, IFormCollection collection)
        {
            foreach (var item in collection)
            {
                paymentModel.Attributes.Add(new SanalPosTRAttribute {
                    Key = item.Key.ToLower(), Value = item.Value
                });
            }

            var validateResult = await Validate3D(paymentModel, collection);

            if (validateResult.Status)
            {
                return(await base.VerifyPayment(paymentModel, collection));
            }
            else
            {
                return(new PaymentResult()
                {
                    Status = false,
                    Error = validateResult.Error,
                    ErrorCode = validateResult.ErrorCode
                });
            }
        }
Ejemplo n.º 2
0
        private async Task <PaymentResult> Validate3D(VerifyPaymentModel paymentModel, IFormCollection collection)
        {
            var config = (YKBConfiguration)ProviderConfiguration;

            string encKey = config.HashKey;

            if (paymentModel.Order.CurrencyCode.IsEmpty())
            {
                paymentModel.Order.CurrencyCode = "TL";
            }

            Log.Information($"YKBProvider:ENC:{encKey}");

            string xid            = collection["Xid"];
            var    amount         = (decimal.Parse(collection["Amount"], new CultureInfo("tr-TR"))).ToString("0", new CultureInfo("en-US"));
            string firstShaString = encKey + ';' + config.TerminalId;
            string firstHash      = HashHelper.GetSHA256(firstShaString);
            string macShaString   = xid + ';' + amount + ';' + paymentModel.Order.CurrencyCode + ';' + config.MerchantId + ';' + firstHash;
            string mac            = HashHelper.GetSHA256(macShaString);

            Log.Information($"YKBProvider:firstShaString:{firstShaString}");
            Log.Information($"YKBProvider:firstHash:{firstHash}");
            Log.Information($"YKBProvider:sha256String:{macShaString}");
            Log.Information($"YKBProvider:mac:{mac}");



            paymentModel.Attributes.Add(new SanalPosTRAttribute {
                Key = "mac", Value = mac
            });

            string template = TemplateHelper.ReadEmbedResource($"{EmbededDirectory}.3D_Resolve.xml");
            string postData = TemplateHelper.PrepaireXML(new ViewModel
            {
                Use3DSecure   = true,
                Configuration = ProviderConfiguration,
                Attributes    = paymentModel.Attributes
            }, template);

            var post = GetPostForm();

            post.Content = System.Net.WebUtility.UrlEncode(postData);

            HTTPClient client = new HTTPClient(EndPointConfiguration.BaseUrl);
            var        result = await client.Post(EndPointConfiguration.ApiEndPoint, post, Handler);

            if (TemplateHelper.GetInlineContent(result.ServerResponseRaw, "mdStatus") != "1")
            {
                result.Status    = false;
                result.ErrorCode = TemplateHelper.GetInlineContent("mdErrorMessage", result.ServerResponseRaw);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public virtual string OnCompilingTemplate(VerifyPaymentModel paymentModel, string template)
        {
            var viewModel = new ViewModel
            {
                Configuration = ProviderConfiguration,
                Order         = paymentModel.Order,
                Attributes    = paymentModel.Attributes
            };

            return(OnCompilingTemplate(viewModel, template));
        }
Ejemplo n.º 4
0
        public async virtual Task <PaymentResult> VerifyPayment(VerifyPaymentModel paymentModel, IFormCollection collection)
        {
            Log.Information($"{paymentModel.Order.OrderId} - VerifyPayment Process");

            var    postForm        = GetPostForm();
            var    resource        = $"{EmbededDirectory}.3DEnd.xml";
            string embededResource = TemplateHelper.ReadEmbedResource(resource);
            string viewModel       = OnCompilingTemplate(paymentModel, embededResource);

            postForm.Content = viewModel;

            Log.Information($"{paymentModel.Order.OrderId} - VerifyPayment Http Post");


            HTTPClient httpClient = new HTTPClient(EndPointConfiguration.BaseUrl);

            return(await httpClient.Post(EndPointConfiguration.SecureReturnEndPoint, postForm, Handler));
        }
Ejemplo n.º 5
0
        public override async Task <PaymentResult> VerifyPayment(VerifyPaymentModel paymentModel, IFormCollection collection)
        {
            if (Validate3D(collection))
            {
                paymentModel.Attributes.Add(new SanalPosTRAttribute {
                    Key = "OrderId", Value = collection["oid"]
                });
                paymentModel.Attributes.Add(new SanalPosTRAttribute {
                    Key = "PayerTxnId", Value = collection["xid"]
                });
                paymentModel.Attributes.Add(new SanalPosTRAttribute {
                    Key = "PayerSecurityLevel", Value = collection["eci"]
                });
                paymentModel.Attributes.Add(new SanalPosTRAttribute {
                    Key = "PayerAuthenticationCode", Value = collection["cavv"]
                });
                paymentModel.Attributes.Add(new SanalPosTRAttribute {
                    Key = "CardNumber", Value = collection["md"]
                });

                if (paymentModel.Order.Installment.HasValue && (paymentModel.Order.Installment == 1 || paymentModel.Order.Installment == 0))
                {
                    paymentModel.Order.Installment = null;
                }

                return(await base.VerifyPayment(paymentModel, collection));
            }
            else
            {
                PaymentResult paymentResult = new PaymentResult();
                paymentResult.Error     = collection["ErrMsg"];
                paymentResult.ErrorCode = collection["ProcReturnCode"];
                paymentResult.Status    = false;
                return(paymentResult);
            }
        }