Project

General

Profile

Payment Plugins » History » Version 4

Valérie Isaksen, 07/14/2011 05:15 PM

1 1 Max Milbers
h1. Payment Plugins
2
3 2 Max Milbers
Payment plugins are used both in the front-end and the backend. They must be created as classes deriving from the base class *vmPaymentPlugin*:
4 1 Max Milbers
5
<pre><code class="php">
6
class plgVmPayment<myPlugin> extends vmPaymentPlugin {
7
	function plgVmPayment<myPlugin>(&$subject, $config) {
8
		$this->_pelement = basename(__FILE__, '.php');	// Required!
9
		$this->_createTable();				// Required, see below
10
		parent::__construct($subject, $config);
11
	}
12
}
13
</code></pre>
14
15
Below is the list with events and a description on what moment they are fired.
16
* *plgVmOnSelectPayment()* - This event is fired during the checkout process. It allows the shopper to select one of the available payment methods.
17
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.
18
+Return:+
19
It must return the HTML code for displaying the form (radio button and optional extra selections).
20
+Parameters:+
21
# (VirtueMartCart object) The cart object 
22
# (integer, default 0) ID of an already selected payment method ID, if any
23
24
* *plgVmOnPaymentSelectCheck()* - This event is fired after the payment method has been selected. It can be used to store
25
additional payment info in the cart.
26
+Return:+
27
Plugins that were not selected must return null, otherwise True of False must be returned indicating Success or Failure.
28
+Parameters:+
29
# (VirtueMartCart object) The cart object 
30
31
32
33
* *plgVmOnCheckoutCheckPaymentData()* - This event is fired during the checkout process. It can be used to validate the payment data as entered by the user.
34
+Return:+
35
Plugins that were not selected must return null, otherwise True of False must be returned indicating Success or Failure.
36
+Parameters:+
37
None
38
39
* *plgVmOnConfirmedOrderStorePaymentData()* - This event is fired after the payment has been processed; it stores the payment method-specific data.
40
All plugins _must_ reimplement this method.
41
+Return:+
42
If the plugin is NOT actually executed (not the selected payment method), this method must return NULL
43
If this plugin IS executed, it MUST return the order status code that the order should get. This triggers the stock updates if required
44
+Parameters:+
45
# (integer) The ordernumber being processed
46
# (object) Data from the cart
47
# (array) Price information for this order
48
	
49
* *plgVmOnShowOrderPaymentBE()* - This method is fired when showing the order details in the backend. It displays the the payment method-specific data.
50
All plugins _must_ reimplement this method.
51
+Return:+
52
Null when for payment methods that were not selected, text (HTML) otherwise
53
+Parameters:+
54
# (integer) The order ID
55
# (integer) Payment method used for this order
56
57
* *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.
58
When reimplementing this methis, the body _must_ start with this code:
59
<pre><code class="php">$_paymethodID = $this->getPaymentMethodForOrder($_orderID);
60
if (!$this->selectedThisMethod($this->_pelement, $_paymethodID)) {
61
	return;
62
}</code></pre>
63
+Parameters:+
64
 (integer The order ID
65
 (char) Previous order status
66
 (char) New order status
67
68
* *plgVmOnShipOrderPayment()* - This event is fired when the status of an order is changed to Shipped. It can be used to confirm or capture payments
69
When reimplementing this methis, the body _must_ start with this code:
70
<pre><code class="php">$_paymethodID = $this->getPaymentMethodForOrder($_orderID);
71
if (!$this->selectedThisMethod($this->_pelement, $_paymethodID)) {
72
	return;
73
}</code></pre>
74
+Return:+
75
True on success, False on failure, Null if this plugin was not activated
76
+Parameters:+
77
# (integer) Order ID
78
79 4 Valérie Isaksen
* *plgVmOnPaymentNotification()* - This event is fired after Recieving a asynchronous payment Notification. It can be used to store the payment  specific data.
80
81
+Parameters:+
82
# (integer ) pelement
83
 
84
* *plgVmOnPaymentResponseReceived()* - This event is fired after the synchronous payment response has been received
85
86
+Parameters:+
87
# (integer ) pelement
88
89
90 1 Max Milbers
Other helper functions inherited from the base class:
91
92
* *_ createTable()* - This method is used to create and maintain the plugin specific database table(s).
93
It _must_ be reimplemented by all plugins.
94
+Example:+
95
<pre><code class="php">
96
$_scheme = DbScheme::get_instance();
97
$_scheme->create_scheme('#__vm_order_payment_'.$this->_pelement);
98
$_schemeCols = array(
99
	 'id' => array (
100
			 'type' => 'int'
101
			,'length' => 11
102
			,'auto_inc' => true
103
			,'null' => false
104
	)
105
	,'order_id' => array (
106
			 'type' => 'int'
107
			,'length' => 11
108
			,'null' => false
109
	)
110
	,'payment_method_id' => array (
111
			 'type' => 'text'
112
			,'null' => false
113
	)
114
);
115
$_schemeIdx = array(
116
	 'idx_order_payment' => array(
117
			 'columns' => array ('order_id')
118
			,'primary' => false
119
			,'unique' => false
120
			,'type' => null
121
	)
122
);
123
$_scheme->define_scheme($_schemeCols);
124
$_scheme->define_index($_schemeIdx);
125
if (!$_scheme->scheme()) {
126
	JError::raiseWarning(500, $_scheme->get_db_error());
127
}
128
$_scheme->reset();
129
</code></pre>
130
131
* *getPaymentMethodForOrder()* - Get the order payment ID for a given order number
132
+Return:+
133
The payment method ID, or -1 when not found 
134
+Parameters:+
135
# (integer) The order ID
136
137
* *getThisMethodName()* - Get the name of the payment method.
138
This method can _not_ be reimplemented
139
+Return:+
140
Paymenent method name
141
+Parameters:+
142
# (integer) The payment method ID
143
144
* *selectedThisMethod()* - This method checks if the selected payment method matches the current plugin
145
+Return:+
146
True if the calling plugin has the given payment ID, False otherwise.
147
+Parameters:+
148
# (string) Element name, taken from the plugin filename
149
# (integer) The payment method ID
150
151
* *writePaymentData()* - This method writes all payment plugin specific data to the plugin's table
152
+Return:+
153
True if the calling plugin has the given payment ID, False otherwise.
154
+Parameters:+
155
# (array) Indexed array in the format 'column_name' => 'value'
156
# (string) Table name
157 3 Max Milbers
158
Back to [[Plugin system]]