Actions
Payment Plugins » History » Revision 5
« Previous |
Revision 5/6
(diff)
| Next »
Valérie Isaksen, 07/14/2011 05:20 PM
Payment Plugins¶
Payment plugins are used both in the front-end and the backend. They must be created as classes deriving from the base class vmPaymentPlugin:
class plgVmPayment<myPlugin> extends vmPaymentPlugin {
function plgVmPayment<myPlugin>(&$subject, $config) {
$this->_pelement = basename(__FILE__, '.php'); // Required!
$this->_createTable(); // Required, see below
parent::__construct($subject, $config);
}
}
Below is the list with events and a description on what moment they are fired.
- plgVmOnSelectPayment() - This event is fired during the checkout process. It allows the shopper to select one of the available payment methods.
It should display a radio button (name: paym_id) to select the payment method. Other information (like credit card info) might be selected as well, depending on the plugin.
Return:
It must return the HTML code for displaying the form (radio button and optional extra selections).
Parameters: - (VirtueMartCart object) The cart object
- (integer, default 0) ID of an already selected payment method ID, if any
- plgVmOnPaymentSelectCheck() - This event is fired after the payment method has been selected. It can be used to store
additional payment info in the cart.
Return:
Plugins that were not selected must return null, otherwise True of False must be returned indicating Success or Failure.
Parameters: - (VirtueMartCart object) The cart object
- plgVmOnCheckoutCheckPaymentData() - This event is fired during the checkout process. It can be used to validate the payment data as entered by the user.
Return:
Plugins that were not selected must return null, otherwise True of False must be returned indicating Success or Failure.
Parameters:
None
- plgVmOnConfirmedOrderStorePaymentData() - This event is fired after the payment has been processed; it stores the payment method-specific data.
All plugins must reimplement this method.
Return:
If the plugin is NOT actually executed (not the selected payment method), this method must return NULL
If this plugin IS executed, it MUST return the order status code that the order should get. This triggers the stock updates if required
Parameters: - (integer) The ordernumber being processed
- (object) Data from the cart
- (array) Price information for this order
- plgVmOnShowOrderPaymentBE() - This method is fired when showing the order details in the backend. It displays the the payment method-specific data.
All plugins must reimplement this method.
Return:
Null when for payment methods that were not selected, text (HTML) otherwise
Parameters: - (integer) The order ID
- (integer) Payment method used for this order
- plgVmOnCancelPayment() - This event is fired each time the status of an order is changed to Cancelled. It can be used to refund payments, void authorization etc.
When reimplementing this methis, the body must start with this code:$_paymethodID = $this->getPaymentMethodForOrder($_orderID); if (!$this->selectedThisMethod($this->_pelement, $_paymethodID)) { return; }
Parameters:
(integer The order ID
(char) Previous order status
(char) New order status
- plgVmOnShipOrderPayment() - This event is fired when the status of an order is changed to Shipped. It can be used to confirm or capture payments
When reimplementing this methis, the body must start with this code:$_paymethodID = $this->getPaymentMethodForOrder($_orderID); if (!$this->selectedThisMethod($this->_pelement, $_paymethodID)) { return; }
Return:
True on success, False on failure, Null if this plugin was not activated
Parameters: - (integer) Order ID
- plgVmOnPaymentNotification() - This event is fired after Recieving a asynchronous payment Notification. It can be used to store the payment specific data.
Parameters: - (integer ) pelement
- plgVmOnPaymentResponseReceived() - This event is fired after the synchronous payment response has been received
Parameters: - (integer ) pelement
Other helper functions inherited from the base class:
- _ createTable() - This method is used to create and maintain the plugin specific database table(s).
It must be reimplemented by all plugins.
Example:$_scheme = DbScheme::get_instance(); $_scheme->create_scheme('#__vm_order_payment_'.$this->_pelement); $_schemeCols = array( 'id' => array ( 'type' => 'int' ,'length' => 11 ,'auto_inc' => true ,'null' => false ) ,'order_id' => array ( 'type' => 'int' ,'length' => 11 ,'null' => false ) ,'payment_method_id' => array ( 'type' => 'text' ,'null' => false ) ); $_schemeIdx = array( 'idx_order_payment' => array( 'columns' => array ('order_id') ,'primary' => false ,'unique' => false ,'type' => null ) ); $_scheme->define_scheme($_schemeCols); $_scheme->define_index($_schemeIdx); if (!$_scheme->scheme()) { JError::raiseWarning(500, $_scheme->get_db_error()); } $_scheme->reset();
- getPaymentMethodForOrder() - Get the order payment ID for a given order number
Return:
The payment method ID, or -1 when not found
Parameters: - (integer) The order ID
- getThisMethodName() - Get the name of the payment method.
This method can not be reimplemented
Return:
Paymenent method name
Parameters: - (integer) The payment method ID
- selectedThisMethod() - This method checks if the selected payment method matches the current plugin
Return:
True if the calling plugin has the given payment ID, False otherwise.
Parameters: - (string) Element name, taken from the plugin filename
- (integer) The payment method ID
- writePaymentData() - This method writes all payment plugin specific data to the plugin's table
Return:
True if the calling plugin has the given payment ID, False otherwise.
Parameters: - (array) Indexed array in the format 'column_name' => 'value'
- (string) Table name
Back to Plugin system
Updated by Valérie Isaksen over 13 years ago · 5 revisions