Skip to content

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:, PayPalPro, and PayPal Express. It also has a handy feature where you can add an 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 section of the Cart66 options, instead of creating a whole new section (like PayPal vs., as the parameters ended up being very similar. This means you only need to add the gateway URL ( 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

NoTranslates the gateway response code value (for TransFirst)

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

Yes, unchangedjust lists the available card types

Yeshelper method to add fields to internal storage

Added validation to check if key is in _possibleFields

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

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

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