Project

General

Profile

Payment Plugins » History » Version 6

Valérie Isaksen, 08/31/2011 12:36 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 6 Valérie Isaksen
* *plgVmOnPaymentNotification()* - This event is fired after receiving a asynchronous payment Notification. It can be used to store the payment specific data.
80 4 Valérie Isaksen
+Parameters:+
81
# (integer ) pelement
82
 
83 6 Valérie Isaksen
* *plgVmOnPaymentResponseReceived()* - This event is fired after the asynchronous payment response has been received
84 4 Valérie Isaksen
+Parameters:+
85
# (integer ) pelement
86
87
88 1 Max Milbers
Other helper functions inherited from the base class:
89
90
* *_ createTable()* - This method is used to create and maintain the plugin specific database table(s).
91
It _must_ be reimplemented by all plugins.
92
+Example:+
93
<pre><code class="php">
94
$_scheme = DbScheme::get_instance();
95
$_scheme->create_scheme('#__vm_order_payment_'.$this->_pelement);
96
$_schemeCols = array(
97
	 'id' => array (
98
			 'type' => 'int'
99
			,'length' => 11
100
			,'auto_inc' => true
101
			,'null' => false
102
	)
103
	,'order_id' => array (
104
			 'type' => 'int'
105
			,'length' => 11
106
			,'null' => false
107
	)
108
	,'payment_method_id' => array (
109
			 'type' => 'text'
110
			,'null' => false
111
	)
112
);
113
$_schemeIdx = array(
114
	 'idx_order_payment' => array(
115
			 'columns' => array ('order_id')
116
			,'primary' => false
117
			,'unique' => false
118
			,'type' => null
119
	)
120
);
121
$_scheme->define_scheme($_schemeCols);
122
$_scheme->define_index($_schemeIdx);
123
if (!$_scheme->scheme()) {
124
	JError::raiseWarning(500, $_scheme->get_db_error());
125
}
126
$_scheme->reset();
127
</code></pre>
128
129
* *getPaymentMethodForOrder()* - Get the order payment ID for a given order number
130
+Return:+
131
The payment method ID, or -1 when not found 
132
+Parameters:+
133
# (integer) The order ID
134
135
* *getThisMethodName()* - Get the name of the payment method.
136
This method can _not_ be reimplemented
137
+Return:+
138
Paymenent method name
139
+Parameters:+
140
# (integer) The payment method ID
141
142
* *selectedThisMethod()* - This method checks if the selected payment method matches the current plugin
143
+Return:+
144
True if the calling plugin has the given payment ID, False otherwise.
145
+Parameters:+
146
# (string) Element name, taken from the plugin filename
147
# (integer) The payment method ID
148
149
* *writePaymentData()* - This method writes all payment plugin specific data to the plugin's table
150
+Return:+
151
True if the calling plugin has the given payment ID, False otherwise.
152
+Parameters:+
153
# (array) Indexed array in the format 'column_name' => 'value'
154
# (string) Table name
155 3 Max Milbers
156
Back to [[Plugin system]]