A couple of months back I wrote a basic payment module for capturing an order, which allows users to pay over the phone. This was all well and good, but perhaps some additional information needs to go along with this payment method? In my case I needed a BACS payment option, which comes with instructions (such as who to pay!). This module was easy to make because it’s is virtually identical to the check/money order method.
I’m going to miss out a lot of the instructions for creating this module and just pick out the key points, because large parts of it are the same as my last post about this. The files are all available to download here:
DOWNLOAD bacs-payment-module.zip (33KB)
Here are the module files required:
Block/Form/Bacs.phpBlock/Info/Bacs.phpetc/config.xmletc/system.xmlModel/Method/Bacs.phpFrontend files required:
payment/form/bacs.phtmlpayment/info/bacs.phtmlAdmin files required:
Below is an overview of some of the important aspects of some of the files:
We need to add a new field to the form in the configuration which sets up this payment method. In this example I will call it ‘instructions’. This simply gets added to the existing fields in system.xml. I add it as a textarea.
This will result in an admin interface similar to the one below:

The model file has been moved into a ‘Method’ file to properly define it as an extension of the ‘Model_Method’ class.
class Creare_Bacs_Model_Method_Bacs extends Mage_Payment_Model_Method_Abstract{ protected $_code = 'bacs'; protected $_formBlockType = 'bacs/form_bacs'; protected $_infoBlockType = 'bacs/info_bacs'; protected $_isInitializeNeeded = true; protected $_canUseInternal = false; protected $_canUseForMultishipping = false; public function assignData($data) { $details = array(); if ($this->getInstructions()) { $details['instructions'] = $this->getInstructions(); } if (!empty($details)) { $this->getInfoInstance()->setAdditionalData(serialize($details)); } return $this; } public function getInstructions() { return $this->getConfigData('instructions'); }}A getInstructions() function will be used to return the user-configured instructions to the Form and Info pages. The final result will mean that the instructions appear when a user select this payment method during checkout. The instructions will also be present on the order email as well as in the admin area.

If you’d like to download the module and contribute any ideas/improvements, please let me know. Thanks for reading the Magento Blog at Ecommerce Web Design.
Adam Moss Author Page
Không có nhận xét nào:
Đăng nhận xét