Skip to content

Commit

Permalink
Corrige o problema de Internal Server Error ao finalizar uma compra (#20
Browse files Browse the repository at this point in the history
)

* feat(admin-settings.html.php): update do formulário caso exista falha de conexão

* feat(admin-settings.html.php): update do form caso a conexão tenha falha com a Vindi

* fix(admin-settings.html.php): upload só ocorre se existir uma chame válida

* fix(RedirectCheckout.php): Corrigido a verificação de usuários não logados

* fix(admin-settings.html.php):Contador de tentativas de conexão para atualizar os dados

* fix(admin-settings.html.php):Contador de tentativas de conexão para atualizar os dados

* fix(admin-settings.html.php):Contador de tentativas de conexão para atualizar os dados

* fix(admin-settings.html.php):Contador de letras da chave

* feat(PaymentProcessor.php): debug para o log

* fix(PaymentProcessor.php): Tratamento para os cycles dos produtos

* fix(): Tratamento diverso dos Hooks e dos Subscriptions

* fix(): Tratamento diverso dos Hooks e dos Subscriptions

* Repositório da Vindi Woocommerce

* (fix:issue#4) Corrigido o erro de Internal Server

* Correcao do teste

* Apply suggestions from code review

* Apply suggestions from code review

* Update PaymentProcessor.php

* Update PaymentProcessor.php

* Apply suggestions from code review

* Update Settings.php

* Apply suggestions from code review

* (fix):Correção do Erro 500 e dos fretes no pedido

* changelog

* Remove alterações fora do escopo

* Remove arquivos desnecessários

* (fix):issue#4 Corrigido a entrada de frete e taxas

* (fix):issue#4 Corrigido o produto avulso

* (fix):issue#4 Corrigido o produto avulso

* (fix):issue#4 Corrigido o produto avulso

* (fix):issue#4 Correção para o teste

* (fix):issue#4 Correção para o teste

* (fix):issue#4 Correção para o teste

* debug - não corrigido, testes criação de produto avulso

* (fix:1.0.2) issue#4 - Correções comentadas no changelog

* (fix:1.0.2) issue#4 - Correções comentadas no changelog

* Ajuste do Código

* (fix) Taxas agrupadas e taxas por itens issue#4

* (fix) Criando o codigo vindi_bill_id issue#4

* Update PaymentProcessor.php

Produto de teste

* (fix) Formulário de Customer

* Update src/controllers/CustomerController.php

* Update readme.txt

* Update PaymentProcessor.php

Correção do Produto de Teste

* Update PaymentProcessor.php

Correção do Teste

* Update PaymentProcessor.php

Correção para os testes

* Update PaymentProcessor.php

Voltando configuração de pull

* Versionamento

* Versionamento

Co-authored-by: Laerte Guimarães <[email protected]>
Co-authored-by: laerte-guimaraes <[email protected]>
Co-authored-by: Cleber Boni <[email protected]>
  • Loading branch information
4 people authored Nov 25, 2020
1 parent 07b40dd commit fa5d9eb
Show file tree
Hide file tree
Showing 16 changed files with 1,349 additions and 1,144 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
composer.phar
/vendor/
.notes
.DS_Store
.vscode*
*.zip

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
12 changes: 10 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== Vindi WooCommerce 2 (BETA) ===
Contributors: MatheusKindrazki, thihxm
Contributors: laertejr, rodasistemas, cleberbonifacio
Plugin Name: Vindi WooCommerce 2 (BETA)
Plugin URI: https://github.com/vindi/vindi-woocommerce
Website Link: https://www.vindi.com.br
Expand All @@ -11,7 +11,7 @@ Tested up to: 5.4.2
WC requires at least: 3.0.0
WC tested up to: 4.2.1
Requires PHP: 5.6
Stable Tag: 1.0.1
Stable Tag: 1.0.2
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -39,6 +39,12 @@ Para dúvidas e suporte técnico, entre em contato com a equipe Vindi através d
5. Configurações de pagamentos via cartão de crédito

== Changelog ==
= 1.0.2 - 25/11/2020 =
- Lançamento da versão de patch.
- **Correção**: Corrigido a falha crítica na adesão de assinaturas por boleto e cartão.
- **Correção**: Corrigido periodicidade do frete para assinaturas recorrentes.


= 1.0.1 - 28/10/2020 =
- Lançamento da versão de patch.
- **Correção**: Removido obrigatoriedade de login do usuário para compras avulsas.
Expand All @@ -59,6 +65,8 @@ Para dúvidas e suporte técnico, entre em contato com a equipe Vindi através d
- **Melhoria**: Juros configuráveis em compras parceladas.

== Upgrade Notice ==
= 1.0.2 - 25/11/2020 =
Patch de correções para o plugin da Vindi
= 1.0.1 - 28/10/2020 =
Patch de correções para o plugin da Vindi

Expand Down
10 changes: 7 additions & 3 deletions src/controllers/PlansController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function __construct(VindiSettings $vindi_settings)
*/
function create($post_id, $post, $update, $recreated = false)
{

// Check if the post is a draft
if (strpos(get_post_status($post_id), 'draft') !== false) {
return;
Expand Down Expand Up @@ -194,6 +195,7 @@ function create($post_id, $post, $update, $recreated = false)
),
));


