コード例 #1
0
 public function requestPayment($items, $client, $reference = null, $shipping = null, $redirect = '/', $currency = 'BRL', $callBack)
 {
     $requestPayment = new PagSeguroPaymentRequest();
     $requestPayment->setCurrency($currency);
     $itemId = 1;
     foreach ($items as $item) {
         $item['id'] = $this->formatNumber($itemId++);
         $requestPayment->addItem($item);
     }
     $requestPayment->setReference($reference);
     $requestPayment->setSenderName($client['client_name']);
     $requestPayment->setSenderEmail($client['client_email']);
     $requestPayment->setSenderPhone($client['client_ddd'], $client['client_phone']);
     $requestPayment->setShippingType($shipping['frete']);
     $requestPayment->setShippingCost(0);
     $requestPayment->setShippingAddress($shipping['cep'], $shipping['rua'], $shipping['numero'], $shipping['complemento'], $shipping['bairro'], $shipping['cidade'], $shipping['estado'], $shipping['pais']);
     $requestPayment->setRedirectURL($redirect);
     $requestPayment->setMaxAge(86400 * 3);
     try {
         return $requestPayment->register($this->getCredentials());
     } catch (PagSeguroServiceException $e) {
         foreach ($e->getErrors() as $key => $error) {
             echo $error->getCode();
             echo $error->getMessage();
         }
     }
 }
コード例 #2
0
 /**
  * Pagseguro
  *
  * @access public
  * @param int(11) idVenda
  */
 public function pagseguro($idVenda)
 {
     if ($this->session->userdata('logged_in') == true && $this->session->userdata('userData')->idTipoUsuario == 4) {
         $this->data['hasError'] = false;
         $this->data['errorList'] = array();
         $venda = array_shift($this->Vendas_model->getVenda(array('idVenda' => $idVenda)));
         // validações
         if (!is_object($venda)) {
             $this->data['hasError'] = true;
             $this->data['errorList'][] = array('message' => 'Não foi possível localizar sua compra.');
         }
         if (!$this->data['hasError']) {
             $userObj = $this->session->userdata('userData');
             $promocao = $this->Promocoes_model->getPromocaoById($venda->idPromocao);
             // Pega o estado do usuário
             $estadoObj = null;
             if ($userObj->idEstado) {
                 $filter = array('idEstado' => $userObj->idEstado);
                 $estadoObj = array_shift($this->Estados_model->getEstado($filter));
             }
             // Instantiate a new payment request
             $paymentRequest = new PagSeguroPaymentRequest();
             // Sets the currency
             $paymentRequest->setCurrency("BRL");
             // Sets a reference code for this payment request, it is useful to
             // identify this payment in future notifications.
             $paymentRequest->setReference($venda->idVenda);
             // Add an item for this payment request
             $paymentRequest->addItem('0001', substr($promocao->nome, 0, 80), 1, number_format($venda->valorDevido, 2, '.', ''));
             $paymentRequest->setShippingType(3);
             $paymentRequest->setShippingAddress(str_replace('-', '', str_replace('.', '', $userObj->CEP)), $userObj->endereco, $userObj->numero, $userObj->complemento, $userObj->bairro, $userObj->cidade, $estadoObj->sigla ? $estadoObj->sigla : '', 'BRA');
             // Sets your customer information.
             $paymentRequest->setSenderName(substr($userObj->nome, 0, 40));
             $paymentRequest->setSenderEmail($userObj->email);
             $paymentRequest->setSenderPhone($userObj->telefone1);
             $paymentRequest->setRedirectUrl(base_url('ofertas/retornoPagamento'));
             $paymentRequest->setMaxAge(86400 * 3);
             try {
                 $credentials = new PagSeguroAccountCredentials($this->config->item('pagseguroAccount'), $this->config->item('pagseguroToken'));
                 $url = $paymentRequest->register($credentials);
                 $dados = array('meioPagamento' => 2, 'statusPagamento' => 1, 'dataAtualizacao' => date('Y-m-d H:i:s'));
                 $this->Vendas_model->update($dados, $venda->idVenda);
                 redirect($url);
             } catch (PagSeguroServiceException $e) {
                 $this->data['hasError'] = true;
                 $this->data['errorList'][] = array('message' => 'Ocorreu um erro ao comunicar com o Pagseguro.' . $e->getCode() . ' - ' . $e->getMessage());
             }
             var_dump($this->data['errorList']);
         }
     } else {
         redirect(base_url('login'));
     }
 }
