Ejemplo n.º 1
0
 public function pagSeguro()
 {
     /*
             /* Carrega a biblioteca do CodeIgniter responsável pela validação dos formulários */
     $this->load->library('form_validation', 'PagSeguroLibrary');
     $this->load->model('presentes_model');
     /* Define as tags onde a mensagem de erro será exibida na página */
     $this->form_validation->set_error_delimiters('<span>', '</span>');
     /* Define as regras para validação */
     $this->form_validation->set_rules('valor', 'decimal', 'required');
     /* Executa a validação e caso houver erro... */
     if ($this->form_validation->run() === FALSE) {
         /* Chama a função index do controlador */
         $this->load->view('pages/presentes.php');
         /* Senão, caso sucesso na validação... */
     } else {
         /* Recebe os dados do formulário (visão) */
         $data['valor'] = $this->input->post('valor');
         $data['descricao'] = 'Presente Luana e Juninho';
         //inserir data atual também....
         /* Chama a função inserir do modelo */
         $this->presentes_model->pagSeguro($data);
         //redirect('#contact');
     }
     /** INICIO PROCESSO PAGSEGURO */
     require_once APPPATH . 'libraries/PagSeguroLibrary/PagSeguroLibrary.php';
     /** INICIO PROCESSO PAGSEGURO */
     $paymentrequest = new PagSeguroPaymentRequest();
     $data = array('id' => '01', 'description' => 'Presente Luana e Juninho', 'quantity' => 1, 'amount' => $this->input->post('valor'));
     $item = new PagSeguroItem($data);
     /* $paymentRequest deve ser um objeto do tipo PagSeguroPaymentRequest */
     $paymentrequest->addItem($item);
     //Definindo moeda
     $paymentrequest->setCurrency('BRL');
     // 1- PAC(Encomenda Normal)
     // 2-SEDEX
     // 3-NOT_SPECIFIED(Não especificar tipo de frete)
     $paymentrequest->setShipping(3);
     //Url de redirecionamento
     //$paymentrequest->setRedirectURL($redirectURL);// Url de retorno
     $credentials = PagSeguroConfig::getAccountCredentials();
     //credenciais do vendedor
     //$compra_id = App_Lib_Compras::insert($produto);
     //$paymentrequest->setReference($compra_id);//Referencia;
     $url = $paymentrequest->register($credentials);
     header("Location: {$url}");
 }
 public function pay($id)
 {
     \PagSeguroLibrary::init();
     \PagSeguroConfig::setEnvironment('production');
     $this->plan = Plans::find($id);
     $this->client = User::find(Auth::user()->id);
     $this->payment = Payments::create(['plan_name' => $this->plan->name, 'plan_value' => $this->plan->value, 'plan_id' => $this->plan->id, 'user_id' => $this->client->id, 'confirmed' => 0]);
     // Instantiate a new payment request
     $paymentRequest = new \PagSeguroPaymentRequest();
     // Set the currency
     $paymentRequest->setCurrency("BRL");
     /* // Add an item for this payment request
        $paymentRequest->addItem('0001', 'Sempre da Negócio - Plano '.$this->plan->name, 1, $this->plan->value);*/
     $paymentRequest->addItem($this->plan->id, 'Sempre da Negócio - Plano ' . $this->plan->name, 1, $this->plan->value);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $paymentRequest->setReference($this->payment->id);
     //Create object PagSeguroShipping
     $shipping = new \PagSeguroShipping();
     //Set Type Shipping
     $type = new \PagSeguroShippingType(3);
     $shipping->setType($type);
     //Set address of client
     $data = array('postalCode' => $this->client->zipcode, 'street' => $this->client->address, 'number' => $this->client->number, 'city' => $this->client->city, 'state' => $this->client->state);
     $address = new \PagSeguroAddress($data);
     $shipping->setAddress($address);
     //Add Shipping to Payment Request
     $paymentRequest->setShipping($shipping);
     // Set your customer information.
     $phone = str_replace(['(', ')', ' ', '-'], ['', '', '', ''], $this->client->phone);
     $paymentRequest->setSender($this->client->name, $this->client->email_responsible, substr($phone, 0, 2), substr($phone, 2));
     try {
         /*
                      * #### Credentials #####
                      * Replace the parameters below with your credentials (e-mail and token)
                      * You can also get your credentials from a config file. See an example:
                      * $credentials = PagSeguroConfig::getAccountCredentials();
                     //  */
         $credentials = new \PagSeguroAccountCredentials($this->email, $this->token);
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $onlyCheckoutCode = true;
         $code = $paymentRequest->register($credentials, $onlyCheckoutCode);
         return view('site.pages.confirma_pagamento', compact('code'));
     } catch (\PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
Ejemplo n.º 3
0
 /**
  * Generate PagSeguro Payment Request
  * @return \PagSeguroPaymentRequest
  */
 private function _generatePagSeguroPaymentRequestObject()
 {
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName("REAL"));
     $paymentRequest->setExtraAmount($this->_generateExtraAmount());
     $paymentRequest->setRedirectURL($this->_getPagSeguroRedirectUrl());
     $paymentRequest->setNotificationURL($this->_getPagSeguroNotificationURL());
     $paymentRequest->setItems($this->_generatePagSeguroProductsData());
     $paymentRequest->setSender($this->_generatepagSeguroSenderDataObject());
     $paymentRequest->setShipping($this->_generatePagSeguroShippingDataObject());
     return $paymentRequest;
 }
 /**
  * Create PagSeguro payment request html with payment url
  * @return string
  */
 private function createPaymentRequest()
 {
     $helper = Mage::helper('pagseguro');
     // Get references that stored in the database
     $reference = $helper->getStoreReference();
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName(self::REAL));
     $paymentRequest->setReference($reference . $this->order->getId());
     //Order ID
     $paymentRequest->setShipping($this->getShippingInformation());
     //Shipping
     $paymentRequest->setSender($this->getSenderInformation());
     //Sender
     $paymentRequest->setItems($this->getItensInformation());
     //Itens
     $paymentRequest->setShippingType(SHIPPING_TYPE);
     $paymentRequest->setShippingCost(number_format($this->order->getShippingAmount(), 2, '.', ''));
     $paymentRequest->setNotificationURL($this->getNotificationURL());
     $helper->getDiscount($paymentRequest);
     //Define Redirect Url
     $redirectUrl = $this->getRedirectUrl();
     if (!empty($redirectUrl) and $redirectUrl != null) {
         $paymentRequest->setRedirectURL($redirectUrl);
     } else {
         $paymentRequest->setRedirectURL(Mage::getUrl() . 'checkout/onepage/success/');
     }
     //Define Extra Amount Information
     $paymentRequest->setExtraAmount($this->extraAmount());
     try {
         $paymentUrl = $paymentRequest->register($this->getCredentialsInformation());
     } catch (PagSeguroServiceException $ex) {
         Mage::log($ex->getMessage());
         $this->redirectUrl(Mage::getUrl() . 'checkout/onepage');
     }
     return $paymentUrl;
 }
