|
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
|
|
|
'jquery', |
|
27
|
|
|
'Payone_Core/js/view/payment/method-renderer/base', |
|
28
|
|
|
'Magento_Ui/js/model/messageList', |
|
29
|
|
|
'mage/translate', |
|
30
|
|
|
'Payone_Core/js/action/handle-redirect', |
|
31
|
|
|
'Magento_Checkout/js/model/full-screen-loader' |
|
32
|
|
|
], |
|
33
|
|
|
function ($, Component, messageList, $t, handleRedirectAction, fullScreenLoader) { |
|
34
|
|
|
'use strict'; |
|
35
|
|
|
return Component.extend({ |
|
36
|
|
|
defaults: { |
|
37
|
|
|
template: 'Payone_Core/payment/creditcard', |
|
38
|
|
|
firstname: '', |
|
39
|
|
|
lastname: '', |
|
40
|
|
|
pseudocardpan: '' |
|
41
|
|
|
}, |
|
42
|
|
|
|
|
43
|
|
|
initObservable: function () { |
|
44
|
|
|
this._super() |
|
45
|
|
|
.observe([ |
|
46
|
|
|
'firstname', |
|
47
|
|
|
'lastname', |
|
48
|
|
|
'pseudocardpan' |
|
49
|
|
|
]); |
|
50
|
|
|
return this; |
|
51
|
|
|
}, |
|
52
|
|
|
|
|
53
|
|
|
getData: function () { |
|
54
|
|
|
var parentReturn = this._super(); |
|
55
|
|
|
if (parentReturn.additional_data === null) { |
|
56
|
|
|
parentReturn.additional_data = {}; |
|
57
|
|
|
} |
|
58
|
|
|
parentReturn.additional_data.firstname = this.firstname(); |
|
59
|
|
|
parentReturn.additional_data.lastname = this.lastname(); |
|
60
|
|
|
parentReturn.additional_data.pseudocardpan = document.getElementById(this.getCode() + '_pseudocardpan').value; |
|
61
|
|
|
return parentReturn; |
|
62
|
|
|
}, |
|
63
|
|
|
|
|
64
|
|
|
handleIframes: function () { |
|
65
|
|
|
var fieldconfig = window.checkoutConfig.payment.payone.fieldConfig; |
|
66
|
|
|
if (typeof fieldconfig.language != 'undefined') { |
|
67
|
|
|
if (fieldconfig.language == 'de') { |
|
68
|
|
|
fieldconfig.language = Payone.ClientApi.Language.de; |
|
|
|
|
|
|
69
|
|
|
} else if (fieldconfig.language == 'en') { |
|
70
|
|
|
fieldconfig.language = Payone.ClientApi.Language.en; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
window.iframes = new Payone.ClientApi.HostedIFrames(fieldconfig, window.checkoutConfig.payment.payone.hostedRequest); |
|
75
|
|
|
window.iframes.setCardType("V"); |
|
76
|
|
|
|
|
77
|
|
|
var sCardTypeId = this.getCode() + '_credit_card_type'; |
|
78
|
|
|
if (document.getElementById(sCardTypeId)) { |
|
79
|
|
|
document.getElementById(sCardTypeId).onchange = function () { |
|
80
|
|
|
window.iframes.setCardType(this.value); // on change: set new type of credit card to process |
|
81
|
|
|
}; |
|
82
|
|
|
} |
|
83
|
|
|
}, |
|
84
|
|
|
showCvc: function () { |
|
85
|
|
|
return window.checkoutConfig.payment.payone.checkCvc; |
|
86
|
|
|
}, |
|
87
|
|
|
getInstructions: function () { |
|
88
|
|
|
return window.checkoutConfig.payment.instructions[this.item.method]; |
|
89
|
|
|
}, |
|
90
|
|
|
getCreditcardTypes: function () { |
|
91
|
|
|
return window.checkoutConfig.payment.payone.availableCardTypes; |
|
92
|
|
|
}, |
|
93
|
|
|
getHostedParam: function (sParam) { |
|
94
|
|
|
return window.checkoutConfig.payment.payone.hostedParams[sParam]; |
|
95
|
|
|
}, |
|
96
|
|
|
getCcMonths: function () { |
|
97
|
|
|
return window.checkoutConfig.payment.ccform.months[this.getCode()]; |
|
98
|
|
|
}, |
|
99
|
|
|
getCcYears: function () { |
|
100
|
|
|
return window.checkoutConfig.payment.ccform.years[this.getCode()]; |
|
101
|
|
|
}, |
|
102
|
|
|
getCcMonthsValues: function () { |
|
103
|
|
|
return _.map(this.getCcMonths(), function (value, key) { |
|
|
|
|
|
|
104
|
|
|
return { |
|
105
|
|
|
'value': key, |
|
106
|
|
|
'month': value |
|
107
|
|
|
} |
|
108
|
|
|
}); |
|
109
|
|
|
}, |
|
110
|
|
|
getCcYearsValues: function () { |
|
111
|
|
|
return _.map(this.getCcYears(), function (value, key) { |
|
|
|
|
|
|
112
|
|
|
return { |
|
113
|
|
|
'value': key, |
|
114
|
|
|
'year': value |
|
115
|
|
|
}; |
|
116
|
|
|
}); |
|
117
|
|
|
}, |
|
118
|
|
|
|
|
119
|
|
|
validate: function () { |
|
120
|
|
|
if (document.getElementById(this.getCode() + '_credit_card_type').value == '') { |
|
121
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please choose the creditcard type.')}); |
|
122
|
|
|
return false; |
|
123
|
|
|
} |
|
124
|
|
|
if (this.firstname() == '') { |
|
125
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please enter the firstname.')}); |
|
126
|
|
|
return false; |
|
127
|
|
|
} |
|
128
|
|
|
if (this.lastname() == '') { |
|
129
|
|
|
this.messageContainer.addErrorMessage({'message': $t('Please enter the lastname.')}); |
|
130
|
|
|
return false; |
|
131
|
|
|
} |
|
132
|
|
|
return true; |
|
133
|
|
|
}, |
|
134
|
|
|
|
|
135
|
|
|
handleCreditcardCheck: function () { |
|
136
|
|
|
// PayOne Request if the data is valid |
|
137
|
|
|
if (window.iframes.isComplete()) { |
|
138
|
|
|
window.ccjs = this; |
|
139
|
|
|
window.iframes.creditCardCheck('processPayoneResponseCCHosted'); // Perform "CreditCardCheck" to create and get a |
|
140
|
|
|
// PseudoCardPan; then call your function "payCallback" |
|
141
|
|
|
fullScreenLoader.startLoader(); |
|
142
|
|
|
} else { |
|
143
|
|
|
this.messageContainer.addErrorMessage({'message': $t("Please enter complete data.")}); |
|
144
|
|
|
} |
|
145
|
|
|
}, |
|
146
|
|
|
|
|
147
|
|
|
processPayoneResponseCCHosted: function (response) { |
|
148
|
|
|
fullScreenLoader.stopLoader(); |
|
149
|
|
|
if (response.status === "VALID") { |
|
150
|
|
|
if (document.getElementById(this.getCode() + '_pseudocardpan')) { |
|
151
|
|
|
document.getElementById(this.getCode() + '_pseudocardpan').value = response.pseudocardpan; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
this.selectPaymentMethod(); |
|
155
|
|
|
handleRedirectAction(this.getData(), this.messageContainer); |
|
156
|
|
|
} else if (response.status === "INVALID") { |
|
157
|
|
|
this.messageContainer.addErrorMessage({'message': $t(response.errormessage)}); |
|
158
|
|
|
} else if (response.status === "ERROR") { |
|
159
|
|
|
this.messageContainer.addErrorMessage({'message': $t(response.errormessage)}); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
}); |
|
163
|
|
|
|
|
164
|
|
|
} |
|
165
|
|
|
); |
|
166
|
|
|
|
|
167
|
|
|
function processPayoneResponseCCHosted(response) |
|
168
|
|
|
{ |
|
169
|
|
|
window.ccjs.processPayoneResponseCCHosted(response); |
|
170
|
|
|
} |
|
171
|
|
|
|
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.