Skip to content
Article

Creating Custom Gateway in WordPress Plugin Cart66

Ah payment gateways.  The, uh, gateway…to making payments. Yeah.

Previously called PHPurchase, Cart66 (and its free sibling Cart66 Lite) are full-featured e-commerce plugins for selling products via WordPress. Cart66 comes out-of-the-box with several integrated gateways:  Authorize.net, PayPalPro, and PayPal Express. It also has a handy feature where you can add an Authorize.net-compatible gateway right in the payment options menu.

But, what if you need a customized payment gateway? Like, say TransFirst TransLink?

After purchasing/downloading Cart66 (I’m using the paid version 1.0.7), follow these “easy” steps —

  1. Add additional option for your payment gateway to the option list in contentpluginscart66adminsettings.php
  2. Make a copy of an existing gateway file (such as contentpluginscart66progatewaysCart66AuthorizeNet.php)
  3. Update the properties of the gateway class to handle the payment in an appropriate manner specific to that gateway — remap fields, change the remote-request format, etc (see the following table)
  4. Add shortcodes for the checkout form of your new gateway:
    • to the shortcode init function initShortcodes() in contentpluginscart66modelsCart66.php, register the checkout shortcode itself like checkout_xxxgatewayxxx
    • to the shortcode manager class contentpluginscart66modelsCart66ShortcodeManager.php, add the shortcode callback xxxgatewayxxxCheckout()
    • to the actual checkout page (via the WP dashboard) on your checkout page, add/replace the default gateway checkout shortcode with your new shortcode checkout_xxxgatewayxxx
    • also allow the new gateway type by adding your gateway class name to the $supportedGateways array in contentpluginscart66viewscheckout.php

Please note that in step 1, I chose to simply add the gateway to the Authorize.net section of the Cart66 options, instead of creating a whole new section (like PayPal vs. Auth.net), as the parameters ended up being very similar. This means you only need to add the gateway URL (http://epaysecure1.transfirst.com/elink/authpd.asp) to the select-list (in /content/plugins/cart66/admin/settings.php), and processing is handled by Cart66.

The meat of the change, obviously, comes in your custom gateway class. Download the sourcecode for the custom class (attached).

I’ve added some additional methods not present in the original gateway abstract to help with processing and validation:

Method/PropertyInherited From Abstract?Description

$field_string, $fields, $response, etc
Yes, unchangedinternal storage for gateway parameters

$_amountFieldKey, $_possibleFields, $_requiredFields, etc
Nohelper lists of potential fields – for validation, and in the case of TransFirst to keep track of everything

gatewayResponseDescription
NoTranslates the gateway response code value (for TransFirst)

__construct
Yes +Modified constructor – add default fields and initialize the _possibleFields, etc.

getCreditCardTypes
Yes, unchangedjust lists the available card types

addField
Yeshelper method to add fields to internal storage

Added validation to check if key is in _possibleFields


initCheckout
Yes +Gets the payment and billing details, then sets up the checkout properties.
Added $mapFields loop to set up variables

parseResponse
NoProcess the string response into meaningful sections, and return transaction success or failure (with reason)

doSale
YesHandles the curl (remote-request) to the actual payment gateway after building the post-string from the user submission.

Minor changes here – mostly remapping the different fields


getResponseReasonText, getTransactionId, etc
Yes, unchangedhelper methods for retrieving stuff

Update: I’ve since found out about the built-in WordPress remote-request function wp_remote_post. I haven’t updated the source file, but any use of curl should be replaced with this function.

Update 2: Added the gateway URL per commenter request.

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

Are there differences in application architecture that are important for the cloud?
It is important to build applications and workloads specifically for the cloud. You will want to carefully consider what services the cloud provider of your choice has to offer and how your application leverages those services.
Learn More about Are there differences in application architecture that are important for the cloud?
Are there any drawbacks to cloud hosting?
Yes, there will always be some risks associated with any hosting option. You are relying on the resiliency and engineering of infrastructure that has scaled at an astounding rate.
Learn More about Are there any drawbacks to cloud hosting?
What’s the benefit of hosting in the cloud vs. traditional options?
Reasons not to host in the cloud are few and far between. If you don't host in the cloud, you will spend more in both CapEx and OpEx to manage your applications or websites in a traditional environment.
Learn More about What’s the benefit of hosting in the cloud vs. traditional options?
How can I improve the performance of my application?
There are several primary reasons that applications perform poorly, and in some cases it’s a combination of several. 1) Data latency: If your application is making calls to a data source (whether it’s an API or a direct call) and there is latency at the data provider, your application performance will suffer.
Learn More about How can I improve the performance of my application?
Should I move my application to the cloud?
The answer is ‘probably yes’. There aren’t many reasons for an application to be hosted elsewhere, aside from occasional compliance standards, or requirements to integrate with local services that would require large amounts of data to move from on-premise to cloud.
Learn More about Should I move my application to the cloud?
Where should my application be hosted?

There are many different options for hosting, but most applications would do well with one of the cloud providers -- Amazon Web Services, Google Cloud Platform, Microsoft Azure.

Learn More about Where should my application be hosted?