1'use strict'; 2 3var Ajax = require('./ajax.js'); 4var CardInfo = require('/js/libs/card-info.min.js'); 5//var payment = require('/const/payment'); 6//var checkout = YandexCheckout(payment.yandex.shop_id); 7 8CardInfo.setDefaultOptions({ 9 banksLogosPath: '/img/banks/banks-logos/', 10 brandsLogosPath: '/img/banks/brands-logos/' 11}); 12 13 14var $card = $('#bank-card'); 15var $bankLink = $card.find('.bank-link'); 16var $brandLogo = $card.find('.brand-logo'); 17var $number = $card.find('.card-number'); 18var $code = $card.find('.card-code'); 19var $mm = $('#mm'); 20var $yy = $('#yy'); 21 22$mm.mask('##'); 23$yy.mask('##'); 24 25 26$number.on('keyup change paste', function () { 27 var cardInfo = new CardInfo($number.val()); 28 if (cardInfo.bankUrl) { 29 $bankLink 30 .attr('href', cardInfo.bankUrl) 31 .css('backgroundImage', 'url("' + cardInfo.bankLogo + '")') 32 .show(); 33 } else { 34 $bankLink.hide(); 35 } 36 37 $card.css('background', cardInfo.backgroundGradient).css('color', cardInfo.textColor); 38 39 $code.attr('placeholder', cardInfo.codeName ? cardInfo.codeName : ''); 40 $number.mask(cardInfo.numberMask); 41 if (cardInfo.brandLogo) { 42 $brandLogo 43 .attr('src', cardInfo.brandLogo) 44 .attr('alt', cardInfo.brandName) 45 .show(); 46 } else { 47 $brandLogo.hide(); 48 } 49}).trigger('keyup'); 50 51/* 52$card.find('input').blur(validateCard); 53 54function validateCard() { 55 var res = checkout.validate({ 56 number: $number.val().replace(/ /g, ''), 57 cvc: $code.val(), 58 month: $mm.val(), 59 year: $yy.val() 60 }); 61 62 if (res.status !== 'success') { 63 showCardErrors(res); 64 } else { 65 $card.find('input.error').removeClass('error'); 66 } 67} 68 69function showCardErrors(err, error_for_empty) { 70 $card.find('input.error').removeClass('error'); 71 72 err.error.params.forEach(function(v) { 73 var $el = null; 74 switch(v.code) { 75 case 'invalid_number': 76 $el = $number; 77 break; 78 79 case 'invalid_cvc': 80 $el = $code; 81 break; 82 83 case 'invalid_expiry_month': 84 $el = $mm; 85 break; 86 87 case 'invalid_expiry_year': 88 $el = $yy; 89 break; 90 } 91 92 if (!$el) { 93 return; 94 } 95 96 if ((!$el.val().trim()) && (!error_for_empty)) { 97 return 98 } 99 100 $el.addClass('error'); 101 $el.parent().find('.error-tip div').text(v.message); 102 }); 103} 104*/ 105 106 107function pay(url, params) { 108 Ajax.postJSON(url, params, function(data) { 109 if (data.response) { 110 data = data.response; 111 112 if (data.redirect) { 113 window.location.href = data.redirect; 114 return; 115 } 116 117 if (typeof paymentHandler[data.status] === 'function') { 118 paymentHandler[data.status](data); 119 } else { 120 // ÐоÑемÑ-Ñо Ð½ÐµÑ Ð¾Ð±ÑабоÑÑика... 121 console.log(data); 122 $('body').removeClass('show-loader2'); 123 } 124 } else if (data.error) { 125 if (typeof paymentHandler[data.error.code] === 'function') { 126 paymentHandler[data.error.code](data.error); 127 } else { 128 // ÐоÑемÑ-Ñо Ð½ÐµÑ Ð¾Ð±ÑабоÑÑика... 129 console.error(data); 130 $('body').removeClass('show-loader2'); 131 if (data.error && data.error.raw && data.error.raw.message) { 132 alert(data.error.raw.message); 133 } 134 } 135 } 136 }); 137} 138 139 140function showFlushError(text) { 141 $('#card-error').show().find('div').text(text); 142} 143 144var paymentHandler = { 145 pending: function(data) { 146 if (data.confirmation) { 147 if (data.confirmation.type === 'redirect') { 148 window.location.href = data.confirmation.confirmation_url; 149 return; 150 } 151 152 if (data.confirmation.type === 'external') { 153 showFlushError(I18n.t('error.validator.client.card.actions_in_external_system')); 154 $('body').removeClass('show-loader2'); 155 return; 156 } 157 } 158 159 $('body').removeClass('show-loader2'); 160 }, 161 162 canceled: function(data) { 163 $('body').removeClass('show-loader2'); 164 165 if (!data.cancellation_details) { 166 // ÐепонÑÑно поÑÐµÐ¼Ñ 167 showFlushError(I18n.t('error.validator.client.card.pay_blocked')); 168 return; 169 } 170 171 var reason = data.cancellation_details.reason; 172 switch(reason) { 173 case 'invalid_card_number': $number.addClass('error').parent().find('.error-tip div').text(I18n.t('error.validator.client.card.invalid_card_number')); break; 174 case 'invalid_csc': $code.addClass('error').parent().find('.error-tip div').text(I18n.t('error.validator.client.card.invalid_csc')); break; 175 176 case 'call_issuer': showFlushError(I18n.t('error.validator.client.card.call_issuer')); break; 177 case 'card_expired': showFlushError(I18n.t('error.validator.client.card.card_expired')); break; 178 case 'country_forbidden': showFlushError(I18n.t('error.validator.client.card.country_forbidden')); break; 179 case 'fraud_suspected': showFlushError(I18n.t('error.validator.client.card.fraud_suspected')); break; 180 case 'general_decline': showFlushError(I18n.t('error.validator.client.card.general_decline')); break; 181 case 'identification_required': showFlushError(I18n.t('error.validator.client.card.identification_required')); break; 182 case 'insufficient_funds': showFlushError(I18n.t('error.validator.client.card.insufficient_funds')); break; 183 case 'issuer_unavailable': showFlushError(I18n.t('error.validator.client.card.issuer_unavailable')); break; 184 case 'payment_method_limit_exceeded': showFlushError(I18n.t('error.validator.client.card.payment_method_limit_exceeded')); break; 185 case 'payment_method_restricted': showFlushError(I18n.t('error.validator.client.card.payment_method_restricted')); break; 186 case 'insufficient_funds_on_balance': showFlushError(I18n.t('error.validator.client.card.insufficient_funds_on_balance')); break; 187 188 default: showFlushError(I18n.t('error.validator.client.card.general_decline')); break; 189 } 190 191 }, 192 193 stripe_redirect_to_checkout: function(data) { 194 if (typeof Stripe !== 'function') { 195 // ÐоÑемÑ-Ñо Ð½ÐµÑ Ð±Ð¸Ð±Ð»Ð¸Ð¾Ñеки... 196 console.error('typeof stripe = ', typeof stripe); 197 $('body').removeClass('show-loader2'); 198 return; 199 } 200 201 var stripe = Stripe(data.public_key); 202
203 stripe.redirectToCheckout({ 204 sessionId: data.session_id 205 }).then(function(result) { 206 console.log(result); 207 }); 208 }, 209 210 internal_server_error: function(data) { 211 $('body').removeClass('show-loader2'); 212 213 showFlushError(I18n.t('error.validator.client.card.pay_blocked') + '[' + data.message + ']'); 214 return; 215 }, 216 217 500: function(data) { 218 $('body').removeClass('show-loader2'); 219 220 showFlushError(I18n.t('error.validator.client.card.pay_blocked') + '[' + (data.data || data.message) + ']'); 221 return; 222 }, 223 224 403: function(data) { 225 $('body').removeClass('show-loader2'); 226 227 showFlushError(data.message + ': ' + data.data); 228 return; 229 }, 230 231 404: function(data) { 232 $('body').removeClass('show-loader2'); 233 234 showFlushError(data.message + ': ' + data.data); 235 return; 236 } 237}; 238 239/* 240function getToken(callback) { 241 checkout.tokenize({ 242 number: $number.val().replace(/ /g, ''), 243 cvc: $code.val(), 244 month: $mm.val(), 245 year: $yy.val() 246 }).then(function(res) { 247 if (res.status === 'success') { 248 callback({token: res.data.response.paymentToken}); 249 } else { 250 $('body').removeClass('show-loader2'); 251 showCardErrors(res, true); 252 } 253 }); 254} 255*/ 256 257module.exports = { 258 //getToken: getToken, 259 pay: pay 260};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.