Skip to content
Article

.NET Online Payment Gateways: A Factory Pattern Model

One thing that any good development company should do is strive to create reusable code.  Thinking back to projects I’ve worked on in my first year here, it occurred to me that quite a few of them have involved some form of online payment processing.  However, each client has used a different payment processor that has required custom programming.  I began thinking how nice it would be to submit a generic payment object to a gateway with large disregard to what particular vendor the payment is being submitted to.   Early on in developing this, it occurred to me that a factory pattern would be the way to go; essentially what I want is a “factory” that will figure out what type of online payment gateway I need and construct that for me.

To start things, I made a simple payment .NET gateway interface to make sure my gateway objects will do the one thing I need them to:


public interface IPaymentGateway
{
string SubmitPayment(Payment payment);
}

Essentially what I’m saying here is that no matter what type of gateway I’m using, I’ll need to submit a payment.

Next, we have a simple factory pattern to return some type of gateway:

public class PaymentGatewayFactory
{
public IPaymentGateway CreatePaymentGateway()
{
PaymentGatewayRepository paymentGatewayRepository = new PaymentGatewayRepository();
string gatewayType = paymentGatewayRepository.GetGatewayType();

switch(gatewayType)
{
case “Authnet”:
return new Authnet();
case “Paypal”:
return new Paypal();
case “Payflow”:
return new PayflowPro();
default:
throw new NotSupportedException(“This payment gateway is not supported.”);
}
}
}

Here we have a call to a PaymentGatewayRepository class (not included), which will read a config file and return a string representing what type of payment gateway the client is using. Next, a simple switch is done that will return the appropriate payment gateway class (or a custom exception if the gateway is not yet supported). Each of the gateway classes implements the IPaymentGateway interface.

The beauty of this is that once this project is built, submitting payments is a breeze. Just include the assembly in a project, reference it, and then follow these three easy steps:

  1. Add the necessary config keys.<!-- Gateway types | Possible Values: Authnet, Paypal, Payflow -->
    <add key="GatewayType" value="Authnet">
    <!– Authnet Keys –>
    <add key=”Anet_URL” value=”http://test.authorize.net/gateway/transact.dll”/>
    <add key=”payment_login_key” value=”123456789″/>
    <add key=”payment_tran_key” value=”987654321″/>
    <add key=”payment_auth_name” value=”Example”/>
  2. Build the payment object.Payment payment = new Payment();
    payment.BillingFirstName = "Jeremy";
    payment.BillingLastName = "Wiggins";
    etc…
  3. Submit the payment.IPaymentGateway gateway = new PaymentGatewayFactory().CreatePaymentGateway();
    gateway.SubmitPayment(payment);

And that’s all there is to it. This will be a nice addition to a reusable component library. Once the logic has been implemented for a new payment gateway, it never has to be thought about again. Just add a few lines to a config file and submit payments in a couple of easy steps.

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Insights

Atlantic BT's Insights

We’re sharing the latest concepts in tech, design, and software development. Learn more about our findings.

Questions & Answers

Can you integrate with my existing systems and teams?

Yes, both technically and operationally. On the technical side, our engineering heritage allows us to connect modern cloud, data, and AI capabilities securely to your existing ERPs, CRMs, and proprietary software using SOC 2 Type 2 certified practices. On the operational side, we never work in a silo. Our senior architects embed directly with your in-house developers and stakeholders, aligning with your governance protocols and building internal capability so your team can confidently maintain and scale the system.

Learn More about Can you integrate with my existing systems and teams?
Why should we pay for a discovery phase when we can jump straight into development?

Investing in a strategy and discovery phase prevents costly rework, scope creep, and misaligned features before your engineering budget is committed to full-scale development. While jumping straight into writing code can feel faster at the beginning, uncovering hidden legacy bottlenecks, unclear user requirements, or integration roadblocks midway through a build is significantly more expensive to fix in production than on paper.

A structured discovery phase protects your budget and timeline in four practical ways:

  • Validates Assumptions Before Engineering Begins: Through stakeholder interviews, workflow observations, and a clickable prototype, your team can test user flows and gather real feedback early so we can ensure we build the exact features your business needs.
  • Uncovers Hidden Technical Constraints: Auditing your existing databases, APIs, and security requirements upfront reveals integration hurdles and technical debt before developers write a single line of production code.
  • Produces Accurate Budgets & Timelines: Defining clear technical requirements and architecture blueprints eliminates guesswork, giving leadership reliable cost estimates and realistic delivery milestones.
  • Aligns Leadership & Technical Teams: Getting executive sponsors, end users, and IT stakeholders on the same page early prevents mid-project priority shifts that stall momentum and inflate costs.

Learn More about Why should we pay for a discovery phase when we can jump straight into development?
What does my business get by the end of a technology consulting engagement?

At the end of a technology consulting engagement with Atlantic BT, your business walks away with a clear, actionable blueprint and a validated prototype so your leadership team can move into development with full confidence. Rather than leaving you with high-level theory, our senior architects deliver concrete artifacts built around your actual operations:

  • Stakeholder & Workflow Findings: Insights gathered from executive stakeholder interviews and hands-on contextual inquiries that map out how your teams currently work and where daily bottlenecks occur.
  • Comprehensive Systems Audit: A technical evaluation of your existing software stack, databases, integrations, and security posture to pinpoint technical debt and modernization opportunities.
  • Prioritized Recommendations & Roadmap: An objective, vendor-agnostic plan outlining which software, cloud, or AI solutions will deliver the highest return on investment, complete with scope, timeline, and budget estimates.
  • Fully Clickable Prototype: If building software, an interactive front-end prototype that lets your team test user flows, validate assumptions, and gather real feedback before investing in full-scale engineering.

Learn More about What does my business get by the end of a technology consulting engagement?
What does enterprise technology consulting cost for businesses?

A focused enterprise AI readiness assessment and strategy roadmap typically ranges from $10,000 to $75,000, depending on the complexity of your data infrastructure, security requirements, and the number of workflows evaluated. At Atlantic BT, we scope engagements transparently around defined deliverables, such as a systems audit, prioritized ROI roadmap, and working prototype, so you can validate business value before committing to full-scale development. 

Our initial AI strategy discovery process starts at $10,000 and includes evaluation of 3 workflows and initial suggestions.

Learn More about What does enterprise technology consulting cost for businesses?