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 —
- Add additional option for your payment gateway to the option list in
- Make a copy of an existing gateway file (such as
- 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)
- Add shortcodes for the checkout form of your new gateway:
- to the shortcode init function
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
- to the shortcode init function
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|
|Yes, unchanged||internal storage for gateway parameters|
|No||helper lists of potential fields – for validation, and in the case of TransFirst to keep track of everything|
|No||Translates the gateway response code value (for TransFirst)|
|Yes +||Modified constructor – add default fields and initialize the _possibleFields, etc.|
|Yes, unchanged||just lists the available card types|
|Yes||helper 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.|
|No||Process the string response into meaningful sections, and return transaction success or failure (with reason)|
|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
|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.