Skip to content

Commit

Permalink
feat: adiciona metodo para salvar os dados no DB
Browse files Browse the repository at this point in the history
  • Loading branch information
valdeir2000 committed Sep 2, 2020
1 parent da37f20 commit 58df225
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
3 changes: 3 additions & 0 deletions upload/catalog/controller/extension/payment/pagseguro.php
Expand Up @@ -13,6 +13,9 @@ public function callback()

$transaction = $this->model_extension_payment_pagseguro->checkStatusByNotificationCode($notificationCode);

var_dump($transaction);
die();

// Logger

$status = $transaction->getStatus();
Expand Down
58 changes: 55 additions & 3 deletions upload/catalog/model/extension/payment/pagseguro.php
Expand Up @@ -3,6 +3,7 @@
require_once DIR_SYSTEM . 'library/PagSeguro/vendor/autoload.php';

use ValdeirPsr\PagSeguro\Domains\Environment;
use ValdeirPsr\PagSeguro\Domains\Transaction;
use ValdeirPsr\PagSeguro\Request\Session;
use ValdeirPsr\PagSeguro\Request\Notification;

Expand Down Expand Up @@ -48,9 +49,14 @@ public function generateSession(): string
*/
public function checkStatusByNotificationCode(string $notification_code): ?array
{
$env = $this->factoryEnvironment();
$request = new Notification($env);
$transaction = $request->capture($notification_code);
try {
$env = $this->factoryEnvironment();
$request = new Notification($env);
$transaction = $request->capture($notification_code);
} catch (Exception $e) {
// Logger
return null;
}

$order = $this->db->query('
SELECT
Expand All @@ -69,6 +75,52 @@ public function checkStatusByNotificationCode(string $notification_code): ?array
return null;
}

/**
* Salva os dados no banco de dados
*
* @param int $order_id
* @param Transaction $transaction
*
* @return void
*/
public function addOrder(int $order_id, Transaction $transaction)
{
$code = $this->db->escape($transaction->getCode());
$last_event_date = $this->db->escape($transaction->getLastEventDate()->format('Y-m-d'));

$payment_method = $this->db->escape($transaction->getPayment()->getMethod());

if ($payment_method === 'boleto') {
$payment_link = $this->db->escape($transaction->getPayment()->getPaymentLink());
} else {
$payment_link = '';
}

$gross_amount = $this->db->escape($transaction->getGrossAmount());
$discount_amount = $this->db->escape($transaction->getDiscountAmount());
$fee_amount = $this->db->escape($transaction->getFeeAmount());
$net_amount = $this->db->escape($transaction->getNetAmount());
$extra_amount = $this->db->escape($transaction->getExtraAmount());
$raw = $this->db->escape(serialize($transaction));

$this->db->query('
INSERT INTO ' . DB_PREFIX . 'pagseguro_orders
VALUES (
"' . $code . '",
"' . $order_id . '",
"' . $last_event_date . '",
"' . $payment_method . '",
"' . $payment_link . '",
"' . $gross_amount . '",
"' . $discount_amount . '",
"' . $fee_amount . '",
"' . $net_amount . '",
"' . $extra_amount . '",
"' . $raw . '"
);
');
}

/**
* Captura o valor do frete
*
Expand Down

0 comments on commit 58df225

Please sign in to comment.