Skip to content

Commit

Permalink
Merge pull request #136 from LinkNacional/dev
Browse files Browse the repository at this point in the history
1.17.0 Adição de compatibilidade com configurações de retentativas para assinaturas
  • Loading branch information
emanuellopess authored Feb 10, 2025
2 parents 5c0c194 + e88280e commit e3b8893
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
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/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: "1.16.0"
custom_tag: "1.17.0"

# Generate new release
- name: Generate new Release
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.17.0 - 06/12/2024
* Adição de compatibilidade com configurações de retentativas para assinaturas.

# 1.16.0 - 31/01/2025
* Adição do notice de donwloado do plugin: fraud-detection-for-woocommerce.
* Adição de mensagem de avaliação do plugin no footer.
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.1
Stable tag: 1.16.0
Stable tag: 1.17.0
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.17.0 =
**06/02/2025**
* Added compatibility with retry settings for subscriptions.

= 1.16.0 =
**31/01/2025**
* Added the download notice for the plugin: fraud-detection-for-woocommerce.
Expand Down
41 changes: 28 additions & 13 deletions includes/LknWCGatewayCieloCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use DateTime;
use Exception;
use WC_Logger;
use WC_Payment_Gateway;
use WC_Subscriptions_Order;
use WC_Payment_Gateway;
use WC_Subscription;

/**
* Lkn_WC_Gateway_Cielo_Credit class.
Expand Down Expand Up @@ -92,7 +93,7 @@ public function __construct()
// Action hook to load custom JavaScript
add_action('wp_enqueue_scripts', array($this, 'payment_gateway_scripts'));

add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscription_payment'), 10, 2);
add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'process_subscription_payment'), 10, 3);

// Action hook to load admin JavaScript
if (function_exists('get_plugins')) {
Expand All @@ -107,9 +108,9 @@ public function __construct()
* @param WC_Order $order
* @return void
*/
public function process_subscription_payment($amount, $order): void
public function process_subscription_payment($amount, $order, $isRetry = false): void
{
do_action('lkn_wc_cielo_scheduled_subscription_payment', $amount, $order);
do_action('lkn_wc_cielo_scheduled_subscription_payment', $amount, $order, $isRetry);
}

/**
Expand Down Expand Up @@ -564,14 +565,14 @@ public function process_payment($order_id)
$merchantOrderId = uniqid('invoice_');
$amount = $order->get_total();
$capture = ($this->get_option('capture', 'yes') == 'yes') ? true : false;
$saveCard = ($this->get_option('save_card_token', 'yes') == 'yes') ? true : false;
$description = sanitize_text_field($this->get_option('invoiceDesc'));
$description = preg_replace('/[^a-zA-Z\s]+/', '', $description);
$description = preg_replace('/\s+/', ' ', $description);
$provider = $this->get_card_provider($cardNum);
$debug = $this->get_option('debug');
$currency = $order->get_currency();
$activeInstallment = $this->get_option('installment_payment');
$subscriptionSaveCard = false;

if ($this->validate_card_holder_name($cardName, false) === false) {
$message = __('Card Holder Name is required!', 'lkn-wc-gateway-cielo');
Expand Down Expand Up @@ -607,7 +608,7 @@ public function process_payment($order_id)
// Adicione esta linha para processar o pagamento recorrente se o pedido contiver uma assinatura
if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = apply_filters('lkn_wc_cielo_process_recurring_payment', $order);
$subscriptionSaveCard = true;
$saveCard = true;
}

// Convert the amount to equivalent in BRL
Expand Down Expand Up @@ -664,13 +665,16 @@ public function process_payment($order_id)
'CardNumber' => $cardNum,
'ExpirationDate' => $cardExp,
'SecurityCode' => $cardCvv,
'SaveCard' => $subscriptionSaveCard,
'SaveCard' => $saveCard,
'Brand' => $provider,
'CardOnFile' => array(
'Usage' => 'First'
)
),
),
);

$body = apply_filters('lkn_wc_cielo_process_body', $body, $_POST, $order_id);
do_action('lkn_wc_cielo_zero_auth', $body, $args['headers'], $this);

$args['body'] = wp_json_encode($body);

Expand Down Expand Up @@ -716,7 +720,7 @@ public function process_payment($order_id)
$order->add_meta_data('paymentId', $responseDecoded->Payment->PaymentId, true);
do_action("lkn_wc_cielo_change_order_status", $order, $this, $capture);

if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
if ($saveCard || (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order_id))) {
// Salvar o token e a bandeira do cartão no meta do pedido
$user_id = $order->get_user_id();

Expand All @@ -730,11 +734,22 @@ public function process_payment($order_id)
'brand' => $provider,
);

// Codificar os dados do cartão de pagamento em base64
$paymentOptions = array('payment' => base64_encode(json_encode($cardPayment)));
$cardsArray = get_user_meta($user_id, 'card_array', true);
$cardsArray = is_array($cardsArray) ? $cardsArray : [];
$lastFourDigits = $responseDecoded->Payment->CreditCard->CardNumber;
$expirationDate = $responseDecoded->Payment->CreditCard->ExpirationDate;

// Adiciona o novo cartão à lista
$cardsArray[] = array(
'cardToken' => $cardPayment['cardToken'],
'brand' => $provider,
'cardDigits' => $lastFourDigits,
'expirationDate' => $expirationDate,
);

// Atualizar o user meta com os dados codificados em base64
update_user_meta($user_id, 'cielo_card_token', $paymentOptions['payment']);
// Atualiza os metadados do usuário
update_user_meta($user_id, 'card_array', $cardsArray);
update_user_meta($user_id, 'default_card', array_key_last($cardsArray));
}

// Remove cart
Expand Down
4 changes: 2 additions & 2 deletions lkn-wc-gateway-cielo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Payment Gateway for Cielo API on WooCommerce
* Plugin URI: https://www.linknacional.com.br/wordpress/woocommerce/cielo/
* Description: Adds the Cielo API 3.0 Payments gateway to your WooCommerce website.
* Version: 1.16.0
* Version: 1.17.0
* Author: Link Nacional
* Author URI: https://linknacional.com.br
* Text Domain: lkn-wc-gateway-cielo
Expand Down Expand Up @@ -326,7 +326,7 @@ private static function setup_constants(): void
{
// Defines addon version number for easy reference.
if (! defined('LKN_WC_CIELO_VERSION')) {
define('LKN_WC_CIELO_VERSION', '1.16.0');
define('LKN_WC_CIELO_VERSION', '1.17.0');
}
if (! defined('LKN_WC_CIELO_TRANSLATION_PATH')) {
define('LKN_WC_CIELO_TRANSLATION_PATH', plugin_dir_path(__FILE__) . 'languages/');
Expand Down

0 comments on commit e3b8893

Please sign in to comment.