Magento is a powerful and open-source ecommerce platform that has gained a lot of popularity and has been the system of choice for many developers and online stores. Magento allows developers to extend the platform with custom payment options to allow them to make requests APIs and payment processing providers of their choice, such as PayTrace, iATS Payments or Stripe, to process their store’s orders. To do this, we will be inheriting and extending multiple classes such as:

  • Mage_Payment_Model_Method_Cc
  • Mage_Core_Helper_Abstract
  • Mage_Core_Controller_Front_Action
  • Mage_Payment_Block_Info
  • Mage_Payment_Block_Form_Ccsave

Most of the configuration work is just knowing what to hook up, so rather than go into detail I’ve provided the XML files and PHP files in this post. To build your own module, simply swap out the words “Acumen” with your project name (or namespace you want to use) and “Pay” with whatever you want to name the extension.

The real work is done in our extending of the Mage_Payment_Model_Method_Cc class inside of the app/code/local/Acumen/Model/Pay.php file. This is used when the order is submitted. You will see the capture and authorize functions, two of the functions called on submission.

Capture is to actually accept the payment for the sale. You will see that inside of that function, we use callApi and pass it the type of “Sale”. We can use that value to determine what API call to make (sale or authorize), or to simply pass it to the API.

Authorize is to check that the payment can be made, but it does not actually process the sale. Similarly to Capture, we pass a type parameter, this time using the string “Authorization”. Again, we can use this to manipulate our API call accordingly.

CallApi is where the request to the API is to be made, using a cURL request or otherwise. If the API successfully completed the authorization or sale, set $approved to true; otherwise, set it to false.

To view the source code, check out my GitHub repository.

If you’re looking for a custom extension for your Magento store or you need help setting up a Magento store and start selling, we can help. Check out our Magento page for more information.