|
1
|
|
|
/** |
|
2
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
|
3
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
4
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
5
|
|
|
* (at your option) any later version. |
|
6
|
|
|
* |
|
7
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
|
8
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10
|
|
|
* GNU Lesser General Public License for more details. |
|
11
|
|
|
* |
|
12
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
13
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
|
14
|
|
|
* |
|
15
|
|
|
* PHP version 5 |
|
16
|
|
|
* |
|
17
|
|
|
* @category Payone |
|
18
|
|
|
* @package Payone_Magento2_Plugin |
|
19
|
|
|
* @author FATCHIP GmbH <[email protected]> |
|
20
|
|
|
* @copyright 2003 - 2016 Payone GmbH |
|
21
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
|
22
|
|
|
* @link http://www.payone.de |
|
23
|
|
|
*/ |
|
24
|
|
|
define( |
|
25
|
|
|
[ |
|
26
|
|
|
'Magento_Checkout/js/view/payment/default', |
|
27
|
|
|
'mage/translate' |
|
28
|
|
|
], |
|
29
|
|
|
function (Component, $t) { |
|
30
|
|
|
'use strict'; |
|
31
|
|
|
return Component.extend({ |
|
32
|
|
|
defaults: { |
|
33
|
|
|
template: 'Payone_Core/payment/safe_invoice', |
|
34
|
|
|
birthday: '', |
|
35
|
|
|
birthmonth: '', |
|
36
|
|
|
birthyear: '' |
|
37
|
|
|
}, |
|
38
|
|
|
initObservable: function () { |
|
39
|
|
|
this._super() |
|
40
|
|
|
.observe([ |
|
41
|
|
|
'birthday', |
|
42
|
|
|
'birthmonth', |
|
43
|
|
|
'birthyear' |
|
44
|
|
|
]); |
|
45
|
|
|
return this; |
|
46
|
|
|
}, |
|
47
|
|
|
requestBirthday: function () { |
|
48
|
|
|
if (window.checkoutConfig.payment.payone.customerHasGivenBirthday == false) { |
|
49
|
|
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
return false; |
|
52
|
|
|
}, |
|
53
|
|
|
isCustomerTooYoung: function () { |
|
54
|
|
|
var sBirthDate = this.birthyear() + "-" + this.birthmonth() + "-" + this.birthday(); |
|
55
|
|
|
var oBirthDate = new Date(sBirthDate); |
|
56
|
|
|
var oMinDate = new Date(new Date().setYear(new Date().getFullYear() - 18)); |
|
57
|
|
|
if(oBirthDate < oMinDate) { |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
return true; |
|
61
|
|
|
}, |
|
62
|
|
|
validate: function () { |
|
63
|
|
|
if (this.isCustomerTooYoung()) { |
|
64
|
|
|
this.messageContainer.addErrorMessage({'message': $t('You have to be at least 18 years old to use this payment type!')}); |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
return true; |
|
68
|
|
|
}, |
|
69
|
|
|
getData: function () { |
|
70
|
|
|
var parentReturn = this._super(); |
|
71
|
|
|
if (parentReturn.additional_data === null) { |
|
72
|
|
|
parentReturn.additional_data = {}; |
|
73
|
|
|
} |
|
74
|
|
|
parentReturn.additional_data.birthday = this.birthday(); |
|
75
|
|
|
parentReturn.additional_data.birthmonth = this.birthmonth(); |
|
76
|
|
|
parentReturn.additional_data.birthyear = this.birthyear(); |
|
77
|
|
|
return parentReturn; |
|
78
|
|
|
}, |
|
79
|
|
|
/** Returns payment method instructions */ |
|
80
|
|
|
getInstructions: function () { |
|
81
|
|
|
return window.checkoutConfig.payment.instructions[this.item.method]; |
|
82
|
|
|
} |
|
83
|
|
|
}); |
|
84
|
|
|
} |
|
85
|
|
|
); |
|
86
|
|
|
|