public async Task <ActionResult> Notify([ModelBinder(typeof(PayFastNotifyModelBinder))] PayFastNotify payFastNotifyViewModel)
        {
            payFastNotifyViewModel.SetPassPhrase(this.payFastSettings.PassPhrase);

            var calculatedSignature = payFastNotifyViewModel.GetCalculatedSignature();

            var isValid = payFastNotifyViewModel.signature == calculatedSignature;

            System.Diagnostics.Debug.WriteLine($"Signature Validation Result: {isValid}");

            // The PayFast Validator is still under developement
            // Its not recommended to rely on this for production use cases
            var payfastValidator = new PayFastValidator(this.payFastSettings, payFastNotifyViewModel, IPAddress.Parse(this.HttpContext.Request.UserHostAddress));

            var merchantIdValidationResult = payfastValidator.ValidateMerchantId();

            System.Diagnostics.Debug.WriteLine($"Merchant Id Validation Result: {merchantIdValidationResult}");

            var ipAddressValidationResult = payfastValidator.ValidateSourceIp();

            System.Diagnostics.Debug.WriteLine($"Ip Address Validation Result: {merchantIdValidationResult}");

            // Currently seems that the data validation only works for successful payments
            var paymentId = payFastNotifyViewModel.m_payment_id;

            if (payFastNotifyViewModel.payment_status == PayFastStatics.CompletePaymentConfirmation)
            {
                var dataValidationResult = await payfastValidator.ValidateData();

                System.Diagnostics.Debug.WriteLine($"Data Validation Result: {dataValidationResult}");
            }

            if (payFastNotifyViewModel.payment_status == PayFastStatics.CancelledPaymentConfirmation)
            {
                System.Diagnostics.Debug.WriteLine($"Subscription was cancelled");
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Notify([ModelBinder(BinderType = typeof(PayFastNotifyModelBinder))] PayFastNotify payFastNotifyViewModel)
        {
            if (payFastNotifyViewModel != null)
            {
                Ok();
            }
            int CustomerID = (int)TempData["CustomerID"];

            payFastNotifyViewModel.SetPassPhrase(this.payFastSettings.PassPhrase);
            var calculatedSignature = payFastNotifyViewModel.GetCalculatedSignature();
            var isValid             = payFastNotifyViewModel.signature == calculatedSignature;

            logger.LogInformation($"Signature Validation Result: {isValid}");

            var payfastValidator = new PayFastValidator(this.payFastSettings, payFastNotifyViewModel, this.HttpContext.Connection.RemoteIpAddress);

            var merchantIdValidationResult = payfastValidator.ValidateMerchantId();

            logger.LogInformation($"Merchant Id Validation Result: {merchantIdValidationResult}");

            var ipAddressValidationResult = await payfastValidator.ValidateSourceIp();

            logger.LogInformation($"Ip Address Validation Result: {ipAddressValidationResult}");
            // Currently seems that the data validation only works for success
            if (payFastNotifyViewModel.payment_status == PayFastStatics.CompletePaymentConfirmation)
            {
                var dataValidationResult = await payfastValidator.ValidateData();

                logger.LogInformation($"Data Validation Result: {dataValidationResult}");
            }

            if (payFastNotifyViewModel.payment_status == PayFastStatics.CancelledPaymentConfirmation)
            {
                logger.LogInformation($"Subscription was cancelled");
            }
            repo.CustomerPaymentReceived(payFastNotifyViewModel.m_payment_id);
            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Notify([ModelBinder(BinderType = typeof(PayFastNotifyModelBinder))] PayFastNotify payFastNotifyViewModel)
        {
            payFastNotifyViewModel.SetPassPhrase(this.payFastSettings.PassPhrase);

            var calculatedSignature = payFastNotifyViewModel.GetCalculatedSignature();

            var isValid = payFastNotifyViewModel.signature == calculatedSignature;

            this.logger.LogInformation($"Signature Validation Result: {isValid}");

            // The PayFast Validator is still under developement
            // Its not recommended to rely on this for production use cases
            var payfastValidator = new PayFastValidator(this.payFastSettings, payFastNotifyViewModel, this.HttpContext.Connection.RemoteIpAddress);

            var merchantIdValidationResult = payfastValidator.ValidateMerchantId();

            this.logger.LogInformation($"Merchant Id Validation Result: {merchantIdValidationResult}");

            var ipAddressValidationResult = await payfastValidator.ValidateSourceIp();

            this.logger.LogInformation($"Ip Address Validation Result: {ipAddressValidationResult}");

            // Currently seems that the data validation only works for success
            if (payFastNotifyViewModel.payment_status == PayFastStatics.CompletePaymentConfirmation)
            {
                var dataValidationResult = await payfastValidator.ValidateData();

                this.logger.LogInformation($"Data Validation Result: {dataValidationResult}");
            }

            if (payFastNotifyViewModel.payment_status == PayFastStatics.CancelledPaymentConfirmation)
            {
                this.logger.LogInformation($"Subscription was cancelled");
            }

            return(Ok());
        }
Ejemplo n.º 4
0
        //public void Post([FromBody]string value)
        public async Task <IActionResult> Post([ModelBinder(BinderType = typeof(PayFastNotifyModelBinder))] PayFastNotify payFastNotifyViewModel)
        {
            payFastNotifyViewModel.SetPassPhrase(this._payFastSettings.PassPhrase);
            var calculatedSignature = payFastNotifyViewModel.GetCalculatedSignature();
            var isValid             = payFastNotifyViewModel.signature == calculatedSignature;

            // The PayFast Validator is still under developement
            // Its not recommended to rely on this for production use cases
            var payfastValidator = new PayFastValidator(this._payFastSettings, payFastNotifyViewModel, this.HttpContext.Connection.RemoteIpAddress);

            var merchantIdValidationResult = payfastValidator.ValidateMerchantId();

            var ipAddressValidationResult = await payfastValidator.ValidateSourceIp();

            // Currently seems that the data validation only works for success
            if (payFastNotifyViewModel.payment_status == PayFastStatics.CompletePaymentConfirmation)
            {
                var dataValidationResult = await payfastValidator.ValidateData();

                //Complete Order
                //Todo take this to the application layer service
                //var order = await _ctx.Orders.FirstOrDefaultAsync(x => x.PaymentReference == payFastNotifyViewModel.m_payment_id);
                var order = await _ctx.Orders
                            .Include(x => x.User)
                            .FirstOrDefaultAsync(x => x.OrderNumber == payFastNotifyViewModel.m_payment_id);

                //Place the order
                order.Status = Domain.Enums.OrderStatus.Placed;

                //do cin7 push here
                //var so = await Cin7SalesOrderRequest(order);
                await _ctx.SaveChangesAsync();

                string cmsLink = Url.Action("SingleOrder", "Admin", new { id = order.OrderNumber }, Request.Scheme);


                var address = await _ctx.Addresses.FirstOrDefaultAsync(a => a.Id == order.AddressId);

                Console.WriteLine("PAYFAST LOG TEST");

                if (order.Account != null)
                {
                    Dictionary <string, string> vars = new Dictionary <string, string>
                    {
                        { "ordernumber", order.OrderNumber },
                        { "orderprice", string.Format("R {0}", order.SubTotal) },
                        { "orderdate", DateTime.UtcNow.ToString("dd MMM yyyy") },
                        //    { "location-costcenter", string.Format("", order.Account.CompanyName, order.Account.)},
                        { "orderaddress", string.Format("{0}<br/>{1}<br/>{2}<br/>{3}<br/>{4}<br/>{5}", order.Account.CompanyName, order.Location.Name, address?.Address1, address?.Address2, address?.City, address?.PostCode) },
                        { "cmslink", string.Format("<a href='{0}'>{0}</a>", cmsLink) }
                    };

                    Message m = new Message
                    {
                        FromEmail = "*****@*****.**",
                        FromName  = "Officebox",
                        Subject   = string.Format("OfficeBox Order Placed - {0}", order.OrderNumber),
                        To        = new To[]
                        {
                            new To {
                                Email = "*****@*****.**", Name = "OfficeBox"
                            }
                            //new To { Email = "*****@*****.**", Name = "Carel" }
                        }
                    };

                    _emailSender.SendEmailByTemplate(vars, "internal-order-confirmation-account", m);
                }
                else
                {
                    Dictionary <string, string> vars = new Dictionary <string, string>
                    {
                        { "ordernumber", order.OrderNumber },
                        { "orderprice", string.Format("R {0}", order.SubTotal) },
                        { "orderdate", DateTime.Now.ToString("dd MMM yyyy") },
                        { "orderaddress", string.Format("{0}<br/>{1}<br/>{2}<br/>{3}", address?.Address1, address?.Address2, address?.City, address?.PostCode) },
                        { "cmslink", string.Format("<a href='{0}'>{0}</a>", cmsLink) }
                    };

                    Message m = new Message
                    {
                        FromEmail = "*****@*****.**",
                        FromName  = "Officebox",
                        Subject   = string.Format("OfficeBox Order Placed - {0}", order.OrderNumber),
                        To        = new To[]
                        {
                            new To {
                                Email = "*****@*****.**", Name = "OfficeBox"
                            }
                            //new To { Email = "*****@*****.**", Name = "Carel" }
                        }
                    };

                    _emailSender.SendEmailByTemplate(vars, "internal-order-confirmation", m);
                }



                //_emailSender.SendEmailByTemplate("*****@*****.**", vars, "internal-order-confirmation", m);

                Dictionary <string, string> vars2 = new Dictionary <string, string>
                {
                    { "greeting", string.Format("Hi {0}", order.User.FirstName) },
                    { "greetingdescription", string.Format("Your order {0} has been confirmed and is being processed accordingly.", order.OrderNumber) },
                    { "ordernumber", order.OrderNumber },
                    { "orderprice", string.Format("R {0}", order.SubTotal.ToString("N2")) },
                    { "orderdate", DateTime.UtcNow.ToString("dd MMM yyyy") },
                    { "ordertime", DateTime.UtcNow.ToString("hh:mm tt") },
                    { "orderaddress", string.Format("{0}<br/>{1}<br/>{2}<br/>{3}", address?.Address1, address?.Address2, address?.City, address?.PostCode) },
                };

                Message m2 = new Message
                {
                    FromEmail = "*****@*****.**",
                    FromName  = "Officebox",
                    Subject   = string.Format("Awesome - We’ve received the order - {0}", order.OrderNumber),
                    To        = new To[]
                    {
                        new To {
                            Email = order.User.Email, Name = order.User.FirstName
                        }
                    }
                };

                _emailSender.SendEmailByTemplate(vars2, "finalcomfirmation", m2);
            }
            else if (payFastNotifyViewModel.payment_status == PayFastStatics.CancelledPaymentConfirmation)
            {
                //Cancel Order - delete it
                //Todo take this to the application layer service
                var order = _ctx.Orders.FirstOrDefault(x => x.PaymentReference == payFastNotifyViewModel.m_payment_id);
                _ctx.Orders.Remove(order);
                await _ctx.SaveChangesAsync();
            }

            return(Ok());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Notify([ModelBinder(BinderType = typeof(PayFastNotifyModelBinder))] PayFastNotify payFastNotifyViewModel)
        {
            logger.LogInformation("Payfast Notify URL accessed");

            payFastNotifyViewModel.SetPassPhrase(this._payFastSettings.PassPhrase);

            var calculatedSignature = payFastNotifyViewModel.GetCalculatedSignature();

            var isValid = payFastNotifyViewModel.signature == calculatedSignature;

            // The PayFast Validator is still under developement
            // Its not recommended to rely on this for production use cases
            var payfastValidator = new PayFastValidator(this._payFastSettings, payFastNotifyViewModel, this.HttpContext.Connection.RemoteIpAddress);

            var merchantIdValidationResult = payfastValidator.ValidateMerchantId();

            var ipAddressValidationResult = await payfastValidator.ValidateSourceIp();

            // Currently seems that the data validation only works for success
            if (payFastNotifyViewModel.payment_status == PayFastStatics.CompletePaymentConfirmation)
            {
                var dataValidationResult = await payfastValidator.ValidateData();

                //Compelte Order
                //Todo take this to the application layer service
                var order = _ctx.Orders.FirstOrDefault(x => x.PaymentReference == payFastNotifyViewModel.m_payment_id);

                //Place the order
                order.Status = Domain.Enums.OrderStatus.Placed;

                //do cin7 push here
                //var so = await Cin7SalesOrderRequest(order);
                await _ctx.SaveChangesAsync();

                string cmsLink = Url.Action("SingleOrder", "Admin", new { id = order.OrderNumber }, Request.Scheme);

                Location location = await _ctx.Locations
                                    .Include(l => l.Address)
                                    .Include(l => l.Authorizer)
                                    .FirstOrDefaultAsync(l => l.Id == order.LocationId);

                Dictionary <string, string> vars = new Dictionary <string, string>
                {
                    { "ordernumber", order.OrderNumber },
                    { "orderprice", string.Format("R {0}", order.SubTotal) },
                    { "orderdate", DateTime.UtcNow.ToString("dd MMM yyyy") },
                    { "orderaddress", string.Format("<strong>{0}</strong><br/>{1}<br/>{2}<br/>{3}<br/>{4}", location.Name, location.Address.Address1, location.Address.Address2, location.Address.City, location.Address.PostCode) },
                    { "cmslink", string.Format("<a href='{0}'>{0}</a>", cmsLink) },
                };

                Message m = new Message
                {
                    FromEmail = "*****@*****.**",
                    FromName  = "Officebox",
                    Subject   = string.Format("OfficeBox Order Placed - {0}", order.OrderNumber),
                    To        = new To[]
                    {
                        new To {
                            Email = "*****@*****.**", Name = "OfficeBox"
                        }
                        //new To { Email = "*****@*****.**", Name = "Carel" }
                    }
                };

                _emailSender.SendEmailByTemplate(vars, "internal-order-confirmation", m);
                //_emailSender.SendEmailByTemplate("*****@*****.**", vars, "internal-order-confirmation", m);
            }
            else if (payFastNotifyViewModel.payment_status == PayFastStatics.CancelledPaymentConfirmation)
            {
                //Cancle Order - delete it
                //Todo take this to the application layer service
                var order = _ctx.Orders.FirstOrDefault(x => x.PaymentReference == payFastNotifyViewModel.m_payment_id);

                _ctx.Orders.Remove(order);

                string cmsLink = Url.Action("SingleOrder", "Admin", new { id = order.OrderNumber }, Request.Scheme);

                Location location = await _ctx.Locations
                                    .Include(l => l.Address)
                                    .Include(l => l.Authorizer)
                                    .FirstOrDefaultAsync(l => l.Id == order.LocationId);

                Dictionary <string, string> vars = new Dictionary <string, string>
                {
                    { "ordernumber", order.OrderNumber },
                    { "orderprice", string.Format("R {0}", order.SubTotal) },
                    { "orderdate", DateTime.UtcNow.ToString("dd MMM yyyy") },
                    { "orderaddress", string.Format("<strong>{0}</strong><br/>{1}<br/>{2}<br/>{3}<br/>{4}", location.Name, location.Address.Address1, location.Address.Address2, location.Address.City, location.Address.PostCode) },
                    { "cmslink", string.Format("<a href='{0}'>OfficeBox Order Cancelled</a>", cmsLink) },
                };

                Message m = new Message
                {
                    FromEmail = "*****@*****.**",
                    FromName  = "Officebox",
                    Subject   = string.Format("OfficeBox Order Cancelled - {0}", order.OrderNumber),
                    To        = new To[]
                    {
                        new To {
                            Email = "*****@*****.**", Name = "OfficeBox"
                        }
                        //new To { Email = "*****@*****.**", Name = "Carel" }
                    }
                };

                _emailSender.SendEmailByTemplate(vars, "internal-order-confirmation", m);
                //_emailSender.SendEmailByTemplate("*****@*****.**", vars, "internal-order-confirmation", m);

                await _ctx.SaveChangesAsync();
            }

            return(Ok());
        }