spree_core 2.0.13 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/base_controller.rb +3 -0
  3. data/app/helpers/spree/base_helper.rb +6 -16
  4. data/app/helpers/spree/products_helper.rb +3 -8
  5. data/app/helpers/spree/taxons_helper.rb +1 -1
  6. data/app/mailers/spree/base_mailer.rb +0 -5
  7. data/app/models/spree/ability.rb +10 -7
  8. data/app/models/spree/address.rb +7 -17
  9. data/app/models/spree/adjustment.rb +15 -11
  10. data/app/models/spree/app_configuration.rb +0 -5
  11. data/app/models/spree/billing_integration.rb +0 -1
  12. data/app/models/spree/calculator/flat_percent_item_total.rb +1 -3
  13. data/app/models/spree/calculator/flat_rate.rb +2 -4
  14. data/app/models/spree/calculator/flexi_rate.rb +6 -9
  15. data/app/models/spree/calculator/per_item.rb +2 -4
  16. data/app/models/spree/calculator/percent_per_item.rb +1 -3
  17. data/app/models/spree/calculator/price_sack.rb +4 -9
  18. data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +1 -2
  19. data/app/models/spree/calculator/shipping/flat_rate.rb +2 -4
  20. data/app/models/spree/calculator/shipping/flexi_rate.rb +4 -9
  21. data/app/models/spree/calculator/shipping/per_item.rb +2 -3
  22. data/app/models/spree/calculator/shipping/price_sack.rb +4 -9
  23. data/app/models/spree/classification.rb +0 -3
  24. data/app/models/spree/country.rb +1 -3
  25. data/app/models/spree/credit_card.rb +37 -38
  26. data/app/models/spree/gateway/bogus_simple.rb +0 -8
  27. data/app/models/spree/gateway.rb +1 -3
  28. data/app/models/spree/image.rb +1 -3
  29. data/app/models/spree/inventory_unit.rb +5 -8
  30. data/app/models/spree/legacy_user.rb +0 -4
  31. data/app/models/spree/line_item.rb +2 -15
  32. data/app/models/spree/option_type.rb +2 -5
  33. data/app/models/spree/option_value.rb +1 -3
  34. data/app/models/spree/order/checkout.rb +4 -13
  35. data/app/models/spree/order.rb +47 -99
  36. data/app/models/spree/order_contents.rb +4 -7
  37. data/app/models/spree/order_inventory.rb +4 -8
  38. data/app/models/spree/order_updater.rb +13 -12
  39. data/app/models/spree/payment/processing.rb +12 -19
  40. data/app/models/spree/payment.rb +17 -30
  41. data/app/models/spree/payment_method.rb +2 -3
  42. data/app/models/spree/preference.rb +1 -1
  43. data/app/models/spree/preferences/configuration.rb +1 -1
  44. data/app/models/spree/preferences/preferable.rb +1 -1
  45. data/app/models/spree/preferences/store.rb +1 -1
  46. data/app/models/spree/price.rb +0 -7
  47. data/app/models/spree/product/scopes.rb +16 -17
  48. data/app/models/spree/product.rb +27 -62
  49. data/app/models/spree/product_property.rb +3 -5
  50. data/app/models/spree/promotion/actions/create_adjustment.rb +9 -8
  51. data/app/models/spree/promotion/actions/create_line_items.rb +1 -2
  52. data/app/models/spree/promotion/rules/first_order.rb +1 -1
  53. data/app/models/spree/promotion/rules/item_total.rb +2 -4
  54. data/app/models/spree/promotion/rules/product.rb +2 -2
  55. data/app/models/spree/promotion/rules/user.rb +1 -3
  56. data/app/models/spree/promotion.rb +23 -24
  57. data/app/models/spree/promotion_action.rb +0 -2
  58. data/app/models/spree/promotion_action_line_item.rb +1 -3
  59. data/app/models/spree/promotion_rule.rb +0 -2
  60. data/app/models/spree/property.rb +2 -4
  61. data/app/models/spree/prototype.rb +0 -2
  62. data/app/models/spree/return_authorization.rb +6 -9
  63. data/app/models/spree/role.rb +0 -2
  64. data/app/models/spree/shipment.rb +19 -25
  65. data/app/models/spree/shipping_calculator.rb +0 -2
  66. data/app/models/spree/shipping_category.rb +0 -2
  67. data/app/models/spree/shipping_method.rb +6 -20
  68. data/app/models/spree/shipping_rate.rb +12 -10
  69. data/app/models/spree/state.rb +2 -4
  70. data/app/models/spree/stock/availability_validator.rb +2 -2
  71. data/app/models/spree/stock/estimator.rb +6 -20
  72. data/app/models/spree/stock/packer.rb +1 -1
  73. data/app/models/spree/stock/quantifier.rb +2 -3
  74. data/app/models/spree/stock/splitter/base.rb +1 -1
  75. data/app/models/spree/stock_item.rb +8 -18
  76. data/app/models/spree/stock_location.rb +2 -11
  77. data/app/models/spree/stock_movement.rb +2 -5
  78. data/app/models/spree/stock_transfer.rb +0 -2
  79. data/app/models/spree/tax_category.rb +0 -2
  80. data/app/models/spree/tax_rate.rb +12 -12
  81. data/app/models/spree/taxon.rb +1 -13
  82. data/app/models/spree/taxonomy.rb +3 -6
  83. data/app/models/spree/tracker.rb +0 -2
  84. data/app/models/spree/variant/scopes.rb +2 -2
  85. data/app/models/spree/variant.rb +13 -31
  86. data/app/models/spree/zone.rb +2 -7
  87. data/app/models/spree/zone_member.rb +0 -2
  88. data/app/views/spree/payments/_payment.html.erb +1 -3
  89. data/config/locales/en.yml +11 -26
  90. data/db/default/spree/countries.rb +230 -229
  91. data/db/default/spree/states.rb +57 -56
  92. data/db/default/spree/zones.rb +5 -5
  93. data/db/migrate/20130213191427_create_default_stock.rb +4 -7
  94. data/db/migrate/20130417120035_update_adjustment_states.rb +2 -2
  95. data/db/migrate/20130417123427_add_shipping_rates_to_shipments.rb +1 -1
  96. data/db/migrate/20130509115210_add_number_to_stock_transfer.rb +1 -1
  97. data/db/migrate/20130611054351_rename_shipping_methods_zones_to_spree_shipping_methods_zones.rb +0 -5
  98. data/db/migrate/20130611185927_add_user_id_index_to_spree_orders.rb +5 -0
  99. data/db/migrate/20130618041418_add_updated_at_to_spree_countries.rb +9 -0
  100. data/db/migrate/20130619012236_add_updated_at_to_spree_states.rb +9 -0
  101. data/db/migrate/20130802022321_migrate_tax_categories_to_line_items.rb +4 -5
  102. data/db/migrate/20130806145853_set_default_stock_location_on_shipments.rb +1 -1
  103. data/lib/generators/spree/dummy/dummy_generator.rb +3 -14
  104. data/lib/generators/spree/dummy/templates/rails/database.yml +0 -10
  105. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -7
  106. data/lib/generators/spree/install/install_generator.rb +11 -8
  107. data/lib/spree/core/calculated_adjustments.rb +9 -8
  108. data/lib/spree/core/controller_helpers/auth.rb +2 -3
  109. data/lib/spree/core/controller_helpers/order.rb +8 -13
  110. data/lib/spree/core/controller_helpers/ssl.rb +13 -22
  111. data/lib/spree/core/controller_helpers/strong_parameters.rb +36 -0
  112. data/lib/spree/core/delegate_belongs_to.rb +0 -2
  113. data/lib/spree/core/engine.rb +1 -5
  114. data/lib/spree/core/ext/active_record.rb +2 -9
  115. data/lib/spree/core/permalinks.rb +1 -5
  116. data/lib/spree/core/product_duplicator.rb +2 -16
  117. data/lib/spree/core/product_filters.rb +37 -33
  118. data/lib/spree/core/search/base.rb +1 -1
  119. data/lib/spree/core/version.rb +1 -1
  120. data/lib/spree/core.rb +3 -31
  121. data/lib/spree/i18n.rb +0 -1
  122. data/lib/spree/money.rb +2 -177
  123. data/lib/spree/permitted_attributes.rb +95 -0
  124. data/lib/spree/promo/coupon_applicator.rb +4 -12
  125. data/lib/spree/testing_support/capybara_ext.rb +13 -17
  126. data/lib/spree/testing_support/common_rake.rb +1 -1
  127. data/lib/spree/testing_support/controller_requests.rb +3 -3
  128. data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -1
  129. data/lib/spree/testing_support/factories/product_factory.rb +0 -4
  130. data/lib/spree/testing_support/factories/shipping_method_factory.rb +1 -3
  131. data/lib/spree/testing_support/factories/user_factory.rb +1 -1
  132. data/lib/spree/testing_support/factories/variant_factory.rb +0 -15
  133. data/lib/spree/testing_support/factories.rb +1 -1
  134. data/lib/spree/testing_support/order_walkthrough.rb +1 -1
  135. data/lib/tasks/core.rake +2 -2
  136. data/vendor/assets/javascripts/jquery.payment.js +497 -0
  137. metadata +166 -172
  138. data/app/views/spree/admin/shared/_report_order_criteria.html.erb +0 -17
  139. data/db/migrate/20130417120034_add_index_to_source_columns_on_adjustments.rb +0 -5
  140. data/db/migrate/20130830001033_add_shipping_category_to_shipping_methods_and_products.rb +0 -15
  141. data/db/migrate/20130830001159_migrate_old_shipping_calculators.rb +0 -19
  142. data/db/migrate/20130909115621_change_states_required_for_countries.rb +0 -9
  143. data/db/migrate/20131001013410_remove_unused_credit_card_fields.rb +0 -12
  144. data/db/migrate/20131026154747_add_track_inventory_to_variant.rb +0 -5
  145. data/db/migrate/20131113035136_add_channel_to_spree_orders.rb +0 -5
  146. data/db/migrate/20140120160805_add_index_to_variant_id_and_currency_on_prices.rb +0 -5
  147. data/db/migrate/20140205181631_default_variant_weight_to_zero.rb +0 -11
  148. data/db/migrate/20140415041315_add_user_id_created_by_id_index_to_order.rb +0 -5
  149. data/lib/spree/core/preference_rescue.rb +0 -25
