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_Ui/js/model/messageList', |
28
|
|
|
'mage/translate' |
29
|
|
|
], |
30
|
|
|
function (Component, messageList, $t) { |
31
|
|
|
'use strict'; |
32
|
|
|
return Component.extend({ |
33
|
|
|
defaults: { |
34
|
|
|
template: 'Payone_Core/payment/debit', |
35
|
|
|
bankCountry: '', |
36
|
|
|
iban: '', |
37
|
|
|
bic: '' |
38
|
|
|
}, |
39
|
|
|
|
40
|
|
|
initObservable: function () { |
41
|
|
|
this._super() |
42
|
|
|
.observe([ |
43
|
|
|
'bankCountry', |
44
|
|
|
'iban', |
45
|
|
|
'bic' |
46
|
|
|
]); |
47
|
|
|
return this; |
48
|
|
|
}, |
49
|
|
|
|
50
|
|
|
validate: function () { |
51
|
|
|
if (document.getElementById(this.getCode() + '_country').value == '') { |
52
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please choose the bank country.')}); |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
if (this.iban() == '') { |
56
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please enter a valid IBAN.')}); |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
if (this.requestBic() == 1 && this.bic() == '') { |
60
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please enter a valid BIC.')}); |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
return true; |
64
|
|
|
}, |
65
|
|
|
|
66
|
|
|
handleBankaccountCheck: function () { |
67
|
|
|
var oBasicRequest = window.checkoutConfig.payment.payone.bankaccountcheckRequest; |
68
|
|
|
oBasicRequest.iban = this.iban(); |
69
|
|
|
if (this.requestBic() == 1) { |
70
|
|
|
oBasicRequest.bic = this.bic(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
window.elvjs = this; |
74
|
|
|
window.processPayoneResponseELV = window.processPayoneResponseELV || function (response) { |
75
|
|
|
window.elvjs.processPayoneResponseELV(response); |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
var options = { |
79
|
|
|
return_type : 'object', |
80
|
|
|
callback_function_name : 'processPayoneResponseELV' |
81
|
|
|
}; |
82
|
|
|
|
83
|
|
|
var request = new PayoneRequest(oBasicRequest, options); |
|
|
|
|
84
|
|
|
request.checkAndStore(); |
85
|
|
|
}, |
86
|
|
|
|
87
|
|
|
/** Returns payment method instructions */ |
88
|
|
|
getInstructions: function () { |
89
|
|
|
return window.checkoutConfig.payment.instructions[this.item.method]; |
90
|
|
|
}, |
91
|
|
|
|
92
|
|
|
getCountries: function () { |
93
|
|
|
return window.checkoutConfig.payment.payone.sepaCountries; |
94
|
|
|
}, |
95
|
|
|
getCleanedNumber: function (sDirtyNumber) { |
96
|
|
|
var sCleanedNumber = ''; |
97
|
|
|
var sTmpChar; |
98
|
|
|
for (var i = 0; i < sDirtyNumber.length; i++) { |
99
|
|
|
sTmpChar = sDirtyNumber.charAt(i); |
100
|
|
|
if (sTmpChar != ' ' && (!isNaN(sTmpChar) || /^[A-Za-z]/.test(sTmpChar))) { |
101
|
|
|
if (/^[a-z]/.test(sTmpChar)) { |
102
|
|
|
sTmpChar = sTmpChar.toUpperCase(); |
103
|
|
|
} |
104
|
|
|
sCleanedNumber = sCleanedNumber + sTmpChar; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
return sCleanedNumber; |
108
|
|
|
}, |
109
|
|
|
|
110
|
|
|
getData: function () { |
111
|
|
|
document.getElementById(this.getCode() + '_iban').value = this.getCleanedNumber(this.iban()); |
112
|
|
|
if (this.requestBic() == 1) { |
113
|
|
|
document.getElementById(this.getCode() + '_bic').value = this.getCleanedNumber(this.bic()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
var parentReturn = this._super(); |
117
|
|
|
if (parentReturn.additional_data === null) { |
118
|
|
|
parentReturn.additional_data = {}; |
119
|
|
|
} |
120
|
|
|
parentReturn.additional_data.bank_country = this.bankCountry(); |
121
|
|
|
parentReturn.additional_data.iban = this.getCleanedNumber(this.iban()); |
122
|
|
|
parentReturn.additional_data.bic = this.getCleanedNumber(this.bic()); |
123
|
|
|
return parentReturn; |
124
|
|
|
}, |
125
|
|
|
|
126
|
|
|
isManageMandateActive: function () { |
127
|
|
|
return window.checkoutConfig.payment.payone.mandateManagementActive; |
128
|
|
|
}, |
129
|
|
|
requestBic: function () { |
130
|
|
|
return window.checkoutConfig.payment.payone.requestBic; |
131
|
|
|
}, |
132
|
|
|
processPayoneResponseELV: function (response) { |
133
|
|
|
if (response.get('status') === "VALID") { |
134
|
|
|
window.checkoutConfig.payment.payone.bankCodeValidatedAndValid = true; |
135
|
|
|
this.handleSetPaymentInformation('payone/onepage/debit/'); |
136
|
|
|
} else if (true || response.get('status') === "BLOCKED") { |
137
|
|
|
this.messageContainer.addErrorMessage({'message': window.checkoutConfig.payment.payone.blockedMessage}); |
138
|
|
|
} else { |
139
|
|
|
this.messageContainer.addErrorMessage({'message': $t(response.get('customermessage'))}); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
}); |
143
|
|
|
} |
144
|
|
|
); |
145
|
|
|
|
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.