Understanding Flow of VirtueMart Payment Plugin
We will discuss about the methods used in VirtueMart Payment Plugin here. The methods defined below as per their sequence of usage :
plgVmOnStoreInstallPaymentPluginTable
- The very first function required to be defined when we install a VirtueMart Payment plugin.
- It creates the plugin specific database table for your plugin further working.
plgVmSetOnTablePluginParamsPayment
- After plgVmOnStoreInstallPaymentPluginTable function the next required function for the plugin.
- Used for storing values of payment plugins configuration in database table.
getTableSQLFields
- This function is used to define the column names to be added in the payment table creation.
- One can add columns after installation of plugin as well using this function.
plgVmDeclarePluginParamsPaymentVM3
- You can get the saved plugin configuration values by the help of this function’s parameter.
- This function is called whenever you try to update the configuration of the payment plugin.
plgVmOnCheckAutomaticSelectedPayment
- This function is first called when you finally setup the configuration of payment plugin and redirect to the cart view on store.
- In case you have set your payment plugin as the default payment method by VirtueMart’s Configuration, this function is used.
checkConditions
- This function is called After plgVmOnCheckAutomaticSelectedPayment
- Checks if the payment conditions are fulfilled for the payment method.
- If you want to show/hide the payment plugin on some specific conditions then this function is very useful.
Below is simple example of showing the plugin on the basis of total cart amount value :
/**
* [checkConditions function used to check the details before checkout process.]
*
* @param array $cart cart details
* @param object $method method data
* @param object $cart_prices cart prices object
*
* @author Webkul Software Private Limited
* @copyright Copyright (c) 2010-2018 Webkul Software Private Limited (https://webkul.com)
* @license https://store.webkul.com/license.html
*
* @return boolean
*/
protected function checkConditions($cart, $method, $cart_prices)
{
if ($cart_prices['billTotal'] < 50) {
return false;
}
}
plgVmonSelectedCalculatePricePayment
- This function is used to calculate the price of the payment method. Price calculation is done on checkbox selection of payment method at cart view.
- If you forget to add this function in your plugin code, your payment plugin will not be selectable at all on the cart view.
plgVmDisplayListFEPayment
- This is a required function for your payment plugin and called after plgVmonSelectedCalculatePricePayment.
- This function is used to display the payment plugin name on cart view payment option list.
- This function has a parameter $html by the help of which you can add additional view, if required to be shown with payment name.
Now on Proceeding to the Checkout functionality –
plgVmOnSelectCheckPayment
- This function is triggered when the user tries to checkout from the cart view.
- You can use this function to store additional information.
plgVmOnCheckoutCheckDataPayment
- This function is also triggered at the time of checkout but after plgVmOnSelectCheckPayment.
- It can be used to validate the method data entered by the user.
plgVmConfirmedOrder
- This function is triggered when the user click on the Confirm Purchase button on cart view.
- You can store the transaction/order related details using this function.
- You can set your html with a variable name html at the end of this function, to be shown be thank you message.
plgVmOnPaymentResponseReceived
- This function is used If user redirection to the Payment gateway is required.
- You can use this function as redirect URL for the payment gateway and receive response from payment gateway here.
YOUR_SITE/.'index.php?option=com_virtuemart&view=vmplg&task=pluginresponsereceived'
This task pluginresponsereceived calls the function written in your payment plugin.
plgVmOnShowOrderFEPayment
- This function is triggered after plgVmConfirmedOrder, to display the payment related information in order.
Similarly, If you want to add payment related information in back-end Order details as well, then you can use plgVmOnShowOrderBEPayment.
This function is triggered when we view the order details in administrator.