-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_przelewy24.module
163 lines (136 loc) · 5.17 KB
/
commerce_przelewy24.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
<?php
// $Id: $
/**
* @file
* Implements przelewy24 Payments in Drupal Commerce checkout.
*/
function commerce_przelewy24_menu() {
$items['commerce_przelewy24/verify'] = array(
'title' => 'Callback transaction',
'page callback' => 'commerce_przelewy24_verify',
'page arguments' => array(),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file' => 'commerce_przelewy24.inc',
'file path' => drupal_get_path('module', 'commerce_przelewy24').'/includes',
);
return $items;
}
function commerce_przelewy24_commerce_payment_method_info() {
$payment_methods = array();
$payment_methods['przelewy24'] = array(
'base' => 'commerce_przelewy24',
'title' => t('Przelewy24'),
'short_title' => t('Przelewy24'),
'description' => t('Płać z Przelewy24'),
'terminal' => FALSE,
'offsite' => TRUE,
);
return $payment_methods;
}
function commerce_przelewy24_settings_form($settings = NULL) {
$form = array();
$settings = (array) $settings + array(
'id_sp' => 0,
'crc' => '',
'test' => 0
);
$form['id_sp'] = array(
'#title' => t('ID sprzedawcy'),
'#type' => 'textfield',
'#default_value' => $settings['id_sp'],
'#description' => t('Id sprzedawcy (Moje dane->Dane konta).'),
'#required' => TRUE,
);
$form['crc'] = array(
'#title' => t('Kod CRC'),
'#type' => 'textfield',
'#default_value' => $settings['crc'],
'#description' => t('Wprowadzić z panelu sprzedawcy (Moje dane->Klucz do CRC).'),
'#required' => TRUE,
);
$form['test'] = array(
'#title' => t('Tryb testowy'),
'#type' => 'select',
'#default_value' => $settings['test'],
'#options' => array(
0 => t('Nie'),
1 => t('Tak'),
),
'#description' => t('Tryb testowy dla transakcji. Wymagane konto sandbox w panelu sprzedawcy (Moje dane->Konto w SANDBOX).'),
);
return $form;
}
function commerce_przelewy24_submit_form($payment_method, $pane_values, $checkout_pane, $order) {
if (empty($payment_method['settings']['id_sp']) /*||
empty($payment_method['settings']['ip'])*/ ) {
drupal_set_message(t('przelewy24 is not configured for use.'), 'error');
}
$form = array();
if (!empty($order->data['commerce_payment_przelewy24'])) {
$pane_values += $order->data['commerce_payment_przelewy24'];
}
return $form;
}
function commerce_przelewy24_redirect_form($form, &$form_state, $order, $payment_method) {
if (empty($payment_method['settings']['id_sp']) /*||
empty($payment_method['settings']['ip'])*/ ) {
drupal_set_message(t('przelewy24 is not configured for use.'), 'error');
}
$wrapper = entity_metadata_wrapper('commerce_order', $order);
//$currency_code = $wrapper->commerce_order_total->currency_code->value();
$amount = $wrapper->commerce_order_total->amount->value();
$url_fail="checkout/".$order->order_id."/payment/back/".$order->data['payment_redirect_key'];
$url_ok='commerce_przelewy24/verify';//"checkout/".$order->order_id."/payment/return/".$order->data['payment_redirect_key'];
$i_amount=$amount;
$s_session_id=$order->order_id.'|'.md5(time().'+'.$payment_method['settings']['id_sp']);
$s_crc=md5($s_session_id.'|'.$payment_method['settings']['id_sp']
.'|'.$i_amount.'|'.$payment_method['settings']['crc']);
$data = array(
'p24_session_id' => $s_session_id,
'p24_id_sprzedawcy' => $payment_method['settings']['id_sp'],
'p24_crc' => $s_crc,
'p24_kwota' => $i_amount,
'p24_opis' => t('Zamówienie @order_number w @store', array('@order_number' => $order->order_number, '@store' => variable_get('site_name', url('<front>', array('absolute' => TRUE))))),
'p24_klient' => '',
'p24_adres' => '',
'p24_miasto' => '',
'p24_kod' => '',
'p24_kraj' => '',
'p24_email' => $order->mail,
'p24_return_url_ok' => url($url_ok, array('absolute' => TRUE)),
'p24_return_url_error' => url($url_fail, array('absolute' => TRUE))
);
$params_map = array(
'p24_klient' => 'name_line',
'p24_adres' => 'thoroughfare',
'p24_miasto' => 'locality',
'p24_kod' => 'postal_code',
'p24_kraj' => 'country',
);
foreach ($params_map as $key => $value) {
if (isset($wrapper->commerce_customer_billing->commerce_customer_address->$value)) {
$data[$key] = $wrapper->commerce_customer_billing->commerce_customer_address->$value->value();
}
}
//$data['md5sum'] = md5($payment_method['settings']['id_sp'] . $amount/100 . $order->order_id .':'. $order->data['payment_redirect_key'] . $payment_method['settings']['cod']);
if($payment_method['settings']['test']==0)
{
$form['#action'] = 'https://secure.przelewy24.pl';
}
else
{
$form['#action'] = 'https://sandbox.przelewy24.pl';
unset($data['p24_crc']);
}
foreach ($data as $name => $value) {
if (!empty($value)) {
$form[$name] = array('#type' => 'hidden', '#value' => $value);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Płać przez Przelewy24'),
);
return $form;
}