Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.10.0 Adição de compatibilidade com o plugin oficial do WooCommerce Subscriptions; #73

Merged
merged 7 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9.3"
custom_tag: "1.10.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.10.0 - 03/07/2024
* Adição de compatibilidade com o plugin oficial do WooCommerce Subscriptions;

# 1.9.3 - 18/06/2024
* Adição de compatibilidade com a funcionalidade Orders Auto-Complete do plugin pro;
* Correção de problema de renderização do Cielo débito 3DS.
Expand Down
9 changes: 9 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ Payment Gateway for Cielo API on WooCommerce plugin is dependent on WooCommerce

== Changelog ==

= 1.10.0 =
**03/07/2024**
* Add compatibility with the official WooCommerce Subscriptions plugin;

= 1.9.3 =
**18/06/2024**
* Add compatibility with the Orders Auto-Complete functionality of the pro plugin;
* Fixed rendering issue for Cielo Debit 3DS card.

= 1.9.2 =
**05/06/2024**
* Correction of validation in the cardholder name field;
Expand Down
45 changes: 44 additions & 1 deletion includes/LknWCGatewayCieloCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use WC_Logger;
use WC_Payment_Gateway;
use WC_Subscriptions_Order;

/**
* Lkn_WC_Gateway_Cielo_Credit class.
Expand Down Expand Up @@ -88,6 +89,8 @@ 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 );

// Action hook to load admin JavaScript
if (function_exists('get_plugins')) {
// Only load if pro plugin doesn't exist
Expand All @@ -99,6 +102,17 @@ public function __construct() {
}
}

/**
* Process subscription payment.
*
* @param float $amount
* @param WC_Order $order
* @return 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.
*/
Expand Down Expand Up @@ -452,6 +466,7 @@ public function process_payment($order_id) {
$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 @@ -484,6 +499,12 @@ public function process_payment($order_id) {
throw new Exception($message);
}

// Adicione esta linha para processar o pagamento recorrente se o pedido contiver uma assinatura
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = apply_filters('lkn_wc_cielo_process_recurring_payment', $order);
$subscriptionSaveCard = true;
}

// Convert the amount to equivalent in BRL
if ('BRL' !== $currency) {
$amount = apply_filters('lkn_wc_cielo_convert_amount', $amount, $currency);
Expand Down Expand Up @@ -539,7 +560,7 @@ public function process_payment($order_id) {
'Holder' => $cardName,
'ExpirationDate' => $cardExp,
'SecurityCode' => $cardCvv,
'SaveCard' => false,
'SaveCard' => $subscriptionSaveCard,
'Brand' => $provider,
),
),
Expand All @@ -565,6 +586,28 @@ public function process_payment($order_id) {
if (isset($responseDecoded->Payment) && (1 == $responseDecoded->Payment->Status || 2 == $responseDecoded->Payment->Status)) {
$order->payment_complete($responseDecoded->Payment->PaymentId);

if (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();

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.');
}

// Dados do cartão de pagamento
$cardPayment = array(
'cardToken' => $responseDecoded->Payment->CreditCard->CardToken,
'brand' => $provider,
);

// Codificar os dados do cartão de pagamento em base64
$paymentOptions = array('payment' => base64_encode(json_encode($cardPayment)));

// Atualizar o user meta com os dados codificados em base64
update_user_meta($user_id, 'cielo_card_token', $paymentOptions['payment']);

}

// Remove cart
WC()->cart->empty_cart();
$update_order = apply_filters("lkn_wc_cielo_update_order", $order_id);
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 @@ -4,7 +4,7 @@
* 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.9.3
* Version: 1.10.0
*
* Author: Link Nacional
* Author URI: https://linknacional.com.br
Expand Down Expand Up @@ -308,7 +308,7 @@ public static function email_order_meta_fields($fields, $sent_to_admin, $order)
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.9.3');
define('LKN_WC_CIELO_VERSION', '1.10.0');
}
if ( ! defined('LKN_WC_CIELO_TRANSLATION_PATH')) {
define('LKN_WC_CIELO_TRANSLATION_PATH', plugin_dir_path(__FILE__) . 'languages/');
Expand Down