Ejemplo n.º 5
0
 /**
  *  Generates PagSeguro request data
  */
 private function _generatePagSeguroRequestData()
 {
     $payment_request = new PagSeguroPaymentRequest();
     $payment_request->setCurrency(PagSeguroCurrencies::getIsoCodeByName('Real'));
     /* Currency */
     $payment_request->setExtraAmount($this->_getExtraAmountValues());
     /* Extra amount */
     $payment_request->setItems($this->_generateProductsData());
     /* Products */
     $payment_request->setSender($this->_generateSenderData());
     /* Sender */
     $payment_request->setShipping($this->_generateShippingData());
     /* Shipping */
     if (!Tools::isEmpty(Configuration::get('PAGSEGURO_URL_REDIRECT'))) {
         /* Redirect URL */
         $payment_request->setRedirectURL(Configuration::get('PAGSEGURO_URL_REDIRECT'));
     }
     $this->_payment_request = $payment_request;
 }
 private function _generatePagSeguroRequestData($order, $notify_url, $return_url)
 {
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName('REAL'));
     // currency
     $paymentRequest->setReference($order->order_id);
     // reference
     $paymentRequest->setRedirectURL($return_url);
     // redirect url
     $paymentRequest->setNotificationURL($notify_url);
     // notification url
     $paymentRequest->setItems($this->_generateProductsData($order));
     // products
     $paymentRequest->setExtraAmount($this->_getExtraAmountValues($order));
     // extra values
     $paymentRequest->setSender($this->_generateSenderData($order));
     // sender
     $paymentRequest->setShipping($this->_generateShippingData($order));
     // shipping
     return $paymentRequest;
 }