@@ -0,0 +1,497 @@
1
+ // Generated by CoffeeScript 1.4.0
2
+ (function() {
3
+ var $, cardFromNumber, cardFromType, cards, defaultFormat, formatBackCardNumber, formatBackExpiry, formatCardNumber, formatExpiry, formatForwardExpiry, formatForwardSlash, hasTextSelected, luhnCheck, reFormatCardNumber, restrictCVC, restrictCardNumber, restrictExpiry, restrictNumeric, setCardType,
4
+ __slice = [].slice,
5
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
6
+ _this = this;
7
+
8
+ $ = jQuery;
9
+
10
+ $.payment = {};
11
+
12
+ $.payment.fn = {};
13
+
14
+ $.fn.payment = function() {
15
+ var args, method;
16
+ method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
17
+ return $.payment.fn[method].apply(this, args);
18
+ };
19
+
20
+ defaultFormat = /(\d{1,4})/g;
21
+
22
+ cards = [
23
+ {
24
+ type: 'maestro',
25
+ pattern: /^(5018|5020|5038|6304|6759|676[1-3])/,
26
+ format: defaultFormat,
27
+ length: [12, 13, 14, 15, 16, 17, 18, 19],
28
+ cvcLength: [3],
29
+ luhn: true
30
+ }, {
31
+ type: 'dinersclub',
32
+ pattern: /^(36|38|30[0-5])/,
33
+ format: defaultFormat,
34
+ length: [14],
35
+ cvcLength: [3],
36
+ luhn: true
37
+ }, {
38
+ type: 'laser',
39
+ pattern: /^(6706|6771|6709)/,
40
+ format: defaultFormat,
41
+ length: [16, 17, 18, 19],
42
+ cvcLength: [3],
43
+ luhn: true
44
+ }, {
45
+ type: 'jcb',
46
+ pattern: /^35/,
47
+ format: defaultFormat,
48
+ length: [16],
49
+ cvcLength: [3],
50
+ luhn: true
51
+ }, {
52
+ type: 'unionpay',
53
+ pattern: /^62/,
54
+ format: defaultFormat,
55
+ length: [16, 17, 18, 19],
56
+ cvcLength: [3],
57
+ luhn: false
58
+ }, {
59
+ type: 'discover',
60
+ pattern: /^(6011|65|64[4-9]|622)/,
61
+ format: defaultFormat,
62
+ length: [16],
63
+ cvcLength: [3],
64
+ luhn: true
65
+ }, {
66
+ type: 'mastercard',
67
+ pattern: /^5[1-5]/,
68
+ format: defaultFormat,
69
+ length: [16],
70
+ cvcLength: [3],
71
+ luhn: true
72
+ }, {
73
+ type: 'amex',
74
+ pattern: /^3[47]/,
75
+ format: /(\d{1,4})(\d{1,6})?(\d{1,5})?/,
76
+ length: [15],
77
+ cvcLength: [3, 4],
78
+ luhn: true
79
+ }, {
80
+ type: 'visa',
81
+ pattern: /^4/,
82
+ format: defaultFormat,
83
+ length: [13, 14, 15, 16],
84
+ cvcLength: [3],
85
+ luhn: true
86
+ }
87
+ ];
88
+
89
+ cardFromNumber = function(num) {
90
+ var card, _i, _len;
91
+ num = (num + '').replace(/\D/g, '');
92
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
93
+ card = cards[_i];
94
+ if (card.pattern.test(num)) {
95
+ return card;
96
+ }
97
+ }
98
+ };
99
+
100
+ cardFromType = function(type) {
101
+ var card, _i, _len;
102
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
103
+ card = cards[_i];
104
+ if (card.type === type) {
105
+ return card;
106
+ }
107
+ }
108
+ };
109
+
110
+ luhnCheck = function(num) {
111
+ var digit, digits, odd, sum, _i, _len;
112
+ odd = true;
113
+ sum = 0;
114
+ digits = (num + '').split('').reverse();
115
+ for (_i = 0, _len = digits.length; _i < _len; _i++) {
116
+ digit = digits[_i];
117
+ digit = parseInt(digit, 10);
118
+ if ((odd = !odd)) {
119
+ digit *= 2;
120
+ }
121
+ if (digit > 9) {
122
+ digit -= 9;
123
+ }
124
+ sum += digit;
125
+ }
126
+ return sum % 10 === 0;
127
+ };
128
+
129
+ hasTextSelected = function($target) {
130
+ var _ref;
131
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== $target.prop('selectionEnd')) {
132
+ return true;
133
+ }
134
+ if (typeof document !== "undefined" && document !== null ? (_ref = document.selection) != null ? typeof _ref.createRange === "function" ? _ref.createRange().text : void 0 : void 0 : void 0) {
135
+ return true;
136
+ }
137
+ return false;
138
+ };
139
+
140
+ reFormatCardNumber = function(e) {
141
+ var _this = this;
142
+ return setTimeout(function() {
143
+ var $target, value;
144
+ $target = $(e.currentTarget);
145
+ value = $target.val();
146
+ value = $.payment.formatCardNumber(value);
147
+ return $target.val(value);
148
+ });
149
+ };
150
+
151
+ formatCardNumber = function(e) {
152
+ var $target, card, digit, length, re, upperLength, value;
153
+ digit = String.fromCharCode(e.which);
154
+ if (!/^\d+$/.test(digit)) {
155
+ return;
156
+ }
157
+ $target = $(e.currentTarget);
158
+ value = $target.val();
159
+ card = cardFromNumber(value + digit);
160
+ length = (value.replace(/\D/g, '') + digit).length;
161
+ upperLength = 16;
162
+ if (card) {
163
+ upperLength = card.length[card.length.length - 1];
164
+ }
165
+ if (length >= upperLength) {
166
+ return;
167
+ }
168
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
169
+ return;
170
+ }
171
+ if (card && card.type === 'amex') {
172
+ re = /^(\d{4}|\d{4}\s\d{6})$/;
173
+ } else {
174
+ re = /(?:^|\s)(\d{4})$/;
175
+ }
176
+ if (re.test(value)) {
177
+ e.preventDefault();
178
+ return $target.val(value + ' ' + digit);
179
+ } else if (re.test(value + digit)) {
180
+ e.preventDefault();
181
+ return $target.val(value + digit + ' ');
182
+ }
183
+ };
184
+
185
+ formatBackCardNumber = function(e) {
186
+ var $target, value;
187
+ $target = $(e.currentTarget);
188
+ value = $target.val();
189
+ if (e.meta) {
190
+ return;
191
+ }
192
+ if (e.which !== 8) {
193
+ return;
194
+ }
195
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
196
+ return;
197
+ }
198
+ if (/\d\s$/.test(value)) {
199
+ e.preventDefault();
200
+ return $target.val(value.replace(/\d\s$/, ''));
201
+ } else if (/\s\d?$/.test(value)) {
202
+ e.preventDefault();
203
+ return $target.val(value.replace(/\s\d?$/, ''));
204
+ }
205
+ };
206
+
207
+ formatExpiry = function(e) {
208
+ var $target, digit, val;
209
+ digit = String.fromCharCode(e.which);
210
+ if (!/^\d+$/.test(digit)) {
211
+ return;
212
+ }
213
+ $target = $(e.currentTarget);
214
+ val = $target.val() + digit;
215
+ if (/^\d$/.test(val) && (val !== '0' && val !== '1')) {
216
+ e.preventDefault();
217
+ return $target.val("0" + val + " / ");
218
+ } else if (/^\d\d$/.test(val)) {
219
+ e.preventDefault();
220
+ return $target.val("" + val + " / ");
221
+ }
222
+ };
223
+
224
+ formatForwardExpiry = function(e) {
225
+ var $target, digit, val;
226
+ digit = String.fromCharCode(e.which);
227
+ if (!/^\d+$/.test(digit)) {
228
+ return;
229
+ }
230
+ $target = $(e.currentTarget);
231
+ val = $target.val();
232
+ if (/^\d\d$/.test(val)) {
233
+ return $target.val("" + val + " / ");
234
+ }
235
+ };
236
+
237
+ formatForwardSlash = function(e) {
238
+ var $target, slash, val;
239
+ slash = String.fromCharCode(e.which);
240
+ if (slash !== '/') {
241
+ return;
242
+ }
243
+ $target = $(e.currentTarget);
244
+ val = $target.val();
245
+ if (/^\d$/.test(val) && val !== '0') {
246
+ return $target.val("0" + val + " / ");
247
+ }
248
+ };
249
+
250
+ formatBackExpiry = function(e) {
251
+ var $target, value;
252
+ if (e.meta) {
253
+ return;
254
+ }
255
+ $target = $(e.currentTarget);
256
+ value = $target.val();
257
+ if (e.which !== 8) {
258
+ return;
259
+ }
260
+ if (($target.prop('selectionStart') != null) && $target.prop('selectionStart') !== value.length) {
261
+ return;
262
+ }
263
+ if (/\d(\s|\/)+$/.test(value)) {
264
+ e.preventDefault();
265
+ return $target.val(value.replace(/\d(\s|\/)*$/, ''));
266
+ } else if (/\s\/\s?\d?$/.test(value)) {
267
+ e.preventDefault();
268
+ return $target.val(value.replace(/\s\/\s?\d?$/, ''));
269
+ }
270
+ };
271
+
272
+ restrictNumeric = function(e) {
273
+ var input;
274
+ if (e.metaKey || e.ctrlKey) {
275
+ return true;
276
+ }
277
+ if (e.which === 32) {
278
+ return false;
279
+ }
280
+ if (e.which === 0) {
281
+ return true;
282
+ }
283
+ if (e.which < 33) {
284
+ return true;
285
+ }
286
+ input = String.fromCharCode(e.which);
287
+ return !!/[\d\s]/.test(input);
288
+ };
289
+
290
+ restrictCardNumber = function(e) {
291
+ var $target, card, digit, value;
292
+ $target = $(e.currentTarget);
293
+ digit = String.fromCharCode(e.which);
294
+ if (!/^\d+$/.test(digit)) {
295
+ return;
296
+ }
297
+ if (hasTextSelected($target)) {
298
+ return;
299
+ }
300
+ value = ($target.val() + digit).replace(/\D/g, '');
301
+ card = cardFromNumber(value);
302
+ if (card) {
303
+ return value.length <= card.length[card.length.length - 1];
304
+ } else {
305
+ return value.length <= 16;
306
+ }
307
+ };
308
+
309
+ restrictExpiry = function(e) {
310
+ var $target, digit, value;
311
+ $target = $(e.currentTarget);
312
+ digit = String.fromCharCode(e.which);
313
+ if (!/^\d+$/.test(digit)) {
314
+ return;
315
+ }
316
+ if (hasTextSelected($target)) {
317
+ return;
318
+ }
319
+ value = $target.val() + digit;
320
+ value = value.replace(/\D/g, '');
321
+ if (value.length > 6) {
322
+ return false;
323
+ }
324
+ };
325
+
326
+ restrictCVC = function(e) {
327
+ var $target, digit, val;
328
+ $target = $(e.currentTarget);
329
+ digit = String.fromCharCode(e.which);
330
+ if (!/^\d+$/.test(digit)) {
331
+ return;
332
+ }
333
+ val = $target.val() + digit;
334
+ return val.length <= 4;
335
+ };
336
+
337
+ setCardType = function(e) {
338
+ var $target, allTypes, card, cardType, val;
339
+ $target = $(e.currentTarget);
340
+ val = $target.val();
341
+ cardType = $.payment.cardType(val) || 'unknown';
342
+ if (!$target.hasClass(cardType)) {
343
+ allTypes = (function() {
344
+ var _i, _len, _results;
345
+ _results = [];
346
+ for (_i = 0, _len = cards.length; _i < _len; _i++) {
347
+ card = cards[_i];
348
+ _results.push(card.type);
349
+ }
350
+ return _results;
351
+ })();
352
+ $target.removeClass('unknown');
353
+ $target.removeClass(allTypes.join(' '));
354
+ $target.addClass(cardType);
355
+ $target.toggleClass('identified', cardType !== 'unknown');
356
+ return $target.trigger('payment.cardType', cardType);
357
+ }
358
+ };
359
+
360
+ $.payment.fn.formatCardCVC = function() {
361
+ this.payment('restrictNumeric');
362
+ this.on('keypress', restrictCVC);
363
+ return this;
364
+ };
365
+
366
+ $.payment.fn.formatCardExpiry = function() {
367
+ this.payment('restrictNumeric');
368
+ this.on('keypress', restrictExpiry);
369
+ this.on('keypress', formatExpiry);
370
+ this.on('keypress', formatForwardSlash);
371
+ this.on('keypress', formatForwardExpiry);
372
+ this.on('keydown', formatBackExpiry);
373
+ return this;
374
+ };
375
+
376
+ $.payment.fn.formatCardNumber = function() {
377
+ this.payment('restrictNumeric');
378
+ this.on('keypress', restrictCardNumber);
379
+ this.on('keypress', formatCardNumber);
380
+ this.on('keydown', formatBackCardNumber);
381
+ this.on('keyup', setCardType);
382
+ this.on('paste', reFormatCardNumber);
383
+ return this;
384
+ };
385
+
386
+ $.payment.fn.restrictNumeric = function() {
387
+ this.on('keypress', restrictNumeric);
388
+ return this;
389
+ };
390
+
391
+ $.payment.fn.cardExpiryVal = function() {
392
+ return $.payment.cardExpiryVal($(this).val());
393
+ };
394
+
395
+ $.payment.cardExpiryVal = function(value) {
396
+ var month, prefix, year, _ref;
397
+ value = value.replace(/\s/g, '');
398
+ _ref = value.split('/', 2), month = _ref[0], year = _ref[1];
399
+ if ((year != null ? year.length : void 0) === 2 && /^\d+$/.test(year)) {
400
+ prefix = (new Date).getFullYear();
401
+ prefix = prefix.toString().slice(0, 2);
402
+ year = prefix + year;
403
+ }
404
+ month = parseInt(month, 10);
405
+ year = parseInt(year, 10);
406
+ return {
407
+ month: month,
408
+ year: year
409
+ };
410
+ };
411
+
412
+ $.payment.validateCardNumber = function(num) {
413
+ var card, _ref;
414
+ num = (num + '').replace(/\s+|-/g, '');
415
+ if (!/^\d+$/.test(num)) {
416
+ return false;
417
+ }
418
+ card = cardFromNumber(num);
419
+ if (!card) {
420
+ return false;
421
+ }
422
+ return (_ref = num.length, __indexOf.call(card.length, _ref) >= 0) && (card.luhn === false || luhnCheck(num));
423
+ };
424
+
425
+ $.payment.validateCardExpiry = function(month, year) {
426
+ var currentTime, expiry, prefix, _ref;
427
+ if (typeof month === 'object' && 'month' in month) {
428
+ _ref = month, month = _ref.month, year = _ref.year;
429
+ }
430
+ if (!(month && year)) {
431
+ return false;
432
+ }
433
+ month = $.trim(month);
434
+ year = $.trim(year);
435
+ if (!/^\d+$/.test(month)) {
436
+ return false;
437
+ }
438
+ if (!/^\d+$/.test(year)) {
439
+ return false;
440
+ }
441
+ if (!(parseInt(month, 10) <= 12)) {
442
+ return false;
443
+ }
444
+ if (year.length === 2) {
445
+ prefix = (new Date).getFullYear();
446
+ prefix = prefix.toString().slice(0, 2);
447
+ year = prefix + year;
448
+ }
449
+ expiry = new Date(year, month);
450
+ currentTime = new Date;
451
+ expiry.setMonth(expiry.getMonth() - 1);
452
+ expiry.setMonth(expiry.getMonth() + 1, 1);
453
+ return expiry > currentTime;
454
+ };
455
+
456
+ $.payment.validateCardCVC = function(cvc, type) {
457
+ var _ref, _ref1;
458
+ cvc = $.trim(cvc);
459
+ if (!/^\d+$/.test(cvc)) {
460
+ return false;
461
+ }
462
+ if (type) {
463
+ return _ref = cvc.length, __indexOf.call((_ref1 = cardFromType(type)) != null ? _ref1.cvcLength : void 0, _ref) >= 0;
464
+ } else {
465
+ return cvc.length >= 3 && cvc.length <= 4;
466
+ }
467
+ };
468
+
469
+ $.payment.cardType = function(num) {
470
+ var _ref;
471
+ if (!num) {
472
+ return null;
473
+ }
474
+ return ((_ref = cardFromNumber(num)) != null ? _ref.type : void 0) || null;
475
+ };
476
+
477
+ $.payment.formatCardNumber = function(num) {
478
+ var card, groups, upperLength, _ref;
479
+ card = cardFromNumber(num);
480
+ if (!card) {
481
+ return num;
482
+ }
483
+ upperLength = card.length[card.length.length - 1];
484
+ num = num.replace(/\D/g, '');
485
+ num = num.slice(0, +upperLength + 1 || 9e9);
486
+ if (card.format.global) {
487
+ return (_ref = num.match(card.format)) != null ? _ref.join(' ') : void 0;
488
+ } else {
489
+ groups = card.format.exec(num);
490
+ if (groups != null) {
491
+ groups.shift();
492
+ }
493
+ return groups != null ? groups.join(' ') : void 0;
494
+ }
495
+ };
496
+
497
+ }).call(this);