Posts

Showing posts from 2015

Promise Sharing in AngularJS

The Problem As any software project's complexity increases, separation of concerns becomes more and more important for overall maintainability. Angular services are a great way for multiple controllers to share functionality, and promotes the kind of decoupling that leads to clean, maintainable code. Although Angular services can really do anything, one of the more common uses of Angular services is to reach out to your server (via $http) and get some data. This is a great way to separate data-fetching logic from the business logic of your web application. However, this can also be a problem as your application becomes large. Let's say your application has multiple subviews, each with its own controller. These controllers know nothing about each other (since you're a good architect), and each has a dependency on the same Angular service to fetch some data from the same API endpoint. This results in two service calls to the server, each requesting the same data. For

Creating a PayPal IPN Web API Endpoint

Image
PayPal's IPN service allows you to perform server side business logic once you are sure that payment has been received. This is extremely useful if you want to hold off on shipping order until payment has arrived. However, as convenient as it is, it is equally under-documented, and there are little resources for a .NET developer. Here is one way of setting up a PayPal IPN endpoint using Web API. [RoutePrefix("paypal")] public class PayPalController : ApiController { private PayPalValidator _validator; public PayPalController() { this._validator = new PayPalValidator(); } [HttpPost] [Route("ipn")] public void ReceiveIPN(IPNBindingModel model) { if (!_validator.ValidateIPN(model.RawRequest)) throw new Exception("Error validating payment"); switch (model.PaymentStatus) { case "Compl