Skip to content

Commit

Permalink
Correção do bug "installment value invalid value"
Browse files Browse the repository at this point in the history
Corrige bug com a notificação automática
  • Loading branch information
valdeir2000 committed Dec 9, 2017
1 parent b0e0385 commit 944b12b
Show file tree
Hide file tree
Showing 4 changed files with 703 additions and 0 deletions.
53 changes: 53 additions & 0 deletions upload/pagseguro.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
class ControllerExtensionPaymentPagseguro extends Controller {

public function callback() {

$this->log->write($this->request->post['notificationCode']);

$this->load->model('extension/payment/pagseguro');
$this->load->model('checkout/order');

$result = $this->model_extension_payment_pagseguro->notification($this->request->post['notificationCode']);

$notificar = $this->config->get('pagseguro_notificar_cliente');

if (is_array($result['status'])) {
$status = reset($result['status']);
} else {
$status = $result['status'];
}

switch ($status) {
case 1:
$status = $this->config->get('pagseguro_aguardando_pagamento');
break;
case 2:
$status = $this->config->get('pagseguro_analise');
break;
case 3:
$status = $this->config->get('pagseguro_paga');
break;
case 4:
$status = $this->config->get('pagseguro_disponivel');
$notificar = false;
break;
case 5:
$status = $this->config->get('pagseguro_disputa');
break;
case 6:
$status = $this->config->get('pagseguro_devolvida');
break;
case 7:
$status = $this->config->get('pagseguro_cancelada');
break;
default:
$status = $this->config->get('pagseguro_aguardando_pagamento');
break;
}

$this->model_checkout_order->addOrderHistory($result['order_id'], $status, '', $notificar);
}

}
?>
191 changes: 191 additions & 0 deletions upload/pagseguro_boleto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php
class ControllerExtensionPaymentPagseguroBoleto extends Controller {

public function index() {

$data = array();

$this->load->model('checkout/order');

$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

$this->load->model('extension/payment/pagseguro');

$session_id = $this->model_extension_payment_pagseguro->captureToken();

if (strlen($session_id) != 32) {
$data["warning"] = $session_id;
} else {
$data["warning"] = false;
}

$data["session_id"] = $session_id;

/* CPF */
if (isset($order_info['custom_field'][$this->config->get('payment_pagseguro_cpf')])) {
if (!preg_match('/(\.|-)/', $order_info['telephone'])) {
$data['cpf'] = preg_replace('/([\d]{3})([\d]{3})([\d]{3})([\d]{2})/', '$1.$2.$3-$4', $order_info['custom_field'][$this->config->get('payment_pagseguro_cpf')]);
} else {
$data['cpf'] = $order_info['custom_field'][$this->config->get('payment_pagseguro_cpf')];
}
} else {
$data['cpf'] = '';
}

$data['continue'] = $this->url->link('checkout/success', '', true);

return $this->load->view('extension/payment/pagseguro_boleto', $data);

}

public function transition() {

/* ID do Pedido */
$order_id = $this->session->data['order_id'];

/* Models */
$this->load->model('checkout/order');
$this->load->model('extension/payment/pagseguro');

/* Informações do Pedido */
$order_info = $this->model_checkout_order->getOrder($order_id);

/* Config */
$data['email'] = $this->config->get('payment_pagseguro_email');
$data['token'] = $this->config->get('payment_pagseguro_token');
$data['paymentMode'] = 'default';
$data['paymentMethod'] = 'boleto';
$data['currency'] = 'BRL';
$data['notificationURL'] = $this->url->link('extension/payment/pagseguro/callback', '', true);
$data['reference'] = 'Pedido #' . $order_id;

/* Produtos */
$count = 1;

foreach($this->cart->getProducts() as $product) {
if ($product['price'] > 0) {
$data['itemId' . $count] = $product['product_id'];
$data['itemDescription' . $count] = $product['name'] . ' | ' . $product['model'];
$data['itemAmount' . $count] = number_format($this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value'], false), 2, '.', '');
$data['itemQuantity' . $count] = $product['quantity'];

$count++;
}
}

/* Vale-presentes */
if (isset($this->session->data['vouchers'])) {
foreach($this->session->data['vouchers'] as $voucher_id => $voucher) {
if ($voucher['amount'] > 0) {
$data['itemId' . $count] = $voucher_id;
$data['itemDescription' . $count] = $voucher['description'];
$data['itemAmount' . $count] = number_format($this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'], false), 2, '.', '');
$data['itemQuantity' . $count] = 1;

$count++;
}
}
}

/* Valores extra (Desconto e Acréscimo) */
$data["extraAmount"] = $order_info["total"] - $this->cart->getSubTotal();

/* Formata os dados */
$data['extraAmount'] = number_format($data['extraAmount'], 2, '.', '');

/* Nome do Cliente */
$data['senderName'] = utf8_decode(trim($order_info['firstname']) . ' ' . trim($order_info['lastname']));

/* CPF do Cliete */
$data['senderCPF'] = preg_replace('/[^0-9]/', '', $this->request->post['cpf']);

/* DDD */
$data['senderAreaCode'] = substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 0, 2);

/* Telefone do Cliente */
$data['senderPhone'] = substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 2);

/* E-mail do Cliente */
$data['senderEmail'] = $order_info['email'];

/* Hash(Identificador) da transação */
$data['senderHash'] = $this->request->post['senderHash'];

/* Endereço do Cliente */
if (isset($this->session->data['shipping_address'])) {
$data['shippingAddressStreet'] = utf8_decode($order_info['shipping_address_1']);
$data['shippingAddressNumber'] = $this->model_extension_payment_pagseguro->getAddressNumber($order_info['shipping_custom_field']);
$data['shippingAddressDistrict'] = utf8_decode($order_info['shipping_address_2']);
$data['shippingAddressPostalCode'] = preg_replace('/[^\d]/', '', $order_info['shipping_postcode']);
$data['shippingAddressCity'] = utf8_decode($order_info['shipping_city']);
$data['shippingAddressState'] = $order_info['shipping_zone_code'];
$data['shippingAddressCountry'] = $order_info['shipping_iso_code_3'];
} else {
$data['shippingAddressStreet'] = utf8_decode($order_info['payment_address_1']);
$data['shippingAddressNumber'] = $this->model_extension_payment_pagseguro->getAddressNumber($order_info['payment_custom_field']);
$data['shippingAddressDistrict'] = utf8_decode($order_info['payment_address_2']);
$data['shippingAddressPostalCode'] = preg_replace('/[^\d]/', '', $order_info['payment_postcode']);
$data['shippingAddressCity'] = utf8_decode($order_info['payment_city']);
$data['shippingAddressState'] = $order_info['payment_zone_code'];
$data['shippingAddressCountry'] = $order_info['payment_iso_code_3'];
}

$shipping_free = $this->model_extension_payment_pagseguro->checkShippingFree();

/* Tipo e Valor do Frete */
if ($this->cart->hasShipping() && !$shipping_free){
$data['shippingType'] = $this->model_extension_payment_pagseguro->getShippingType();

$data['shippingCost'] = number_format($this->session->data['shipping_method']['cost'], 2, '.', '');
}

/* Captura o retorno da requisição */
$result = $this->model_extension_payment_pagseguro->transition($data);

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($result));
}

public function confirm() {
$this->load->model('checkout/order');

switch ($this->request->post['status']) {
case 1:
$status = $this->config->get('payment_pagseguro_aguardando_pagamento');
break;
case 2:
$status = $this->config->get('payment_pagseguro_analise');
break;
case 3:
$status = $this->config->get('payment_pagseguro_paga');
break;
case 4:
$status = $this->config->get('payment_pagseguro_disponivel');
break;
case 5:
$status = $this->config->get('payment_pagseguro_disputa');
break;
case 6:
$status = $this->config->get('payment_pagseguro_devolvida');
break;
case 7:
$status = $this->config->get('payment_pagseguro_cancelada');
break;
default:
$status = $this->config->get('payment_pagseguro_aguardando_pagamento');
break;
}

$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $status);

if (isset($this->session->data['order_id'])) {
$this->cart->clear();
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['comment']);
unset($this->session->data['coupon']);
}
}
}

0 comments on commit 944b12b

Please sign in to comment.