Changeset 2881978
- Timestamp:
- 03/17/2023 02:37:26 PM (3 years ago)
- Location:
- safe2pay/trunk
- Files:
-
- 2 added
- 15 edited
-
LICENSE (added)
-
README.md (modified) (1 diff)
-
assets/css/frontend/transparent-checkout.css (modified) (9 diffs)
-
assets/css/frontend/transparent-checkout.min.css (modified) (8 diffs)
-
assets/js/admin/admin.js (modified) (1 diff)
-
assets/js/frontend/transparent-checkout.js (modified) (1 diff)
-
includes/admin/views/html-admin-help-message.php (modified) (1 diff)
-
includes/admin/views/html-admin-page.php (modified) (2 diffs)
-
includes/admin/views/html-notice-currency-not-supported.php (modified) (1 diff)
-
includes/admin/views/html-notice-missing-ecfb.php (modified) (1 diff)
-
includes/class-wc-safe2pay-api.php (modified) (1 diff)
-
includes/class-wc-safe2pay-gateway.php (modified) (10 diffs)
-
includes/class-wc-safe2pay.php (modified) (1 diff)
-
readme.txt (added)
-
templates/emails/html-instructions.php (modified) (2 diffs)
-
templates/emails/plain-instructions.php (modified) (1 diff)
-
woocommerce-safe2pay.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
safe2pay/trunk/README.md
r2165963 r2881978 1 2 # Safe2Pay Woocomerce 1 # WooCommerce Safe2Pay 3 2 4 3  5 4 6 7 5 ## Aceite pagamentos com Safe2Pay 8 6 9 O plugin do Safe2Pay para Woocomerce permite você aceitar pagamentos via boleto bancário, cartão de crédito, débito e bitcoin diretamente na sua loja online, com rapidez, facilidade e com checkout 100% transparente. 7 O plugin do Safe2Pay para WooCommerce permite você aceitar pagamentos via boleto bancário, cartão de crédito e 8 bitcoin diretamente na sua loja online, com rapidez, facilidade e com checkout 100% transparente. 10 9 11 Transações de pagamento online devem ser rápidas e simples, sem asteriscos ou letras miúdas. É isso que o Safe2Pay proporciona. Feito para todos os modelos de negócios, nossas soluções ajudam a gerenciar pagamentos e recebíveis.12 10 Transações de pagamento online devem ser rápidas e simples, sem asteriscos ou letras miúdas. É isso que o Safe2Pay 11 proporciona. Feito para todos os modelos de negócios, nossas soluções ajudam a gerenciar pagamentos e recebíveis. 13 12 14 13 ## Instalação e configuração 15 14 16 1. Faça o download do plugin no nosso repositório do Github ou na [loja do Wordpress](https://wordpress.org/plugins/safe2pay/)15 1. Faça o download do plugin no nosso repositório do Github. 17 16 2. Após isso, faça login no painel do WordPress, navegue até o menu Plugins e clique em **Adicionar novo**. 18 17 3. Em seguida faça o upload do arquivo e clique em **Instalar agora**. 19 18 4. Após instalar e ativar o plug-in, clique em **configurações** no plugin. 20 5. Insira o seu **Token** e **Secret Key**, você pode consulta-los em https://admin.safe2pay.com.br/configuracao no menu **Integração**. Em seguida clique em salvar. 19 5. Insira o seu **Token** e **Secret Key**, você pode consulta-los em https://admin.safe2pay.com.br/configuracao na 20 menu **Integração**. Em seguida clique em salvar. 21 21 22 ## Uma experiência rápida,fácil e segura22 ## Uma experiência rápida,fácil e segura 23 23 24 Quando os clientes usam o Safe2Pay estão contando com uma solução completa em pagamentos e 100% segura. O Safe2Pay possui anti-fraude permitindo que suas transações sejam sempre monitoradas ajudando a minimizar riscos e perdas por fraude, simplificando o processo de validação de transações. 24 Quando os clientes usam o Safe2Pay estão contando com uma solução completa em pagamentos e 100% segura. O Safe2Pay 25 possui anti-fraude permitindo que suas transações sejam sempre monitoradas ajudando a minimizar riscos e perdas por 26 fraude, simplificando o processo de validação de transações. 25 27 26 ## Checkout transparente28 ## Checkout transparente 27 29 28 Os clientes não necessitam sair da loja para finalizar a compra, ignorando formulários on-line, concluindo a operação de forma simples e com alguns cliques, ajudando a aumentar sua conversão de vendas e reduzir o abandono do carrinho de compras. 30 Os clientes não necessitam sair da loja para finalizar a compra, ignorando formulários on-line, concluindo a operação de 31 forma simples e com alguns cliques, ajudando a aumentar sua conversão de vendas e reduzir o abandono do carrinho de 32 compras. 29 33 30 ## Formas de pagamento disponíveis 31 - **Boleto Bancário** 32 - **Cartão de Crédito** 33 - **Cartão de Débito** 34 - **Bitcoin** 34 ## Formas de pagamento disponíveis 35 36 - **Boleto Bancário** 37 - **Pix** 38 - **Cartão de Crédito** 39 - **Criptomoedas** 35 40 36 41 ## Requisitos 42 37 43 - PHP versão 5.6 ou superior. 38 - WooCommerce versão 2.6.x ou superior. 44 - WooCommerce versão 3.0.x ou superior. 45 - 46 Plugin [Brazilian Market on WooCommerce](https://br.wordpress.org/plugins/woocommerce-extra-checkout-fields-for-brazil/) 47 . 39 48 - Ter uma conta no Safe2Pay: [Clique aqui](https://safe2pay.com.br/) 49 50 ## Marketplace 51 52 - Suporte inicial ao plugin multivendedor Dokan 53 - É necessário ter uma conta de perfil Marketplace e habilitar a compatibilidade nas configurações do plugin do 54 Safe2Pay. 55 - 56 Plugin [Brazilian Market on WooCommerce](https://br.wordpress.org/plugins/woocommerce-extra-checkout-fields-for-brazil/) 57 . 58 - O split utilizará os números de documento informados para os vendedores na realização do split 59 - Momentaneamente o suporte será apenas para comissão em percentual. 40 60 41 61 ## Informações adicionais / Contato 42 62 43 Em caso de dúvidas, ficamos à disposição em nossos canais ou diretamente pelo e-mail integracao@safe2pay.com.br. 63 Em caso de dúvidas, ficamos à disposição em nossos canais ou diretamente pelo e-mail integracao@safe2pay.com.br. 44 64 45 Para mais informações acesse: [https://safe2pay.com.br/](https://safe2pay.com.br/)65 Para mais informações acesse: https://safe2pay.com.br -
safe2pay/trunk/assets/css/frontend/transparent-checkout.css
r2165731 r2881978 30 30 } 31 31 32 /* Payment methods */33 32 .woocommerce #payment ul.payment_methods li #safe2pay-payment-methods li, 34 33 .woocommerce-page #payment ul.payment_methods li #safe2pay-payment-methods li { … … 59 58 } 60 59 61 /* Bank transfer items */62 60 .woocommerce #payment ul.payment_methods li #safe2pay-payment-methods li.active, 63 61 .woocommerce-page #payment ul.payment_methods li #safe2pay-payment-methods li.active { … … 149 147 } 150 148 151 /* Banking ticket */152 149 #safe2pay-icon-ticket { 153 150 background: transparent url(../../images/imgBarcode.png) no-repeat; … … 160 157 } 161 158 159 #safe2pay-icon-pix { 160 background: transparent url(../../images/pix.png) no-repeat; 161 display: block; 162 float: left; 163 height: 85px; 164 margin: 0 10px 5px 0; 165 width: 68px; 166 margin-left: 2px; 167 } 168 162 169 #safe2pay-icon-credit-card { 163 170 background: transparent url(../../images/iconcredit.png) no-repeat; 164 display: block;165 float: left;166 height: 85px;167 margin: 0 10px 5px 0;168 width: 68px;169 margin-left: 2px;170 }171 172 #safe2pay-icon-debit-card {173 background: transparent url(../../images/debitAccount.png) no-repeat;174 171 display: block; 175 172 float: left; … … 202 199 } 203 200 204 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-name-field,205 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-number-field,206 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-installments-field,207 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-cpf-field,208 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-name-field,209 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-number-field,210 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-installments-field,211 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-cpf-field {212 float: none;213 width: 100%;214 }215 216 201 .woo-safe2pay-form-storefront .woocommerce-error ul { 217 202 margin: 0; … … 219 204 } 220 205 221 /* Responsive styles */222 206 @media screen and (max-width: 500px) { 223 207 .woocommerce #payment ul.payment_methods li #safe2pay-payment-methods li, … … 247 231 width: 96%; 248 232 } 249 250 .woocommerce #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-first,251 .woocommerce #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-last,252 .woocommerce-page #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-first,253 .woocommerce-page #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-last {254 float: none;255 width: 96%;256 }257 233 } 258 234 … … 260 236 padding: 1rem; 261 237 background: #eee; 262 /* background-image: linear-gradient(148deg,#00304d 12%,#024d66 42%,#036177 57%,#0ad8dd 97%); */263 /* color: white; */264 238 font-family: Open Sans,sans-serif; 265 239 font-size: 3px; … … 269 243 } 270 244 271 272 245 #safe2pay-payment-form{ 273 246 color: black; -
safe2pay/trunk/assets/css/frontend/transparent-checkout.min.css
r2165731 r2881978 1 /* Payment form */2 1 #safe2pay-payment-form { 3 2 display: none; … … 30 29 } 31 30 32 /* Payment methods */33 31 .woocommerce #payment ul.payment_methods li #safe2pay-payment-methods li, 34 32 .woocommerce-page #payment ul.payment_methods li #safe2pay-payment-methods li { … … 149 147 } 150 148 151 /* Banking ticket */152 149 #safe2pay-icon-ticket { 153 150 background: transparent url(../../images/imgBarcode.png) no-repeat; … … 162 159 #safe2pay-icon-credit-card { 163 160 background: transparent url(../../images/iconcredit.png) no-repeat; 164 display: block;165 float: left;166 height: 85px;167 margin: 0 10px 5px 0;168 width: 68px;169 margin-left: 2px;170 }171 172 #safe2pay-icon-debit-card {173 background: transparent url(../../images/debitAccount.png) no-repeat;174 161 display: block; 175 162 float: left; … … 202 189 } 203 190 204 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-name-field,205 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-number-field,206 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-installments-field,207 .woocommerce #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-cpf-field,208 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-name-field,209 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-number-field,210 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-installments-field,211 .woocommerce-page #payment ul.payment_methods li .woo-safe2pay-form-storefront p#safe2pay-debit-card-holder-cpf-field {212 float: none;213 width: 100%;214 }215 191 216 192 .woo-safe2pay-form-storefront .woocommerce-error ul { … … 219 195 } 220 196 221 /* Responsive styles */222 197 @media screen and (max-width: 500px) { 223 198 .woocommerce #payment ul.payment_methods li #safe2pay-payment-methods li, … … 248 223 } 249 224 250 .woocommerce #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-first,251 .woocommerce #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-last,252 .woocommerce-page #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-first,253 .woocommerce-page #payment ul.payment_methods li #safe2pay-debit-card-form p.form-row.form-row-last {254 float: none;255 width: 96%;256 }257 225 } 258 226 … … 260 228 padding: 1rem; 261 229 background: #eee; 262 /* background-image: linear-gradient(148deg,#00304d 12%,#024d66 42%,#036177 57%,#0ad8dd 97%); */263 /* color: white; */264 230 font-family: Open Sans,sans-serif; 265 231 font-size: 3px; -
safe2pay/trunk/assets/js/admin/admin.js
r2165731 r2881978 1 (function ( $) {2 'use strict';1 (function ($) { 2 'use strict'; 3 3 4 $( function () { 4 $(function () { 5 function safe2PaySwitchTCOptions(method) { 6 var fields = $('#woocommerce_safe2pay_tc_credit').closest('.form-table'), 7 heading = fields.prev('h3'); 5 8 6 /** 7 * Switch transparent checkout options display basead in payment type. 8 * 9 * @param {String} method 10 */ 11 function safe2PaySwitchTCOptions( method ) { 12 var fields = $( '#woocommerce_safe2pay_tc_credit' ).closest( '.form-table' ), 13 heading = fields.prev( 'h3' ); 9 if ('transparent' === method) { 10 fields.show(); 11 heading.show(); 12 } else { 13 fields.hide(); 14 heading.hide(); 15 } 16 } 14 17 15 if ( 'transparent' === method ) { 16 fields.show(); 17 heading.show(); 18 } else { 19 fields.hide(); 20 heading.hide(); 21 } 22 } 18 function safe2PaySwitchUserData(checked) { 19 var secretkey = $('#woocommerce_safe2pay_secretkey').closest('tr'), 20 token = $('#woocommerce_safe2pay_token').closest('tr'), 21 sandboxsecretkey = $('#woocommerce_safe2pay_sandbox_secretkey').closest('tr'), 22 sandboxToken = $('#woocommerce_safe2pay_sandbox_token').closest('tr'); 23 23 24 /** 25 * Switch banking ticket message display. 26 * 27 * @param {String} checked 28 */ 29 function safe2PaySwitchOptions( checked ) { 30 var fields = $( '#woocommerce_safe2pay_tc_ticket_message' ).closest( 'tr' ); 24 if (checked) { 25 secretkey.hide(); 26 token.hide(); 27 sandboxsecretkey.show(); 28 sandboxToken.show(); 29 } else { 30 secretkey.show(); 31 token.show(); 32 sandboxsecretkey.hide(); 33 sandboxToken.hide(); 34 } 35 } 31 36 32 if ( checked) {33 fields.show(); 34 } else { 35 fields.hide(); 36 } 37 } 37 function BankslipSwitchUserData(checked) { 38 var instruction = $('#woocommerce_safe2pay_instruction').closest('tr'), 39 message1 = $('#woocommerce_safe2pay_message1').closest('tr'), 40 message2 = $('#woocommerce_safe2pay_message2').closest('tr'), 41 message3 = $('#woocommerce_safe2pay_message3').closest('tr'), 42 duedate = $('#woocommerce_safe2pay_duedate').closest('tr') 38 43 39 /** 40 * Awitch user data for sandbox and production. 41 * 42 * @param {String} checked 43 */ 44 function safe2PaySwitchUserData( checked ) { 45 var secretkey = $( '#woocommerce_safe2pay_secretkey' ).closest( 'tr' ), 46 token = $( '#woocommerce_safe2pay_token' ).closest( 'tr' ), 47 sandboxsecretkey = $( '#woocommerce_safe2pay_sandbox_secretkey' ).closest( 'tr' ), 48 sandboxToken = $( '#woocommerce_safe2pay_sandbox_token' ).closest( 'tr' ); 44 if (checked) { 45 instruction.show(); 46 message1.show(); 47 message2.show(); 48 message3.show(); 49 duedate.show(); 50 } else { 51 instruction.hide(); 52 message1.hide(); 53 message2.hide(); 54 message3.hide(); 55 duedate.hide(); 56 } 57 } 49 58 50 if ( checked ) { 51 secretkey.hide(); 52 token.hide(); 53 sandboxsecretkey.show(); 54 sandboxToken.show(); 55 } else { 56 secretkey.show(); 57 token.show(); 58 sandboxsecretkey.hide(); 59 sandboxToken.hide(); 60 } 61 } 59 safe2PaySwitchTCOptions($('#woocommerce_safe2pay_method').val()); 62 60 63 function BankslipSwitchUserData( checked ) { 64 var instruction = $( '#woocommerce_safe2pay_instruction' ).closest( 'tr' ), 65 message1 = $( '#woocommerce_safe2pay_message1' ).closest( 'tr' ), 66 message2 = $( '#woocommerce_safe2pay_message2' ).closest( 'tr' ), 67 message3 = $( '#woocommerce_safe2pay_message3' ).closest( 'tr' ), 68 duedate = $( '#woocommerce_safe2pay_duedate' ).closest( 'tr' ) 61 $('body').on('change', '#woocommerce_safe2pay_method', function () { 62 safe2PaySwitchTCOptions($(this).val()); 63 }).change(); 69 64 70 if ( checked ) { 71 instruction.show(); 72 message1.show(); 73 message2.show(); 74 message3.show(); 75 duedate.show(); 76 } else { 77 instruction.hide(); 78 message1.hide(); 79 message2.hide(); 80 message3.hide(); 81 duedate.hide(); 82 } 83 } 65 BankslipSwitchUserData($('#woocommerce_safe2pay_tc_ticket').is(':checked')); 66 $('body').on('change', '#woocommerce_safe2pay_tc_ticket', function () { 67 BankslipSwitchUserData($(this).is(':checked')); 68 }); 84 69 85 safe2PaySwitchTCOptions( $( '#woocommerce_safe2pay_method' ).val() ); 70 safe2PaySwitchUserData($('#woocommerce_safe2pay_sandbox').is(':checked')); 71 $('body').on('change', '#woocommerce_safe2pay_sandbox', function () { 72 safe2PaySwitchUserData($(this).is(':checked')); 73 }); 74 }); 86 75 87 $( 'body' ).on( 'change', '#woocommerce_safe2pay_method', function () { 88 safe2PaySwitchTCOptions( $( this ).val() ); 89 }).change(); 90 91 BankslipSwitchUserData( $( '#woocommerce_safe2pay_tc_ticket' ).is( ':checked' ) ); 92 $( 'body' ).on( 'change', '#woocommerce_safe2pay_tc_ticket', function () { 93 BankslipSwitchUserData( $( this ).is( ':checked' ) ); 94 }); 95 96 safe2PaySwitchUserData( $( '#woocommerce_safe2pay_sandbox' ).is( ':checked' ) ); 97 $( 'body' ).on( 'change', '#woocommerce_safe2pay_sandbox', function () { 98 safe2PaySwitchUserData( $( this ).is( ':checked' ) ); 99 }); 100 }); 101 102 }( jQuery )); 76 }(jQuery)); -
safe2pay/trunk/assets/js/frontend/transparent-checkout.js
r2165731 r2881978 1 /*global wc_safe2pay_params, PagSeguroDirectPayment, wc_checkout_params */2 1 (function ($) { 3 'use strict'; 4 5 $(function () { 6 7 var safe2pay_submit = false; 8 9 function safe2PayGetInstallmentOption(installment) { 10 return '<option value="' + installment.quantity + '" data-installment-value="' + installment.installmentAmount + '">' + safe2PayGetPriceText(installment) + '</option>'; 11 } 12 13 function safe2PayGetPriceText(installment) { 14 var installmentParsed = 'R$ ' + parseFloat(installment.installmentAmount, 10).toFixed(2).replace('.', ',').toString(); 15 var totalParsed = 'R$ ' + parseFloat(installment.totalAmount, 10).toFixed(2).replace('.', ',').toString(); 16 var interestFree = (true === installment.interestFree) ? ' ' + wc_safe2pay_params.interest_free : ''; 17 var interestText = interestFree ? interestFree : ' (' + totalParsed + ')'; 18 return installment.quantity + 'x ' + installmentParsed + interestText; 19 } 20 21 function InstallmentInit() { 22 23 try { 24 25 var instalmments = $('body #safe2pay-card-installments'); 26 27 instalmments.empty(); 28 instalmments.removeAttr('disabled'); 29 instalmments.append('<option value="0">--</option>'); 30 31 var currency = $('.amount')[$('.amount').length - 1].innerText; //it works for US-style currency strings as well 32 var cur_re = /\D*(\d+|\d.*?\d)(?:\D+(\d{2}))?\D*$/; 33 var parts = cur_re.exec(currency); 34 var total = parseFloat(parts[1].replace(/\D/, '') + '.' + (parts[2] ? parts[2] : '00')); 35 36 for (let index = 1; index <= 12; index++) { 37 38 var installment = { 39 40 quantity: index, 41 totalAmount: total, 42 installmentAmount: total / index 43 }; 44 45 instalmments.append(safe2PayGetInstallmentOption(installment)); 46 } 47 } catch (error) { 48 ShowMessageError(wc_safe2pay_params.invalid_card); 49 } 50 } 51 52 function ShowMessageError(error) { 53 var wrapper = $('#safe2pay-credit-card-form'); 54 55 $('.woocommerce-error', wrapper).remove(); 56 wrapper.prepend('<div class="woocommerce-error" style="margin-bottom: 0.5em !important;">' + error + '</div>'); 57 } 58 59 function HidePaymentMethods() { 60 var paymentMethods = $('#safe2pay-payment-methods'); 61 if (1 === $('input[type=radio]', paymentMethods).length) { 62 paymentMethods.hide(); 63 } 64 } 65 66 function HidePaymentForm(method) { 67 // window.alert( method ); 68 $('.safe2pay-method-form').hide(); 69 $('#safe2pay-payment-methods li').removeClass('active'); 70 $('#safe2pay-' + method + '-form').show(); 71 $('#safe2pay-payment-method-' + method).parent('label').parent('li').addClass('active'); 72 } 73 74 function Init() { 75 HidePaymentMethods(); 76 InstallmentInit(); 77 78 $('#safe2pay-payment-form').show(); 79 80 HidePaymentForm($('#safe2pay-payment-methods input[type=radio]:checked').val()); 81 82 var MaskBehavior = function (val) { 83 return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009'; 84 }, 85 maskOptions = { 86 onKeyPress: function (val, e, field, options) { 87 field.mask(MaskBehavior.apply({}, arguments), options); 88 } 89 }; 90 } 91 92 function safe2PayformHandler() { 93 if (safe2pay_submit) { 94 safe2pay_submit = false; 95 96 return true; 97 } 98 99 if (!$('#payment_method_safe2pay').is(':checked')) { 100 return true; 101 } 102 103 if ('credit-card' !== $('body li.payment_method_safe2pay input[name=safe2pay_payment_method]:checked').val()) { 104 $('form.checkout, form#order_review').append($('<input name="safe2pay_sender_hash" type="hidden" />').val(PagSeguroDirectPayment.getSenderHash())); 105 106 return true; 107 } 108 109 var form = $('form.checkout, form#order_review'), 110 creditCardForm = $('#safe2pay-credit-card-form', form), 111 error = false, 112 errorHtml = '', 113 holder = $('#safe2pay-card-holder-name').val(), 114 cardNumber = $('#safe2pay-card-number', form).val().replace(/[^\d]/g, ''), 115 cvv = $('#safe2pay-card-cvc', form).val(), 116 expiration = $('#safe2pay-card-expiry', form).val(), 117 expirationMonth = expiration.replace(/[^\d]/g, '').substr(0, 2), 118 expirationYear = expiration.replace(/[^\d]/g, '').substr(2), 119 installments = $('#safe2pay-card-installments', form), 120 today = new Date(); 121 122 // Validate the credit card data. 123 errorHtml += '<ul>'; 124 125 126 // Validate the expiry date. 127 if (2 !== expirationMonth.length || 4 !== expirationYear.length) { 128 errorHtml += '<li>' + wc_safe2pay_params.invalid_expiry + '</li>'; 129 error = true; 130 } 131 132 if ((2 === expirationMonth.length && 4 === expirationYear.length) && (expirationMonth > 12 || expirationYear <= (today.getFullYear() - 1) || expirationYear >= (today.getFullYear() + 20) || (expirationMonth < (today.getMonth() + 2) && expirationYear.toString() === today.getFullYear().toString()))) { 133 errorHtml += '<li>' + wc_safe2pay_params.expired_date + '</li>'; 134 error = true; 135 } 136 137 // Installments. 138 if ('0' === installments.val()) { 139 errorHtml += '<li>' + wc_safe2pay_params.empty_installments + '</li>'; 140 error = true; 141 } 142 143 errorHtml += '</ul>'; 144 // Create the card token. 145 if (!error) { 146 147 $('input[name=safe2pay_credit_card_hash], input[name=safe2pay_credit_card_hash], input[name=safe2pay_installment_value]', form).remove(); 148 149 //add credit card 150 //Holder 151 form.append($('<input name="safe2pay-card-holder-name" type="hidden" />').val(holder)); 152 //Number 153 form.append($('<input name="safe2pay-card-number" type="hidden" />').val(cardNumber)); 154 //Expiration Date 155 form.append($('<input name="safe2pay-card-expiry-field" type="hidden" />').val(expiration)); 156 //CVC 157 form.append($('<input name="safe2pay-card-cvc" type="hidden" />').val(cvv)); 158 //Instalmentes 159 form.append($('<input name="safe2pay-card-installments" type="hidden" />').val(installments.val())); 160 161 form.append($('<input name="safe2pay-card-installments" type="hidden" />').val(installments.val())); 162 163 // Submit the form. 164 safe2pay_submit = true; 165 form.submit(); 166 } else { 167 ShowMessageError(errorHtml); 168 } 169 170 return false; 171 } 172 173 Init(); 174 $('body').on('updated_checkout', function () { 175 Init(); 176 }); 177 178 // Switch the payment method form. 179 $('body').on('click', '#safe2pay-payment-methods input[type=radio]', function () { 180 HidePaymentForm($(this).val()); 181 }); 182 183 184 $('body').on('updated_checkout', function () { 185 var field = $('body #safe2pay-card-number'); 186 187 if (0 < field.length) { 188 field.focusout(); 189 } 190 }); 191 192 // Set the errors. 193 $('body').on('focus', '#safe2pay-card-number, #safe2pay-card-expiry', function () { 194 $('#safe2pay-credit-card-form .woocommerce-error').remove(); 195 }); 196 197 198 // Process the credit card data when submit the checkout form. 199 $('form.checkout').on('checkout_place_order_safe2pay', function () { 200 return safe2PayformHandler(); 201 }); 202 203 $('form#order_review').submit(function () { 204 return safe2PayformHandler(); 205 }); 206 207 }); 2 'use strict'; 3 4 $(function () { 5 6 var safe2pay_submit = false; 7 8 9 function safe2PaySetCreditCardBrand(brand) { 10 $('#safe2pay-credit-card-form').attr('data-credit-card-brand', brand); 11 } 12 13 function safe2PayGetPriceText(installment) { 14 var installmentParsed = 'R$ ' + parseFloat(installment.installmentAmount, 10).toFixed(2).replace('.', ',').toString(); 15 16 return installment.quantity + 'x de ' + installmentParsed; 17 } 18 19 function safe2PayGetInstallmentOption(installment) { 20 return '<option value="' + installment.quantity + '" data-installment-value="' + installment.installmentAmount + '">' + safe2PayGetPriceText(installment) + '</option>'; 21 } 22 23 function ShowMessageError(error) { 24 var wrapper = $('#safe2pay-credit-card-form'); 25 26 $('.woocommerce-error', wrapper).remove(); 27 wrapper.prepend('<div class="woocommerce-error" style="margin-bottom: 0.5em !important;">' + error + '</div>'); 28 } 29 30 function HidePaymentMethods() { 31 var paymentMethods = $('#safe2pay-payment-methods'); 32 if (1 === $('input[type=radio]', paymentMethods).length) { 33 paymentMethods.hide(); 34 } 35 } 36 37 function HidePaymentForm(method) { 38 // window.alert( method ); 39 $('.safe2pay-method-form').hide(); 40 $('#safe2pay-payment-methods li').removeClass('active'); 41 $('#safe2pay-' + method + '-form').show(); 42 $('#safe2pay-payment-method-' + method).parent('label').parent('li').addClass('active'); 43 } 44 45 function Init() { 46 HidePaymentMethods(); 47 48 $('#safe2pay-payment-form').show(); 49 50 HidePaymentForm($('#safe2pay-payment-methods input[type=radio]:checked').val()); 51 52 var MaskBehavior = function (val) { 53 return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009'; 54 }, 55 maskOptions = { 56 onKeyPress: function (val, e, field, options) { 57 field.mask(MaskBehavior.apply({}, arguments), options); 58 } 59 }; 60 } 61 62 function safe2PayformHandler() { 63 if (safe2pay_submit) { 64 safe2pay_submit = false; 65 66 return true; 67 } 68 69 if (!$('#payment_method_safe2pay').is(':checked')) { 70 return true; 71 } 72 73 if ('credit-card' !== $('body li.payment_method_safe2pay input[name=safe2pay_payment_method]:checked').val()) { 74 $('form.checkout, form#order_review').append($('<input name="safe2pay_sender_hash" type="hidden" />').val(S2PDirectPayment.getSenderHash())); 75 76 return true; 77 } 78 79 var form = $('form.checkout, form#order_review'), 80 creditCardForm = $('#safe2pay-credit-card-form', form), 81 error = false, 82 errorHtml = '', 83 holder = $('#safe2pay-card-holder-name').val(), 84 cardNumber = $('#safe2pay-card-number', form).val().replace(/[^\d]/g, ''), 85 cvv = $('#safe2pay-card-cvc', form).val(), 86 expiration = $('#safe2pay-card-expiry', form).val(), 87 expirationMonth = expiration.replace(/[^\d]/g, '').substr(0, 2), 88 expirationYear = expiration.replace(/[^\d]/g, '').substr(2), 89 installments = $('#safe2pay-card-installments', form), 90 today = new Date(); 91 92 errorHtml += '<ul>'; 93 94 if (2 !== expirationMonth.length || 4 !== expirationYear.length) { 95 errorHtml += '<li>' + wc_safe2pay_params.invalid_expiry + '</li>'; 96 error = true; 97 } 98 99 if ((2 === expirationMonth.length && 4 === expirationYear.length) && (expirationMonth > 12 || expirationYear <= (today.getFullYear() - 1) || expirationYear >= (today.getFullYear() + 20) || (expirationMonth < (today.getMonth() + 2) && expirationYear.toString() === today.getFullYear().toString()))) { 100 errorHtml += '<li>' + wc_safe2pay_params.expired_date + '</li>'; 101 error = true; 102 } 103 104 if ('0' === installments.val()) { 105 errorHtml += '<li>' + wc_safe2pay_params.empty_installments + '</li>'; 106 error = true; 107 } 108 109 errorHtml += '</ul>'; 110 if (!error) { 111 112 $('input[name=safe2pay_credit_card_hash], input[name=safe2pay_credit_card_hash], input[name=safe2pay_installment_value]', form).remove(); 113 114 form.append($('<input name="safe2pay-card-holder-name" type="hidden" />').val(holder)); 115 form.append($('<input name="safe2pay-card-number" type="hidden" />').val(cardNumber)); 116 form.append($('<input name="safe2pay-card-expiry-field" type="hidden" />').val(expiration)); 117 form.append($('<input name="safe2pay-card-cvc" type="hidden" />').val(cvv)); 118 form.append($('<input name="safe2pay-card-installments" type="hidden" />').val(installments.val())); 119 120 safe2pay_submit = true; 121 form.submit(); 122 } else { 123 ShowMessageError(errorHtml); 124 } 125 126 return false; 127 } 128 129 Init(); 130 131 $('body').on('updated_checkout', function () { 132 Init(); 133 }); 134 135 $('body').on('click', '#safe2pay-payment-methods input[type=radio]', function () { 136 HidePaymentForm($(this).val()); 137 }); 138 139 $('body').on('updated_checkout', function () { 140 var field = $('body #safe2pay-card-number'); 141 142 if (0 < field.length) { 143 field.focusout(); 144 } 145 }); 146 147 $('#payment').on('submit', function(e) { 148 if (!$('#safe2pay-payment-methods input[type=radio]:checked').length) { 149 e.preventDefault(); 150 alert('É necessário selecionar uma forma de pagamento.'); 151 } 152 }); 153 154 $('body').on('focus', '#safe2pay-card-number, #safe2pay-card-expiry', function () { 155 $('#safe2pay-credit-card-form .woocommerce-error').remove(); 156 }); 157 158 $('form.checkout').on('checkout_place_order_safe2pay', function () { 159 return safe2PayformHandler(); 160 }); 161 162 $('body').on('safe2pay_credit_card_brand', function (event, brand) { 163 if ('error' !== brand) { 164 S2PDirectPayment.getInstallments({ 165 amount: $('body #safe2pay-payment-form').data('cart_total'), 166 brand: brand, 167 success: function (data) { 168 var instalmments = $('body #safe2pay-card-installments'); 169 170 if (false === data.error) { 171 instalmments.empty(); 172 instalmments.removeAttr('disabled'); 173 instalmments.append('<option value="0">--</option>'); 174 175 $.each(data.installments[brand], function (index, installment) { 176 instalmments.append(safe2PayGetInstallmentOption(installment)); 177 }); 178 } else { 179 safe2PayAddErrorMessage(wc_safe2pay_params.invalid_card); 180 } 181 }, 182 error: function () { 183 safe2PayAddErrorMessage(wc_safe2pay_params.invalid_card); 184 } 185 }); 186 } else { 187 safe2PayAddErrorMessage(wc_safe2pay_params.invalid_card); 188 } 189 }); 190 191 192 $('form#order_review').submit(function () { 193 return safe2PayformHandler(); 194 }); 195 196 }); 208 197 209 198 }(jQuery)); 210 199 211 212 200 function MaskcpfCnpj(e) { 213 214 v = e.value; 215 216 //Remove tudo o que não é dígito 217 v = v.replace(/\D/g, ""); 218 219 if (v.length <= 11) { //CPF 220 221 //Coloca um ponto entre o terceiro e o quarto dígitos 222 v = v.replace(/(\d{3})(\d)/, "$1.$2"); 223 224 //Coloca um ponto entre o terceiro e o quarto dígitos 225 //de novo (para o segundo bloco de números) 226 v = v.replace(/(\d{3})(\d)/, "$1.$2"); 227 228 //Coloca um hífen entre o terceiro e o quarto dígitos 229 v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2"); 230 231 } else { //CNPJ 232 233 //Coloca ponto entre o segundo e o terceiro dígitos 234 v = v.replace(/^(\d{2})(\d)/, "$1.$2"); 235 236 //Coloca ponto entre o quinto e o sexto dígitos 237 v = v.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3"); 238 239 //Coloca uma barra entre o oitavo e o nono dígitos 240 v = v.replace(/\.(\d{3})(\d)/, ".$1/$2"); 241 242 //Coloca um hífen depois do bloco de quatro dígitos 243 v = v.replace(/(\d{4})(\d)/, "$1-$2"); 244 245 } 246 247 e.value = v; 201 v = e.value; 202 v = v.replace(/\D/g, ""); 203 204 if (v.length <= 11) { //CPF 205 v = v.replace(/(\d{3})(\d)/, "$1.$2"); 206 v = v.replace(/(\d{3})(\d)/, "$1.$2"); 207 v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2"); 208 } else { //CNPJ 209 v = v.replace(/^(\d{2})(\d)/, "$1.$2"); 210 v = v.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3"); 211 v = v.replace(/\.(\d{3})(\d)/, ".$1/$2"); 212 v = v.replace(/(\d{4})(\d)/, "$1-$2"); 213 } 214 215 e.value = v; 248 216 }; 249 217 250 218 function IsNumber(evt) { 251 evt = (evt) ? evt : window.event;252 var charCode = (evt.which) ? evt.which : evt.keyCode;253 if (charCode > 31 && (charCode < 48 || charCode > 57)) {254 return false;255 }256 return true;219 evt = (evt) ? evt : window.event; 220 var charCode = (evt.which) ? evt.which : evt.keyCode; 221 if (charCode > 31 && (charCode < 48 || charCode > 57)) { 222 return false; 223 } 224 return true; 257 225 } 258 226 259 227 function ExpiryMask(evt, e) { 260 228 261 evt = (evt) ? evt : window.event; 262 var charCode = (evt.which) ? evt.which : evt.keyCode; 263 if (charCode > 31 && (charCode < 48 || charCode > 57)) { 264 return false; 265 } 266 267 v = e.value; 268 269 //Remove tudo o que não é dígito 270 v = v.replace(/\D/g, ""); 271 272 //Coloca um ponto entre o terceiro e o quarto dígitos 273 v = v.replace(/(\d{2})(\d{0})/, "$1/$2"); 274 275 276 e.value = v; 277 278 return true; 279 229 evt = (evt) ? evt : window.event; 230 var charCode = (evt.which) ? evt.which : evt.keyCode; 231 if (charCode > 31 && (charCode < 48 || charCode > 57)) { 232 return false; 233 } 234 235 v = e.value; 236 v = v.replace(/\D/g, ""); 237 v = v.replace(/(\d{2})(\d{0})/, "$1/$2"); 238 239 e.value = v; 240 241 return true; 280 242 } -
safe2pay/trunk/includes/admin/views/html-admin-help-message.php
r2165731 r2881978 1 1 <?php 2 /**3 * Admin help message.4 *5 * @package WooCommerce_Safe2Pay/Admin/Settings6 */7 2 8 3 if ( ! defined( 'ABSPATH' ) ) { -
safe2pay/trunk/includes/admin/views/html-admin-page.php
r2165731 r2881978 1 1 <?php 2 /**3 * Admin options screen.4 *5 * @package WooCommerce_Safe2Pay/Admin/Settings6 */7 2 8 3 if ( ! defined( 'ABSPATH' ) ) { … … 29 24 <?php $this->generate_settings_html(); ?> 30 25 </table> 26 -
safe2pay/trunk/includes/admin/views/html-notice-currency-not-supported.php
r2165731 r2881978 1 1 <?php 2 /**3 * Admin View: Notice - Currency not supported.4 *5 * @package WooCommerce_Safe2Pay/Admin/Notices6 */7 2 8 3 if ( ! defined( 'ABSPATH' ) ) { -
safe2pay/trunk/includes/admin/views/html-notice-missing-ecfb.php
r2165731 r2881978 1 1 <?php 2 /**3 * Missing WooCommerce Extra Checkout Fields for Brazil notice4 *5 * @package WooCommerce_Safe2Pay/Admin/Notices6 */7 2 8 3 if ( ! defined( 'ABSPATH' ) ) { -
safe2pay/trunk/includes/class-wc-safe2pay-api.php
r2165817 r2881978 1 1 <?php 2 2 3 /**4 * Safe2Pay API class5 *6 * @package WooCommerce_Safe2Pay/Classes/API7 * @version 2.12.08 */9 10 3 if (!defined('ABSPATH')) { 11 exit;4 exit; 12 5 } 13 6 14 7 class WC_Safe2Pay_API 15 8 { 16 17 protected $gateway; 18 19 20 public function __construct($gateway = null) 21 { 22 $this->gateway = $gateway; 23 } 24 25 26 protected function HttpClient($url, $method = 'POST', $data = array(), $headers = array()) 27 { 28 $params = array( 29 'method' => $method, 30 'timeout' => 60, 31 ); 32 33 if ('POST' == $method && !empty($data)) { 34 $params['body'] = $data; 35 } 36 37 if (!empty($headers)) { 38 $params['headers'] = $headers; 39 } 40 41 return wp_safe_remote_post($url, $params); 42 } 43 44 protected function GetPaymentURI() 45 { 46 return 'https://payment.safe2pay.com.br/v2/Payment'; 47 } 48 49 public function GetCallbackURI($orderId) 50 { 51 52 // output: /myproject/index.php 53 $currentPath = $_SERVER['PHP_SELF']; 54 55 // output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index ) 56 $pathInfo = pathinfo($currentPath); 57 58 // output: localhost 59 $hostName = $_SERVER['HTTP_HOST']; 60 61 // output: http:// 62 $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, 5)) == 'https' ? 'https' : 'http'; 63 64 // return: http://localhost/myproject/ 65 return $protocol . '://' . $hostName . $pathInfo['dirname'] . "/" . 'wp-json/safe2pay/v2/callback/' . $orderId; 66 } 67 68 public function GetPaymentMethod($method) 69 { 70 $methods = array( 71 'credit-card' => 'creditCard', 72 'banking-ticket' => 'boleto', 73 'debit-card' => 'debitCard', 74 'crypto-currency' => 'cryptocurrency', 75 ); 76 77 return isset($methods[$method]) ? $methods[$method] : ''; 78 } 79 80 protected function GetAvailablePaymentMethods() 81 { 82 $methods = array(); 83 84 $token = strtoupper($this->gateway->settings['sandbox']) !== "NO" ? $this->gateway->sandbox_token : $this->gateway->token; 85 $response = $this->HttpClient('https://api.safe2pay.com.br/v2/MerchantPaymentMethod/List', 'GET', null, array('Content-Type' => 'application/json', 'X-API-KEY' => $token)); 86 87 $response = json_decode($response['body']); 88 89 if ($response->HasError == false) { 90 91 92 foreach ($response->ResponseDetail as $key => $value) { 93 94 if ($value->PaymentMethod->Code === '1') { 95 $methods[] = 'banking-ticket'; 96 } 97 98 if ($value->PaymentMethod->Code === '2') { 99 $methods[] = 'credit-card'; 100 } 101 102 if ($value->PaymentMethod->Code === '3') { 103 $methods[] = 'crypto-currency'; 104 } 105 106 if ($value->PaymentMethod->Code === '4') { 107 $methods[] = 'debit-card'; 108 } 109 } 110 } 111 112 113 return $methods; 114 } 115 116 protected function GetPayload($order, $posted, $IsSandbox) 117 { 118 119 //Metodo de pagamento 120 $method = isset($posted['safe2pay_payment_method']) ? $this->GetPaymentMethod($posted['safe2pay_payment_method']) : ''; 121 //Get Version 122 $woo = new WooCommerce(); 123 //PaymentMethod Code 124 $paymentMethod = 0; 125 //PaymentMethod Object 126 $PaymentObject = null; 127 128 //Produto do payload 129 $Products = array( 130 (object) array( 131 'Code' => 1, 132 'Description' => "Ordem #" . $order->get_id(), 133 'Quantity' => 1, 134 'UnitPrice' => $order->get_total() 135 ) 136 ); 137 138 switch (strtoupper($method)) { 139 case 'BOLETO': 140 141 $paymentMethod = "1"; 142 $PaymentObject = $this->gateway->GetBankSlipConfig(); 143 144 break; 145 case 'CREDITCARD': 146 $paymentMethod = "2"; 147 148 $PaymentObject = array( 149 'Holder' => sanitize_text_field($posted['safe2pay-card-holder-name']), 150 'CardNumber' => sanitize_text_field($posted['safe2pay-card-number']), 151 'ExpirationDate' => sanitize_text_field($posted['safe2pay-card-expiry-field']), 152 'SecurityCode' => sanitize_text_field($posted['safe2pay-card-cvc']), 153 'InstallmentQuantity' => sanitize_text_field($posted['safe2pay-card-installments']) 154 ); 155 156 break; 157 case 'CRYPTOCURRENCY': 158 $paymentMethod = "3"; 159 160 $PaymentObject = array( 161 'Symbol' => sanitize_text_field($posted['safe2pay_currency-type']), 162 ); 163 164 break; 165 case 'DEBITCARD': 166 $paymentMethod = "4"; 167 168 $PaymentObject = array( 169 'Holder' => sanitize_text_field($posted['safe2pay-debit-card-holder-name']), 170 'CardNumber' => sanitize_text_field($posted['safe2pay-debit-card-number']), 171 'ExpirationDate' => sanitize_text_field($posted['safe2pay-debit-card-expiry']), 172 'SecurityCode' => sanitize_text_field($posted['safe2pay-debit-card-cvc']) 173 ); 174 175 break; 176 default: 177 return array( 178 'url' => '', 179 'data' => '', 180 'error' => 'Método de pagamento não selecionado', 181 ); 182 }; 183 184 //Monta payload Safe2Pay 185 $payload = array( 186 'IsSandbox' => $IsSandbox, 187 'Application' => 'Woocomerce ' . $woo->version, 188 'PaymentMethod' => $paymentMethod, 189 'PaymentObject' => $PaymentObject, 190 'Reference' => $order->get_id(), 191 'Products' => $Products, 192 'Customer' => array( 193 "Name" => sanitize_text_field($posted['billing_first_name'] . ' ' . $posted['billing_last_name']), 194 "Identity" => sanitize_text_field(preg_replace("/[^0-9]/", "", $posted['billing_cpf'])), 195 "Phone" => sanitize_text_field($posted['billing_phone']), 196 "Email" => sanitize_text_field($posted['billing_email']), 197 "Address" => array( 198 "Street" => sanitize_text_field($posted['billing_address_1']), 199 "Number" => sanitize_text_field(isset($posted['billing_number']) ? $posted['billing_number'] : 'S/N'), 200 "District" => sanitize_text_field(isset($posted['billing_neighborhood']) ? $posted['billing_neighborhood'] : 'Não informado'), 201 "ZipCode" => sanitize_text_field($posted['billing_postcode']), 202 "CityName" => sanitize_text_field($posted['billing_city']), 203 "StateInitials" => sanitize_text_field($posted['billing_state']), 204 "CountryName" => 'BRASIL' 205 ) 206 ), 207 'CallbackUrl' => $this->GetCallbackURI($order->Id) 208 ); 209 210 return json_encode($payload); 211 } 212 213 public function CheckoutController($order, $posted) 214 { 215 216 try { 217 218 $IsSandbox = (strtoupper($this->gateway->settings['sandbox']) !== "NO" ? true : false); 219 220 $payload = $this->GetPayload($order, $posted, $IsSandbox); 221 222 if ('yes' == $this->gateway->debug) { 223 $this->gateway->log->add($this->gateway->id, 'Requesting token for order ' . $order->get_order_number() . ' with the following data: ' . $payload); 224 } 225 226 $token = strtoupper($this->gateway->settings['sandbox']) !== "NO" ? $this->gateway->sandbox_token : $this->gateway->token; 227 228 $response = $this->HttpClient($this->GetPaymentURI(), 'POST', $payload, array('Content-Type' => 'application/json', 'X-API-KEY' => $token)); 229 230 if ($response['response']['code'] === 200) { 231 232 233 $response = json_decode($response["body"]); 234 235 236 if ($response->HasError == false) { 237 238 return array( 239 'url' => $this->gateway->GetPaymentURI(), 240 'data' => $response, 241 'error' => '', 242 ); 243 244 245 if ('yes' == $this->gateway->debug) { 246 $this->gateway->log->add($this->gateway->id, 'Transação efetuada com sucesso!'); 247 } 248 249 return array( 250 'url' => $this->GetPaymentURI(), 251 'token' => $response->TransactionId, 252 'error' => '', 253 ); 254 } 255 } else if ($response['response']['code'] === 401) { 256 257 if ('yes' == $this->gateway->debug) { 258 $this->gateway->log->add($this->gateway->id, 'Invalid token and/or email settings!'); 259 } 260 261 return array( 262 'url' => '', 263 'data' => '', 264 'error' => array(__('Too bad! The email or token from the Safe2Pay are invalids my little friend!', 'woo-safe2pay')), 265 ); 266 } 267 } catch (Exception $e) { 268 269 // Return error message. 270 return array( 271 'url' => '', 272 'token' => '', 273 'error' => array('<strong>' . __('Safe2Pay', 'woo-safe2pay') . '</strong>: ' . __('An error has occurred while processing your payment, please try again. Or contact us for assistance.', 'woo-safe2pay')), 274 ); 275 } 276 } 277 278 public function PaymentController($order, $posted) 279 { 280 $payment_method = isset($posted['safe2pay_payment_method']) ? $posted['safe2pay_payment_method'] : ''; 281 282 /** 283 * Validate if has selected a payment method. 284 */ 285 if (!in_array($payment_method, $this->GetAvailablePaymentMethods())) { 286 return array( 287 'url' => '', 288 'data' => '', 289 'error' => array('<strong>' . __('Safe2Pay', 'woo-safe2pay') . '</strong>: ' . __('Please, select a payment method.', 'woo-safe2pay')), 290 ); 291 } 292 293 $IsSandbox = (strtoupper($this->gateway->settings['sandbox']) !== "NO" ? true : false); 294 295 $payload = $this->GetPayload($order, $posted, $IsSandbox); 296 297 298 if ('yes' == $this->gateway->debug) { 299 $this->gateway->log->add($this->gateway->id, 'Requesting direct payment for order ' . $order->get_order_number() . ' with the following data: ' . $payload); 300 } 301 302 $token = strtoupper($this->gateway->settings['sandbox']) !== "NO" ? $this->gateway->sandbox_token : $this->gateway->token; 303 304 $response = $this->HttpClient($this->GetPaymentURI(), 'POST', $payload, array('Content-Type' => 'application/json', 'X-API-KEY' => $token)); 305 306 if (is_wp_error($response)) { 307 if ('yes' == $this->gateway->debug) { 308 $this->gateway->log->add($this->gateway->id, 'WP_Error in requesting the direct payment:'); 309 } 310 } else if (401 === $response['response']['code']) { 311 if ('yes' == $this->gateway->debug) { 312 $this->gateway->log->add($this->gateway->id, 'The user does not have permissions to use the Safe2Pay Transparent Checkout!'); 313 } 314 315 return array( 316 'url' => '', 317 'data' => '', 318 'error' => array(__('You are not allowed to use the Safe2Pay Transparent Checkout. Looks like you neglected to installation guide of this plugin. This is not pretty, do you know?', 'woo-safe2pay')), 319 ); 320 } else { 321 try { 322 323 $response = json_decode($response["body"]); 324 325 326 if ($response->HasError == false) { 327 if ($response->ResponseDetail->Status == 8) { 328 return array( 329 'url' => '', 330 'data' => '', 331 'error' => array('<strong>' . __('Safe2Pay', 'woo-safe2pay') . '</strong>: ' . __($response->ResponseDetail->Message, 'woo-safe2pay')), 332 ); 333 } 334 335 336 if ('yes' == $this->gateway->debug) { 337 $this->gateway->log->add($this->gateway->id, 'Pagamento gerado com sucesso!'); 338 } 339 340 return array( 341 'url' => $this->gateway->get_return_url($order), 342 'data' => $response->ResponseDetail, 343 'error' => '', 344 ); 345 } else { 346 347 // $this->gateway->log->add($this->gateway->id, '!'); 348 349 return array( 350 'url' => '', 351 'data' => '', 352 'error' => array('<strong>' . __('Safe2Pay', 'woo-safe2pay') . '</strong>: ' . __($response->Error, 'woo-safe2pay')), 353 ); 354 } 355 } catch (Exception $e) { 356 $data = ''; 357 358 if ('yes' == $this->gateway->debug) { 359 $this->gateway->log->add($this->gateway->id, 'Error while parsing the Safe2Pay response: ' . print_r($e->getMessage(), true)); 360 } 361 } 362 } 363 } 364 365 366 367 public function get_direct_payment_url() 368 { 369 return 'https://stc.' . '' . 'pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js'; 370 } 9 protected $gateway; 10 11 public function __construct($gateway = null) 12 { 13 $this->gateway = $gateway; 14 } 15 16 protected function HttpClient($url, $method = 'POST', $data = array(), $headers = array()) 17 { 18 $params = array( 19 'method' => $method, 20 'timeout' => 30, 21 ); 22 23 if ('POST' == $method && !empty($data)) { 24 $params['body'] = $data; 25 } 26 27 if (!empty($headers)) { 28 $params['headers'] = $headers; 29 } 30 31 return wp_safe_remote_post($url, $params); 32 } 33 34 protected function GetPaymentURI() 35 { 36 return 'https://payment.safe2pay.com.br/v2/Payment'; 37 } 38 39 public function get_callback_uri($orderId) 40 { 41 return get_home_url() . "/" . 'wp-json/safe2pay/v2/callback/' . $orderId; 42 } 43 44 public function GetPaymentMethod($method) 45 { 46 $methods = [ 47 'bank-slip' => 'bankslip', 48 'credit-card' => 'creditcard', 49 'crypto-currency' => 'cryptocurrency', 50 'pix' => 'pix', 51 ]; 52 53 return isset($methods[$method]) ? $methods[$method] : ''; 54 } 55 56 protected function GetAvailablePaymentMethods() 57 { 58 $methods = array(); 59 60 $token = strtoupper($this->gateway->settings['sandbox']) !== "NO" ? $this->gateway->sandbox_token : $this->gateway->token; 61 $response = $this->HttpClient('https://api.safe2pay.com.br/v2/MerchantPaymentMethod/List', 'GET', null, array('Content-Type' => 'application/json', 'X-API-KEY' => $token)); 62 63 $response = json_decode($response['body']); 64 65 if ($response->HasError == false) { 66 67 foreach ($response->ResponseDetail as $key => $value) { 68 69 if ($value->PaymentMethod->Code === '1') { 70 $methods[] = 'bank-slip'; 71 } 72 73 if ($value->PaymentMethod->Code === '2') { 74 $methods[] = 'credit-card'; 75 } 76 77 if ($value->PaymentMethod->Code === '3') { 78 $methods[] = 'crypto-currency'; 79 } 80 81 if ($value->PaymentMethod->Code === '6') { 82 $methods[] = 'pix'; 83 } 84 } 85 } 86 87 return $methods; 88 } 89 90 public function set_split_data($order) 91 { 92 $split_data = []; 93 $splits = []; 94 $is_pay_tax = false; 95 96 if ($this->gateway->settings['dokan_enable_split'] == 'yes') { 97 $items = $order->get_items(); 98 $sellers_shipping_cost = []; 99 100 if ($this->gateway->settings['dokan_receiver_pay_tax'] == 'yes') { 101 $is_pay_tax = true; 102 } 103 104 foreach ($order->get_items('shipping') as $shipping) { 105 $shipping_cost_amount = $shipping->get_total(); 106 $seller_id = $shipping->get_meta('seller_id'); 107 108 if (!$seller_id) 109 continue; 110 111 $sellers_shipping_cost[$seller_id] = $shipping_cost_amount; 112 } 113 114 $items_per_seller = []; 115 116 foreach ($items as $key => $item) { 117 $item_id = $item->get_product_id(); 118 $seller_id = get_post_field('post_author', $item_id); 119 $price_item = $item->get_total(); 120 121 if (!isset($items_per_seller[$seller_id])) { 122 $items_per_seller[$seller_id] = 0; 123 } 124 125 $items_per_seller[$seller_id] += $price_item; 126 } 127 128 foreach ($items_per_seller as $seller_id => $total) { 129 130 if ($this->gateway->settings['dokan_shipping_commission'] == 'yes') { 131 $shipping_cost_amount = isset($sellers_shipping_cost[$seller_id]) ? $sellers_shipping_cost[$seller_id] : 0; 132 $total += $shipping_cost_amount; 133 } 134 135 $admin_commission_percentage = dokan_get_option('admin_percentage', 'dokan_selling', '10'); 136 $admin_commission_total = ($total / 100) * $admin_commission_percentage; 137 138 $seller_commission_total = $total - $admin_commission_total; 139 if (!isset($split_data[$seller_id])) $split_data[$seller_id] = 0; 140 $split_data[$seller_id] += $seller_commission_total; 141 } 142 143 if ($this->gateway->settings['dokan_shipping_commission'] != 'yes') { 144 foreach ($sellers_shipping_cost as $seller_id => $total) { 145 if (!isset($split_data[$seller_id])) 146 continue; 147 $split_data[$seller_id] += $total; 148 } 149 } 150 151 if ($split_data) { 152 foreach ($split_data as $item_seller_id => $item_value) { 153 $seller_data = get_userdata($item_seller_id); 154 155 $seller_cpf = get_user_meta($item_seller_id, 'billing_cpf', true); 156 $seller_cnpj = get_user_meta($item_seller_id, 'billing_cnpj', true); 157 $identity = $seller_cnpj ? $seller_cnpj : $seller_cpf; 158 159 $split = [ 160 'Name' => $seller_data->first_name . ' ' . isset($seller_data->last_name), 161 'Identity' => preg_replace('([^0-9])', '', $identity), 162 'Amount' => $item_value, 163 'IsPayTax' => $is_pay_tax, 164 'CodeReceiverType' => '1', 165 'CodeTaxType' => '2' 166 ]; 167 168 $splits[] = $split; 169 } 170 } 171 } 172 173 return $splits; 174 } 175 176 protected function get_payload($order, $posted, $IsSandbox) 177 { 178 $method = isset($posted['safe2pay_payment_method']) ? $this->GetPaymentMethod($posted['safe2pay_payment_method']) : ''; 179 $woo = new WooCommerce(); 180 $PaymentObject = null; 181 182 $Products = array( 183 (object)array( 184 'Code' => 1, 185 'Description' => "Pedido #" . $order->get_id(), 186 'Quantity' => 1, 187 'UnitPrice' => $order->get_total() 188 ) 189 ); 190 191 switch ($method) { 192 case 'bankslip': 193 194 $paymentMethod = "1"; 195 $PaymentObject = $this->gateway->GetBankSlipConfig(); 196 197 break; 198 case 'creditcard': 199 $paymentMethod = "2"; 200 201 $PaymentObject = array( 202 'Holder' => sanitize_text_field($posted['safe2pay-card-holder-name']), 203 'CardNumber' => sanitize_text_field($posted['safe2pay-card-number']), 204 'ExpirationDate' => sanitize_text_field($posted['safe2pay-card-expiry-field']), 205 'SecurityCode' => sanitize_text_field($posted['safe2pay-card-cvc']) 206 ); 207 208 $installment = isset($posted['safe2pay_card_installments']) ? absint($posted['safe2pay_card_installments']) : 1; 209 210 if (!empty($posted['safe2pay_card_installments'])) { 211 $PaymentObject['InstallmentQuantity'] = $installment; 212 } 213 214 $interest_rates = isset($posted['tc_interest_rate']) ? explode(';', $posted['tc_interest_rate']) : array_fill(0, $installment, 0); 215 $interest_rate = isset($interest_rates[$installment - 1]) ? floatval($interest_rates[$installment - 1]) : 0; 216 217 if ($interest_rate > 0) { 218 $PaymentObject['IsApplyInterest'] = true; 219 $PaymentObject['InterestRate'] = floatval($interest_rate); 220 } 221 222 break; 223 case 'cryptocurrency': 224 $paymentMethod = "3"; 225 break; 226 case 'pix': 227 $paymentMethod = "6"; 228 break; 229 default: 230 return [ 231 'url' => '', 232 'data' => '', 233 'error' => 'Método de pagamento não selecionado', 234 ]; 235 }; 236 237 $identity = null; 238 239 if (!empty($posted['billing_cpf'])) { 240 $identity = sanitize_text_field($posted['billing_cpf']); 241 } else if (!empty($posted['billing_cnpj'])) { 242 $identity = sanitize_text_field($posted['billing_cnpj']); 243 } else if (!empty($posted['customer_identity'])) { 244 $identity = sanitize_text_field($posted['customer_identity']); 245 } 246 247 $payload = [ 248 'IsSandbox' => $IsSandbox, 249 'Application' => 'WooCommerce v' . $woo->version, 250 'PaymentMethod' => $paymentMethod, 251 'PaymentObject' => $PaymentObject, 252 'Reference' => $order->get_id(), 253 'IpAddress' => WC_Geolocation::get_ip_address(), 254 'Products' => $Products, 255 'Customer' => [ 256 "Name" => sanitize_text_field($posted['billing_first_name'] . ' ' . $posted['billing_last_name']), 257 "Identity" => $identity, 258 "Phone" => sanitize_text_field($posted['billing_phone']), 259 "Email" => sanitize_text_field($posted['billing_email']), 260 "Address" => [ 261 "Street" => sanitize_text_field($posted['billing_address_1']), 262 "Number" => sanitize_text_field(isset($posted['billing_number']) ? $posted['billing_number'] : 'S/N'), 263 "District" => sanitize_text_field(isset($posted['billing_neighborhood']) ? $posted['billing_neighborhood'] : 'Não informado'), 264 "ZipCode" => sanitize_text_field($posted['billing_postcode']), 265 "CityName" => sanitize_text_field($posted['billing_city']), 266 "StateInitials" => sanitize_text_field($posted['billing_state']), 267 "CountryName" => sanitize_text_field(isset($posted['billing_country']) ? $posted['billing_country'] : 'Brasil') 268 ] 269 ], 270 'CallbackUrl' => $this->get_callback_uri($order->get_id()) 271 ]; 272 273 if (is_plugin_active('dokan-lite/dokan.php') || is_plugin_active('dokan-pro/dokan-pro.php')) { 274 if ($this->gateway->settings['dokan_enable_split'] == 'yes') { 275 $splits = $this->set_split_data($order); 276 $payload['Splits'] = $splits; 277 } 278 } 279 280 return json_encode($payload); 281 } 282 283 public function CheckoutController($order, $posted) 284 { 285 try { 286 $IsSandbox = strtoupper($this->gateway->settings['sandbox']) !== "NO"; 287 288 $payload = $this->get_payload($order, $posted, $IsSandbox); 289 290 if ('yes' == $this->gateway->debug) { 291 $this->gateway->log->add($this->gateway->id, 'Requesting token for order ' . $order->get_order_number()); 292 } 293 294 $token = strtoupper($this->gateway->settings['sandbox']) !== "NO" ? $this->gateway->sandbox_token : $this->gateway->token; 295 296 $response = $this->HttpClient($this->GetPaymentURI(), 'POST', $payload, array('Content-Type' => 'application/json', 'X-API-KEY' => $token)); 297 298 if ($response['response']['code'] === 200) { 299 300 $response = json_decode($response["body"]); 301 302 if ($response->HasError == false) { 303 return array( 304 'url' => $this->gateway->GetPaymentURI(), 305 'data' => $response, 306 'error' => '', 307 ); 308 } 309 } else if ($response['response']['code'] === 401) { 310 311 if ('yes' == $this->gateway->debug) { 312 $this->gateway->log->add($this->gateway->id, 'Invalid token and/or email settings!'); 313 } 314 315 return array( 316 'url' => '', 317 'data' => '', 318 'error' => array(__('Too bad! The email or token from the Safe2Pay are invalids my little friend!', 'woo-safe2pay')), 319 ); 320 } else { 321 wc_add_notice(__('Erro ', 'woo-safe2pay') . $response->ErrorCode . ' - ' . $response->Error, 'error'); 322 } 323 } catch (Exception $e) { 324 325 return array( 326 'url' => '', 327 'token' => '', 328 'error' => array('<strong>' . __('Safe2Pay', 'woo-safe2pay') . '</strong>: ' . __('An error has occurred while processing your payment, please try again. Or contact us for assistance.', 'woo-safe2pay')), 329 ); 330 } 331 } 332 333 public function PaymentController($order, $posted) 334 { 335 $payment_method = isset($posted['safe2pay_payment_method']) ? $posted['safe2pay_payment_method'] : ''; 336 337 $IsSandbox = strtoupper($this->gateway->settings['sandbox']) !== "NO"; 338 339 $payload = $this->get_payload($order, $posted, $IsSandbox); 340 341 if ('yes' == $this->gateway->debug) { 342 $this->gateway->log->add($this->gateway->id, 'Requesting direct payment for order ' . $order->get_order_number()); 343 } 344 345 $token = strtoupper($this->gateway->settings['sandbox']) !== "NO" ? $this->gateway->sandbox_token : $this->gateway->token; 346 347 $response = $this->HttpClient($this->GetPaymentURI(), 'POST', $payload, array('Content-Type' => 'application/json', 'X-API-KEY' => $token)); 348 349 if (is_wp_error($response)) { 350 if ('yes' == $this->gateway->debug) { 351 $this->gateway->log->add($this->gateway->id, 'WP_Error in requesting the direct payment:'); 352 } 353 } else if (401 === $response['response']['code']) { 354 if ('yes' == $this->gateway->debug) { 355 $this->gateway->log->add($this->gateway->id, 'The user does not have permissions to use the Safe2Pay Transparent Checkout!'); 356 } 357 358 return array( 359 'url' => '', 360 'data' => '', 361 'error' => array(__('You are not allowed to use the Safe2Pay Transparent Checkout. Looks like you neglected to installation guide of this plugin. This is not pretty, do you know?', 'woo-safe2pay')), 362 ); 363 } else { 364 try { 365 $response = json_decode($response["body"]); 366 367 if ( $response->HasError == true ) { 368 if ( $this->gateway->debug == 'yes' ) { 369 $this->gateway->log->add( $this->gateway->id, print_r($response, true ) ); 370 } 371 372 wc_add_notice( __( 'Erro: ', 'woo-safe2pay' ) . $response->ErrorCode . ' - ' . $response->Error, 'error' ); 373 } else if ( $response->ResponseDetail->Status == 6 || $response->ResponseDetail->Status == 8 ) { 374 if ( $this->gateway->debug == 'yes' ) { 375 $this->gateway->log->add( $this->gateway->id, 'Erro no pedido ' . $order->get_order_number() . ' com a seguinte responsta: ' . print_r($response, true ) ); 376 } 377 378 wc_add_notice( __( 'Erro: ', 'woo-safe2pay' ) . $response->ResponseDetail->Message, 'error' ); 379 } else { 380 if ( $this->gateway->debug == 'yes' ) { 381 $this->gateway->log->add( $this->gateway->id, 'Transação ' . $response->ResponseDetail->IdTransaction . ' gerada para o pedido ' . $order->get_order_number() . ' com o seguinte conteúdo: ' . print_r($response, true ) ); 382 } 383 384 return array( 385 'url' => $this->gateway->get_return_url( $order ), 386 'data' => $response->ResponseDetail, 387 'error' => '', 388 ); 389 } 390 } catch (Exception $e) { 391 $data = ''; 392 393 if ('yes' == $this->gateway->debug) { 394 $this->gateway->log->add($this->gateway->id, 'Error while parsing the Safe2Pay response: ' . print_r($e->getMessage(), true)); 395 } 396 } 397 } 398 } 399 400 public function get_direct_payment_url() 401 { 402 return 'https://payment.safe2pay.com.br/v2/Payment'; 403 } 371 404 } -
safe2pay/trunk/includes/class-wc-safe2pay-gateway.php
r2165817 r2881978 1 1 <?php 2 2 3 /** 4 * Safe2Pay Gateway class 5 * 6 * @package WooCommerce_Safe2Pay/Classes/Gateway 7 * @version 2.13.0 8 */ 9 10 11 if (!defined('ABSPATH')) { 3 if ( ! defined( 'ABSPATH' ) ) { 12 4 exit; 13 5 } 14 6 15 /** 16 * Safe2Pay gateway. 17 */ 18 class WC_Safe2Pay_Gateway extends WC_Payment_Gateway 19 { 20 21 /** 22 * Constructor for the gateway. 23 */ 24 public function __construct() 25 { 7 class WC_Safe2Pay_Gateway extends WC_Payment_Gateway { 8 public function __construct() { 26 9 $this->id = 'safe2pay'; 27 $this->icon = apply_filters('woocommerce_safe2pay_icon', plugins_url('assets/images/safe2pay.png', plugin_dir_path(__FILE__))); 28 $this->method_title = __('Safe2Pay', 'woo-safe2pay'); 29 $this->method_description = __('Accept payments by credit card, bank debit or banking ticket using the Safe2Pay.', 'woo-safe2pay'); 30 $this->order_button_text = __('Finalizar', 'woo-safe2pay'); 31 32 // Load the form fields. 10 $this->icon = apply_filters( 'woocommerce_safe2pay_icon', plugins_url( 'assets/images/safe2pay.png', plugin_dir_path( __FILE__ ) ) ); 11 $this->method_title = __( 'Safe2Pay', 'woo-safe2pay' ); 12 $this->method_description = __( 'Aceite pagamentos por boleto, cartões de crédito e Pix pelo Safe2Pay.', 'woo-safe2pay' ); 13 $this->order_button_text = __( 'Finalizar', 'woo-safe2pay' ); 14 33 15 $this->init_form_fields(); 34 35 // Load the settings.36 16 $this->init_settings(); 37 17 38 // Define user set variables. 39 $this->title = $this->get_option('title'); 40 $this->description = $this->get_option('description'); 41 $this->secretkey = $this->get_option('secretkey'); 42 $this->token = $this->get_option('token'); 43 $this->sandbox_secretkey = $this->get_option('sandbox_secretkey'); 44 $this->sandbox_token = $this->get_option('sandbox_token'); 45 $this->method = $this->get_option('method', 'direct'); 46 $this->tc_credit = $this->get_option('tc_credit', 'no'); 47 $this->tc_debit = $this->get_option('tc_debit', 'no'); 48 $this->tc_ticket = $this->get_option('tc_ticket', 'no'); 49 $this->tc_cryptocurrency = $this->get_option('tc_cryptocurrency', 'no'); 50 $this->invoice_prefix = $this->get_option('invoice_prefix', 'WC-'); 51 $this->sandbox = $this->get_option('sandbox', 'no'); 52 $this->debug = $this->get_option('debug'); 53 $this->instruction = $this->get_option('instruction'); 54 $this->message1 = $this->get_option('message1'); 55 $this->message2 = $this->get_option('message2'); 56 $this->message3 = $this->get_option('message3'); 57 $this->duedate = $this->get_option('duedate'); 58 $this->cancelAfterDue = $this->get_option('cancelAfterDue'); 59 $this->penaltyRate = $this->get_option('penaltyRate'); 60 $this->interestRate = $this->get_option('interestRate'); 61 $this->isEnablePartialPayment = $this->get_option('isEnablePartialPayment'); 62 63 // Active logs. 64 if ('yes' === $this->debug) { 65 if (function_exists('wc_get_logger')) { 18 $this->title = $this->get_option( 'title' ); 19 $this->description = $this->get_option( 'description' ); 20 $this->secretkey = $this->get_option( 'secretkey' ); 21 $this->token = $this->get_option( 'token' ); 22 $this->sandbox_secretkey = $this->get_option( 'sandbox_secretkey' ); 23 $this->sandbox_token = $this->get_option( 'sandbox_token' ); 24 $this->method = $this->get_option( 'method', 'direct' ); 25 $this->tc_credit = $this->get_option( 'tc_credit', 'no' ); 26 $this->tc_installments = $this->get_option( 'tc_installments' ); 27 $this->tc_minimum_installment_amount = $this->get_option( 'tc_minimum_installment_amount' ); 28 $this->tc_interest_rate = $this->get_option( 'tc_interest_rate' ); 29 $this->tc_pix = $this->get_option( 'tc_pix', 'no' ); 30 $this->tc_ticket = $this->get_option( 'tc_ticket', 'no' ); 31 $this->tc_cryptocurrency = $this->get_option( 'tc_cryptocurrency', 'no' ); 32 $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' ); 33 $this->sandbox = $this->get_option( 'sandbox', 'no' ); 34 $this->debug = $this->get_option( 'debug' ); 35 $this->instruction = $this->get_option( 'instruction' ); 36 $this->message1 = $this->get_option( 'message1' ); 37 $this->message2 = $this->get_option( 'message2' ); 38 $this->message3 = $this->get_option( 'message3' ); 39 $this->duedate = $this->get_option( 'duedate' ); 40 $this->cancelAfterDue = $this->get_option( 'cancelAfterDue' ); 41 $this->penaltyRate = $this->get_option( 'penaltyRate' ); 42 $this->interestRate = $this->get_option( 'interestRate' ); 43 $this->isEnablePartialPayment = $this->get_option( 'isEnablePartialPayment' ); 44 $this->discount_bank_slip = $this->get_option( 'discount_bank_slip' ); 45 $this->discount_amount_bank_slip = $this->get_option( 'discount_amount_bank_slip' ); 46 $this->dokan_enable_split = $this->get_option( 'dokan_enable_split' ); 47 $this->dokan_shipping_commission = $this->get_option( 'dokan_shipping_commission' ); 48 $this->dokan_receiver_pay_tax = $this->get_option( 'dokan_receiver_pay_tax' ); 49 50 if ( 'yes' === $this->debug ) { 51 if ( function_exists( 'wc_get_logger' ) ) { 66 52 $this->log = wc_get_logger(); 67 53 } else { … … 70 56 } 71 57 72 // Set the API. 73 $this->api = new WC_Safe2Pay_API($this); 58 $this->api = new WC_Safe2Pay_API( $this ); 74 59 75 60 add_action('valid_safe2pay_ipn_request', array($this, 'update_order_status')); … … 77 62 add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page')); 78 63 79 // Transparent checkout actions. 80 if ('transparent' === $this->method) { 81 add_action('woocommerce_thankyou_' . $this->id, array($this, 'thankyou_page')); 82 add_action('woocommerce_email_after_order_table', array($this, 'email_instructions'), 10, 3); 83 add_action('wp_enqueue_scripts', array($this, 'checkout_scripts')); 84 } 85 } 86 87 88 /** 89 * Returns a bool that indicates if currency is amongst the supported ones. 90 * 91 * @return bool 92 */ 93 public function using_supported_currency() 94 { 64 // add_action('woocommerce_thankyou_' . $this->id, array($this, 'thankyou_page')); 65 add_action('woocommerce_order_details_after_order_table', array($this, 'thankyou_page')); 66 67 add_action('woocommerce_email_after_order_table', array($this, 'email_instructions'), 10, 3); 68 add_action('wp_enqueue_scripts', array($this, 'checkout_scripts')); 69 } 70 71 public function using_supported_currency() { 95 72 return 'BRL' === get_woocommerce_currency(); 96 73 } 97 74 98 /** 99 * Get token. 100 * 101 * @return string 102 */ 103 public function GetAPIKEY() 104 { 75 public function GetAPIKEY() { 105 76 return 'yes' === $this->sandbox ? $this->sandbox_token : $this->token; 106 77 } 107 78 108 public function IsNullOrEmptyString($str) 109 { 110 return (!isset($str) || trim($str) === ''); 111 } 112 113 /** 114 * Get DueDate Days. 115 * 116 * @return int 117 */ 118 public function GetBankSlipConfig() 119 { 120 79 public function IsNullOrEmptyString( $str ) { 80 return ( ! isset( $str ) || trim( $str ) === '' ); 81 } 82 83 public function GetBankSlipConfig() { 121 84 $dueDateConfig = new DateTime(); 122 $dueDateConfig = $dueDateConfig->add(new DateInterval('P' . ($this->duedate >= 1 ? $this->duedate : 3) . 'D'))->format('Y-m-d'); 123 124 125 $Instruction = isset($this->instruction) ? $this->instruction : null; 126 $IsEnableParcialPayment = $this->isEnablePartialPayment == "yes" ? true : false; 127 $CancelAfterDue = $this->cancelAfterDue == "yes" ? true : false; 128 $DueDate = $dueDateConfig; 129 $PenaltyRate = floatval(($this->penaltyRate > 0 ? $this->penaltyRate : 0)); 130 $InterestRate = floatval(($this->interestRate > 0 ? $this->interestRate : 0)); 85 $dueDateConfig = $dueDateConfig->add( new DateInterval( 'P' . ( $this->duedate >= 1 ? $this->duedate : 3 ) . 'D' ) )->format( 'Y-m-d' ); 86 87 $Instruction = isset( $this->instruction ) ? $this->instruction : null; 88 $IsEnablePartialPayment = $this->isEnablePartialPayment == "yes" ? true : false; 89 $CancelAfterDue = $this->cancelAfterDue == "yes" ? true : false; 90 $DueDate = $dueDateConfig; 91 $PenaltyRate = floatval( ( $this->penaltyRate > 0 ? $this->penaltyRate : 0 ) ); 92 $InterestRate = floatval( ( $this->interestRate > 0 ? $this->interestRate : 0 ) ); 131 93 132 94 $Messages = array(); 133 95 134 if (!$this->IsNullOrEmptyString($this->message1)) { 135 array_push($Messages, $this->message1); 136 } 137 138 if (!$this->IsNullOrEmptyString($this->message2)) { 139 array_push($Messages, $this->message2); 140 } 141 142 if (!$this->IsNullOrEmptyString($this->message3)) { 143 array_push($Messages, $this->message3); 144 } 145 146 $BankSlipSetting = (object) array( 147 "DueDate" => $DueDate, 148 "Instruction" => $Instruction, 149 "Message" => $Messages, 150 "PenaltyRate" => $PenaltyRate, 151 "InterestRate" => $InterestRate, 152 "CancelAfterDue" => $CancelAfterDue, 153 "IsEnablePartialPayment" => $IsEnableParcialPayment 154 96 if ( ! $this->IsNullOrEmptyString( $this->message1 ) ) { 97 array_push( $Messages, $this->message1 ); 98 } 99 100 if ( ! $this->IsNullOrEmptyString( $this->message2 ) ) { 101 array_push( $Messages, $this->message2 ); 102 } 103 104 if ( ! $this->IsNullOrEmptyString( $this->message3 ) ) { 105 array_push( $Messages, $this->message3 ); 106 } 107 108 $BankSlipSetting = array( 109 "DueDate" => $DueDate, 110 "Instruction" => $Instruction, 111 "Message" => $Messages, 112 "PenaltyRate" => $PenaltyRate, 113 "InterestRate" => $InterestRate, 114 "CancelAfterDue" => $CancelAfterDue, 115 "IsEnablePartialPayment" => $IsEnablePartialPayment 155 116 ); 156 117 118 if ( $this->discount_bank_slip == "yes" && isset( $this->discount_amount_bank_slip ) ) { 119 $order_total = $this->get_order_total(); 120 121 $discount_percentage = $this->discount_amount_bank_slip; 122 $discount_amount = ( $order_total / 100 ) * $discount_percentage; 123 124 $BankSlipSetting['DiscountDue'] = $dueDateConfig; 125 $BankSlipSetting['DiscountType'] = '1'; 126 $BankSlipSetting['DiscountAmount'] = $discount_amount; 127 } 128 157 129 return $BankSlipSetting; 158 130 } 159 131 160 /** 161 * Returns a value indicating the the Gateway is available or not. It's called 162 * automatically by WooCommerce before allowing customers to use the gateway 163 * for payment. 164 * 165 * @return bool 166 */ 167 public function IsAvailable() 168 { 169 // Test if is valid for use. 170 $available = 'yes' === $this->get_option('enabled') && $this->using_supported_currency(); 171 return $available; 172 } 173 174 /** 175 * Checkout scripts. 176 */ 177 public function checkout_scripts() 178 { 179 if ($this->IsAvailable()) { 180 if (!get_query_var('order-received')) {; 181 wp_enqueue_style('safe2pay-checkout', plugins_url('assets/css/frontend/transparent-checkout.css', plugin_dir_path(__FILE__)), array(), WC_SAFE2PAY_VERSION); 182 wp_enqueue_script('safe2pay-checkout', plugins_url('assets/js/frontend/transparent-checkout.js', plugin_dir_path(__FILE__)), array('jquery', 'safe2pay-library'), WC_SAFE2PAY_VERSION, true); 183 184 wp_enqueue_script('safe2pay-library', $this->api->get_direct_payment_url(), array(), WC_SAFE2PAY_VERSION, true); 132 public function IsAvailable() { 133 return 'yes' === $this->get_option( 'enabled' ) && $this->using_supported_currency(); 134 } 135 136 public function checkout_scripts() { 137 if ( $this->IsAvailable() ) { 138 if ( ! get_query_var( 'order-received' ) ) { 139 wp_enqueue_style( 'safe2pay-checkout', plugins_url( 'assets/css/frontend/transparent-checkout.css', plugin_dir_path( __FILE__ ) ), array(), WC_SAFE2PAY_VERSION ); 140 wp_enqueue_script( 'safe2pay-checkout', plugins_url( 'assets/js/frontend/transparent-checkout.js', plugin_dir_path( __FILE__ ) ), array( 141 'jquery', 142 'safe2pay-library' 143 ), WC_SAFE2PAY_VERSION, true ); 144 145 wp_enqueue_script( 'safe2pay-library', $this->api->get_direct_payment_url(), array(), WC_SAFE2PAY_VERSION, true ); 185 146 186 147 wp_localize_script( … … 188 149 'wc_safe2pay_params', 189 150 array( 190 'interest_free' => __( 'interest free', 'woo-safe2pay'),191 'invalid_card' => __( 'Invalid credit card number.', 'woo-safe2pay'),192 'invalid_expiry' => __( 'Invalid expiry date, please use the MM / YYYY date format.', 'woo-safe2pay'),193 'expired_date' => __( 'Please check the expiry date and use a valid format as MM / YYYY.', 'woo-safe2pay'),194 'general_error' => __( 'Unable to process the data from your credit card on the Safe2Pay, please try again or contact us for assistance.', 'woo-safe2pay'),195 'empty_installments' => __( 'Select a number of installments.', 'woo-safe2pay'),151 'interest_free' => __( 'interest free', 'woo-safe2pay' ), 152 'invalid_card' => __( 'Número de cartão inválido.', 'woo-safe2pay' ), 153 'invalid_expiry' => __( 'Data de expiração inválida, use o formato MM / AAAA.', 'woo-safe2pay' ), 154 'expired_date' => __( 'Por favor, preencha a data no formato MM / AAAA.', 'woo-safe2pay' ), 155 'general_error' => __( 'Não foi possível processar sua compra com os dados fornecidos, entre em contato para maiores informações.', 'woo-safe2pay' ), 156 'empty_installments' => __( 'Selecione a quantidade de parcelas.', 'woo-safe2pay' ), 196 157 ) 197 158 ); … … 200 161 } 201 162 202 protected function get_log_view() 203 { 204 if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.2', '>=')) { 205 return '<a href="' . esc_url(admin_url('admin.php?page=wc-status&tab=logs&log_file=' . esc_attr($this->id) . '-' . sanitize_file_name(wp_hash($this->id)) . '.log')) . '">' . __('System Status > Logs', 'woo-safe2pay') . '</a>'; 206 } 207 208 return '<code>woocommerce/logs/' . esc_attr($this->id) . '-' . sanitize_file_name(wp_hash($this->id)) . '.txt</code>'; 209 } 210 211 public function init_form_fields() 212 { 163 protected function get_log_view() { 164 if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.2', '>=' ) ) { 165 return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' . esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' . __( 'System Status > Logs', 'woo-safe2pay' ) . '</a>'; 166 } 167 168 return '<code>woocommerce/logs/' . esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.txt</code>'; 169 } 170 171 public function init_form_fields() { 213 172 $this->form_fields = array( 214 'enabled' => array(215 'title' => __( 'Ativar/Desativar', 'woo-safe2pay'),173 'enabled' => array( 174 'title' => __( 'Ativar/Desativar', 'woo-safe2pay' ), 216 175 'type' => 'checkbox', 217 'label' => __( 'Ativar Safe2Pay', 'woo-safe2pay'),218 'default' => 'yes' ,219 ), 220 'title' => array(221 'title' => __( 'Título', 'woo-safe2pay'),222 'type' => 'text', 223 'description' => __( 'Título do método de pagamento', 'woo-safe2pay'),176 'label' => __( 'Ativar Safe2Pay', 'woo-safe2pay' ), 177 'default' => 'yes' 178 ), 179 'title' => array( 180 'title' => __( 'Título', 'woo-safe2pay' ), 181 'type' => 'text', 182 'description' => __( 'Título do método de pagamento', 'woo-safe2pay' ), 224 183 'desc_tip' => true, 225 'default' => __( 'Safe2Pay', 'woo-safe2pay'),226 ), 227 'description' => array(228 'title' => __( 'Descrição do método de pagamento', 'woo-safe2pay'),184 'default' => __( 'Safe2Pay', 'woo-safe2pay' ) 185 ), 186 'description' => array( 187 'title' => __( 'Descrição do método de pagamento', 'woo-safe2pay' ), 229 188 'type' => 'textarea', 230 'description' => __( 'Descrição do método de pagamento durante o checkout.', 'woo-safe2pay'),231 'default' => __( 'Pagar via Safe2Pay', 'woo-safe2pay'),232 ), 233 'integration' => array(234 'title' => __( 'Integração', 'woo-safe2pay'),189 'description' => __( 'Descrição do método de pagamento durante o checkout.', 'woo-safe2pay' ), 190 'default' => __( 'Pagar via Safe2Pay', 'woo-safe2pay' ), 191 ), 192 'integration' => array( 193 'title' => __( 'Integração', 'woo-safe2pay' ), 235 194 'type' => 'title', 236 'description' => '' ,237 ), 238 'method' => array(239 'title' => __( 'Método de integração', 'woo-safe2pay'),195 'description' => '' 196 ), 197 'method' => array( 198 'title' => __( 'Método de integração', 'woo-safe2pay' ), 240 199 'type' => 'select', 241 'description' => __( 'Choose how the customer will interact with the Safe2Pay. Redirect (Client goes to Safe2Pay page) or Lightbox (Inside your store)', 'woo-safe2pay'),200 'description' => __( 'Choose how the customer will interact with the Safe2Pay. Redirect (Client goes to Safe2Pay page) or Lightbox (Inside your store)', 'woo-safe2pay' ), 242 201 'desc_tip' => true, 243 202 'default' => 'direct', 244 203 'class' => 'wc-enhanced-select', 245 204 'options' => array( 246 'transparent' => __( 'Transparent Checkout', 'woo-safe2pay'),247 ) ,248 ), 249 'sandbox' => array(250 'title' => __( 'Safe2Pay Sandbox', 'woo-safe2pay'),205 'transparent' => __( 'Transparent Checkout', 'woo-safe2pay' ) 206 ) 207 ), 208 'sandbox' => array( 209 'title' => __( 'Safe2Pay Sandbox', 'woo-safe2pay' ), 251 210 'type' => 'checkbox', 252 'label' => __( 'Ativar/Desativar Safe2Pay Sandbox', 'woo-safe2pay'),211 'label' => __( 'Ativar/Desativar Safe2Pay Sandbox', 'woo-safe2pay' ), 253 212 'desc_tip' => true, 254 213 'default' => 'no', 255 'description' => __('Safe2Pay Sandbox pode ser utilizado para testes de pagamento.', 'woo-safe2pay'), 256 ), 257 'token' => array( 258 'title' => __('Safe2Pay Token', 'woo-safe2pay'), 259 'type' => 'text', 260 /* translators: %s: link to Safe2Pay settings */ 261 'description' => sprintf(__('Insira seu Token aqui. Isso é necessário para processar os pagamentos.', 'woo-safe2pay'), '<a href="https://admin.safe2pay.com.br/integracao">' . __('here', 'woo-safe2pay') . '</a>'), 262 'default' => '', 263 ), 264 'secretkey' => array( 265 'title' => __('Safe2Pay SecretKey', 'woo-safe2pay'), 266 'type' => 'text', 267 /* translators: %s: link to Safe2Pay settings */ 268 'description' => sprintf(__('Insira sua Secret Key aqui. Isso é necessário para receber notificações de mudanças de status do pagamento.', 'woo-safe2pay'), '<a href="https://admin.safe2pay.com.br/integracao">' . __('here', 'woo-safe2pay') . '</a>'), 269 'default' => '', 270 ), 271 'sandbox_token' => array( 272 'title' => __('Safe2Pay Sandbox Token', 'woo-safe2pay'), 273 'type' => 'text', 274 /* translators: %s: link to Safe2Pay settings */ 275 'description' => sprintf(__('Insira seu Token de Sandbox aqui. Isso é necessário para processar os pagamentos em ambiente de teste.', 'woo-safe2pay'), '<a href=https://admin.safe2pay.com.br/integracao">' . __('here', 'woo-safe2pay') . '</a>'), 276 'default' => '', 277 ), 278 'sandbox_secretkey' => array( 279 'title' => __('Safe2Pay Sandbox SecretKey', 'woo-safe2pay'), 280 'type' => 'text', 281 /* translators: %s: link to Safe2Pay settings */ 282 'description' => sprintf(__('Insira sua Secret Key de Sandbox aqui. Isso é necessário para receber notificações de mudança de status do pagamento em ambiente de teste.', 'woo-safe2pay'), '<a href="https://admin.safe2pay.com.br/integracao">' . __('here', 'woo-safe2pay') . '</a>'), 283 'default' => '', 284 ), 285 'transparent_checkout' => array( 286 'title' => __('Opções de pagamento', 'woo-safe2pay'), 214 'description' => __( 'Safe2Pay Sandbox pode ser utilizado para testes de pagamento.', 'woo-safe2pay' ) 215 ), 216 'token' => array( 217 'title' => __( 'Safe2Pay Token', 'woo-safe2pay' ), 218 'type' => 'text', 219 'description' => sprintf( __( 'Insira seu Token aqui. Isso é necessário para processar os pagamentos.', 'woo-safe2pay' ), '<a href="https://admin.safe2pay.com.br/integracao">' . __( 'here', 'woo-safe2pay' ) . '</a>' ), 220 'default' => '' 221 ), 222 'secretkey' => array( 223 'title' => __( 'Safe2Pay SecretKey', 'woo-safe2pay' ), 224 'type' => 'text', 225 'description' => sprintf( __( 'Insira sua Secret Key aqui. Isso é necessário para receber notificações de mudanças de status do pagamento.', 'woo-safe2pay' ), '<a href="https://admin.safe2pay.com.br/integracao">' . __( 'here', 'woo-safe2pay' ) . '</a>' ), 226 'default' => '' 227 ), 228 'sandbox_token' => array( 229 'title' => __( 'Safe2Pay Sandbox Token', 'woo-safe2pay' ), 230 'type' => 'text', 231 'description' => sprintf( __( 'Insira seu Token de Sandbox aqui. Isso é necessário para processar os pagamentos em ambiente de teste.', 'woo-safe2pay' ), '<a href=https://admin.safe2pay.com.br/integracao">' . __( 'here', 'woo-safe2pay' ) . '</a>' ), 232 'default' => '' 233 ), 234 'sandbox_secretkey' => array( 235 'title' => __( 'Safe2Pay Sandbox SecretKey', 'woo-safe2pay' ), 236 'type' => 'text', 237 'description' => sprintf( __( 'Insira sua Secret Key de Sandbox aqui. Isso é necessário para receber notificações de mudança de status do pagamento em ambiente de teste.', 'woo-safe2pay' ), '<a href="https://admin.safe2pay.com.br/integracao">' . __( 'here', 'woo-safe2pay' ) . '</a>' ), 238 'default' => '' 239 ), 240 'transparent_checkout' => array( 241 'title' => __( 'Opções de pagamento', 'woo-safe2pay' ), 287 242 'type' => 'title', 288 'description' => '' ,289 ), 290 'tc_ ticket'=> array(291 'title' => __( 'Boleto Bancário', 'woo-safe2pay'),243 'description' => '' 244 ), 245 'tc_pix' => array( 246 'title' => __( 'Pix', 'woo-safe2pay' ), 292 247 'type' => 'checkbox', 293 'label' => __('Boleto Bancário', 'woo-safe2pay'), 294 'default' => 'yes', 295 ), 296 'duedate' => array( 297 'title' => __('Data de vencimento', 'woo-safe2pay'), 248 'label' => __( 'Pix', 'woo-safe2pay' ), 249 'default' => 'yes' 250 ), 251 'tc_ticket' => array( 252 'title' => __( 'Boleto Bancário', 'woo-safe2pay' ), 253 'type' => 'checkbox', 254 'label' => __( 'Boleto Bancário', 'woo-safe2pay' ), 255 'default' => 'yes' 256 ), 257 'duedate' => array( 258 'title' => __( 'Data de vencimento', 'woo-safe2pay' ), 298 259 'type' => 'number', 299 'description' => __('Número de dias para vencimento do boleto Bancário.', 'woo-safe2pay'), 300 'default' => 3, 301 ), 302 'instruction' => array( 303 'title' => __('Instrução', 'woo-safe2pay'), 304 'type' => 'text', 305 'description' => __('Instrução do boleto bancário.', 'woo-safe2pay'), 306 'default' => '', 307 ), 308 'message1' => array( 309 'title' => __('Mensagem 1', 'woo-safe2pay'), 310 'type' => 'text', 311 'description' => __('Mensagem 1 impressa no boleto bancário.', 'woo-safe2pay'), 312 'default' => '', 313 ), 314 'message2' => array( 315 'title' => __('Mensagem 2', 'woo-safe2pay'), 316 'type' => 'text', 317 'description' => __('Mensagem 3 impressa no boleto bancário.', 'woo-safe2pay'), 318 'default' => '', 319 ), 320 'message3' => array( 321 'title' => __('Mensagem 3', 'woo-safe2pay'), 322 'type' => 'text', 323 'description' => __('Mensagem 3 impressa no boleto bancário.', 'woo-safe2pay'), 324 'default' => '', 325 ), 326 'cancelAfterDue' => array( 327 'title' => __('Cancelar após o vencimento', 'woo-safe2pay'), 260 'description' => __( 'Número de dias para vencimento do boleto Bancário.', 'woo-safe2pay' ), 261 'default' => 3 262 ), 263 'discount_bank_slip' => array( 264 'title' => __( 'Conceder desconto no boleto', 'woo-safe2pay' ), 328 265 'type' => 'checkbox', 329 'description' => __('Cancelar boleto bancário após o vencimento.', 'woo-safe2pay'), 330 'default' => false, 331 ), 332 'isEnablePartialPayment' => array( 333 'title' => __('Pagamento parcial', 'woo-safe2pay'), 266 'description' => __( 'Oferecer desconto no pagamento por boleto.', 'woo-safe2pay' ), 267 'default' => 'no' 268 ), 269 'discount_amount_bank_slip' => array( 270 'title' => __( 'Percentual de desconto', 'woo-safe2pay' ), 271 'type' => 'decimal', 272 'description' => __( 'Percentual de desconto se escolhido o pagamento por boleto.', 'woo-safe2pay' ), 273 'default' => 10.00 274 ), 275 'instruction' => array( 276 'title' => __( 'Instrução', 'woo-safe2pay' ), 277 'type' => 'text', 278 'description' => __( 'Instrução do boleto bancário.', 'woo-safe2pay' ), 279 'default' => '' 280 ), 281 'message1' => array( 282 'title' => __( 'Mensagem 1', 'woo-safe2pay' ), 283 'type' => 'text', 284 'description' => __( 'Mensagem 1 impressa no boleto bancário.', 'woo-safe2pay' ), 285 'default' => '' 286 ), 287 'message2' => array( 288 'title' => __( 'Mensagem 2', 'woo-safe2pay' ), 289 'type' => 'text', 290 'description' => __( 'Mensagem 3 impressa no boleto bancário.', 'woo-safe2pay' ), 291 'default' => '' 292 ), 293 'message3' => array( 294 'title' => __( 'Mensagem 3', 'woo-safe2pay' ), 295 'type' => 'text', 296 'description' => __( 'Mensagem 3 impressa no boleto bancário.', 'woo-safe2pay' ), 297 'default' => '' 298 ), 299 'cancelAfterDue' => array( 300 'title' => __( 'Cancelar após o vencimento', 'woo-safe2pay' ), 334 301 'type' => 'checkbox', 335 'description' => __('Aceitar pagamento parcial do boleto bancário', 'woo-safe2pay'), 336 'default' => false, 337 ), 338 'interestRate' => array( 339 'title' => __('Taxa de juros', 'woo-safe2pay'), 302 'description' => __( 'Cancelar boleto bancário após o vencimento.', 'woo-safe2pay' ), 303 'default' => false 304 ), 305 'isEnablePartialPayment' => array( 306 'title' => __( 'Pagamento parcial', 'woo-safe2pay' ), 307 'type' => 'checkbox', 308 'description' => __( 'Aceitar pagamento parcial do boleto bancário. Será permitido para o cliente pagar entre 50% e 200% do valor total da transação.', 'woo-safe2pay' ), 309 'default' => false 310 ), 311 'interestRate' => array( 312 'title' => __( 'Taxa de juros no Boleto', 'woo-safe2pay' ), 340 313 'type' => 'number', 341 'description' => __( 'Juros aplicado após o vencimento do boleto bancário.', 'woo-safe2pay'),342 'default' => '' ,343 ), 344 'penaltyRate' => array(345 'title' => __( 'Taxa de multa', 'woo-safe2pay'),314 'description' => __( 'Juros aplicado após o vencimento do boleto bancário.', 'woo-safe2pay' ), 315 'default' => '' 316 ), 317 'penaltyRate' => array( 318 'title' => __( 'Taxa de multa', 'woo-safe2pay' ), 346 319 'type' => 'number', 347 'description' => __( 'Multa aplicada após o vencimento do boleto bancário.', 'woo-safe2pay'),348 'default' => '' ,349 ), 350 'tc_credit' => array(351 'title' => __( 'Cartão de Crédito', 'woo-safe2pay'),320 'description' => __( 'Multa aplicada após o vencimento do boleto bancário.', 'woo-safe2pay' ), 321 'default' => '' 322 ), 323 'tc_credit' => array( 324 'title' => __( 'Cartão de Crédito', 'woo-safe2pay' ), 352 325 'type' => 'checkbox', 353 'label' => __('Cartão de crédito', 'woo-safe2pay'), 354 'default' => 'no', 355 ), 356 'tc_debit' => array( 357 'title' => __('Cartão de Débito', 'woo-safe2pay'), 326 'label' => __( 'Cartão de crédito', 'woo-safe2pay' ), 327 'default' => 'no' 328 ), 329 'tc_installments' => array( 330 'title' => __('Número máximo de parcelas', 'woo-safe2pay'), 331 'type' => 'select', 332 'label' => __('Número máximo de parcelas.', 'woo-safe2pay'), 333 'default' => 1, 334 'options' => array( 335 1 => 'Sem parcelamento', 336 2 => '2x', 337 3 => '3x', 338 4 => '4x', 339 5 => '5x', 340 6 => '6x', 341 7 => '7x', 342 8 => '8x', 343 9 => '9x', 344 10 => '10x', 345 11 => '11x', 346 12 => '12x', 347 ) 348 ), 349 'tc_minimum_installment_amount' => array( 350 'title' => __('Valor mínimo da parcela', 'woo-safe2pay'), 351 'type' => 'text', 352 'description' => __('Valor mínimo da parcela.', 'woo-safe2pay'), 353 'default' => 5.00, 354 'custom_attributes' => array( 355 'min' => 5.00 356 ) 357 ), 358 'tc_interest_rate' => array( 359 'title' => __('Taxa de juros por parcela', 'woo-safe2pay'), 360 'type' => 'text', 361 'description' => __('Taxa de juros por parcela. Insira o valor da taxa em porcentagem (ex: 1.5 para 1.5%). Separe os valores por ";" caso haja taxas diferentes para cada parcela. Insira "0" caso não queira adicionar taxa para uma determinada parcela. Ex: 0;0;0;1.5;1.5', 'woo-safe2pay'), 362 'default' => '0;0;0;0;0;0;0;0;0;0;0;0' 363 ), 364 'tc_cryptocurrency' => array( 365 'title' => __( 'Criptomoedas', 'woo-safe2pay' ), 358 366 'type' => 'checkbox', 359 'label' => __('Cartão de débito', 'woo-safe2pay'), 360 'default' => 'no', 361 ), 362 'tc_cryptocurrency' => array( 363 'title' => __('Criptomoedas', 'woo-safe2pay'), 364 'type' => 'checkbox', 365 'label' => __('Criptomoeda', 'woo-safe2pay'), 366 'default' => 'no', 367 ), 368 'behavior' => array( 369 'title' => __('Integration Behavior', 'woo-safe2pay'), 367 'label' => __( 'Criptomoeda', 'woo-safe2pay' ), 368 'default' => 'no' 369 ), 370 'behavior' => array( 371 'title' => __( 'Integration Behavior', 'woo-safe2pay' ), 370 372 'type' => 'title', 371 'description' => '' ,372 ), 373 'invoice_prefix' => array(374 'title' => __( 'Invoice Prefix', 'woo-safe2pay'),375 'type' => 'text', 376 'description' => __( 'Please enter a prefix for your invoice numbers. If you use your Safe2Pay account for multiple stores ensure this prefix is unqiue as Safe2Pay will not allow orders with the same invoice number.', 'woo-safe2pay'),373 'description' => '' 374 ), 375 'invoice_prefix' => array( 376 'title' => __( 'Invoice Prefix', 'woo-safe2pay' ), 377 'type' => 'text', 378 'description' => __( 'Prefixo do Pedido. Se deixado em branco, a referência na Safe2Pay será o número do pedido.', 'woo-safe2pay' ), 377 379 'desc_tip' => true, 378 'default' => 'WC-' ,379 ), 380 'testing' => array(381 'title' => __( 'Gateway Testing', 'woo-safe2pay'),380 'default' => 'WC-' 381 ), 382 'testing' => array( 383 'title' => __( 'Modo de teste', 'woo-safe2pay' ), 382 384 'type' => 'title', 383 'description' => '' ,384 ), 385 'debug' => array(386 'title' => __( 'Debug Log', 'woo-safe2pay'),385 'description' => '' 386 ), 387 'debug' => array( 388 'title' => __( 'Log', 'woo-safe2pay' ), 387 389 'type' => 'checkbox', 388 'label' => __( 'Enable logging', 'woo-safe2pay'),390 'label' => __( 'Ativar log', 'woo-safe2pay' ), 389 391 'default' => 'no', 390 /* translators: %s: log page link */ 391 'description' => sprintf(__('Log Safe2Pay events, such as API requests, inside %s', 'woo-safe2pay'), $this->get_log_view()), 392 ), 392 'description' => sprintf( __( 'Gravar os eventos em log %s', 'woo-safe2pay' ), $this->get_log_view() ) 393 ) 393 394 ); 394 } 395 396 public function admin_options() 397 { 398 $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; 399 400 wp_enqueue_script('safe2pay-admin', plugins_url('assets/js/admin/admin' . $suffix . '.js', plugin_dir_path(__FILE__)), array('jquery'), WC_SAFE2PAY_VERSION, true); 401 402 include dirname(__FILE__) . '/admin/views/html-admin-page.php'; 403 } 404 405 protected function send_email($subject, $title, $message) 406 { 395 396 if ( is_plugin_active( 'dokan-lite/dokan.php' ) || is_plugin_active( 'dokan-pro/dokan-pro.php' ) ) { 397 $this->form_fields['dokan_integration_options'] = 398 array( 399 'title' => __( 'Dokan', 'woo-safe2pay' ), 400 'type' => 'title', 401 'description' => '' 402 ); 403 404 $this->form_fields['dokan_enable_split'] = 405 array( 406 'title' => __( 'Habilitar Split', 'woo-safe2pay' ), 407 'type' => 'checkbox', 408 'label' => __( 'Habilitar Split para subcontas', 'woo-safe2pay' ), 409 'default' => 'no', 410 'description' => __( 'A venda será criada na conta do Marketplace e será enviada para os vendedores que possuam subcontas no Safe2Pay.', 'woo-safe2pay' ) 411 ); 412 413 $this->form_fields['dokan_shipping_commission'] = 414 array( 415 'title' => __( 'Comissão para frete', 'woo-safe2pay' ), 416 'type' => 'checkbox', 417 'label' => __( 'Usar o frete no cálculo de comissões', 'woo-safe2pay' ), 418 'default' => 'no', 419 'description' => __( 'Usar o frete no cálculo de comissões.', 'woo-safe2pay' ) 420 ); 421 422 $this->form_fields['dokan_receiver_pay_tax'] = 423 array( 424 'title' => __( 'Recebedor paga taxa', 'woo-safe2pay' ), 425 'type' => 'checkbox', 426 'label' => __( 'Recebedor paga taxa da transação', 'woo-safe2pay' ), 427 'default' => 'no', 428 'description' => __( 'Recebedor paga taxa da transação.', 'woo-safe2pay' ) 429 ); 430 } 431 } 432 433 public function admin_options() { 434 wp_enqueue_script( 'safe2pay-admin', plugins_url( 'assets/js/admin/admin.js', plugin_dir_path( __FILE__ ) ), array( 'jquery' ), WC_SAFE2PAY_VERSION, true ); 435 436 include dirname( __FILE__ ) . '/admin/views/html-admin-page.php'; 437 } 438 439 protected function send_email( $subject, $title, $message ) { 407 440 $mailer = WC()->mailer(); 408 $mailer->send(get_option('admin_email'), $subject, $mailer->wrap_message($title, $message)); 409 } 410 411 public function payment_fields() 412 { 413 wp_enqueue_script('wc-credit-card-form'); 414 wp_enqueue_script('wc-debit-card-form'); 441 $mailer->send( get_option( 'admin_email' ), $subject, $mailer->wrap_message( $title, $message ) ); 442 } 443 444 public function payment_fields() { 445 wp_enqueue_script( 'wc-credit-card-form' ); 415 446 416 447 $description = $this->get_description(); 417 if ($description) { 418 echo wpautop(wptexturize($description)); // WPCS: XSS ok. 448 449 if ( $description ) { 450 echo wpautop( wptexturize( $description ) ); 419 451 } 420 452 421 453 $cart_total = $this->get_order_total(); 422 454 455 $discount_percentage = $this->discount_amount_bank_slip; 456 $discount_amount = ( $cart_total / 100 ) * $discount_percentage; 457 423 458 wc_get_template( 424 ' transparent-checkout-form.php',459 'checkout-form.php', 425 460 array( 426 'cart_total' => $cart_total, 427 'tc_credit' => $this->tc_credit, 428 'tc_ticket' => $this->tc_ticket, 429 'tc_debit' => $this->tc_debit, 430 'tc_cryptocurrency' => $this->tc_cryptocurrency, 431 'flag' => plugins_url('assets/images/brazilian-flag.png', plugin_dir_path(__FILE__)), 461 'cart_total' => $cart_total, 462 'tc_credit' => $this->tc_credit, 463 'tc_installments' => $this->tc_installments, 464 'tc_minimum_installment_amount' => $this->tc_minimum_installment_amount, 465 'tc_interest_rate' => $this->tc_interest_rate, 466 'tc_pix' => $this->tc_pix, 467 'tc_ticket' => $this->tc_ticket, 468 '$discount_percentage' => $discount_percentage, 469 'discount_bank_slip' => $this->discount_bank_slip, 470 'discount_amount' => $discount_amount, 471 'tc_cryptocurrency' => $this->tc_cryptocurrency, 472 'flag' => plugins_url( 'assets/images/brazilian-flag.png', plugin_dir_path( __FILE__ ) ), 432 473 ), 433 474 'woocommerce/safe2pay/', … … 436 477 } 437 478 438 public function process_payment($order_id) 439 { 440 $order = wc_get_order($order_id); 441 442 if ('transparent' === $this->method) { 443 444 $response = $this->api->PaymentController($order, $_POST); // WPCS: input var ok, CSRF ok. 445 446 if ($response['data']) { 447 $this->update_order_status($response['data'], $order_id); 448 } 449 450 if ($response['url']) { 451 // Remove cart. 452 WC()->cart->empty_cart(); 453 454 return array( 455 'result' => 'success', 456 'redirect' => $response['url'], 457 ); 458 } else { 459 foreach ($response['error'] as $error) { 460 wc_add_notice($error, 'error'); 461 } 462 463 return array( 464 'result' => 'fail', 465 'redirect' => '', 466 ); 467 } 468 } else { 469 $use_shipping = isset($_POST['ship_to_different_address']) ? true : false; // WPCS: input var ok, CSRF ok. 479 public function process_payment( $order_id ) { 480 $order = wc_get_order( $order_id ); 481 482 $response = $this->api->PaymentController( $order, $_POST ); 483 484 if ( $response['data'] ) { 485 $this->update_order_status( $response['data'], $order_id ); 486 } 487 488 if ( $response['url'] ) { 489 WC()->cart->empty_cart(); 470 490 471 491 return array( 472 492 'result' => 'success', 473 'redirect' => add_query_arg(array('use_shipping' => $use_shipping), $order->get_checkout_payment_url(true)),493 'redirect' => $response['url'], 474 494 ); 475 } 476 } 477 478 public function receipt_page($order_id) 479 { 480 $order = wc_get_order($order_id); 481 $request_data = $_POST; // WPCS: input var ok, CSRF ok. 482 if (isset($_GET['use_shipping']) && true === (bool) $_GET['use_shipping']) { // WPCS: input var ok, CSRF ok. 495 } else { 496 wc_add_notice( $response['error'] ); 497 498 return array( 499 'result' => 'fail', 500 'redirect' => '', 501 ); 502 } 503 } 504 505 public function receipt_page( $order_id ) { 506 $order = wc_get_order( $order_id ); 507 $request_data = $_POST; 508 509 if ( isset( $_GET['use_shipping'] ) && true === (bool) $_GET['use_shipping'] ) { 483 510 $request_data['ship_to_different_address'] = true; 484 511 } 485 512 486 $response = $this->api->CheckoutController($order, $request_data); 487 488 if ($response['url']) { 489 // Lightbox script. 513 $response = $this->api->CheckoutController( $order, $request_data ); 514 515 if ( $response['url'] ) { 490 516 wc_enqueue_js( 491 517 ' … … 493 519 $( "#browser-no-has-javascript, #cancel-payment, #submit-payment" ).hide(); 494 520 var isOpenLightbox = Safe2PayLightbox({ 495 code: "' . esc_js( $response['token']) . '"521 code: "' . esc_js( $response['token'] ) . '" 496 522 }, { 497 523 success: function ( transactionCode ) { 498 window.location.href = "' . str_replace( '&', '&', esc_js($this->get_return_url($order))) . '";524 window.location.href = "' . str_replace( '&', '&', esc_js( $this->get_return_url( $order ) ) ) . '"; 499 525 }, 500 526 abort: function () { 501 window.location.href = "' . str_replace( '&', '&', esc_js($order->get_cancel_order_url())) . '";527 window.location.href = "' . str_replace( '&', '&', esc_js( $order->get_cancel_order_url() ) ) . '"; 502 528 } 503 529 }); 504 530 if ( ! isOpenLightbox ) { 505 window.location.href = "' . esc_js( $response['url']) . '";531 window.location.href = "' . esc_js( $response['url'] ) . '"; 506 532 } 507 533 ' … … 519 545 ); 520 546 } else { 521 include dirname(__FILE__) . '/views/html-receipt-page-error.php'; 522 } 523 } 524 525 protected function SavePaymentData($order, $posted) 526 { 547 include dirname( __FILE__ ) . '/views/html-receipt-page-error.php'; 548 } 549 } 550 551 protected function SavePaymentData( $order, $posted ) { 552 $data = $order->get_data(); 553 527 554 $meta_data = array(); 528 555 $payment_data = array( 529 'type' => '', 530 'method' => '', 531 'installments' => '', 532 'link' => '', 533 'WalletAddress' => '', 556 'paymenttype' => '', 557 'description' => '', 558 'method' => '', 559 'installments' => '', 560 'link' => '', 561 'walletaddress' => '', 562 'amount' => '' 534 563 ); 535 564 536 if ($posted->IdTransaction != null) { 537 $meta_data[__('Código da transação', 'woo-safe2pay')] = sanitize_text_field((string) $posted->IdTransaction); 538 } 539 if ($posted->Message != null) { 540 $meta_data[__('Status', 'woo-safe2pay')] = sanitize_text_field((string) $posted->Message); 541 } 542 if ($posted->Description != null) { 543 $meta_data[__('Descrição', 'woo-safe2pay')] = sanitize_text_field((string) $posted->Description); 544 } 545 if ($order->Data['billing']['email'] != null) { 546 $meta_data[__('Email', 'woo-safe2pay')] = sanitize_text_field($order->Data['billing']['email']); 547 } 548 if ($order->Data['billing']['first_name'] != null) { 549 $meta_data[__('Nome', 'woo-safe2pay')] = sanitize_text_field($order->Data['billing']['first_name'] . ' ' . $order->Data['billing']['last_name']); 550 } 551 552 $method = sanitize_text_field(strtoupper($_POST['safe2pay_payment_method'])); 553 554 switch (strtoupper($method)) { 555 case "BANKING-TICKET": 556 557 $payment_data['type'] = '1'; 558 559 if ($posted->BankSlipUrl != null) { 560 $payment_data['link'] = sanitize_text_field((string) $posted->BankSlipUrl); 561 $meta_data[__('URL Boleto', 'woo-safe2pay')] = sanitize_text_field((string) $posted->BankSlipUrl); 562 $meta_data[__('Número Boleto', 'woo-safe2pay')] = sanitize_text_field((string) $posted->BankSlipNumber); 563 $meta_data[__('Código de Barras', 'woo-safe2pay')] = sanitize_text_field((string) $posted->Barcode); 564 $meta_data[__('Data de Vencimento', 'woo-safe2pay')] = sanitize_text_field((string) $posted->DueDate); 565 $meta_data[__('Linha Digitável', 'woo-safe2pay')] = sanitize_text_field((string) $posted->DigitableLine); 566 $meta_data[__('Data da Operação', 'woo-safe2pay')] = sanitize_text_field((string) $posted->OperationDate); 565 if ( $posted->IdTransaction != null ) { 566 $meta_data[ __( 'Código da transação', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->IdTransaction ); 567 } 568 569 if ( $posted->Message != null ) { 570 $meta_data[ __( 'Status', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->Message ); 571 } 572 573 if ( $posted->Description != null ) { 574 $payment_data['description'] = sanitize_text_field( (string) $posted->Description ); 575 $meta_data[ __( 'Description', 'woo-safe2pay' ) ] = $payment_data['description']; 576 } 577 578 if ( $data['billing']['email'] != null ) { 579 $meta_data[ __( 'Email', 'woo-safe2pay' ) ] = sanitize_text_field( $data['billing']['email'] ); 580 } 581 582 if ( $data['billing']['first_name'] != null ) { 583 $meta_data[ __( 'Nome', 'woo-safe2pay' ) ] = sanitize_text_field( $data['billing']['first_name'] . ' ' . $data['billing']['last_name'] ); 584 } 585 586 $method = sanitize_text_field( $_POST['safe2pay_payment_method'] ); 587 588 switch ( $method ) { 589 case "bank-slip": 590 $payment_data['paymenttype'] = '1'; 591 592 $meta_data[ __( '', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->BankSlipUrl ); 593 594 if ( $posted->BankSlipUrl != null ) { 595 $payment_data['link'] = sanitize_text_field( (string) $posted->BankSlipUrl ); 596 $meta_data[ __( 'URL Boleto', 'woo-safe2pay' ) ] = $payment_data['link']; 597 598 $meta_data[ __( 'Número Boleto', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->BankSlipNumber ); 599 $meta_data[ __( 'Código de Barras', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->Barcode ); 600 $meta_data[ __( 'Vencimento', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->DueDate ); 601 $meta_data[ __( 'Linha Digitável', 'woo-safe2pay' ) ] = sanitize_text_field( (string) $posted->DigitableLine ); 567 602 } 568 569 603 break; 570 case "CREDIT-CARD": 571 572 $payment_data['type'] = '2'; 573 574 $payment_data['installments'] = sanitize_text_field($_POST['safe2pay_card_installments']); 575 $meta_data[__('Parcelas', 'woo-safe2pay')] = $payment_data['installments']; 576 604 case "credit-card": 605 $payment_data['paymenttype'] = '2'; 606 607 $payment_data['installments'] = sanitize_text_field( $_POST['safe2pay_card_installments'] ); 608 $meta_data[ __( 'Parcelas', 'woo-safe2pay' ) ] = $payment_data['installments']; 577 609 break; 578 case "CRYPTO-CURRENCY": 579 580 $payment_data['type'] = '3'; 581 582 $payment_data['link'] = sanitize_text_field((string) $posted->QrCode); 583 $meta_data[__('Payment URL', 'woo-safe2pay')] = $payment_data['link']; 584 585 $payment_data['walletaddress'] = sanitize_text_field((string) $posted->WalletAddress); 586 $meta_data[__('WalletAddress', 'woo-safe2pay')] = $payment_data['walletaddress']; 587 610 case "crypto-currency": 611 $payment_data['paymenttype'] = '3'; 612 613 $payment_data['link'] = sanitize_text_field( (string) $posted->QrCode ); 614 $meta_data[ __( 'Payment URL', 'woo-safe2pay' ) ] = $payment_data['link']; 615 616 $payment_data['walletaddress'] = sanitize_text_field( (string) $posted->WalletAddress ); 617 $meta_data[ __( 'Wallet Address', 'woo-safe2pay' ) ] = $payment_data['walletaddress']; 618 619 $payment_data['symbol'] = sanitize_text_field( (string) $posted->Symbol ); 620 $meta_data[ __( 'Symbol', 'woo-safe2pay' ) ] = $payment_data['symbol']; 621 622 $payment_data['amount'] = sanitize_text_field( (string) $posted->AmountBTC ); 623 $meta_data[ __( 'Amount', 'woo-safe2pay' ) ] = $payment_data['amount']; 588 624 break; 589 590 case "DEBIT-CARD": 591 $payment_data['type'] = '4'; 592 625 case "pix": 626 $payment_data['paymenttype'] = '6'; 627 628 if ( $posted->Key != null ) { 629 $payment_data['key'] = sanitize_text_field( (string) $posted->Key ); 630 $meta_data[ __( 'Copia e Cola', 'woo-safe2pay' ) ] = $payment_data['key']; 631 } 632 633 if ( $posted->QrCode != null ) { 634 $payment_data['link'] = sanitize_text_field( (string) $posted->QrCode ); 635 $meta_data[ __( 'Qr-Code', 'woo-safe2pay' ) ] = $payment_data['link']; 636 } 593 637 break; 594 638 } … … 596 640 $meta_data['_wc_safe2pay_payment_data'] = $payment_data; 597 641 598 // WooCommerce 3.0 or later. 599 if (method_exists($order, 'update_meta_data')) { 600 foreach ($meta_data as $key => $value) { 601 $order->update_meta_data($key, $value); 642 if ( method_exists( $order, 'update_meta_data' ) ) { 643 foreach ( $meta_data as $key => $value ) { 644 $order->update_meta_data( $key, $value ); 602 645 } 646 603 647 $order->save(); 604 648 } else { 605 foreach ( $meta_data as $key => $value) {606 update_post_meta( $order->id, $key, $value);649 foreach ( $meta_data as $key => $value ) { 650 update_post_meta( $order->id, $key, $value ); 607 651 } 608 652 } 609 653 } 610 654 611 public function update_order_status($posted, $order_id) 612 { 613 if (isset($posted->IdTransaction)) { 614 $id = (int) str_replace($this->invoice_prefix, '', $posted->IdTransaction); 615 $order = wc_get_order($order_id); 616 617 // Check if order exists. 618 if (!$order) { 655 public function update_order_status( $posted, $order_id ) { 656 if ( isset( $posted->IdTransaction ) ) { 657 $id = (int) str_replace( $this->invoice_prefix, '', $posted->IdTransaction ); 658 659 $order = wc_get_order( $order_id ); 660 661 if ( ! $order ) { 619 662 return; 620 663 } 621 664 622 $order_id = method_exists($order, 'get_id') ? $order->get_id() : $order->id; 623 624 // Checks whether the invoice number matches the order. 625 // If true processes the payment. 626 if ($id > 0) { 627 if ('yes' === $this->debug) { 628 $this->log->add($this->id, 'Safe2Pay payment status for order ' . $order->get_order_number() . ' is: ' . intval($posted->Status)); 665 if ( $id > 0 ) { 666 if ( 'yes' === $this->debug ) { 667 $this->log->add( $this->id, 'Status do pedido ' . $order->get_order_number() . ' é: ' . intval( $posted->Status ) ); 629 668 } 630 669 631 // Save meta data. 632 $this->SavePaymentData($order, $posted); 633 634 switch ($posted->Status) { 635 case "1": 636 $order->update_status('pending', __('Safe2Pay: Pendente.', 'woo-safe2pay')); 637 670 $this->SavePaymentData( $order, $posted ); 671 672 switch ( $posted->Status ) { 673 case '1': 674 $order->update_status( 'on-hold', __( 'Safe2Pay: Pendente.', 'woo-safe2pay' ) ); 638 675 break; 639 case "2": 640 $order->update_status('processing', __('Safe2Pay: Processamento.', 'woo-safe2pay')); 641 642 // Reduce stock for billets. 643 if (function_exists('wc_reduce_stock_levels')) { 644 wc_reduce_stock_levels($order_id); 676 case '2': 677 $order->update_status( 'on-hold', __( 'Safe2Pay: Processamento.', 'woo-safe2pay' ) ); 678 $order->add_order_note( __( 'Safe2Pay: Pagamento em processamento..', 'woo-safe2pay' ) ); 679 break; 680 case '3': 681 if ( method_exists( $order, 'get_status' ) && 'cancelled' === $order->get_status() ) { 682 $order->update_status( 'processing', __( 'Safe2Pay: Pagamento autorizado.', 'woo-safe2pay' ) ); 683 wc_reduce_stock_levels( $order_id ); 684 } else { 685 $order->add_order_note( __( 'Safe2Pay: Autorizado.', 'woo-safe2pay' ) ); 686 $order->payment_complete( sanitize_text_field( (string) $posted->IdTransaction ) ); 645 687 } 646 647 688 break; 648 case "3": 649 // Sometimes Safe2Pay should change an order from cancelled to paid, so we need to handle it. 650 if (method_exists($order, 'get_status') && 'cancelled' === $order->get_status()) { 651 $order->update_status('on-hold', __('Safe2Pay: Payment approved.', 'woo-safe2pay')); 652 wc_reduce_stock_levels($order_id); 653 } else { 654 $order->add_order_note(__('Safe2Pay: Autorizado.', 'woo-safe2pay')); 655 656 // Changing the order for processing and reduces the stock. 657 $order->payment_complete(sanitize_text_field((string) $posted->IdTransaction)); 689 case '5': 690 $order->update_status( 'processing', __( 'Safe2Pay: Em disputa.', 'woo-safe2pay' ) ); 691 $this->send_email( 692 sprintf( __( 'Pagamento para o pedido %s entrou em disputa', 'woo-safe2pay' ), $order->get_order_number() ), 693 __( 'Payment in dispute', 'woo-safe2pay' ), 694 sprintf( __( 'Pedido %s entrou em disputa na Safe2Pay. Acesse seu painel da Safe2Pay para maiores detalhes.', 'woo-safe2pay' ), $order->get_order_number() ) 695 ); 696 697 break; 698 case '6': 699 $order->update_status( 'refunded', __( 'Safe2Pay: Devolvido.', 'woo-safe2pay' ) ); 700 $this->send_email( 701 sprintf( __( 'Pagamento para o pedido %s devolvido', 'woo-safe2pay' ), $order->get_order_number() ), 702 __( 'Pagamento devolvido', 'woo-safe2pay' ), 703 sprintf( __( 'Pedido %s foi devolvido na Safe2Pay.', 'woo-safe2pay' ), $order->get_order_number() ) 704 ); 705 706 if ( function_exists( 'wc_increase_stock_levels' ) ) { 707 wc_increase_stock_levels( $order_id ); 658 708 } 659 709 660 710 break; 661 case "5": 662 $order->update_status('processing', __('Safe2Pay: Em disputa.', 'woo-safe2pay')); 663 $this->send_email( 664 /* translators: %s: order number */ 665 sprintf(__('Payment for order %s came into dispute', 'woo-safe2pay'), $order->get_order_number()), 666 __('Payment in dispute', 'woo-safe2pay'), 667 /* translators: %s: order number */ 668 sprintf(__('Order %s has been marked as on-hold, because the payment came into dispute in Safe2Pay.', 'woo-safe2pay'), $order->get_order_number()) 669 ); 711 case '8': 712 $order->update_status( 'failed', __( 'Safe2Pay: Em cancelamento.', 'woo-safe2pay' ) ); 713 $order->add_order_note( __( 'Safe2Pay: Recusado.', 'woo-safe2pay' ) ); 670 714 671 715 break; 672 case "6": 673 $order->update_status('refunded', __('Safe2Pay: Devolvido.', 'woo-safe2pay')); 674 $this->send_email( 675 /* translators: %s: order number */ 676 sprintf(__('Payment for order %s refunded', 'woo-safe2pay'), $order->get_order_number()), 677 __('Payment refunded', 'woo-safe2pay'), 678 /* translators: %s: order number */ 679 sprintf(__('Order %s has been marked as refunded by Safe2Pay.', 'woo-safe2pay'), $order->get_order_number()) 680 ); 681 682 if (function_exists('wc_increase_stock_levels')) { 683 wc_increase_stock_levels($order_id); 716 case '7': 717 case '12': 718 $order->update_status( 'cancelled', __( 'Safe2Pay: Chargeback.', 'woo-safe2pay' ) ); 719 720 if ( function_exists( 'wc_increase_stock_levels' ) ) { 721 wc_increase_stock_levels( $order_id ); 684 722 } 685 723 686 724 break; 687 case "12":688 $order->update_status('cancelled', __('Safe2Pay: Em cancelamento.', 'woo-safe2pay'));689 690 if (function_exists('wc_increase_stock_levels')) {691 wc_increase_stock_levels($order_id);692 }693 694 break;695 696 725 default: 697 726 break; 698 727 } 699 728 } else { 700 if ( 'yes' === $this->debug) {701 $this->log->add( $this->id, 'Error: Order Key does not match with Safe2Pay reference.');729 if ( 'yes' === $this->debug ) { 730 $this->log->add( $this->id, 'Error: Pedido não encontrado.' ); 702 731 } 703 732 } … … 705 734 } 706 735 707 public function thankyou_page($order_id) 708 { 709 $order = wc_get_order($order_id); 710 // WooCommerce 3.0 or later. 711 if (method_exists($order, 'get_meta')) { 712 $data = $order->get_meta('_wc_safe2pay_payment_data'); 736 public function thankyou_page( $order_id ) { 737 $order = new WC_Order( $order_id ); 738 739 $data = is_callable( [ $order, 'get_meta' ] ) 740 ? $order->get_meta( '_wc_safe2pay_payment_data' ) 741 : get_post_meta( $order_id, '_wc_safe2pay_payment_data', true ); 742 743 if ( isset( $data['paymenttype'] ) ) { 744 switch ( $data['paymenttype'] ) { 745 case '1': 746 wc_get_template( 747 'bs-payment-instructions.php', 748 [ 749 'paymenttype' => $data['paymenttype'], 750 'link' => $data['link'] 751 ], 752 'woocommerce/safe2pay/', 753 WC_Safe2Pay::get_templates_path() 754 ); 755 break; 756 case '2': 757 wc_get_template( 758 'cc-payment-instructions.php', 759 [ 760 'paymenttype' => $data['paymenttype'], 761 'description' => $data['description'], 762 ], 763 'woocommerce/safe2pay/', 764 WC_Safe2Pay::get_templates_path() 765 ); 766 break; 767 case '3': 768 wc_get_template( 769 'crypto-payment-instructions.php', 770 [ 771 'paymenttype' => $data['paymenttype'], 772 'link' => $data['link'], 773 'walletaddress' => $data['walletaddress'], 774 'amount' => $data['amount'], 775 'symbol' => $data['symbol'] 776 ], 777 'woocommerce/safe2pay/', 778 WC_Safe2Pay::get_templates_path() 779 ); 780 break; 781 case '6': 782 wc_get_template( 783 'pix-payment-instructions.php', 784 [ 785 'paymenttype' => $data['paymenttype'], 786 'link' => $data['link'], 787 'key' => $data['key'] 788 ], 789 'woocommerce/safe2pay/', 790 WC_Safe2Pay::get_templates_path() 791 ); 792 break; 793 } 794 } 795 } 796 797 public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { 798 if ( method_exists( $order, 'get_meta' ) ) { 799 if ( $sent_to_admin || 'on-hold' !== $order->get_status() || $this->id !== $order->get_payment_method() ) { 800 return; 801 } 802 803 $data = $order->get_meta( '_wc_safe2pay_payment_data' ); 713 804 } else { 714 $data = get_post_meta($order->id, '_wc_safe2pay_payment_data', true); 715 } 716 717 if (isset($data['type'])) { 805 if ( $sent_to_admin || 'on-hold' !== $order->status || $this->id !== $order->payment_method ) { 806 return; 807 } 808 809 $data = get_post_meta( $order->get_id(), '_wc_safe2pay_payment_data', true ); 810 } 811 812 if ( $plain_text ) { 718 813 wc_get_template( 719 ' payment-instructions.php',814 'emails/plain-instructions.php', 720 815 array( 721 'type' => $data['type'], 722 'link' => $data['link'], 723 'method' => $data['method'], 724 'walletaddress' => isset($data['walletaddress']) ? $data['walletaddress'] : "", 725 'installments' => $data['installments'], 816 'paymenttype' => $data['paymenttype'], 817 'installments' => $data['installments'], 818 'method' => $data['method'], 819 'link' => $data['link'], 820 'walletaddress' => $data['walletaddress'], 821 'amount' => $data['amount'], 822 'symbol' => $data['symbol'] 726 823 ), 727 824 'woocommerce/safe2pay/', 728 825 WC_Safe2Pay::get_templates_path() 729 826 ); 730 }731 }732 733 public function email_instructions($order, $sent_to_admin, $plain_text = false)734 {735 // WooCommerce 3.0 or later.736 if (method_exists($order, 'get_meta')) {737 if ($sent_to_admin || 'on-hold' !== $order->get_status() || $this->id !== $order->get_payment_method()) {738 return;739 }740 741 $data = $order->get_meta('_wc_safe2pay_payment_data');742 827 } else { 743 if ($sent_to_admin || 'on-hold' !== $order->status || $this->id !== $order->payment_method) { 744 return; 745 } 746 747 $data = get_post_meta($order->id, '_wc_safe2pay_payment_data', true); 748 } 749 750 if (isset($data['type'])) { 751 if ($plain_text) { 752 wc_get_template( 753 'emails/plain-instructions.php', 754 array( 755 'type' => $data['type'], 756 'link' => $data['link'], 757 'walletaddress' => isset($data['walletaddress']) ? $data['walletaddress'] : "", 758 'method' => $data['method'], 759 'installments' => $data['installments'], 760 ), 761 'woocommerce/safe2pay/', 762 WC_Safe2Pay::get_templates_path() 763 ); 764 } else { 765 wc_get_template( 766 'emails/html-instructions.php', 767 array( 768 'type' => $data['type'], 769 'link' => $data['link'], 770 'walletaddress' => isset($data['walletaddress']) ? $data['walletaddress'] : "", 771 'method' => $data['method'], 772 'installments' => $data['installments'], 773 ), 774 'woocommerce/safe2pay/', 775 WC_Safe2Pay::get_templates_path() 776 ); 777 } 828 wc_get_template( 829 'emails/html-instructions.php', 830 array( 831 'paymenttype' => $data['paymenttype'], 832 'installments' => $data['installments'], 833 'method' => $data['method'], 834 'link' => $data['link'], 835 'walletaddress' => $data['walletaddress'], 836 'amount' => $data['amount'], 837 'symbol' => $data['symbol'] 838 ), 839 'woocommerce/safe2pay/', 840 WC_Safe2Pay::get_templates_path() 841 ); 778 842 } 779 843 } -
safe2pay/trunk/includes/class-wc-safe2pay.php
r2165817 r2881978 1 1 <?php 2 2 3 /**4 * Safe2Pay main class5 *6 * @package WooCommerce_Safe2Pay7 */8 /**9 * WooCommerce bootstrap class.10 */11 3 class WC_Safe2Pay 12 4 { 5 public static function init() 6 { 7 add_action('rest_api_init', function () { 8 register_rest_route('safe2pay/v2/', 'callback/(?P<order_id>\d+)', array( 9 'methods' => 'POST', 10 'callback' => function ($callback) { 13 11 14 /** 15 * Initialize the plugin public actions. 16 */ 17 public static function init() 18 { 19 add_action('rest_api_init', function () { 20 register_rest_route('safe2pay/v2/', 'callback/(?P<order_id>\d+)', array( 21 'methods' => 'POST', 22 'callback' => function ($callback) { 12 $callback = $callback->get_params(); 13 $gateway = new WC_Safe2Pay_Gateway(); 14 $order_id = $callback['order_id']; 23 15 24 $callback = $callback->get_params(); 16 $UpdateOrder = array( 17 "IdTransaction" => $callback['IdTransaction'], 18 "Status" => $callback['TransactionStatus']['Id'], 19 "Message" => $callback['TransactionStatus']['Name'], 20 "Description" => $callback['TransactionStatus']['Name'], 21 ); 25 22 26 $gateway = new WC_Safe2Pay_Gateway();23 $object = new stdClass(); 27 24 28 $order_id = $callback['order_id']; 25 foreach ($UpdateOrder as $key => $value) { 26 $object->$key = $value; 27 } 29 28 30 $UpdateOrder = array( 31 "IdTransaction"=>$callback['IdTransaction'], 32 "Status"=>$callback['TransactionStatus']['Id'], 33 "Message"=> $callback['TransactionStatus']['Name'], 34 "Description"=> $callback['TransactionStatus']['Name'], 35 36 ); 29 $gateway->update_order_status($object, $order_id); 37 30 38 $object = new stdClass(); 39 foreach ($UpdateOrder as $key => $value) 40 { 41 $object->$key = $value; 42 } 31 $response = new WP_REST_Response(true); 32 $response->set_status(200); 43 33 44 $gateway->update_order_status($object, $order_id); 45 46 $response = new WP_REST_Response(true); 47 $response->set_status(200); 48 return $response; 49 }, 50 'permission_callback' => function ($callback) { 34 return $response; 35 }, 36 'permission_callback' => function ($callback) { 51 37 52 $callback = $callback->get_params(); 53 54 if($callback == null){ 55 return new WP_Error('The request has not been applied because it lacks valid authentication credentials for the target resource.', '', array('status' => 401)); 56 }else{ 38 $callback = $callback->get_params(); 57 39 58 $secretkey = $callback['SecretKey']; 40 if ($callback == null) { 41 return new WP_Error('The request has not been applied because it lacks valid authentication credentials for the target resource.', '', array('status' => 401)); 42 } else { 59 43 60 if($secretkey == null){ 61 return new WP_Error('The request has not been applied because it lacks valid authentication credentials for the target resource.', '', array('status' => 401)); 62 } 44 $secretkey = $callback['SecretKey']; 63 45 64 $gateway = new WC_Safe2Pay_Gateway(); 46 if ($secretkey == null) { 47 return new WP_Error('The request has not been applied because it lacks valid authentication credentials for the target resource.', '', array('status' => 401)); 48 } 65 49 66 if($secretkey == $gateway->secretkey || $secretkey == $gateway->sandbox_secretkey){ 50 $gateway = new WC_Safe2Pay_Gateway(); 67 51 68 return true; 52 if ($secretkey == $gateway->secretkey || $secretkey == $gateway->sandbox_secretkey) { 69 53 70 }else{ 71 return new WP_Error('The request has not been applied because it lacks valid authentication credentials for the target resource.', '', array('status' => 401)); 72 } 73 } 74 } 75 )); 76 }); 54 return true; 77 55 78 79 if (class_exists('WC_Payment_Gateway')) { 80 self::includes(); 56 } else { 57 return new WP_Error('The request has not been applied because it lacks valid authentication credentials for the target resource.', '', array('status' => 401)); 58 } 59 } 60 } 61 )); 62 }); 81 63 82 add_filter('woocommerce_payment_gateways', array(__CLASS__, 'add_gateway')); 83 add_filter('plugin_action_links_' . plugin_basename(WC_SAFE2PAY_PLUGIN_FILE), array(__CLASS__, 'plugin_action_links')); 84 } else { 85 add_action('admin_notices', array(__CLASS__, 'woocommerce_missing_notice')); 86 } 87 } 88 64 if (class_exists('WC_Payment_Gateway')) { 65 self::includes(); 89 66 90 /** 91 * Get templates path. 92 * 93 * @return string 94 */ 95 public static function get_templates_path() 96 { 97 return plugin_dir_path(WC_SAFE2PAY_PLUGIN_FILE) . 'templates/'; 98 } 67 add_filter('woocommerce_payment_gateways', array(__CLASS__, 'add_gateway')); 68 add_filter('plugin_action_links_' . plugin_basename(WC_SAFE2PAY_PLUGIN_FILE), array(__CLASS__, 'plugin_action_links')); 69 } else { 70 add_action('admin_notices', array(__CLASS__, 'woocommerce_missing_notice')); 71 } 72 } 99 73 100 /** 101 * Load the plugin text domain for translation. 102 */ 103 public static function load_plugin_textdomain() 104 { 105 load_plugin_textdomain('woo-safe2pay', false, dirname(plugin_basename(WC_SAFE2PAY_PLUGIN_FILE)) . '/languages/'); 106 } 74 public static function get_templates_path() 75 { 76 return plugin_dir_path(WC_SAFE2PAY_PLUGIN_FILE) . 'templates/'; 77 } 107 78 108 /** 109 * Action links. 110 * 111 * @param array $links Action links. 112 * 113 * @return array 114 */ 115 public static function plugin_action_links($links) 116 { 117 $plugin_links = array(); 118 $plugin_links[] = '<a href="' . esc_url(admin_url('admin.php?page=wc-settings&tab=checkout§ion=safe2pay')) . '">' . __('Settings', 'woo-safe2pay') . '</a>'; 79 public static function load_plugin_textdomain() 80 { 81 load_plugin_textdomain('woo-safe2pay', false, dirname(plugin_basename(WC_SAFE2PAY_PLUGIN_FILE)) . '/languages/'); 82 } 119 83 120 return array_merge($plugin_links, $links); 121 } 84 public static function plugin_action_links($links) 85 { 86 $plugin_links = array(); 87 $plugin_links[] = '<a href="' . esc_url(admin_url('admin.php?page=wc-settings&tab=checkout§ion=safe2pay')) . '">' . __('Settings', 'woo-safe2pay') . '</a>'; 122 88 123 /** 124 * Includes. 125 */ 126 private static function includes() 127 { 128 include_once dirname(__FILE__) . '/class-wc-safe2pay-api.php'; 129 include_once dirname(__FILE__) . '/class-wc-safe2pay-gateway.php'; 130 } 89 return array_merge($plugin_links, $links); 90 } 131 91 132 /** 133 * Add the gateway to WooCommerce. 134 * 135 * @param array $methods WooCommerce payment methods. 136 * 137 * @return array Payment methods with Safe2Pay. 138 */ 139 public static function add_gateway($methods) 140 { 141 $methods[] = 'WC_Safe2Pay_Gateway'; 92 private static function includes() 93 { 94 include_once dirname(__FILE__) . '/class-wc-safe2pay-api.php'; 95 include_once dirname(__FILE__) . '/class-wc-safe2pay-gateway.php'; 96 } 142 97 143 return $methods; 144 } 98 public static function add_gateway($methods) 99 { 100 $methods[] = 'WC_Safe2Pay_Gateway'; 145 101 146 public static function ecfb_missing_notice() 147 { 148 $settings = get_option('woocommerce_safe2pay_settings', array('method' => '')); 102 return $methods; 103 } 149 104 150 if ('transparent' === $settings['method'] && !class_exists('Extra_Checkout_Fields_For_Brazil')) { 151 include dirname(__FILE__) . '/admin/views/html-notice-missing-ecfb.php'; 152 } 153 } 105 public static function ecfb_missing_notice() 106 { 107 $settings = get_option('woocommerce_safe2pay_settings', array('method' => '')); 154 108 155 /** 156 * WooCommerce missing notice. 157 */ 158 public static function woocommerce_missing_notice() 159 { 160 include dirname(__FILE__) . '/admin/views/html-notice-missing-woocommerce.php'; 161 } 109 if ('transparent' === $settings['method'] && !class_exists('Extra_Checkout_Fields_For_Brazil')) { 110 include dirname(__FILE__) . '/admin/views/html-notice-missing-ecfb.php'; 111 } 112 } 113 114 public static function woocommerce_missing_notice() 115 { 116 include dirname(__FILE__) . '/admin/views/html-notice-missing-woocommerce.php'; 117 } 162 118 } -
safe2pay/trunk/templates/emails/html-instructions.php
r2165731 r2881978 1 <?php 1 <?php if (!defined('ABSPATH')) exit; ?> 2 2 3 /** 4 * HTML email instructions. 5 * 6 * @author Lucas Diogo 7 * @package WooCommerce_Safe2Pay/Templates 8 * @version 2.7.0 9 */ 3 <h2><?php _e('Payment', 'woo-safe2pay'); ?></h2> 10 4 11 if (!defined('ABSPATH')) {12 exit; // Exit if accessed directly.13 }14 ?>15 5 16 < h2><?php _e('Payment', 'woo-safe2pay'); ?></h2>6 <?php if ($paymenttype == '1') : ?> 17 7 18 <?php if ('1' == $type) : ?>19 <span>8 <div class="order_details"> 9 <span> 20 10 <a class="button" href="<?php echo esc_url($link); ?>" target="_blank"> 21 11 <?php _e('Visualizar Boleto Bancário', 'woo-safe2pay'); ?> 22 <br />12 <br/> 23 13 </a> 24 14 … … 26 16 Após a confirmação do pagamento, seu pedido será processado.', 'woo-safe2pay'); ?> 27 17 </span> 28 29 <?php elseif ('2' == $type) : ?> 30 <div class="order_details"> 18 </div> 19 20 <?php elseif ($paymenttype == '2') : ?> 21 22 <div class="order_details"> 31 23 <span> 32 24 <?php _e('Pagamento autorizado', 'woo-safe2pay'); ?></a> 33 25 <?php _e('Tudo certo! Seu pedido será processado.', 'woo-safe2pay'); ?> 34 </div> 26 </span> 27 </div> 35 28 36 <?php elseif ('3' == $type) : ?> 37 <div class="order_details"> 38 <div style="margin-left: auto;margin-right: auto;width: 10em;"> 39 <img src="<?php echo esc_url($link); ?>" alt="QR CODE"> 40 <br /> 41 </div> 29 <?php elseif ($paymenttype == '3') : ?> 42 30 43 <div style="text-align: center; font-size: 12px;"> 44 <span style="">Wallet Address: <?php echo ($walletaddress); ?></span> 45 <br> 46 </div> 31 <div class="order_details"> 32 <div style="margin-left: auto;margin-right: auto;width: 10em;"> 33 <img src="<?php echo esc_url($link); ?>" alt="QR CODE"> 34 <br/> 35 </div> 47 36 48 <br /> 37 <div style="text-align: center; font-size: 12px;"> 38 <span style="">Moeda: <?php echo $symbol; ?></span> 39 <br/> 40 <span style="">Valor: <?php echo $amount; ?></span> 41 <br/> 42 <span style="">Carteira: <?php echo $walletaddress; ?></span> 43 <br> 44 </div> 49 45 50 <div style="text-align: center;"> 51 <?php _e('Após a confirmação do pagamento, Seu pedido será processado.', 'woo-safe2pay'); ?> 52 </div> 46 <br/> 53 47 54 <br /> 48 <div style="text-align: center;"> 49 <?php _e('Após a confirmação do pagamento, Seu pedido será processado.', 'woo-safe2pay'); ?> 50 </div> 51 <br/> 52 </div> 55 53 56 </div> 57 <?php elseif ('4' == $type) : ?> 58 <div class="order_details"> 54 <?php elseif ($paymenttype == '4') : ?> 59 55 60 <?php _e('Pagamento autorizado', 'woo-safe2pay'); ?></a> 61 <?php _e('Tudo certo! Seu pedido será processado.', 'woo-safe2pay'); ?> 56 <div class="order_details"> 62 57 63 </div> 58 <span> 59 <a class="button" href="<?php echo esc_url($link); ?>" target="_blank"> 60 <?php _e('Finalizar compra!', 'woo-safe2pay'); ?> 61 <br/> 62 </a> 64 63 65 <?php else : ?> 64 <?php _e('Clique no botão para acessar o internet banking e finalizar a compra. 65 Após a confirmação do pagamento, seu pedido será processado.', 'woo-safe2pay'); ?> 66 </span> 66 67 67 <p class="order_details"><?php echo sprintf(__('You just made the payment in %s using the %s.', 'woo-safe2pay'), '<strong>' . $installments . 'x</strong>', '<strong>' . $method . '</strong>'); ?><br /><?php _e('As soon as the credit card operator confirm the payment, your order will be processed.', 'woo-safe2pay'); ?></p>68 </div> 68 69 69 <?php 70 endif; 70 <?php elseif ($paymenttype == '6') : ?> 71 72 <div class="order_details"> 73 74 <span> 75 <?php echo __('Seu pedido foi recebido. Utilize os dados abaixo para efetuar o pagamento:', 'woo-safe2pay'); ?> 76 <div style="margin-left: auto;margin-right: auto;width: 10em;"> 77 <img src="<?php echo esc_url( $link ); ?>" alt="QR CODE"> 78 <br/> 79 </div> 80 <?php echo __('Copia e Cola: ', 'woo-safe2pay'); ?> <?php echo $key; ?> 81 <br/> 82 <br/> 83 <?php echo __('Após a confirmação do pagamento, seu pedido será liberado.', 'woo-safe2pay'); ?> 84 <br/> 85 </span> 86 87 </div> 88 89 <?php endif; ?> -
safe2pay/trunk/templates/emails/plain-instructions.php
r2165731 r2881978 1 1 <?php 2 /**3 * Plain email instructions.4 *5 * @author Lucas Diogo6 * @package WooCommerce_Safe2Pay/Templates7 * @version 2.7.08 */9 2 10 if ( ! defined( 'ABSPATH' )) {11 exit; // Exit if accessed directly. 3 if (!defined('ABSPATH')) { 4 exit; 12 5 } 13 6 14 _e( 'Payment', 'woo-safe2pay');7 _e('Payment', 'woo-safe2pay'); 15 8 16 9 echo "\n\n"; 17 10 18 if ( '1' == $type) {11 if ($paymenttype == '1') { 19 12 20 _e( 'Please use the link below to view your Banking Ticket, you can print and pay in your internet banking or in a lottery retailer:', 'woo-safe2pay');13 _e('Please use the link below to view your Banking Ticket, you can print and pay in your internet banking or in a lottery retailer:', 'woo-safe2pay'); 21 14 22 echo "\n";15 echo "\n"; 23 16 24 echo esc_url( $link);17 echo esc_url($link); 25 18 26 echo "\n";19 echo "\n"; 27 20 28 _e( 'After we receive the ticket payment confirmation, your order will be processed.', 'woo-safe2pay');21 _e('After we receive the ticket payment confirmation, your order will be processed.', 'woo-safe2pay'); 29 22 30 } elseif ( '2' == $type) {23 } elseif ($paymenttype == '2') { 31 24 32 _e( 'Please use the link below to make the payment in your bankline:', 'woo-safe2pay');25 _e('After we receive the ticket payment confirmation, your order will be processed', 'woo-safe2pay'); 33 26 34 echo "\n";27 echo "\n"; 35 28 36 echo esc_url( $link);29 _e('After we receive the confirmation from the bank, your order will be processed.', 'woo-safe2pay'); 37 30 38 echo "\n"; 31 } elseif ($paymenttype == '3') { 39 32 40 _e( 'After we receive the confirmation from the bank, your order will be processed.', 'woo-safe2pay' ); 33 _e('Please use the link below to make the payment in your bankline:', 'woo-safe2pay'); 34 35 echo "\n"; 36 37 echo esc_url($link); 38 39 echo "\n"; 40 41 _e('After we receive the confirmation from the bank, your order will be processed.', 'woo-safe2pay'); 42 43 } elseif ($paymenttype == '4') { 44 45 _e('Please use the link below to make the payment in your bankline:', 'woo-safe2pay'); 46 47 echo "\n"; 48 49 echo esc_url($link); 50 51 echo "\n"; 52 53 _e('After we receive the confirmation from the bank, your order will be processed.', 'woo-safe2pay'); 41 54 42 55 } else { 43 56 44 echo sprintf( __( 'You just made the payment in %s using the %s.', 'woo-safe2pay' ), $installments . 'x', $method );57 echo "\n"; 45 58 46 echo "\n"; 47 48 _e( 'As soon as the credit card operator confirm the payment, your order will be processed.', 'woo-safe2pay' ); 59 _e('As soon as the credit card operator confirm the payment, your order will be processed.', 'woo-safe2pay'); 49 60 50 61 } -
safe2pay/trunk/woocommerce-safe2pay.php
r2165817 r2881978 1 1 <?php 2 2 3 /** 3 * Plugin Name: Safe2Pay Woocomerce4 * Plugin URI: https:// github.com/LucasDiogo96/Woocomerce-Safe2Pay5 * Description: A gestão de pagamentos online pode parecer complexa. Nosso objetivo é simplificá-la para você. Conecte sua empresa às nossas soluções de pagamento e descubra um novo modo de fechar negócios..6 * Author: Lucas Diogo7 * Version: 1. 34 * Plugin Name: Safe2Pay para WooCommerce 5 * Plugin URI: https://safe2pay.com.br/ 6 * Description: Aceite pagamentos por boleto, cartões de crédito e Pix pelo Safe2Pay. 7 * Author: Safe2Pay 8 * Version: 1.9 8 9 * License: GPLv3 or later 9 10 * Text Domain: woo-safe2pay 10 11 * Domain Path: /languages 11 * WC requires at least: 3.0.0 12 * WC tested up to: 3.5.0 13 14 * @package WooCommerce_Safe2Pay 12 * WC requires at least: 5.0.0 13 * WC tested up to: 4.2.2 15 14 */ 16 15 17 defined( 'ABSPATH') || exit;16 defined('ABSPATH') || exit; 18 17 19 // Plugin constants. 20 define( 'WC_SAFE2PAY_VERSION', '2.13.1' ); 21 define( 'WC_SAFE2PAY_PLUGIN_FILE', __FILE__ ); 18 define('WC_SAFE2PAY_VERSION', '1.9'); 19 define('WC_SAFE2PAY_PLUGIN_FILE', __FILE__); 22 20 23 if ( ! class_exists( 'WC_Safe2Pay' ) ) { 24 include_once dirname( __FILE__ ) . '/includes/class-wc-safe2pay.php'; 25 add_action( 'plugins_loaded', array( 'WC_Safe2Pay', 'init' ) ); 21 if (!class_exists('WC_Safe2Pay')) { 22 include_once dirname(__FILE__) . '/includes/class-wc-safe2pay.php'; 23 include_once(ABSPATH . 'wp-admin/includes/plugin.php'); 24 25 add_action('plugins_loaded', array('WC_Safe2Pay', 'init')); 26 26 }
Note: See TracChangeset
for help on using the changeset viewer.