Skip to content

Commit

Permalink
Merge pull request #18 from jvoliveiraGN/master
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
jvoliveiraGN authored Jul 6, 2021
2 parents 535f35f + 91c34d2 commit 1933ba2
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 99 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.0
* Fix: Compatibilidade com PHP 8
* Fix: Adequação de funções depreciadas

# 1.2.1
* Add: Ajuste do header da requisição
* Fix: Compatibilidade com Brazilian Market on Woocommerce
Expand Down Expand Up @@ -143,4 +147,4 @@

# v0.1.0

* Versão Beta
* Versão Beta
Binary file modified auto/woo-gerencianet-official.zip
Binary file not shown.
50 changes: 22 additions & 28 deletions manual/woo-gerencianet-official/includes/class-wc-gerencianet-oficial-gateway.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
return false;
}

$e2eid = get_post_meta($order->id, 'endToEndId', true);
$apiID = get_post_meta($order->id, 'charge_id', true);
$e2eid = get_post_meta($order->get_id(), 'endToEndId', true);
$apiID = get_post_meta($order->get_id(), 'charge_id', true);

if(isset($e2eid) && $e2eid != ""){

Expand Down Expand Up @@ -1139,7 +1139,7 @@ public function gerencianet_pay_billet($checkout_type, $order_id, $charge_id)
add_post_meta(intval($post_order_id), 'billet_discount_value', $discountBilletTotal, true);
}
$order->update_status('on-hold', __('Waiting'));
$order->reduce_order_stock();
wc_reduce_stock_levels($order_id);
WC()->cart->empty_cart();
} else {
if ('yes' == $this->debug) {
Expand Down Expand Up @@ -1506,20 +1506,20 @@ protected function generate_payment_page_options($order_id)
}
}

if ($validate->_corporate($order->billing_company)) {
if ($validate->_corporate($order->get_billing_company())) {
$gn_billing_name_corporate_validate = true;
$gn_order_name_corporate = $order->billing_company;
$gn_order_name_corporate = $order->get_billing_company();
}
}