コード例 #3
0
 /**
  * Pagseguro
  *
  * @access public
  * @param int(11) idVenda
  */
 public function pagseguro($idVenda)
 {
     if ($idVenda) {
         $hasError = false;
         $errorList = array();
         // procura sua transação no banco de dados
         $venda = $this->db->get_where('tabela_vendas', array('idVenda' => $idVenda))->row();
         // validações
         if (!is_object($venda)) {
             $hasError = true;
             $errorList[] = array('message' => 'Não foi possível localizar sua compra.');
         }
         if (!$hasError) {
             // Instantiate a new payment request
             $paymentRequest = new PagSeguroPaymentRequest();
             // Sets the currency
             $paymentRequest->setCurrency("BRL");
             // Sets a reference code for this payment request, it is useful to
             // identify this payment in future notifications.
             $paymentRequest->setReference($venda->idVenda);
             // Add an item for this payment request
             $paymentRequest->addItem('0001', 'nome do item', 1, number_format($venda->valorDevido, 2, '.', ''));
             $paymentRequest->setShippingType(3);
             $paymentRequest->setShippingAddress(str_replace('-', '', str_replace('.', '', $venda->CEP)), utf8_decode($venda->endereco), $venda->numero, utf8_decode($venda->complemento), utf8_decode($venda->bairro), utf8_decode($venda->cidade), $venda->sigla ? $venda->sigla : '', 'BRA');
             // Sets your customer information.
             $telefone = $venda->telefone1;
             // 				$paymentRequest->setSenderName(truncate($userObj->nome, 40));
             $paymentRequest->setSenderEmail($venda->email);
             $paymentRequest->setSenderPhone(substr($telefone, 0, 2), substr($telefone, 2, 8));
             // TODO Alterar a URL de RETORNO DE PAGAMENTO SUA URL
             $paymentRequest->setRedirectUrl($this->urlRetornoPagamento);
             $paymentRequest->setMaxAge(86400 * 3);
             try {
                 $credentials = new PagSeguroAccountCredentials($this->config->item('pagseguroAccount'), $this->config->item('pagseguroToken'));
                 $url = $paymentRequest->register($credentials);
                 $parts = parse_url($url);
                 parse_str($parts['query'], $query);
                 if ($this->input->is_ajax_request()) {
                     $data = array('hasError' => FALSE, 'checkoutCode' => $query['code']);
                     $this->output->set_content_type('application/json')->set_output(json_encode($data));
                 } else {
                     redirect($url);
                 }
             } catch (PagSeguroServiceException $e) {
                 $hasError = true;
                 $errorList[] = array('message' => 'Ocorreu um erro ao comunicar com o Pagseguro.' . $e->getCode() . ' - ' . $e->getMessage());
             }
         }
     } else {
         redirect(base_url());
     }
 }
コード例 #4
0
ファイル: PagSeguro.php プロジェクト: kaabsimas/caravana
 public function paymentRequests($billId)
 {
     if (!isset($_SESSION['user'])) {
         redirect('site/login', 'refresh');
     }
     $billInfo = $this->billing->getBillingInfo($billId);
     $items = [];
     $sender = [];
     if (!empty($billInfo)) {
         $package = $billInfo['package'];
         $client = $billInfo['client'];
         $items[] = ['id' => 1, 'descricao' => $package->description, 'quantidade' => 1, 'valor' => $package->price, 'peso' => NULL, 'frete' => NULL];
         foreach ($billInfo['acquisition']['modifiers'] as $k => $modifier) {
             $items[] = ['id' => 2 + $k, 'descricao' => $modifier->description, 'quantidade' => 1, 'valor' => $modifier->price_modifier, 'peso' => NULL, 'frete' => NULL];
         }
         $sender = array('nome' => $this->userinfo->partialName($client->id), 'email' => $client->main_email, 'ddd' => NULL, 'telefone' => NULL);
     }
     if (!empty($items)) {
         $paymentRequest = new PagSeguroPaymentRequest();
         foreach ($items as $item) {
             $paymentRequest->addItem($item['id'], $item['descricao'], 1, (double) $item['valor']);
         }
         if ($sender != NULL) {
             $paymentRequest->setSender($sender['nome'], $sender['email'], $sender['ddd'], $sender['telefone']);
         }
         $paymentRequest->setCurrency('BRL');
         $paymentRequest->setReference($billId);
         $paymentRequest->setMaxAge(172800);
         $paymentRequest->setRedirectURL(site_url('client/profile'));
         $paymentRequest->setNotificationURL(site_url('PagSeguro/notification'));
         $checkoutUrl = NULL;
         try {
             $credentials = PagSeguroConfig::getAccountCredentials();
             $checkoutUrl = $paymentRequest->register($credentials);
         } catch (PagSeguroServiceException $e) {
             die(var_dump($e));
         }
         if ($checkoutUrl != NULL) {
             redirect($checkoutUrl, 'refresh');
         } else {
             $alert = ['message' => 'Ouve um problema ao emitir cobrança no PagSeguro', 'class' => 'alert-danger', 'icon' => 'glyphicon-remove'];
             $this->session->set_flashdata('alert', $alert);
             //redirect( 'client/acquisitions', 'refresh' );
         }
     }
     return FALSE;
 }