/
PaymentPaymill.php
117 lines (69 loc) · 3.47 KB
/
PaymentPaymill.php
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
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
class PaymentPaymill extends IsotopePayment {
public function checkoutForm() {
error_reporting(E_ALL);
$this->import('Isotope');
$objOrder = new IsotopeOrder();
if (!$objOrder->findBy('cart_id', $this->Isotope->Cart->id))
$this->redirect($this->addToUrl('step=failed', true));
$strCountryId = strtoupper($this->Isotope->Cart->billingAddress->country);
$objTemplate = new FrontendTemplate("iso_payment_paymill");
$objTemplate->action = $this->Environment->base . $this->Environment->request;
$objTemplate->paymill_public_key = $this->paymill_public_key;
return $objTemplate->parse();
}
public function processPayment() {
$objOrder = new IsotopeOrder();
if (!$objOrder->findBy('cart_id', $this->Isotope->Cart->id))
return false;
if ($objOrder->date_paid > 0 && $objOrder->date_paid <= time()) {
IsotopeFrontend::clearTimeout();
return true;
}
if (IsotopeFrontend::setTimeout()) {
global $objPage;
$objPage->noSearch = 1;
$objPage->cache = 0;
$objTemplate = new FrontendTemplate('mod_message');
$objTemplate->type = 'processing';
$objTemplate->message = $GLOBALS['TL_LANG']['MSC']['payment_processing'];
return $objTemplate->parse();
}
$this->log('Payment could not be processed.', __METHOD__, TL_ERROR);
$this->redirect($this->addToUrl('step=failed', true));
}
public function processPostSale() {
$intOrderId = $this->Input->get("paymillToken");
if ($token = $_POST['paymillToken']) {
require(TL_ROOT . '/system/modules/isotope_paymill/paymill/Transactions.php');
$transactionsObject = new Services_Paymill_Transactions($this->paymill_private_key, 'https://api.paymill.com/v2/');
$params = array(
'amount' => '15', // E.g. "15" for 0.15 EUR!
'currency' => 'EUR', // ISO 4217
'token' => $token,
'description' => 'Test Transaction'
);
$transaction = $transactionsObject->create($params);
}
if ($transaction['id']) {
$this->log("Order " . $intOrderId . " successfully payed (hashes match).", "PaymentPaymill processPostSale()", TL_GENERAL);
$this->Database->prepare("UPDATE tl_iso_orders SET date_paid = ? WHERE id = ?")->execute(time(), $intOrderId);
header('HTTP/1.1 200 OK');
exit;
} else {
$this->log('Payment could not be processed.', __METHOD__, TL_ERROR);
$this->redirect($this->addToUrl('step=failed', true));
}
}
public function backendInterface($intOrderId) {
$objOrder = $this->Database->prepare("SELECT date_paid FROM tl_iso_orders WHERE id = ?")->execute($intOrderId);
$objTemplate = new BackendTemplate("be_paymill");
$objTemplate->href = $this->getReferer(true);
$objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['backBT']);
$objTemplate->link = $GLOBALS['TL_LANG']['MSC']['backBT'];
$objTemplate->h2 = sprintf($GLOBALS['TL_LANG']['ISO']['paymillH2'], $intOrderId);
$objTemplate->label = $GLOBALS['TL_LANG']['ISO']['paymillLabel'];
$objTemplate->text = strlen($objOrder->date_paid) ? sprintf($GLOBALS['TL_LANG']['ISO']['paymillText']['done'], $this->parseDate($GLOBALS["TL_CONFIG"]["dateFormat"], $objOrder->date_paid), $this->parseDate($GLOBALS["TL_CONFIG"]["timeFormat"], $objOrder->date_paid)) : $GLOBALS["TL_LANG"]["ISO"]["paymillText"]["open"];
return $objTemplate->parse();
}
}