Newer
Older
* Estonian Banks payment gateway for MoneySuite
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
*/
require_once('inc/ms_ep.admin.inc');
require_once('inc/ms_ep.banklink.inc');
require_once('inc/ms_ep.nordea.inc');
/**
* Implements hook_ms_core_payment_gateway().
*/
function ms_ep_ms_core_payment_gateway() {
$methods = array(
'seb' => t('SEB Estonia'),
'swedbank' => t('Swedbank Estonia'),
'sampo' => t('Sampo Estonia'),
'nordea' => t('Nordea Estonia'),
);
$gateways = array();
foreach ($methods as $method => $name) {
$gateways['ms_ep_' . $method] = array(
'name' => $name,
'display_name' => $name,
'description' => ms_ep_get_icon($method) . '<br />' . t('Payment method for @name bank.', array('@name' => $name)),
'module' => 'ms_ep_' . $method,
'display_title' => ms_ep_get_icon($method),
'settings' => call_user_func('ms_ep_' . $method . '_admin'),
'checkout_form' => 'ms_ep_' . $method . '_redirect_form',
'return_callback' => 'ms_ep_return',
);
}
return $gateways;
}
/**
* Handles the return callback and entering a payment into the system.
*/
function ms_ep_return(MsOrder $order) {
if (isset($_POST['VK_SERVICE'])) {
if ($_POST['VK_SERVICE'] == 1101) {
$key_test = ms_ep_banklink_verify_signature($_POST, $order);
}
}
if (isset($_GET['SOLOPMT_RETURN_STAMP'])) {
if ($_GET['SOLOPMT_RETURN_VERSION'] == 0003) {
$nordea_test = ms_ep_banklink_verify_nordea_signature($_GET, $order);
}
}
if (isset($_POST['VK_AMOUNT']) && isset($_POST['VK_CURRENCY'])) {
// Check that the currency and amount match the order.
if (!ms_core_valid_payment($order, 'cart', $_POST['VK_AMOUNT']) || $_POST['VK_CURRENCY'] != $order->currency) {
drupal_set_message(t('There was an error with the payment. Please contact the site administrator.'), 'error');
ms_core_log_error('ms_ep', 'Possible spoofing attempt. Price mismatch. Ignoring IPN. Order: !order IPN: !ipn',
array('!order' => ms_core_print_r($order), '!ipn' => ms_core_print_r($_POST)));
return FALSE;
}
}
// Test bank signature if results are not empty then create payment.
$payment = ms_core_new_payment($order->oid, $order->gateway, 'cart', $order->amount, $order->currency);
if (isset($key_test)) {
$payment->transaction = $_POST['VK_T_NO'];
}
if (isset($nordea_test)) {
$payment->transaction = $_GET['SOLOPMT_RETURN_STAMP'];
}
if (!isset($key_test) && !isset($nordea_test)) {
$payment->amount = 0;
$payment->type = 'failed';
ms_core_enter_payment($payment);
drupal_set_message(t("Payment cancelled."), 'error');
return FALSE;
}
if ($existing_payment = ms_core_load_payment_by_transaction_id($payment->transaction)) {
drupal_set_message(t("This payment has already been acted on."), 'error');
ms_core_log_error("ms_ep", "Duplicate transaction data received and ignored: Details: !details",
array('!details' => ms_core_print_r($_POST)));
return FALSE;
}
ms_core_enter_payment($payment);
return TRUE;
}
/**
* Load icons for cart pages.
*/
function ms_ep_get_icon($bank_name) {
$src = base_path() . drupal_get_path('module', 'ms_ep') . "/images/$bank_name.gif";
$name = $bank_name;
return <<<html
<img style="vertical-align: middle" src="$src" alt="$name" />
html;
}