|
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
|
|
|
'Payone_Core/js/view/payment/method-renderer/base', |
|
27
|
|
|
'Magento_Checkout/js/model/quote', |
|
28
|
|
|
'mage/translate' |
|
29
|
|
|
], |
|
30
|
|
|
function (Component, quote, $t) { |
|
31
|
|
|
'use strict'; |
|
32
|
|
|
return Component.extend({ |
|
33
|
|
|
defaults: { |
|
34
|
|
|
template: 'Payone_Core/payment/klarna', |
|
35
|
|
|
telephone: '', |
|
36
|
|
|
addinfo: '', |
|
37
|
|
|
delAddinfo: '', |
|
38
|
|
|
gender: '', |
|
39
|
|
|
personalId: '', |
|
40
|
|
|
birthday: '', |
|
41
|
|
|
birthmonth: '', |
|
42
|
|
|
birthyear: '', |
|
43
|
|
|
agreement: false |
|
44
|
|
|
}, |
|
45
|
|
|
initObservable: function () { |
|
46
|
|
|
this._super() |
|
47
|
|
|
.observe([ |
|
48
|
|
|
'telephone', |
|
49
|
|
|
'addinfo', |
|
50
|
|
|
'delAddinfo', |
|
51
|
|
|
'gender', |
|
52
|
|
|
'personalId', |
|
53
|
|
|
'birthday', |
|
54
|
|
|
'birthmonth', |
|
55
|
|
|
'birthyear', |
|
56
|
|
|
'agreement' |
|
57
|
|
|
]); |
|
58
|
|
|
return this; |
|
59
|
|
|
}, |
|
60
|
|
|
requestTelephone: function () { |
|
61
|
|
|
if (this.getBillingCountry() !== false && this.getBillingCountry() !== '') { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
return true; |
|
65
|
|
|
}, |
|
66
|
|
|
requestAddressAddInfo: function () { |
|
67
|
|
|
if (this.getBillingCountry() !== false && this.getBillingCountry() !== 'NL') { |
|
68
|
|
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
return true; |
|
71
|
|
|
}, |
|
72
|
|
|
requestDelAddressAddInfo: function () { |
|
73
|
|
|
if (this.getBillingCountry() !== false && this.getBillingCountry() !== 'NL') { |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
return true; |
|
77
|
|
|
}, |
|
78
|
|
|
requestGender: function () { |
|
79
|
|
|
var aTriggerCountries = ['DE', 'NL', 'AT']; |
|
80
|
|
|
if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
|
81
|
|
|
if (window.checkoutConfig.payment.payone.customerHasGivenGender == false) { |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
return false; |
|
86
|
|
|
}, |
|
87
|
|
|
requestPersonalId: function () { |
|
88
|
|
|
var aTriggerCountries = ['DK', 'FI', 'NO', 'SE']; |
|
89
|
|
|
if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
|
90
|
|
|
return true; |
|
91
|
|
|
} |
|
92
|
|
|
return false; |
|
93
|
|
|
}, |
|
94
|
|
|
requestBirthday: function () { |
|
95
|
|
|
var aTriggerCountries = ['DE', 'NL', 'AT']; |
|
96
|
|
|
if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
|
97
|
|
|
if (window.checkoutConfig.payment.payone.customerHasGivenBirthday == false) { |
|
98
|
|
|
return true; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
return false; |
|
102
|
|
|
}, |
|
103
|
|
|
requestAgreement: function () { |
|
104
|
|
|
var aTriggerCountries = ['DE', 'AT']; |
|
105
|
|
|
if (this.getBillingCountry() !== false && aTriggerCountries.indexOf(this.getBillingCountry()) !== -1) { |
|
106
|
|
|
return true; |
|
107
|
|
|
} |
|
108
|
|
|
return false; |
|
109
|
|
|
}, |
|
110
|
|
|
getBillingCountry: function () { |
|
111
|
|
|
if (quote.billingAddress() !== null && typeof quote.billingAddress().countryId !== 'undefined') { |
|
112
|
|
|
return quote.billingAddress().countryId; |
|
113
|
|
|
} |
|
114
|
|
|
return false; |
|
115
|
|
|
}, |
|
116
|
|
|
getData: function () { |
|
117
|
|
|
var parentReturn = this._super(); |
|
118
|
|
|
if (parentReturn.additional_data === null) { |
|
119
|
|
|
parentReturn.additional_data = {}; |
|
120
|
|
|
} |
|
121
|
|
|
parentReturn.additional_data.telephone = this.telephone(); |
|
122
|
|
|
parentReturn.additional_data.addinfo = this.addinfo(); |
|
123
|
|
|
parentReturn.additional_data.del_addinfo = this.delAddinfo(); |
|
124
|
|
|
parentReturn.additional_data.gender = this.gender(); |
|
125
|
|
|
parentReturn.additional_data.personal_id = this.personalId(); |
|
126
|
|
|
parentReturn.additional_data.birthday = this.birthday(); |
|
127
|
|
|
parentReturn.additional_data.birthmonth = this.birthmonth(); |
|
128
|
|
|
parentReturn.additional_data.birthyear = this.birthyear(); |
|
129
|
|
|
return parentReturn; |
|
130
|
|
|
}, |
|
131
|
|
|
getKlarnaStoreId: function () { |
|
132
|
|
|
var storeIds = window.checkoutConfig.payment.payone.klarnaStoreIds; |
|
133
|
|
|
var country = this.getBillingCountry(); |
|
134
|
|
|
if (storeIds.hasOwnProperty(country)) { |
|
135
|
|
|
return storeIds[country]; |
|
136
|
|
|
} |
|
137
|
|
|
return 0; |
|
138
|
|
|
}, |
|
139
|
|
|
getKlarnaUrl: function (sLanguage) { |
|
140
|
|
|
return 'https://cdn.klarna.com/1.0/shared/content/legal/terms/' + this.getKlarnaStoreId() + '/de_' + sLanguage + '/consent'; |
|
141
|
|
|
}, |
|
142
|
|
|
validate: function () { |
|
143
|
|
|
if (this.requestAgreement() === true && this.agreement() === false) { |
|
144
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please confirm the transmission of the necessary data to Klarna!')}); |
|
145
|
|
|
return false; |
|
146
|
|
|
} |
|
147
|
|
|
return true; |
|
148
|
|
|
}, |
|
149
|
|
|
/** Returns payment method instructions */ |
|
150
|
|
|
getInstructions: function () { |
|
151
|
|
|
return window.checkoutConfig.payment.instructions[this.item.method]; |
|
152
|
|
|
}, |
|
153
|
|
|
loadKlarnaTerms: function () { |
|
154
|
|
|
var oElement = document.getElementById('payone_klarna_invoice_terms'); |
|
155
|
|
|
if (oElement.innerHTML.length === 0) { |
|
156
|
|
|
var terms = new Klarna.Terms.Invoice({ |
|
|
|
|
|
|
157
|
|
|
el: oElement, |
|
158
|
|
|
eid: this.getKlarnaStoreId(), // Your merchant ID |
|
159
|
|
|
country: this.getBillingCountry().toLowerCase(), |
|
160
|
|
|
charge: 0 |
|
161
|
|
|
}); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
}); |
|
165
|
|
|
} |
|
166
|
|
|
); |
|
167
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.