Atlanticbt.com

Search Get in Touch Menu
May 4, 2011

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/Property Inherited From Abstract? Description

$field_string, $fields, $response, etc
Yes, unchanged internal storage for gateway parameters

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

gatewayResponseDescription
No Translates the gateway response code value (for TransFirst)

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

getCreditCardTypes
Yes, unchanged just lists the available card types

addField
Yes helper 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
No Process the string response into meaningful sections, and return transaction success or failure (with reason)

doSale
Yes Handles 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, unchanged helper 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

Partner With Us

Ready for modern web technology and a sharp, user-friendly design? We want to give you exactly that. Contact us to get started.

Contact
  • This field is for validation purposes and should be left unchanged.