Skip to content

Commit

Permalink
PagBank 😍 Magento
Browse files Browse the repository at this point in the history
  • Loading branch information
elisei committed Feb 15, 2024
1 parent 82e1eb7 commit 02420c4
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
41 changes: 41 additions & 0 deletions Cron/GetStatusUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use PagBank\PaymentMagento\Gateway\Config\Config;
use PagBank\PaymentMagento\Model\Console\Command\Orders\Update;

/**
Expand All @@ -26,6 +27,11 @@ class GetStatusUpdate
*/
public const PAYMENT_METHOD_CC = 'pagbank_paymentmagento_cc';

/**
* Payment Method Vault.
*/
public const PAYMENT_METHOD_VAULT = 'pagbank_paymentmagento_cc_vault';

/**
* Payment Method Pix.
*/
Expand All @@ -41,6 +47,11 @@ class GetStatusUpdate
*/
protected $logger;

/**
* @var Config
*/
protected $config;

/**
* @var NotifierInterface
*/
Expand All @@ -60,17 +71,20 @@ class GetStatusUpdate
* Constructor.
*
* @param Logger $logger
* @param Config $config
* @param NotifierInterface $notifierInterface
* @param Update $update
* @param CollectionFactory $collectionFactory
*/
public function __construct(
Logger $logger,
Config $config,
NotifierInterface $notifierInterface,
Update $update,
CollectionFactory $collectionFactory
) {
$this->logger = $logger;
$this->config = $config;
$this->notifierInterface = $notifierInterface;
$this->update = $update;
$this->collectionFactory = $collectionFactory;
Expand All @@ -85,12 +99,18 @@ public function __construct(
*/
public function getFilterdOrders($method)
{
$exclude = $this->config->getAddtionalValue('exclude_fetch_cron');
$exclude = explode(',', $exclude);

$orders = $this->collectionFactory->create()
->addFieldToFilter('state', [
'in' => [
Order::STATE_NEW,
Order::STATE_PAYMENT_REVIEW,
],
])
->addFieldToFilter('status', [
'nin' => $exclude,
]);

$orders->getSelect()
Expand Down Expand Up @@ -167,6 +187,27 @@ public function findCc()
}
}

/**
* Find Vault.
*
* @return void
*/
public function findVault()
{
$orders = $this->getFilterdOrders(self::PAYMENT_METHOD_VAULT);

foreach ($orders as $order) {
$incrementId = $order->getIncrementId();

try {
$this->update->getUpdate($incrementId);
} catch (\Throwable $th) {
$this->errorNotificationManager($order);
continue;
}
}
}

/**
* Error Notification Manager.
*
Expand Down
52 changes: 52 additions & 0 deletions Model/Adminhtml/Source/OrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* PagBank Payment Magento Module.
*
* Copyright © 2023 PagBank. All rights reserved.
*
* @author Bruno Elisei <brunoelisei@o2ti.com>
* @license See LICENSE for license details.
*/

namespace PagBank\PaymentMagento\Model\Adminhtml\Source;

use Magento\Sales\Model\Order\Status;
use Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory;
use Magento\Framework\Option\ArrayInterface;

class OrderStatus implements ArrayInterface
{
/**
* @var CollectionFactory
*/
protected $statusColFactory;

/**
* Constructor
*
* @param CollectionFactory $statusColFactory
*/
public function __construct(
CollectionFactory $statusColFactory
) {
$this->statusColFactory = $statusColFactory;
}

/**
* Get options
*
* @return array
*/
public function toOptionArray()
{
$options = [];
$statusCollection = $this->statusColFactory->create();
foreach ($statusCollection as $status) {
$options[] = [
'value' => $status->getStatus(),
'label' => $status->getLabel()
];
}
return $options;
}
}
6 changes: 6 additions & 0 deletions etc/adminhtml/system/developers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
<field id="*/*/settings/environment">production</field>
</depends>
</field>
<field id="exclude_fetch_cron" translate="label comment" type="multiselect" sortOrder="150" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Exclude Status for Order Fetch via Cron</label>
<config_path>payment/pagbank_paymentmagento/exclude_fetch_cron</config_path>
<source_model>PagBank\PaymentMagento\Model\Adminhtml\Source\OrderStatus</source_model>
<comment>The selected statuses will be excluded from the cron flow for order update.</comment>
</field>
<include path="PagBank_PaymentMagento::system/relationship.xml"/>
</group>
</include>
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<min_order_total>5</min_order_total>
<max_order_total>200000</max_order_total>
<allowspecific>1</allowspecific>
<exclude_fetch_cron>fraud,processing,pending_payment,holded,complete,closed,canceled,paypal_canceled_reversal,paypal_reversed,pending_paypal</exclude_fetch_cron>
<debugReplaceKeys>header</debugReplaceKeys>
<cipher_text_production>TDTmdLh3LyGKMrRqdg6CLF4FxWhSBDRMYFqG7o4EwUIS6vESXJCmtjjzdX8NY+ggxLci6dcZrNfnYYezdY/wSi/sdNNzijSDgjVX5nRSdExr8DXPdlgTlEAKg8iZFeoFvtxJZPqgxeEJVjZ3bwRm2nYGU/YPXTH5wk+w2LOKeaSEfewgMfiElFZW8F9ay+Exwivmxosa8nqQzlmLyJhBnvYLjHJuaXy+lAjFyFSQh75gHnr3bGcKGZx2roDnozFLQlMf+ix4RywVaMg0+5Y3Z8BaYwIjtyX0gddgi4hRm2nFVFVaAHf2uFWvUlLGMNZiLhCpixe9tjFJ25Qlcuf+sA==</cipher_text_production>
<cipher_text_sandbox>JIPYFxLrvP0wFDYTdUSzvvDCetb/GQxDRGEqfKsh4vSEKZvQKaQtvy8+/dyYclbkZhQPxiTdN2mg6Z6GVSrRJg2JPp62EzGGZt+9cI6xTQDlqCByolVPP2rJLF1IcRnnUjdHNjipXpL6B8Q7FANzoCgIGMux6frge3VdhXCb1zIkWhGeAGCunmBDjNetrUyt91Tw+xJ04grQNhrUvIHZfJ8qmapoGja4jrhA9hZFoBTGIg5UJKBJdLze/cmNnhDTt5WFBQEbq2I2kwsxuStSVT9rnS3Jet2lYCLEk0WAqmZmMg1ux0JTMU7Bk2S3MUn/w/hIfjccG7q4Lh7MX5zb3A==</cipher_text_sandbox>
Expand Down
3 changes: 3 additions & 0 deletions etc/crontab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<job name="pagbank_update_cc" instance="PagBank\PaymentMagento\Cron\GetStatusUpdate" method="findCc">
<schedule>0 */8 * * *</schedule>
</job>
<job name="pagbank_update_vault" instance="PagBank\PaymentMagento\Cron\GetStatusUpdate" method="findVault">
<schedule>0 */8 * * *</schedule>
</job>
<job name="pagbank_update_pix" instance="PagBank\PaymentMagento\Cron\GetStatusUpdate" method="findPix">
<schedule>*/30 * * * *</schedule>
</job>
Expand Down
5 changes: 4 additions & 1 deletion i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"Update not available because the initial state is incompatible: %1","Update not available because the initial state is incompatible: %1"
"Installments Interest","Installments Interest"
"Discount in cash","Discount in cash"
"Default Config","Default Config"
Expand All @@ -7,6 +6,7 @@ Production,Production
"Authorize for the store %1 in %2","Authorize for the store %1 in %2"
"Disallow for the store %1 in %2","Disallow for the store %1 in %2"
"Order not found.","Order not found."
"Not Apply.","Not Apply."
"You are diconnected to PagBank.","You are diconnected to PagBank."
"You are connected to PagBank. =)","You are connected to PagBank. =)"
"Unable to get the code, try again. =(","Unable to get the code, try again. =("
Expand Down Expand Up @@ -72,6 +72,7 @@ Finished,Finished
"Order cancelled, payment deadline has expired.","Order cancelled, payment deadline has expired."
"Order %1 was in state %2 has been updated to state %3.","Order %1 was in state %2 has been updated to state %3."
"Order not found","Order not found"
"Update not available because the initial state is incompatible: %1","Update not available because the initial state is incompatible: %1"
"Boleto Bancário - PagBank","Boleto Bancário - PagBank"
"Cartão de Crédito - PagBank","Cartão de Crédito - PagBank"
"Pix - PagBank","Pix - PagBank"
Expand Down Expand Up @@ -192,6 +193,8 @@ Debug,Debug
"Your PagBank Account ID. Automatically captured after APP authorization.","Your PagBank Account ID. Automatically captured after APP authorization."
"Custom notification URL","Custom notification URL"
"You can use services like <a href='https://pipedream.com/'>Pipedream</a> to intercept outgoing notifications.","You can use services like <a href='https://pipedream.com/'>Pipedream</a> to intercept outgoing notifications."
"Exclude Status for Order Fetch via Cron","Exclude Status for Order Fetch via Cron"
"The selected statuses will be excluded from the cron flow for order update.","The selected statuses will be excluded from the cron flow for order update."
Pix,Pix
"Pix is with P for PagBank: just like PagBank, it is 100% digital and faster than traditional TEDs or DOCs.","Pix is with P for PagBank: just like PagBank, it is 100% digital and faster than traditional TEDs or DOCs."
"Deadline for payment","Deadline for payment"
Expand Down
5 changes: 4 additions & 1 deletion i18n/pt_BR.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"Update not available because the initial state is incompatible: %1","Atualização não disponível pois state inicial é incompativel: %1"
"Installments Interest","Juros de Parcelamento"
"Discount in cash","Desconto à vista"
"Default Config","Configuração Padrão"
Expand All @@ -7,6 +6,7 @@ Production,Produção
"Authorize for the store %1 in %2","Autorizar a loja %1 em %2"
"Disallow for the store %1 in %2","Desautorizar a loja %1 em %2"
"Order not found.","Pedido não encontrado."
"Not Apply.","Não Aplicado."
"You are diconnected to PagBank.","Você foi desconectado do PagBank."
"You are connected to PagBank. =)","Você foi conectado ao PagBank. =)"
"Unable to get the code, try again. =(","Não foi possível obter o código, tente novamente. =("
Expand Down Expand Up @@ -72,6 +72,7 @@ Finished,Finalizado
"Order cancelled, payment deadline has expired.","Pedido cancelado, prazo de pagamento expirou."
"Order %1 was in state %2 has been updated to state %3 expired?","O pedido %1 estava no estado %2 foi atualizado para o estado %3 expirou?"
"Order not found","Pedido não encontrado"
"Update not available because the initial state is incompatible: %1","Atualização não disponível pois state inicial é incompativel: %1"
"Boleto Bancário - PagBank","Boleto Bancário - PagBank"
"Cartão de Crédito - PagBank","Cartão de Crédito - PagBank"
"Pix - PagBank","Pix - PagBank"
Expand Down Expand Up @@ -192,6 +193,8 @@ Debug,Debug
"Your PagBank Account ID. Automatically captured after APP authorization.","É o código da sua conta no PagBank. Essa informação é capturada automaticamente após autorizar o APP."
"Custom notification URL","URL de notificação personalizada"
"You can use services like <a href='https://pipedream.com/'>Pipedream</a> to intercept outgoing notifications.","Você pode usar serviços como <a href='https://pipedream.com/'>Pipedream</a> para interceptar notificações enviadas."
"Exclude Status for Order Fetch via Cron","Excluir Status para busca de pedido via cron"
"The selected statuses will be excluded from the cron flow for order update.","Os status selecionados serão excluídos do fluxo de cron para atualização de pedidos."
Pix,Pix
"Pix is with P for PagBank: just like PagBank, it is 100% digital and faster than traditional TEDs or DOCs.","Pix está com P de PagBank: assim como o PagBank, é 100% digital e mais rápido que os tradicionais TEDs ou DOCs."
"Deadline for payment","Prazo para pagamento"
Expand Down

0 comments on commit 02420c4

Please sign in to comment.