-
Notifications
You must be signed in to change notification settings - Fork 0
/
payone_payment.module
111 lines (99 loc) · 2.84 KB
/
payone_payment.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
<?php
use \Drupal\payone_payment\CreditCardController;
use \Drupal\payone_payment\PaypalECController;
use \Drupal\payone_payment\Statuses;
use \Drupal\payone_payment\Transaction;
/**
* Implements hook_menu().
*/
function payone_payment_menu() {
$items['payone-payment/%payone_payment_return_method/%entity_object/%'] = [
'load arguments' => ['payment'],
'page callback' => 'payone_payment_return',
'page arguments' => [1, 2],
'access callback' => 'payone_payment_return_access',
'access arguments' => [1, 2, 3],
];
return $items;
}
/**
* Menu item load callback: Check if this is a valid return method.
*/
function payone_payment_return_method_load($method) {
if (in_array($method, ['success', 'error', 'back'])) {
return $method;
}
return FALSE; // 404
}
/**
* Access callback: Check the hash signature.
*/
function payone_payment_return_access($method, \Payment $payment, $hash) {
return PaypalECController::sign($method, $payment->pid) === $hash;
}
/**
* Page callback: Return for e-wallet payments.
*/
function payone_payment_return($method, \Payment $payment) {
// Set the appropriate status. The finish callback takes it from there.
switch ($method) {
case 'success':
$payment->setStatus(new \PaymentStatusItem(PAYMENT_STATUS_SUCCESS));
break;
case 'error':
$payment->setStatus(new \PaymentStatusItem(PAYMENT_STATUS_FAILED));
break;
case 'back':
$payment->setStatus(new \PaymentStatusItem(PAYMENT_STATUS_CANCELLED));
break;
}
$payment->finish();
}
/**
* Implements hook_payment_method_controller_info().
*/
function payone_payment_payment_method_controller_info() {
$controllers['payone_payment_credit_card'] = CreditCardController::class;
$controllers['payone_payment_paypal_ec'] = PaypalECController::class;
return $controllers;
}
/**
* Implements hook_payment_status_info().
*/
function payone_payment_payment_status_info() {
return [
new PaymentStatusInfo([
'description' => t('User has been redirected to an external payment page.'),
'status' => Statuses::REDIRECTED,
'parent' => PAYMENT_STATUS_PENDING,
'title' => t('Redirected (waiting for user to return)'),
]),
];
}
/**
* Implements hook_theme().
*/
function payone_payment_theme() {
$items['payone_payment_redirect_info'] = [
'variables' => ['payment' => NULL],
'template' => 'payone-payment-redirect-info',
];
return $items;
}
/**
* Implements hook_payment_delete().
*/
function payone_payment_payment_delete(\Payment $payment) {
$psiids = array_map(function ($s) {
return $s->psiid;
}, $payment->statuses);
Transaction::deleteIds($psiids);
}
/**
* Implements hook_d7csp_hosts().
*/
function payone_payment_d7csp_hosts() {
$hosts['connect-src'][] = 'https://secure.pay1.de';
$hosts['script-src'][] = 'https://secure.pay1.de';
return $hosts;
}