Ejemplo n.º 7
0
 /**
  * Generates PagSeguro request data
  * @param VirtueMartCart $cart
  * @param array $order
  * @param TablePaymentmethods $method
  * @return PagSeguroPaymentRequest
  */
 private function _generatePagSeguroRequestData(VirtueMartCart $cart, array $order, TablePaymentmethods $method)
 {
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName('REAL'));
     // currency
     $paymentRequest->setReference($order['details']['BT']->virtuemart_order_id);
     // reference
     $paymentRequest->setRedirectURL($this->_getRedirectUrl($method->pagseguro_url_redirect));
     // redirect url
     $paymentRequest->setNotificationURL($this->_getNotificationUrl($method->pagseguro_url_notification));
     // notification url
     $paymentRequest->setItems($this->_generateProductsData($cart));
     // products
     $paymentRequest->setExtraAmount($this->_getExtraAmountValues($cart));
     // extra values
     $sender = isset($order['details']['ST']) && count($order['details']['ST'] > 0) ? $order['details']['ST'] : $order['details']['BT'];
     $paymentRequest->setSender($this->_generateSenderData($sender));
     // sender
     $paymentRequest->setShipping($this->_generateShippingData($sender, $cart->pricesUnformatted['salesPriceShipment']));
     // shipping
     return $paymentRequest;
 }
/**
 * Processa o formulário, 
 */
function process_form()
{
    //var_dump($_POST);
    //die();
    require_once "PagSeguroLibrary/PagSeguroLibrary.php";
    $id = $_POST['item_id'];
    $descricao = $_POST['item_descricao'];
    $qtd = $_POST['item_qtd'];
    $valor = $_POST['item_valor'];
    $peso = $_POST['item_peso'];
    $frete = $_POST['frete'];
    $valor = str_replace(",", ".", $valor);
    //Instancia uma requisicao de pagamento
    $paymentRequest = new PagSeguroPaymentRequest();
    //Seta a moeda
    $paymentRequest->setCurrency("BRL");
    //Adiciona os itens para gerar a url
    $paymentRequest->addItem($id, $descricao, $qtd, $valor, $peso);
    //Seta o ambiente de producao, se é Sandbox, ou production
    $is_sandbox = get_option('ps_config_enable_sandbox');
    if (strlen($is_sandbox) > 0) {
        PagSeguroConfig::setEnvironment('sandbox');
        $PagSeguroConfig['log']['active'] = TRUE;
    } else {
        PagSeguroConfig::setEnvironment('production');
    }
    /* Infos seguintes apenas para referencia*/
    // Add another item for this payment request
    //$paymentRequest->addItem('0002', 'Notebook rosa', 2, 1.00);
    // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
    //$paymentRequest->setReference($dadosComprador["codReference"]);
    // Sets shipping information for this payment request
    //$CODIGO_SEDEX = PagSeguroShippingType::getCodeByType('SEDEX');
    //$paymentRequest->setShippingType($CODIGO_SEDEX);
    //$paymentRequest->setShippingAddress('30315230', 'Rua Zito Soares', '179', '', 'Mangabeiras', 'Belo Horizonte', 'MG', 'BRA');
    /* Criando o tipo de frete */
    $shippingType = new PagSeguroShippingType();
    /* Definindo tipo de frete 'PAC' */
    $shippingType->setByType('PAC');
    $shipping = new PagSeguroShipping();
    $shipping->setType($shippingType);
    $data = array('postalCode' => '01452002', 'street' => 'Av. Brig. Faria Lima', 'number' => '1384', 'complement' => 'apto. 114', 'district' => 'Jardim Paulistano', 'city' => 'São Paulo', 'state' => 'SP', 'country' => 'BRA');
    $address = new PagSeguroAddress($data);
    // objeto PagSeguroAddress
    $shipping->setAddress($address);
    $type = $shipping->getType();
    // Objeto PagSeguroShippingType
    $address = $shipping->getAddress();
    // objeto PagSeguroAddress
    $cost = $shipping->getCost();
    // Float
    $shipping->setCost($cost);
    /* $paymentRequest deve ser um objeto do tipo PagSeguroPaymentRequest */
    $paymentRequest->setShipping($shipping);
    var_dump($shipping->setCost);
    die;
    // Sets your customer information.
    //$paymentRequest->setSender($dadosComprador["nome"] . ' ' . $dadosComprador["sobrenome"], $dadosComprador["email"]);
    //Seta a URL de retorno
    $paymentRequest->setRedirectUrl(get_option('ps_config_return_url'));
    try {
        //Inicializa as credenciais
        $credentials = new PagSeguroAccountCredentials(get_option('ps_config_auth_email'), get_option('ps_config_auth_token'));
        //obtem-se a URL da compra
        $url = $paymentRequest->register($credentials);
        //faz o redirect para a url do pagseguro
        wp_redirect($url);
        exit;
    } catch (PagSeguroServiceException $e) {
        die($e->getMessage());
    }
    var_dump($dadosComprador);
    die;
}