Skip to content

Commit

Permalink
Merge pull request #121 from LinkNacional/dev
Browse files Browse the repository at this point in the history
1.14.1 Fixed error on orders log
  • Loading branch information
emanuellopess authored Dec 6, 2024
2 parents b0a2ccd + d3e4e3b commit 287e329
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 138 deletions.
29 changes: 14 additions & 15 deletions .devcontainer/devcontainer.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@
{
"name": "PHP",
// https: //github.com/devcontainers/images/tree/main/src/php
"image": "mcr.microsoft.com/vscode/devcontainers/php:8.1",
"mounts": [
{
"source": "/path/to/your/wordpress-stubs",
"target": "/home/vscode/_wordpress",
"type": "bind"
}
],
"image": "mcr.microsoft.com/vscode/devcontainers/php:7.4",
"features": {
// https://github.com/devcontainers/features/tree/main/src/node
"ghcr.io/devcontainers/features/node:1": {
"version": "18.14.0",
"nvmVersion": "0.39.3"
}
},
"mounts": [
{
"source": "/home/{yourusername}/wordpress",
"target": "/home/vscode/_wordpress",
"type": "bind"
}
],
"postCreateCommand": "npm install",
"customizations": {
"vscode": {
"extensions": [
"junstyle.php-cs-fixer",
"bmewburn.vscode-intelephense-client",
"neilbrayfield.php-docblocker",
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"jkiviluoto.tws",
"lacroixdavid1.vscode-format-context-menu",
"Gruntfuggly.todo-tree",
"Natizyskunk.sftp"
],
"settings": {
"[html]": {
Expand All @@ -34,7 +38,6 @@
"editor.tabSize": 4
},
"[javascript]": {
"editor.defaultFormatter": "junstyle.php-cs-fixer",
"editor.rulers": [
80,
120
Expand Down Expand Up @@ -64,12 +67,8 @@
"html.format.wrapAttributes": "force-expand-multiline",
"html.format.wrapAttributesIndentSize": 4,
"html.format.wrapLineLength": 120,
"intelephense.completion.maxItems": 10,
"intelephense.environment.documentRoot": "src",
"intelephense.environment.phpVersion": "8.1",
"intelephense.environment.includePaths": [
"/home/vscode/wordpress"
],
"intelephense.files.associations": [
"*.php"
],
Expand All @@ -92,4 +91,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: "1.14.0"
custom_tag: "1.14.1"

# Generate new release
- name: Generate new Release
Expand Down
3 changes: 2 additions & 1 deletion .vscode/.php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@
))
->setIndent(' ')
->setLineEnding("\n")
->setRiskyAllowed(true);
->setRiskyAllowed(true)
;
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.14.1 - 06/12/2024
* Correção de bug para a função de mostrar logs no pedido.

# 1.14.0 - 05/12/2024
* Adição de compatibilidade com botão para capturar pedido;
* Adição de configurações para adicionar logs no pedido;
Expand Down
6 changes: 5 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.linknacional.com.br/wordpress/woocommerce/cielo/
Tags: woocommerce, payment, paymethod, card, credit
Requires at least: 5.7
Tested up to: 6.7
Stable tag: 1.14.0
Stable tag: 1.14.1
Requires PHP: 7.2
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -93,6 +93,10 @@ Payment Gateway for Cielo API on WooCommerce plugin is dependent on WooCommerce
7. Debit card front page with payment fields.

== Changelog ==
= 1.14.1 =
**06/12/2024**
* Fix bug on show detailed logs on order.

= 1.14.0 =
**05/12/2024**
* Add compatibility with button to capture order;
Expand Down
67 changes: 25 additions & 42 deletions includes/LknWCGatewayCieloCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// Exit if accessed directly.
if (! defined('ABSPATH')) {
if ( ! defined('ABSPATH')) {
exit;
}

Expand All @@ -29,8 +29,7 @@
*
* @version 1.0.0
*/
final class LknWCGatewayCieloCredit extends WC_Payment_Gateway
{
final class LknWCGatewayCieloCredit extends WC_Payment_Gateway {
/**
* Define instructions to configure and use this plugin.
*
Expand Down Expand Up @@ -61,8 +60,7 @@ final class LknWCGatewayCieloCredit extends WC_Payment_Gateway
/**
* Constructor for the gateway.
*/
public function __construct()
{
public function __construct() {
$this->id = 'lkn_cielo_credit';
$this->icon = apply_filters('lkn_wc_cielo_gateway_icon', '');
$this->has_fields = true;
Expand Down Expand Up @@ -112,16 +110,14 @@ public function __construct()
* @param WC_Order $order
* @return void
*/
public function process_subscription_payment($amount, $order): void
{
public function process_subscription_payment($amount, $order): void {
do_action('lkn_wc_cielo_scheduled_subscription_payment', $amount, $order);
}

/**
* Load admin JavaScript for the admin page.
*/
public function admin_load_script(): void
{
public function admin_load_script(): void {
wp_enqueue_script('lkn-wc-gateway-admin', plugin_dir_url(__FILE__) . '../resources/js/admin/lkn-wc-gateway-admin.js', array('wp-i18n'), $this->version, 'all');

$page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
Expand All @@ -142,8 +138,7 @@ public function admin_load_script(): void
/**
* Load gateway scripts/styles.
*/
public function payment_gateway_scripts(): void
{
public function payment_gateway_scripts(): void {
// Don't load scripts outside payment page
if (
! is_checkout()
Expand Down Expand Up @@ -177,8 +172,7 @@ public function payment_gateway_scripts(): void
/**
* Initialise Gateway Settings Form Fields.
*/
public function init_form_fields(): void
{
public function init_form_fields(): void {
$this->form_fields = array(
'general' => array(
'title' => esc_attr__('General', 'lkn-wc-gateway-cielo'),
Expand Down Expand Up @@ -293,13 +287,13 @@ public function init_form_fields(): void
);

if ($this->get_option('debug') == 'yes') {
$this->form_fields['show_order_logs'] = array(
$this->form_fields['show_order_logs'] = array(
'title' => __('Visualizar Log no Pedido', 'lkn-wc-gateway-cielo'),
'type' => 'checkbox',
'label' => sprintf('Habilita visualização do log da transação dentro do pedido.', 'lkn-wc-gateway-cielo'),
'default' => 'no',
);
$this->form_fields['clear_order_records'] = array(
$this->form_fields['clear_order_records'] = array(
'title' => __('Limpar logs nos Pedidos', 'lkn-wc-gateway-cielo'),
'type' => 'button',
'id' => 'validateLicense',
Expand All @@ -309,16 +303,15 @@ public function init_form_fields(): void

$customConfigs = apply_filters('lkn_wc_cielo_get_custom_configs', array(), $this->id);

if (! empty($customConfigs)) {
if ( ! empty($customConfigs)) {
$this->form_fields = array_merge($this->form_fields, $customConfigs);
}
}

/**
* Render the payment fields.
*/
public function payment_fields(): void
{
public function payment_fields(): void {
$activeInstallment = $this->get_option('installment_payment');
$total_cart = number_format($this->get_order_total(), 2, '.', '');
$noLoginCheckout = isset($_GET['pay_for_order']) ? sanitize_text_field($_GET['pay_for_order']) : 'false';
Expand Down Expand Up @@ -484,10 +477,9 @@ class="lkn-cvv"
*
* @return bool
*/
public function validate_fields()
{
public function validate_fields() {
$validateCompatMode = $this->get_option('input_validation_compatibility', 'no');
if (! wp_verify_nonce($_POST['nonce_lkn_cielo_credit'], 'nonce_lkn_cielo_credit')) {
if ( ! wp_verify_nonce($_POST['nonce_lkn_cielo_credit'], 'nonce_lkn_cielo_credit')) {
$this->log->log('error', 'Nonce verification failed. Nonce: ' . var_export($_POST['nonce_lkn_cielo_credit'], true), array('source' => 'woocommerce-cielo-credit'));
$this->add_notice_once(__('Nonce verification failed, try reloading the page', 'lkn-wc-gateway-cielo'), 'error');
return false;
Expand Down Expand Up @@ -518,11 +510,10 @@ public function validate_fields()
*
* @return array
*/
public function process_payment($order_id)
{
public function process_payment($order_id) {
$nonceInactive = $this->get_option('nonce_compatibility', 'no');

if (! wp_verify_nonce($_POST['nonce_lkn_cielo_credit'], 'nonce_lkn_cielo_credit') && 'no' === $nonceInactive) {
if ( ! wp_verify_nonce($_POST['nonce_lkn_cielo_credit'], 'nonce_lkn_cielo_credit') && 'no' === $nonceInactive) {
$this->log->log('error', 'Nonce verification failed. Nonce: ' . var_export($_POST['nonce_lkn_cielo_credit'], true), array('source' => 'woocommerce-cielo-credit'));
$this->add_notice_once(__('Nonce verification failed, try reloading the page', 'lkn-wc-gateway-cielo'), 'error');
throw new Exception(esc_attr(__('Nonce verification failed, try reloading the page', 'lkn-wc-gateway-cielo')));
Expand Down Expand Up @@ -703,7 +694,7 @@ public function process_payment($order_id)
// Salvar o token e a bandeira do cartão no meta do pedido
$user_id = $order->get_user_id();

if (! isset($responseDecoded->Payment->CreditCard->CardToken)) {
if ( ! isset($responseDecoded->Payment->CreditCard->CardToken)) {
$order->add_order_note('O token para cobranças automáticas não foi gerado, então as cobranças automáticas não poderão ser efetuadas.');
}

Expand Down Expand Up @@ -783,8 +774,7 @@ public function process_payment($order_id)
/**
* Calculate the total value of items in the WooCommerce cart.
*/
public static function lknGetCartTotal()
{
public static function lknGetCartTotal() {
$cart = WC()->cart;

if (empty($cart)) {
Expand All @@ -811,8 +801,7 @@ public static function lknGetCartTotal()
*
* @return bool
*/
public function process_refund($order_id, $amount = null, $reason = '')
{
public function process_refund($order_id, $amount = null, $reason = '') {
// Do your refund here. Refund $amount for the order with ID $order_id
$url = ($this->get_option('env') == 'production') ? 'https://api.cieloecommerce.cielo.com.br/' : 'https://apisandbox.cieloecommerce.cielo.com.br/';
$merchantId = sanitize_text_field($this->get_option('merchant_id'));
Expand Down Expand Up @@ -856,8 +845,7 @@ public function process_refund($order_id, $amount = null, $reason = '')
*
* @return bool
*/
private function validate_card_number($ccnum, $renderNotice)
{
private function validate_card_number($ccnum, $renderNotice) {
if (empty($ccnum)) {
if ($renderNotice) {
$this->add_notice_once(__('Credit Card number is required!', 'lkn-wc-gateway-cielo'), 'error');
Expand All @@ -878,8 +866,7 @@ private function validate_card_number($ccnum, $renderNotice)
return true;
}

private function validate_card_holder_name($cardName, $renderNotice)
{
private function validate_card_holder_name($cardName, $renderNotice) {
if (empty($cardName) || strlen($cardName) < 3) {
if ($renderNotice) {
$this->add_notice_once(__('Card Holder Name is required!', 'lkn-wc-gateway-cielo'), 'error');
Expand All @@ -899,8 +886,7 @@ private function validate_card_holder_name($cardName, $renderNotice)
*
* @return bool
*/
private function validate_exp_date($expDate, $renderNotice)
{
private function validate_exp_date($expDate, $renderNotice) {
if (empty($expDate)) {
if ($renderNotice) {
$this->add_notice_once(__('Expiration date is required!', 'lkn-wc-gateway-cielo'), 'error');
Expand Down Expand Up @@ -940,8 +926,7 @@ private function validate_exp_date($expDate, $renderNotice)
*
* @return bool
*/
private function validate_cvv($cvv, $renderNotice)
{
private function validate_cvv($cvv, $renderNotice) {
if (empty($cvv)) {
if ($renderNotice) {
$this->add_notice_once(__('CVV is required!', 'lkn-wc-gateway-cielo'), 'error');
Expand All @@ -968,9 +953,8 @@ private function validate_cvv($cvv, $renderNotice)
* @param string $message
* @param string $type
*/
private function add_notice_once($message, $type): void
{
if (! wc_has_notice($message, $type)) {
private function add_notice_once($message, $type): void {
if ( ! wc_has_notice($message, $type)) {
wc_add_notice($message, $type);
}
}
Expand All @@ -982,8 +966,7 @@ private function add_notice_once($message, $type): void
*
* @return string|bool
*/
private function get_card_provider($cardNumber)
{
private function get_card_provider($cardNumber) {
$brand = '';
$brand = apply_filters('lkn_wc_cielo_get_card_brand', $brand, $cardNumber);

Expand Down
11 changes: 5 additions & 6 deletions includes/LknWCGatewayCieloDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Lkn\WCCieloPaymentGateway\Includes;
use DateTime;

use Exception;
use Lkn\WCCieloPaymentGateway\Includes\LknWcCieloHelper;
use WC_Logger;
Expand Down Expand Up @@ -341,13 +340,13 @@ public function init_form_fields(): void {
);

if ( $this->get_option('debug') == 'yes' ) {
$this->form_fields['show_order_logs'] = array(
$this->form_fields['show_order_logs'] = array(
'title' => __('Visualizar Log no Pedido', 'lkn-wc-gateway-cielo'),
'type' => 'checkbox',
'label' => sprintf('Habilita visualização do log da transação dentro do pedido.', 'lkn-wc-gateway-cielo'),
'default' => 'no',
);
$this->form_fields['clear_order_records'] = array(
$this->form_fields['clear_order_records'] = array(
'title' => __('Limpar logs nos Pedidos', 'lkn-wc-gateway-cielo'),
'type' => 'button',
'id' => 'validateLicense',
Expand Down Expand Up @@ -1246,13 +1245,13 @@ public function process_payment($order_id) {
'body' => json_decode($args['body'], true), // Decodificar como array associativo
'response' => json_decode(json_encode($responseDecoded), true) // Certificar que responseDecoded é um array associativo
);

// Censurar o número do cartão de crédito
$orderLogsArray['body']['Payment']['CreditCard']['CardNumber'] = substr($orderLogsArray['body']['Payment']['CreditCard']['CardNumber'], 0, 6) . '******' . substr($orderLogsArray['body']['Payment']['CreditCard']['CardNumber'], -4);

// Remover a parte de "Links"
unset($orderLogsArray['response']['Payment']['Links']);

$orderLogs = json_encode($orderLogsArray);
$order->update_meta_data('lknWcCieloOrderLogs', $orderLogs);
}
Expand Down
Loading

0 comments on commit 287e329

Please sign in to comment.