@@ -13,6 +13,8 @@ define(
13
13
'mage/translate'
14
14
] ,
15
15
function ( _ , Component , creditCardData , cardNumberValidator , $t ) {
16
+ 'use strict' ;
17
+
16
18
return Component . extend ( {
17
19
defaults : {
18
20
creditCardType : '' ,
@@ -39,26 +41,33 @@ define(
39
41
'creditCardSsIssue' ,
40
42
'selectedCardType'
41
43
] ) ;
44
+
42
45
return this ;
43
46
} ,
44
47
45
- initialize : function ( ) {
48
+ /**
49
+ * Init component
50
+ */
51
+ initialize : function ( ) {
46
52
var self = this ;
53
+
47
54
this . _super ( ) ;
48
55
49
56
//Set credit card number to credit card data object
50
- this . creditCardNumber . subscribe ( function ( value ) {
57
+ this . creditCardNumber . subscribe ( function ( value ) {
51
58
var result ;
59
+
52
60
self . selectedCardType ( null ) ;
53
61
54
- if ( value == '' || value == null ) {
62
+ if ( value === '' || value = == null ) {
55
63
return false ;
56
64
}
57
65
result = cardNumberValidator ( value ) ;
58
66
59
67
if ( ! result . isPotentiallyValid && ! result . isValid ) {
60
68
return false ;
61
69
}
70
+
62
71
if ( result . card !== null ) {
63
72
self . selectedCardType ( result . card . type ) ;
64
73
creditCardData . creditCard = result . card ;
@@ -71,25 +80,34 @@ define(
71
80
} ) ;
72
81
73
82
//Set expiration year to credit card data object
74
- this . creditCardExpYear . subscribe ( function ( value ) {
83
+ this . creditCardExpYear . subscribe ( function ( value ) {
75
84
creditCardData . expirationYear = value ;
76
85
} ) ;
77
86
78
87
//Set expiration month to credit card data object
79
- this . creditCardExpMonth . subscribe ( function ( value ) {
80
- creditCardData . expirationYear = value ;
88
+ this . creditCardExpMonth . subscribe ( function ( value ) {
89
+ creditCardData . expirationMonth = value ;
81
90
} ) ;
82
91
83
92
//Set cvv code to credit card data object
84
- this . creditCardVerificationNumber . subscribe ( function ( value ) {
93
+ this . creditCardVerificationNumber . subscribe ( function ( value ) {
85
94
creditCardData . cvvCode = value ;
86
95
} ) ;
87
96
} ,
88
97
89
- getCode : function ( ) {
98
+ /**
99
+ * Get code
100
+ * @returns {String }
101
+ */
102
+ getCode : function ( ) {
90
103
return 'cc' ;
91
104
} ,
92
- getData : function ( ) {
105
+
106
+ /**
107
+ * Get data
108
+ * @returns {Object }
109
+ */
110
+ getData : function ( ) {
93
111
return {
94
112
'method' : this . item . method ,
95
113
'additional_data' : {
@@ -104,89 +122,185 @@ define(
104
122
}
105
123
} ;
106
124
} ,
107
- getCcAvailableTypes : function ( ) {
125
+
126
+ /**
127
+ * Get list of available credit card types
128
+ * @returns {Object }
129
+ */
130
+ getCcAvailableTypes : function ( ) {
108
131
return window . checkoutConfig . payment . ccform . availableTypes [ this . getCode ( ) ] ;
109
132
} ,
133
+
134
+ /**
135
+ * Get payment icons
136
+ * @param {String } type
137
+ * @returns {Boolean }
138
+ */
110
139
getIcons : function ( type ) {
111
- return window . checkoutConfig . payment . ccform . icons . hasOwnProperty ( type )
112
- ? window . checkoutConfig . payment . ccform . icons [ type ]
113
- : false
140
+ return window . checkoutConfig . payment . ccform . icons . hasOwnProperty ( type ) ?
141
+ window . checkoutConfig . payment . ccform . icons [ type ]
142
+ : false ;
114
143
} ,
115
- getCcMonths : function ( ) {
144
+
145
+ /**
146
+ * Get list of months
147
+ * @returns {Object }
148
+ */
149
+ getCcMonths : function ( ) {
116
150
return window . checkoutConfig . payment . ccform . months [ this . getCode ( ) ] ;
117
151
} ,
118
- getCcYears : function ( ) {
152
+
153
+ /**
154
+ * Get list of years
155
+ * @returns {Object }
156
+ */
157
+ getCcYears : function ( ) {
119
158
return window . checkoutConfig . payment . ccform . years [ this . getCode ( ) ] ;
120
159
} ,
121
- hasVerification : function ( ) {
160
+
161
+ /**
162
+ * Check if current payment has verification
163
+ * @returns {Boolean }
164
+ */
165
+ hasVerification : function ( ) {
122
166
return window . checkoutConfig . payment . ccform . hasVerification [ this . getCode ( ) ] ;
123
167
} ,
124
- hasSsCardType : function ( ) {
168
+
169
+ /**
170
+ * @deprecated
171
+ * @returns {Boolean }
172
+ */
173
+ hasSsCardType : function ( ) {
125
174
return window . checkoutConfig . payment . ccform . hasSsCardType [ this . getCode ( ) ] ;
126
175
} ,
127
- getCvvImageUrl : function ( ) {
176
+
177
+ /**
178
+ * Get image url for CVV
179
+ * @returns {String }
180
+ */
181
+ getCvvImageUrl : function ( ) {
128
182
return window . checkoutConfig . payment . ccform . cvvImageUrl [ this . getCode ( ) ] ;
129
183
} ,
130
- getCvvImageHtml : function ( ) {
131
- return '<img src="' + this . getCvvImageUrl ( )
132
- + '" alt="' + $t ( 'Card Verification Number Visual Reference' )
133
- + '" title="' + $t ( 'Card Verification Number Visual Reference' )
134
- + '" />' ;
184
+
185
+ /**
186
+ * Get image for CVV
187
+ * @returns {String }
188
+ */
189
+ getCvvImageHtml : function ( ) {
190
+ return '<img src="' + this . getCvvImageUrl ( ) +
191
+ '" alt="' + $t ( 'Card Verification Number Visual Reference' ) +
192
+ '" title="' + $t ( 'Card Verification Number Visual Reference' ) +
193
+ '" />' ;
135
194
} ,
136
- getSsStartYears : function ( ) {
195
+
196
+ /**
197
+ * @deprecated
198
+ * @returns {Object }
199
+ */
200
+ getSsStartYears : function ( ) {
137
201
return window . checkoutConfig . payment . ccform . ssStartYears [ this . getCode ( ) ] ;
138
202
} ,
139
- getCcAvailableTypesValues : function ( ) {
140
- return _ . map ( this . getCcAvailableTypes ( ) , function ( value , key ) {
203
+
204
+ /**
205
+ * Get list of available credit card types values
206
+ * @returns {Object }
207
+ */
208
+ getCcAvailableTypesValues : function ( ) {
209
+ return _ . map ( this . getCcAvailableTypes ( ) , function ( value , key ) {
141
210
return {
142
211
'value' : key ,
143
212
'type' : value
144
- }
213
+ } ;
145
214
} ) ;
146
215
} ,
147
- getCcMonthsValues : function ( ) {
148
- return _ . map ( this . getCcMonths ( ) , function ( value , key ) {
216
+
217
+ /**
218
+ * Get list of available month values
219
+ * @returns {Object }
220
+ */
221
+ getCcMonthsValues : function ( ) {
222
+ return _ . map ( this . getCcMonths ( ) , function ( value , key ) {
149
223
return {
150
224
'value' : key ,
151
225
'month' : value
152
- }
226
+ } ;
153
227
} ) ;
154
228
} ,
155
- getCcYearsValues : function ( ) {
156
- return _ . map ( this . getCcYears ( ) , function ( value , key ) {
229
+
230
+ /**
231
+ * Get list of available year values
232
+ * @returns {Object }
233
+ */
234
+ getCcYearsValues : function ( ) {
235
+ return _ . map ( this . getCcYears ( ) , function ( value , key ) {
157
236
return {
158
237
'value' : key ,
159
238
'year' : value
160
- }
239
+ } ;
161
240
} ) ;
162
241
} ,
163
- getSsStartYearsValues : function ( ) {
164
- return _ . map ( this . getSsStartYears ( ) , function ( value , key ) {
242
+
243
+ /**
244
+ * @deprecated
245
+ * @returns {Object }
246
+ */
247
+ getSsStartYearsValues : function ( ) {
248
+ return _ . map ( this . getSsStartYears ( ) , function ( value , key ) {
165
249
return {
166
250
'value' : key ,
167
251
'year' : value
168
- }
252
+ } ;
169
253
} ) ;
170
254
} ,
171
- isShowLegend : function ( ) {
255
+
256
+ /**
257
+ * Is legend available to display
258
+ * @returns {Boolean }
259
+ */
260
+ isShowLegend : function ( ) {
172
261
return false ;
173
262
} ,
174
- getCcTypeTitleByCode : function ( code ) {
175
- var title = '' ;
263
+
264
+ /**
265
+ * Get available credit card type by code
266
+ * @param {String } code
267
+ * @returns {String }
268
+ */
269
+ getCcTypeTitleByCode : function ( code ) {
270
+ var title = '' ,
271
+ keyValue = 'value' ,
272
+ keyType = 'type' ;
273
+
176
274
_ . each ( this . getCcAvailableTypesValues ( ) , function ( value ) {
177
- if ( value [ 'value' ] == code ) {
178
- title = value [ 'type' ] ;
275
+ if ( value [ keyValue ] = == code ) {
276
+ title = value [ keyType ] ;
179
277
}
180
278
} ) ;
279
+
181
280
return title ;
182
281
} ,
183
- formatDisplayCcNumber : function ( number ) {
282
+
283
+ /**
284
+ * Prepare credit card number to output
285
+ * @param {String } number
286
+ * @returns {String }
287
+ */
288
+ formatDisplayCcNumber : function ( number ) {
184
289
return 'xxxx-' + number . substr ( - 4 ) ;
185
290
} ,
186
- getInfo : function ( ) {
291
+
292
+ /**
293
+ * Get credit card details
294
+ * @returns {Array }
295
+ */
296
+ getInfo : function ( ) {
187
297
return [
188
- { 'name' : 'Credit Card Type' , value : this . getCcTypeTitleByCode ( this . creditCardType ( ) ) } ,
189
- { 'name' : 'Credit Card Number' , value : this . formatDisplayCcNumber ( this . creditCardNumber ( ) ) }
298
+ {
299
+ 'name' : 'Credit Card Type' , value : this . getCcTypeTitleByCode ( this . creditCardType ( ) )
300
+ } ,
301
+ {
302
+ 'name' : 'Credit Card Number' , value : this . formatDisplayCcNumber ( this . creditCardNumber ( ) )
303
+ }
190
304
] ;
191
305
}
192
306
} ) ;
0 commit comments