// Saving product id and plan in the WC goal
if ($createdProduct) {
update_post_meta( $post_id, 'vindi_product_id', $createdProduct['id'] );
Expand All @@ -208,10 +210,12 @@ function create($post_id, $post, $update, $recreated = false)
set_transient('vindi_product_message', 'error', 60);
}

return array(
$response = array(
'product' => $createdProduct,
'plan' => $createdPlan,
);

return $response;
}

function update($post_id)
Expand Down Expand Up @@ -369,11 +373,11 @@ function update($post_id)
} else {
set_transient('vindi_product_message', 'error', 60);
}

return array(
$response = array(
'product' => $updatedProduct,
'plan' => $updatedPlan,
);
return $response;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/controllers/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class VindiControllers
function __construct(VindiSettings $vindi_settings)
{
$this->includes();

$this->plans = new PlansController($vindi_settings);
$this->customers = new CustomerController($vindi_settings);
$this->products = new ProductController($vindi_settings);
Expand Down
11 changes: 5 additions & 6 deletions src/routes/RoutesApi.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<?php

class VindiRoutes
Expand Down Expand Up @@ -239,7 +238,7 @@ public function getSubscription($subscription_id)

return false;
}

/**
* @param string $subscription_id
*
Expand All @@ -256,7 +255,7 @@ public function isSubscriptionActive($subscription_id)
}

$response = $this->getSubscription($subscription_id);

if ($response && array_key_exists('status', $response)) {
if ($response['status'] != 'canceled') {
$this->recentRequest = $response;
Expand Down Expand Up @@ -394,10 +393,10 @@ public function isMerchantStatusTrialOrSandbox($is_config = false)
return true;

$merchant = $is_config ? $this->getMerchant($is_config) : $this->getMerchant();

if ('trial' === $merchant['status'])
return true;

return false;
}

Expand Down Expand Up @@ -489,7 +488,7 @@ public function findBillById($bill_id)
public function refundCharge($charge_id, $data)
{
$response = $this->api->request(sprintf('charges/%s/refund', filter_var($charge_id, FILTER_SANITIZE_NUMBER_INT)), 'POST', $data);

if (isset($response['charge'])) {
return $response['charge'];
}
Expand Down
47 changes: 47 additions & 0 deletions src/services/VindiHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,51 @@ public static function get_matching_subscription_item($subscription, $order_item
public static function sanitize_xss($value) {
return htmlspecialchars(strip_tags($value));
}

/**
* Sort arrays by keys maintains index association.
*
* @since 1.0.1
* @param array $arr. Array to order.
* @param string $on. String key to filter.
* @param defined $order. Order by ASC or DESC
*
* @return array
*/
public static function array_sort($array, $on, $order=SORT_ASC)
{
$new_array = array();
$sortable_array = array();

if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}

switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}

foreach ($sortable_array as $k => $v) {
$new_array[$k] = $array[$k];
}
}

return $new_array;
}
}


5 changes: 2 additions & 3 deletions src/services/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ private function subscription_renew($renew_infos)
$order_id = $subscription->get_last_order();
$order = $this->find_order_by_id($order_id);
$subscription_id = $renew_infos['vindi_subscription_id'];
$order_post_meta = get_post_meta($order->id, 'vindi_order', true);

$order_post_meta = array(get_post_meta($order->id, 'vindi_order', true));
$order_post_meta[$subscription_id]['cycle'] = $renew_infos['cycle'];
$order_post_meta[$subscription_id]['product'] = $renew_infos['plan_name'];
$order_post_meta[$subscription_id]['bill'] = array(
Expand Down Expand Up @@ -474,4 +473,4 @@ private function format_date($date)
{
return date('Y-m-d H:i:s', strtotime($date));
}
}
}
2 changes: 0 additions & 2 deletions src/templates/admin-settings.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,5 @@
</script>
<?php endif;?>
<?php endif;?>


</div>
</div>
10 changes: 5 additions & 5 deletions src/utils/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function process_refund($order_id, $amount = null, $reason = '') {
$order_meta = get_post_meta($order->id, 'vindi_order', true);
foreach ($order_meta as $key => $order_item) {
$bill_id = $order_item['bill']['id'];

$result = $this->refund_transaction($bill_id, null, $reason);

$this->logger->log('Resultado do reembolso: ' . wc_print_r($result, true));
Expand All @@ -259,7 +259,7 @@ public function process_refund($order_id, $amount = null, $reason = '') {
throw new Exception($result->errors[0]->message);
return false;
}
}
}
return true;
}

Expand All @@ -284,7 +284,7 @@ public function get_refund_request($bill_id, $amount = null, $reason = '') {
}
return apply_filters('vindi_refund_request', $request, $bill_id, $amount, $reason);
}

/**
* Refund an order via PayPal.
*
Expand All @@ -309,7 +309,7 @@ public function refund_transaction($bill_id, $amount = null, $reason = '') {

return $refund['last_transaction'];
}

private function find_bill_last_charge($bill_id)
{
$bill_id = filter_var($bill_id, FILTER_SANITIZE_NUMBER_INT);
Expand All @@ -318,7 +318,7 @@ private function find_bill_last_charge($bill_id)
if(!$bill) {
throw new Exception(sprintf(__('A fatura com bill_id #%s não foi encontrada!', VINDI), $bill_id), 2);
}

$charges = $bill['charges'];
return end($charges);
}
Expand Down
Loading

0 comments on commit fa5d9eb

Please sign in to comment.