1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
* |
17
|
|
|
* PHP version 5 |
18
|
|
|
* |
19
|
|
|
* @category Payone |
20
|
|
|
* @package Payone_Magento2_Plugin |
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
22
|
|
|
* @copyright 2003 - 2016 Payone GmbH |
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
24
|
|
|
* @link http://www.payone.de |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace Payone\Core\Model\Methods; |
28
|
|
|
|
29
|
|
|
use Payone\Core\Model\PayoneConfig; |
30
|
|
|
use Magento\Sales\Model\Order; |
31
|
|
|
use Magento\Framework\DataObject; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Model for safe invoice payment method |
35
|
|
|
*/ |
36
|
|
|
class SafeInvoice extends PayoneMethod |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Payment method code |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $_code = PayoneConfig::METHOD_SAFE_INVOICE; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Clearingtype for PAYONE authorization request |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $sClearingtype = 'rec'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Return parameters specific to this payment type |
54
|
|
|
* |
55
|
|
|
* @param Order $oOrder |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function getPaymentSpecificParameters(Order $oOrder) |
59
|
|
|
{ |
60
|
|
|
$aParams = ['clearingsubtype' => 'POV']; |
61
|
|
|
|
62
|
|
|
$sDob = $this->getInfoInstance()->getAdditionalInformation('dob'); |
63
|
|
|
if ($sDob) { |
64
|
|
|
$aParams['birthday'] = $sDob; |
65
|
|
|
} |
66
|
|
|
return $aParams; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns formatted birthday if possible |
71
|
|
|
* |
72
|
|
|
* @param DataObject $data |
73
|
|
|
* @return string|false |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
protected function getFormattedBirthday(DataObject $data) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$sFormattedDob = false; |
78
|
|
|
|
79
|
|
|
$sBirthday = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthday'); |
80
|
|
|
$sBirthmonth = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthmonth'); |
81
|
|
|
$sBirthyear = $this->toolkitHelper->getAdditionalDataEntry($data, 'birthyear'); |
82
|
|
|
if ($sBirthday && $sBirthmonth && $sBirthyear) { |
|
|
|
|
83
|
|
|
$sDob = $sBirthyear.'-'.$sBirthmonth.'-'.$sBirthday; |
84
|
|
|
$iDobTime = strtotime($sDob); |
85
|
|
|
if ($iDobTime !== false) { |
86
|
|
|
$sFormattedDob = date('Ymd', $iDobTime); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
return $sFormattedDob; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Add the checkout-form-data to the checkout session |
94
|
|
|
* |
95
|
|
|
* @param DataObject $data |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
|
|
public function assignData(DataObject $data) |
99
|
|
|
{ |
100
|
|
|
parent::assignData($data); |
101
|
|
|
|
102
|
|
|
$sFormattedDob = $this->getFormattedBirthday($data); |
103
|
|
|
if ($sFormattedDob !== false) { |
104
|
|
|
$oInfoInstance = $this->getInfoInstance(); |
105
|
|
|
$oInfoInstance->setAdditionalInformation('dob', $sFormattedDob); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.