14.2. Design

There are several payment gateways readily available for us to use to process the payments and automate the subscription billing process. For the sake of this book, we will use PayPal as our payment processor of choice, but we will design our application to allow for easy switching to a different payment processor.

We will abstract our payment processor implementation using an interface that will enable us to write tests against mock implementations as well as easily add new implementations of the interface. Almost every payment processing system follows a similar process, in which they notify your application of the transaction information through an HTTP post HTTP post to a callback or notification URL. We want to be able to receive this POST request, parse the data, and apply our business logic. Most payment gateways expect to receive a confirmation from your application that you received the callback — a handshake.

The interface for our payment service is very simple, as shown below and in Figure 14-1.

Figure 14-1. Figure 14-1
public interface IPaymentService
{
    void ProcessPayment(NameValueCollection formCollection);
    void PerformHandShake(HttpRequestBase  Request);
}

Get ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.