I found out that having payment plugin is almost identical with shipment plugin, so if you want to build the installer you can read my previous post here. i won't cover about installation and detection, instead i will go ahead to configuration and script writing

So.. let's get started !

*) Disclaimer: all method explained here comes from a self learning, i'm not a core virtuemart team and probably there's more efficient way to build virtuemart plugin

By now,  i assumse you already have your plugin installed from my previous post. Right now, i'm build my payment plugin for IPAYMU (one of the best Indonesia Payment Gateway), if you happen to be indonesian, this one is a must !

I named the plugin 'Ipaymu' so my class would be plgVmPaymentIpaymu (remember to follow joomla design pattern.. or you will regret), here's my base code:

<?php
defined ('_JEXEC') or die('Restricted access');

if (!class_exists ('vmPSPlugin')) {
    require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
}
class plgVmPaymentIpaymu extends vmPSPlugin {

}
//no close php tag

Step 1 : Configuration Parameter

With above code, the parameter for plugin configuration will not be safe

Virtuemart Payment Plugin Development

 

Paste this snippet inside class plgVmPaymentIpaymu and parameter can be save (when you test it, you can check on table #_virtuemart_paymentmethods under payment_params field)

function __construct (& $subject, $config) {
		parent::__construct ($subject, $config);
		$varsToPush = $this->getVarsToPush ();
		$this->setConfigParameterable ($this->_configTableFieldName, $varsToPush);

	}


	function plgVmDeclarePluginParamsPayment ($name, $id, &$data) {

		return $this->declarePluginParams ('payment', $name, $id, $data);
	}

	function plgVmSetOnTablePluginParamsPayment ($name, $id, &$table) {

		return $this->setOnTablePluginParams ($name, $id, $table);
	}

 

Step 2 - Create Report table for payment plugin

One of the good practice to virtuemart is the feature to build report table when the plugin triggered. Here's the code

on __construct add 3 table parameter:
$this->tableFields = array_keys ($this->getTableSQLFields ());
$this->_tablepkey = 'id';
$this->_tableId = 'id';


and then add 3 additional function:

    public function getVmPluginCreateTableSQL () {
        return $this->createTableSQL ('Payment Standard Table');
    }

function plgVmOnStoreInstallPaymentPluginTable ($jplugin_id) {
        return $this->onStoreInstallPluginTable ($jplugin_id);
    }

function getTableSQLFields () {
        $SQLfields = array(
                'id'                          => 'int(1) UNSIGNED NOT NULL AUTO_INCREMENT',
                'virtuemart_order_id'         => 'int(1) UNSIGNED',
                'transaction_id'                => 'char(64)',
                'paypal_sid'                => 'char(64)',
                'paypal_trx_id'                => 'char(64)',
                'product'                => 'varchar(255)',
                'quantity'                => 'varchar(255)',
                'merchant'                => 'varchar(255)',
                'buyer'                => 'varchar(255)',
                'total'         => 'decimal(15,5) NOT NULL DEFAULT \'0.00000\'',
                'action'            => 'char(255)',
                'comments'        => 'varchar(255)',
                'referer'          => 'varchar(255)',
                'tax_id'            => 'smallint(1)',
                'paypal_trx_id'                => 'varchar(255)',
                'paypal_invoice_number'                => 'varchar(255)',
                'paypal_currency'                => 'varchar(255)',
                'paypal_trx_total'                => 'varchar(255)',
                'paypal_trx_fee'                => 'varchar(255)',
                'paypal_buyer_email'                => 'varchar(255)',
                'paypal_buyer_status'                => 'varchar(255)',
                'paypal_buyer_name'                => 'varchar(255)'
               
        );

you must adjust fields according to parameter that sent by  payment gateway upon transaction (the above is the example for ipaymu).

here's all my code up to this point:

<?php

defined ('_JEXEC') or die('Restricted access');


if (!class_exists ('vmPSPlugin')) {
	require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
}

class plgVmPaymentIpaymu extends vmPSPlugin {
	public static $_this = FALSE;
	function __construct (& $subject, $config) {
		parent::__construct ($subject, $config);
		$varsToPush = $this->getVarsToPush ();
		$this->setConfigParameterable ($this->_configTableFieldName, $varsToPush);
		
		//NEXT STEP - ADD Report Table if not exist
		$this->tableFields = array_keys ($this->getTableSQLFields ());
		$this->_tablepkey = 'id';
		$this->_tableId = 'id';
	}


	function plgVmDeclarePluginParamsPayment ($name, $id, &$data) {

		return $this->declarePluginParams ('payment', $name, $id, $data);
	}

	function plgVmSetOnTablePluginParamsPayment ($name, $id, &$table) {

		return $this->setOnTablePluginParams ($name, $id, $table);
	}

	/**
	 * Create the table for this plugin if it does not yet exist.
	 *
	 * @author Valérie Isaksen
	 */
	public function getVmPluginCreateTableSQL () {
	
		return $this->createTableSQL ('Ipaymu Payment Table');
	}
	
	/**
	 * Fields to create the payment table
	 *
	 * @return string SQL Fileds
	 */
	function getTableSQLFields () {
		$SQLfields = array(
				'id'                          => 'int(1) UNSIGNED NOT NULL AUTO_INCREMENT',
				'virtuemart_order_id'         => 'int(1) UNSIGNED',
				'transaction_id'                => 'char(64)',
				'paypal_sid'                => 'char(64)',
				'paypal_trx_id'                => 'char(64)',
				'product'                => 'varchar(255)',
				'quantity'                => 'varchar(255)',
				'merchant'                => 'varchar(255)',
				'buyer'                => 'varchar(255)',
				'total'         => 'decimal(15,5) NOT NULL DEFAULT \'0.00000\'',
				'action'            => 'char(255)',
				'comments'        => 'varchar(255)',
				'referer'          => 'varchar(255)',
				'tax_id'            => 'smallint(1)',
				'paypal_trx_id'                => 'varchar(255)',
				'paypal_invoice_number'                => 'varchar(255)',
				'paypal_currency'                => 'varchar(255)',
				'paypal_trx_total'                => 'varchar(255)',
				'paypal_trx_fee'                => 'varchar(255)',
				'paypal_buyer_email'                => 'varchar(255)',
				'paypal_buyer_status'                => 'varchar(255)',
				'paypal_buyer_name'                => 'varchar(255)'
				
		);
	
		return $SQLfields;
	}
	
/**
* Create the table for this plugin if it does not yet exist.
* This functions checks if the called plugin is active one.
* When yes it is calling the standard method to create the tables
*
* @author Valérie Isaksen
*
*/
function plgVmOnStoreInstallPaymentPluginTable ($jplugin_id) {

return $this->onStoreInstallPluginTable ($jplugin_id);
} } //no close php tag

 

That's all for the admin backend. Now let's move to the front end on PART 2  for calculation !