if (isset($order->billing_email)) {
if ($validate->_email($order->billing_email)) {
if ($order->get_billing_email() !== NULL) {
if ($validate->_email($order->get_billing_email())) {
$gn_billing_email_validate = true;
}
}

if (isset($order->billing_phone)) {
if ($validate->_phone_number($order->billing_phone)) {
if ($order->get_billing_phone() !== NULL) {
if ($validate->_phone_number($order->get_billing_phone())) {
$gn_billing_phone_number_validate = true;
}
}
Expand All @@ -1530,13 +1530,13 @@ protected function generate_payment_page_options($order_id)
}
}

if (isset($order->billing_address_1)) {
if ($validate->_street($order->billing_address_1)) {
if ($order->get_billing_address_1() !== NULL) {
if ($validate->_street($order->get_billing_address_1())) {
$gn_billing_street_validate = true;
}
}

if (isset($order->billing_number)) {
if ($order->billing_number !== NULL) {
if ($validate->_number($order->billing_number)) {
$gn_billing_number_validate = true;
}
Expand All @@ -1548,26 +1548,20 @@ protected function generate_payment_page_options($order_id)
}
}

if (isset($order->billing_city)) {
if ($validate->_city($order->billing_city)) {
if ($order->get_billing_city() !== NULL) {
if ($validate->_city($order->get_billing_city())) {
$gn_billing_city_validate = true;
}
}

if (isset($order->billing_city)) {
if ($validate->_city($order->billing_city)) {
$gn_billing_city_validate = true;
}
}

if (isset($order->billing_postcode)) {
if ($validate->_zipcode($order->billing_postcode)) {
if ($order->get_billing_postcode() !== NULL) {
if ($validate->_zipcode($order->get_billing_postcode())) {
$gn_billing_zipcode_validate = true;
}
}

if (isset($order->billing_state)) {
if ($validate->_state($order->billing_state)) {
if ($order->get_billing_state() !== NULL) {
if ($validate->_state($order->get_billing_state())) {
$gn_billing_state_validate = true;
}
}
Expand Down Expand Up @@ -1826,7 +1820,7 @@ private function process_payment_method($method_payment, $order_id, $charge_id,

$pay_charge = ($method_payment !== 'pix')
? $this->{$functionCall}('OSC', $order_id, $charge_id)
: Pix::gerencianet_pay_pix('OSC', $order_id, $charge_id, $cpf_cnpj);
: Pix::woocommerce_gerencianet_pay_pix('OSC', $order_id, $charge_id, $cpf_cnpj);

$resultCheckPay = array();
$resultCheckPay = json_decode($pay_charge, true);
Expand Down Expand Up @@ -1888,7 +1882,7 @@ protected function generate_gn_thankyou_page($order_id)
{
$this->styles();
$order = wc_get_order($order_id);
$email = $order->billing_email;
$email = $order->get_billing_email();

$billet_url = get_post_meta($order_id, 'billet', true);
$qrcode = get_post_meta($order_id, 'pix_qr', true);
Expand Down Expand Up @@ -2089,7 +2083,7 @@ public function currency_not_supported_message()
function gn_order_view_billet_link($order)
{

$billet = get_post_meta($order->id, 'billet', true);
$billet = get_post_meta($order->get_id(), 'billet', true);
if (!empty($billet)) {
if ($order->get_status() == "on-hold" || $order->get_status() == "pending") {
echo "
Expand All @@ -2107,7 +2101,7 @@ function gn_order_view_billet_link($order)
function gn_email_billet_link($order)
{

$billet = get_post_meta($order->id, 'billet', true);
$billet = get_post_meta($order->get_id(), 'billet', true);
if (!empty($billet)) {
echo "
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public function _cpf( $data ) {
for ( $t = 9; $t < 11; $t ++ ) {

for ( $d = 0, $c = 0; $c < $t; $c ++ ) {
$d += $cpf{$c} * ( ( $t + 1 ) - $c );
$d += $cpf[$c] * (($t + 1) - $c);
}
$d = ( ( 10 * $d ) % 11 ) % 10;
if ( $cpf{$c} != $d ) {
if ($cpf[$c] != $d) {
return false;
}
}
Expand Down Expand Up @@ -158,21 +158,21 @@ public function _cnpj( $cnpj ) {
}

for ( $i = 0, $j = 5, $soma = 0; $i < 12; $i ++ ) {
$soma += $cnpj{$i} * $j;
$soma += $cnpj[$i] * $j;
$j = ( $j == 2 ) ? 9 : $j - 1;
}
$resto = $soma % 11;
if ( $cnpj{12} != ( $resto < 2 ? 0 : 11 - $resto ) ) {
if ( $cnpj[12] != ( $resto < 2 ? 0 : 11 - $resto ) ) {
return false;
}

for ( $i = 0, $j = 6, $soma = 0; $i < 13; $i ++ ) {
$soma += $cnpj{$i} * $j;
$soma += $cnpj[$i] * $j;
$j = ( $j == 2 ) ? 9 : $j - 1;
}
$resto = $soma % 11;

return $cnpj{13} == ( $resto < 2 ? 0 : 11 - $resto );
return $cnpj[13] == ( $resto < 2 ? 0 : 11 - $resto );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(array $options = null)
'headers' => [
'Content-Type' => 'application/json',
'api-sdk' => 'php-' . $composerData['version'],
'wordpress-plugin' => 'v1.2.1', // ATUALIZAR VERSÃO A CADA ATUALIZAÇÃO
'wordpress-plugin' => 'v1.3.0', // ATUALIZAR VERSÃO A CADA ATUALIZAÇÃO
'partner-token' => $partner_token
]
];
Expand Down
41 changes: 21 additions & 20 deletions manual/woo-gerencianet-official/includes/lib/payments/Pix.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class Pix {
*
* @return string
*/
public static function woocommerce_gerencianet_pay_pix() {
echo Pix::gerencianet_pay_pix('checkout_page', null, null);
public static function woocommerce_gerencianet_pay_pix($typecheck, $order_id, $charge_id, $cpf_cnpj) {
$pix = new Pix();
return $pix->gerencianet_pay_pix($typecheck, $order_id, $charge_id, $cpf_cnpj);
die();
}

Expand Down Expand Up @@ -57,8 +58,7 @@ public function gerencianet_pay_pix($checkout_type, $order_id, $charge_id, $cpf_
$gateway = new WC_Gerencianet_Oficial_Gateway();

//get order data
$post_order_id = isset($arrayDadosPost['order_id']) ? $arrayDadosPost['order_id'] : $order_id;
$order = wc_get_order($post_order_id);
$order = wc_get_order($order_id);
$full_name = $order->get_formatted_billing_full_name();

$totalOrder = strval($gateway->calculatePixDiscount());
Expand All @@ -81,30 +81,31 @@ public function gerencianet_pay_pix($checkout_type, $order_id, $charge_id, $cpf_
],
[
"nome" => "Número do Pedido",
"valor" => "#".$post_order_id
"valor" => "#".$order_id
]
]
];

$credential = Pix::get_gn_api_credentials($gateway->gnIntegration->get_gn_api_credentials());
$gnApiResult = GerencianetIntegration::pay_pix($credential, $body);
$gnApiResult = $gateway->gnIntegration->pay_pix($credential, $body);
$resultCheck = json_decode($gnApiResult, true);

if (isset($resultCheck['txid']) && isset($resultCheck['loc']['id'])) {
$gnApiQrCode = GerencianetIntegration::generate_qrcode($credential, $resultCheck['loc']['id']);
$gnApiQrCode = $gateway->gnIntegration->generate_qrcode($credential, $resultCheck['loc']['id']);
$resultQrCode = json_decode($gnApiQrCode, true);
$resultCheck['charge_id'] = $post_order_id;

$resultCheck['charge_id'] = $order_id;

if(isset($resultQrCode['imagemQrcode'])) {
$resultCheck['imagemQrcode'] = $resultQrCode['imagemQrcode'];
global $wpdb;

if ($order->get_status() != 'failed' && !isset($meta_discount_value_array[0])) {
$order_data = $order->get_data();

if ($order_data['status'] != 'failed' && !isset($meta_discount_value_array[0])) {
$wpdb->insert($wpdb->prefix . 'woocommerce_order_items', array(
'order_item_name' => __('Discount of ', WCGerencianetOficial::getTextDomain()) . str_replace(".", ",", $gateway->discountPix) . __('% Pix', WCGerencianetOficial::getTextDomain()),
'order_item_type' => 'fee',
'order_id' => intval($post_order_id)
'order_id' => intval($order_id)
));
$lastid = $wpdb->insert_id;

Expand Down Expand Up @@ -132,15 +133,15 @@ public function gerencianet_pay_pix($checkout_type, $order_id, $charge_id, $cpf_
'meta_value' => '0'
));

update_post_meta(intval($post_order_id), '_order_total', number_format(intval(ceil($gateway->gn_price_format($totalOrder))) / 100, 2, '.', ''));
update_post_meta(intval($post_order_id), '_payment_method_title', sanitize_text_field(__('Pix - Gerencianet', WCGerencianetOficial::getTextDomain())));
add_post_meta(intval($post_order_id), 'pix_qr', $resultQrCode['imagemQrcode'], true);
add_post_meta(intval($post_order_id), 'pix_qr_copy', $resultQrCode['qrcode'], true);
add_post_meta(intval($post_order_id), 'txid', $resultCheck['txid'], true);
update_post_meta(intval($order_id), '_order_total', number_format(intval(ceil($gateway->gn_price_format($totalOrder))) / 100, 2, '.', ''));
update_post_meta(intval($order_id), '_payment_method_title', sanitize_text_field(__('Pix - Gerencianet', WCGerencianetOficial::getTextDomain())));
add_post_meta(intval($order_id), 'pix_qr', $resultQrCode['imagemQrcode'], true);
add_post_meta(intval($order_id), 'pix_qr_copy', $resultQrCode['qrcode'], true);
add_post_meta(intval($order_id), 'txid', $resultCheck['txid'], true);
}
$order->update_status('on-hold', __('Waiting'));
$order->reduce_order_stock();
WC()->cart->empty_cart();
wc_reduce_stock_levels($order_id);
WC()->cart->empty_cart();
}
else {
if ($gateway->gnIntegration->debug == 'yes') {
Expand Down Expand Up @@ -202,7 +203,7 @@ public static function updateWebhook($gateway) {
$pix_key = $gateway->pix_key;
$skip_mtls = ($gateway->pix_mtls == 'yes') ? 'false' : 'true'; // Precisa ser string

$gnApi = GerencianetIntegration::update_webhook($credential, $pix_key, $skip_mtls, $url);
$gnApi = $gateway->gnIntegration->update_webhook($credential, $pix_key, $skip_mtls, $url);
$result = json_decode($gnApi, true);

if($gateway->debug == 'yes' && $result['webhookUrl']) {
Expand Down Expand Up @@ -259,7 +260,7 @@ public static function successful_webhook($posted) {

// Atualiza status
foreach($orders as &$order) {
add_post_meta(intval($order->id), 'endToEndId', $order_notify->endToEndId, true);
add_post_meta(intval($order->get_id()), 'endToEndId', $order_notify->endToEndId, true);
$order->update_status('processing', __('Paid'));
$order->payment_complete();
}
Expand Down
9 changes: 7 additions & 2 deletions manual/woo-gerencianet-official/readme.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: Gerencianet
Tags: woocommerce, gerencianet, payment, transparent checkout, pix, bank slip, card, brazil, payments brazil
Requires at least: 5.x
Tested up to: 5.6.2
Stable tag: 1.2.1
Tested up to: 5.7
Stable tag: 1.3.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -56,6 +56,11 @@ Caso você tenha alguma dúvida ou sugestão, entre em contato conosco pelo site
10. Recomendamos que antes de disponibilizar pagamentos pela Gerencianet, o lojista realize testes de cobrança com o sandbox(ambiente de testes) ativado para verificar se o procedimento de pagamento está acontecendo conforme esperado.

= Changelog =

= 1.3.0 =
* Fix: Compatibilidade com PHP 8
* Fix: Adequação de funções depreciadas

= 1.2.1 =
* Add: Ajuste do header da requisição
* Fix: Compatibilidade com Brazilian Market on Woocommerce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<div class="gn-row" style="font-size: 15px!important;text-align: center !important;">
<div class="gn-col-12">
<span style="font-weight: bold !important;">
<?php echo $pix_copy_paste ?>
<?php echo __('Or copy the Code below and paste it into the app where you are going to make the payment:', WCGerencianetOficial::getTextDomain()) ; ?>
</span>
</div>
<script>
Expand Down
Loading

0 comments on commit 1933ba2

Please sign in to comment.