function gateway_pagseguro($seperator, $sessionid) { global $wpdb; // Carregando os dados $cart = unserialize($_SESSION['wpsc_cart']); $options = array('email_cobranca' => get_option('pagseguro_email'), 'ref_transacao' => $_SESSION['order_id'], 'encoding' => 'utf-8', 'item_frete_1' => number_format(($cart->total_tax + $cart->base_shipping) * 100, 0, '', '')); // Dados do cliente $_cliente = $_POST["collected_data"]; list($ddd, $telefone) = trataTelefone($_cliente[17]); list($end, $num, $compl) = trataEndereco($_cliente[4]); $cliente = array('nome' => $_POST["collected_data"][2] . " " . $_cliente[3], 'cep' => preg_replace("/[^0-9]/", "", $_cliente[7]), 'end' => $end, 'num' => $num, 'compl' => $compl, 'bairro' => '', 'cidade' => '', 'uf' => '', 'pais' => 'Brasil', 'ddd' => $ddd, 'tel' => $telefone, 'email' => $_cliente[8]); // Usando a session, isso é correto $cart = $cart->cart_items; $produtos = array(); foreach ($cart as $item) { $produtos[] = array("id" => (string) $item->product_id, "descricao" => $item->product_name, "quantidade" => $item->quantity, "valor" => $item->unit_price); } $PGS = new pgs($options); $PGS->cliente($cliente); $PGS->adicionar($produtos); $mostra = array("btn_submit" => 0, "print" => false, "open_form" => false, "show_submit" => false); $form = $PGS->mostra($mostra); $_SESSION["pagseguro_id"] = $sessionid; echo '<form id="form_pagseguro" action="https://pagseguro.uol.com.br/security/webpagamentos/webpagto.aspx" method="post">', $form, '<script>window.onload=function(){form_pagseguro.submit();}</script>'; exit; }
/** * index - Incluido à ultima tela do processo de compra * * @access protected * @return void */ protected function index() { $this->language->load('payment/pagseguro'); $this->load->model('payment/pagseguro'); $this->data['button_confirm'] = $this->language->get('button_confirm'); $this->data['button_back'] = $this->language->get('button_back'); $this->session->data['token'] = isset($this->session->data['token']) ? $this->session->data['token'] : ''; $this->data['continue'] = HTTPS_SERVER . 'index.php?route=checkout/success&token=' . $this->session->data['token']; $this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/payment&token=' . $this->session->data['token']; /* Aplicando a biblioteca PagSeguro */ list($order, $cart) = $this->model_payment_pagseguro->getCart(); $produtos = array(); foreach ($cart as $item) { $produtos[] = array('id' => $item['product_id'], 'descricao' => $item['name'], 'quantidade' => $item['quantity'], 'valor' => $item['total'] / $item['quantity'], 'frete' => 0); } list($ddd, $telefone) = trataTelefone($order['telephone']); $street = explode(',', $order['shipping_address_1']); $street = array_slice(array_merge($street, array("", "", "")), 0, 3); list($endereco, $numero, $complemento) = $street; $cliente = array('nome' => $order['payment_firstname'] . ' ' . $order['payment_lastname'], 'cep' => $order['payment_postcode'], 'end' => $endereco, 'num' => $numero, 'compl' => $complemento, 'cidade' => $order['payment_city'], 'uf' => $order['payment_zone'], 'pais' => $order['payment_country'], 'ddd' => $ddd, 'tel' => $telefone, 'email' => $order['email']); /*Pega cupom e calcula o desconto*/ if (isset($this->session->data['coupon']) && $this->session->data['coupon']) { $coupon = $this->model_checkout_coupon->getCoupon($this->session->data['coupon']); $extras = 0; if (count($coupon['product']) > 0) { foreach ($this->cart->getProducts() as $products) { if (in_array($products['product_id'], $coupon['product'])) { if ($coupon['type'] == 'F') { $extra = $coupon['discount'] > $products['total'] ? $products['total'] : $coupon['discount']; } elseif ($coupon['type'] == 'P') { $extra = $products['total'] * $coupon['discount'] / 100; $extra = $extra > $products['total'] ? $products['total'] : $extra; } $extras += $extra; } } } else { if ($coupon['type'] == 'F') { $extras = $coupon['discount'] > $this->cart->getTotal() ? $this->cart->getTotal() : $coupon['discount']; } elseif ($coupon['type'] == 'P') { $extras = $this->cart->getTotal() * $coupon['discount'] / 100; $extras = $extras > $this->cart->getTotal() ? $this->cart->getTotal() : $extras; } } $extras = $this->cart->getTotal() - $extras == 0 ? $extras - 0.01 : $extras; $extras = sprintf("%01.2f", $extras); $extras = '-' . str_replace('.', '', $extras); } else { $extras = 0; } $pgs = new Pgs(array('email_cobranca' => $this->config->get("pagseguro_mail"), 'extras' => $extras, 'ref_transacao' => $order['order_id'], 'encoding' => 'utf-8')); $pgs->cliente($cliente); if (isset($this->session->data['shipping_method'])) { $produtos[0]['frete'] = str_replace('.', '', sprintf("%01.2f", $this->session->data['shipping_method']['cost'])); } $pgs->adicionar($produtos); $this->form = $pgs->mostra(array('print' => false)); $this->id = 'payment'; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pagseguro.tpl')) { $this->template = $this->config->get('config_template') . '/template/payment/pagseguro.tpl'; } else { $this->template = 'default/template/payment/pagseguro.tpl'; } $this->render(); }
<?php include 'pagseguro/pgs.php'; include 'pagseguro/tratadados.php'; // Criando um novo carrinho $pgs = new pgs(array('email_cobranca' => $processor_data['params']['email'], 'tipo' => 'CP', 'tipo_frete' => $processor_data['params']['tipo_frete'], 'ref_transacao' => $order_info['order_id'])); list($telefone_ddd, $telefone) = trataTelefone($order_info['phone']); $pgs->cliente(array('nome' => $order_info['s_firstname'] . " " . $order_info['s_lastname'], 'cep' => $order_info['s_zipcode'], 'end' => $order_info['s_address'], 'num' => $order_info[''], 'compl' => $order_info['s_address_2'], 'cidade' => $order_info['s_city'], 'uf' => $order_info[''], 'pais' => $order_info[''], 'ddd' => $telefone_ddd, 'tel' => $telefone, 'email' => $order_info['email'])); $pedido = array(); foreach ($order_info['items'] as $item) { $pedido[] = array('id' => $item['item_id'], 'quantidade' => $item['amount'], 'valor' => $item['subtotal'], 'descricao' => strip_tags($item['product'])); } $extra = array('Frete' => $order_info['shipping_cost'], 'Outras taxas' => $order_info['tax_value']); foreach ($extra as $k => $v) { if (!$v) { continue; } $pedido[] = array('id' => $order_info['order_id'], 'quantidade' => 1, 'valor' => $v, 'descricao' => $k); } $pgs->adicionar($pedido); echo <<<EOT <html><head><title></title></head> <body onLoad="document.forms[0].submit();"> {$pgs->mostra(array('show_submit' => false, 'print' => false))} </body></html> EOT ;