forked from blazeyo/commerce_platnosci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommerce_platnosci.module
221 lines (196 loc) · 5.99 KB
/
commerce_platnosci.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* Blazej Owczarczyk
* http://drupal.org/user/353861
*
* Name: commerce platnosci
* Description: Drupal commerce platnosci.pl payment method
*/
/**
* Implements hook_menu().
*
* @return array
*/
function commerce_platnosci_menu() {
$items['checkout/update'] = array(
'title' => 'Payment',
'description' => 'Platnosci.pl update page',
'page callback' => 'commerce_platnosci_payment_update',
'page arguments' => array(),
'access arguments' => array('access content'),
'file' => 'commerce_platnosci.pages.inc',
);
return $items;
}
/**
* Implements hook_commerce_payment_method_info().
*
* @return array
*/
function commerce_platnosci_commerce_payment_method_info() {
$payment_methods = array();
$payment_methods['commerce_platnosci'] = array(
'base' => 'commerce_platnosci',
'title' => t('Płatności.pl'),
'short_title' => t('Płatności.pl'),
'description' => t('Płatności.pl offsite payment'),
'terminal' => FALSE,
'offsite' => TRUE,
'active' => TRUE,
);
return $payment_methods;
}
/**
* Payment method's settings form callback.
*
* @return array
*/
function commerce_platnosci_settings_form($settings = NULL) {
$form
['pos_id'] = array(
'#type' => 'textfield',
'#title' => t('POS ID'),
'#default_value' => $settings['pos_id'],
'#description' => t('POS ID assinged by Platności.pl (pos_id)'),);
$form
['pos_auth_key'] = array(
'#type' => 'textfield',
'#title' => t('Payment authorization key (pos_auth_key)'),
'#default_value' => $settings['pos_auth_key'],
'#description' => t('Payment authorization key assinged by Platności.pl (pos_auth_key)'),);
$form
['key1'] = array(
'#type' => 'textfield',
'#title' => t('Primary Key (md5)'),
'#default_value' => $settings['key1'],
'#description' => t('md5 Primary Key generated by Płatności.pl'),);
$form
['key2'] = array(
'#type' => 'textfield',
'#title' => t('Secondary Key (md5)'),
'#default_value' => $settings['key2'],
'#description' => t('md5 Secondary Key generated by Płatności.pl'),);
$form
['desc'] = array(
'#type' => 'textfield',
'#title' => t('Payment description'),
'#default_value' => $settings['desc'],
'#description' => t('md5 Secondary Key generated by Płatności.pl'),);
return $form;
}
/**
* Payment method's checkout pane form.
*/
function commerce_platnosci_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
$form = array();
// Merge in values from the order.
if (!empty($order->data['commerce_platnosci'])) {
$pane_values += $order->data['commerce_platnosci'];
}
// Merge in default values.
$pane_values += array(
'first_name' => '',
'last_name' => '',
'email' => '',
);
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#default_value' => $pane_values['first_name'],
'#required' => TRUE,
);
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#default_value' => $pane_values['last_name'],
'#required' => TRUE,
);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#default_value' => $pane_values['email'],
'#required' => TRUE,
);
return $form;
}
/**
* Payment method's chechout pane submit handler.
*/
function commerce_platnosci_submit_form_submit($payment_method, $pane_form, $pane_values, $order, $charge) {
$order->data['commerce_platnosci'] = $pane_values;
}
/**
* Form with hidden fields needed by gateway. It's submitted to gateway.
*/
function commerce_platnosci_redirect_form($form, &$form_state, $order, $payment_method) {
// Save data in local variables.
$settings = $payment_method['settings'];
$data = $order->data['commerce_platnosci'];
$charge = $order->commerce_order_total[LANGUAGE_NONE][0];
// Create a transaction with status 'pending'.
$trasaction = commerce_payment_create_transaction($payment_method, $order, $charge);
$form['#action'] = 'https://www.platnosci.pl/paygw/UTF/NewPayment';
$form['pos_id'] = array(
'#type' => 'hidden',
'#value' => $settings['pos_id'],);
$form['pos_auth_key'] = array(
'#type' => 'hidden',
'#value' => $settings['pos_auth_key'],);
$form['session_id'] = array(
'#type' => 'hidden',
'#value' => $order->data['payment_redirect_key'],);
$form['order_id'] = array(
'#type' => 'hidden',
'#value' => $order->order_id,);
$form['desc'] = array(
'#type' => 'hidden',
'#value' => $settings['desc'],);
$form['desc2'] = array(
'#type' => 'hidden',
'#value' => $trasaction->transaction_id,);
$form['amount'] = array(
'#type' => 'hidden',
'#value' => $charge['amount'],);
$form['first_name'] = array(
'#type' => 'hidden',
'#value' => $data['first_name'],);
$form['last_name'] = array(
'#type' => 'hidden',
'#value' => $data['last_name'],);
$form['email'] = array(
'#type' => 'hidden',
'#value' => $data['email'],);
$form['client_ip'] = array(
'#type' => 'hidden',
'#value' => ip_address(),);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Proceed to payment'));
return $form;
}
/**
* Check if payment process went ok.
*/
function commerce_platnosci_redirect_form_validate($order, $payment_method) {
if ($_GET['result'] == 'ok') {
drupal_set_message('Payment is being processed');
return true;
} else {
drupal_set_message('Error processing payment', 'error');
return false;
}
}
/**
* Create a pending transaction.
*/
function commerce_payment_create_transaction($payment_method, $order, $charge) {
$account = user_load($order->uid);
$transaction = commerce_payment_transaction_new('commerce_platnosci', $order->order_id);
$transaction->instance_id = $payment_method['instance_id'];
$transaction->amount = $charge['amount'];
$transaction->currency_code = $charge['currency_code'];
$transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
$transaction->message = 'Processing';
commerce_payment_transaction_save($transaction);
return $transaction;
}