Esempio n. 1
1
 public function inicializaPagamento($cart, $urlRetorno)
 {
     require_once "vendor/PagSeguroLibrary/PagSeguroLibrary.php";
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency("BRL");
     foreach ($cart->getProducts() as $product) {
         $paymentRequest->addItem($product['id_product_attribute'], $product['name'], $product['quantity'], $product['price_wt']);
     }
     $customer = new Customer($cart->id_customer);
     $address = new Address($cart->id_address_delivery);
     $telefone_full = preg_replace("/([^0-9])/", null, $address->phone);
     $telefone_full = str_pad($telefone_full, 11, "0", STR_PAD_LEFT);
     $areacode = substr($telefone_full, 1, 2);
     $phone = substr($telefone_full, 3);
     $state = new State($address->id_state);
     $number = preg_replace("/([^0-9])/", null, $address->address2);
     $paymentRequest->setShippingAddress($address->postcode, $address->address1, $number, null, null, $address->city, $state->iso_code, $address->country);
     $CODIGO_SHIPPING = PagSeguroShippingType::getCodeByType('NOT_SPECIFIED');
     $paymentRequest->setShippingType($CODIGO_SHIPPING);
     $paymentRequest->setShippingCost(number_format($cart->getOrderShippingCost(), 2, ".", ""));
     $paymentRequest->setSender($customer->firstname . " " . $customer->lastname, $customer->email, $areacode, $phone);
     $order_id = (int) Order::getOrderByCartId($cart->id);
     $paymentRequest->setReference($order_id);
     $paymentRequest->setRedirectURL($urlRetorno);
     $credentials = new PagSeguroAccountCredentials(Configuration::get("PAGSEGURO_BUSINESS"), Configuration::get("PAGSEGURO_TOKEN"));
     $url = $paymentRequest->register($credentials);
     return $url;
 }
 public static function main()
 {
     // Instantiate a new payment request
     $directPaymentRequest = new PagSeguroDirectPaymentRequest();
     // Set the Payment Mode for this payment request
     $directPaymentRequest->setPaymentMode('DEFAULT');
     // Set the Payment Method for this payment request
     $directPaymentRequest->setPaymentMethod('CREDIT_CARD');
     /**
      * @todo Change the receiver Email
      */
     $directPaymentRequest->setReceiverEmail('*****@*****.**');
     // Set the currency
     $directPaymentRequest->setCurrency("BRL");
     // Add an item for this payment request
     // Add an item for this payment request
     $directPaymentRequest->addItem('0001', 'Descricao do item a ser vendido', 2, 10.0);
     // Add an item for this payment request
     $directPaymentRequest->addItem('0002', 'Descricao do item a ser vendido', 2, 5.0);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $directPaymentRequest->setReference("REF123");
     // Set your customer information.
     // If you using SANDBOX you must use an email @sandbox.pagseguro.com.br
     $directPaymentRequest->setSender('João Comprador', '*****@*****.**', '11', '56273440', 'CPF', '156.009.442-76', true);
     $directPaymentRequest->setSenderHash("d94d002b6998ca9cd69092746518e50aded5a54aef64c4877ccea02573694986");
     // Set shipping information for this payment request
     $sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
     $directPaymentRequest->setShippingType($sedexCode);
     $directPaymentRequest->setShippingAddress('01452002', 'Av. Brig. Faria Lima', '1384', 'apto. 114', 'Jardim Paulistano', 'São Paulo', 'SP', 'BRA');
     //Set billing information for credit card
     $billing = new PagSeguroBilling(array('postalCode' => '01452002', 'street' => 'Av. Brig. Faria Lima', 'number' => '1384', 'complement' => 'apto. 114', 'district' => 'Jardim Paulistano', 'city' => 'São Paulo', 'state' => 'SP', 'country' => 'BRA'));
     $token = "5b97542cd1524b67a9e89b3d90c1f262";
     $installment = new PagSeguroDirectPaymentInstallment(array("quantity" => 2, "value" => "15.00", "noInterestInstallmentQuantity" => 2));
     $cardCheckout = new PagSeguroCreditCardCheckout(array('token' => $token, 'installment' => $installment, 'holder' => new PagSeguroCreditCardHolder(array('name' => 'João Comprador', 'documents' => array('type' => 'CPF', 'value' => '156.009.442-76'), 'birthDate' => date('01/10/1979'), 'areaCode' => 11, 'number' => 56273440)), 'billing' => $billing));
     //Set credit card for payment
     $directPaymentRequest->setCreditCard($cardCheckout);
     try {
         /**
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         // seller authentication
         //$credentials = new PagSeguroAccountCredentials("*****@*****.**",
         //    "E231B2C9BCC8474DA2E260B6C8CF60D3");
         // application authentication
         $credentials = PagSeguroConfig::getApplicationCredentials();
         $credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $return = $directPaymentRequest->register($credentials);
         self::printTransactionReturn($return);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 public static function main()
 {
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Set the currency
     $paymentRequest->setCurrency("BRL");
     // Add an item for this payment request
     $paymentRequest->addItem('0001', 'Notebook prata', 2, 430.0);
     // Add another item for this payment request
     $paymentRequest->addItem('0002', 'Notebook rosa', 2, 560.0);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $paymentRequest->setReference("REF123");
     // Set shipping information for this payment request
     $sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
     $paymentRequest->setShippingType($sedexCode);
     $paymentRequest->setShippingAddress('01452002', 'Av. Brig. Faria Lima', '1384', 'apto. 114', 'Jardim Paulistano', 'São Paulo', 'SP', 'BRA');
     // Set your customer information.
     $paymentRequest->setSender('João Comprador', '*****@*****.**', '11', '56273440', 'CPF', '156.009.442-76');
     // Set the url used by PagSeguro to redirect user after checkout process ends
     $paymentRequest->setRedirectUrl("http://www.lojamodelo.com.br");
     // Add checkout metadata information
     $paymentRequest->addMetadata('PASSENGER_CPF', '15600944276', 1);
     $paymentRequest->addMetadata('GAME_NAME', 'DOTA');
     $paymentRequest->addMetadata('PASSENGER_PASSPORT', '23456', 1);
     // Another way to set checkout parameters
     $paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas');
     $paymentRequest->addParameter('senderBornDate', '07/05/1981');
     $paymentRequest->addIndexedParameter('itemId', '0003', 3);
     $paymentRequest->addIndexedParameter('itemDescription', 'Notebook Preto', 3);
     $paymentRequest->addIndexedParameter('itemQuantity', '1', 3);
     $paymentRequest->addIndexedParameter('itemAmount', '200.00', 3);
     // Add discount per payment method
     $paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 1.0, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('EFT', 2.9, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('BOLETO', 10.0, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('DEPOSIT', 3.45, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('BALANCE', 0.01, 'DISCOUNT_PERCENT');
     try {
         /*
                      * #### Credentials #####
                      * Replace the parameters below with your credentials
                      * You can also get your credentials from a config file. See an example:
                      * $credentials = PagSeguroConfig::getAccountCredentials();
                     //  */
         // seller authentication
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $url = $paymentRequest->register($credentials);
         self::printPaymentUrl($url);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 public static function main()
 {
     // Instantiate a new payment request
     $directPaymentRequest = new PagSeguroDirectPaymentRequest();
     // Set the Payment Mode for this payment request
     $directPaymentRequest->setPaymentMode('DEFAULT');
     // Set the Payment Method for this payment request
     $directPaymentRequest->setPaymentMethod('EFT');
     /**
      * @todo Change the receiver Email
      */
     $directPaymentRequest->setReceiverEmail('*****@*****.**');
     // Set the currency
     $directPaymentRequest->setCurrency("BRL");
     // Add an item for this payment request
     $directPaymentRequest->addItem('0001', 'Descricao do item a ser vendido', 2, 10.0);
     // Add an item for this payment request
     $directPaymentRequest->addItem('0002', 'Descricao do item a ser vendido', 2, 5.0);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $directPaymentRequest->setReference("REF123");
     // Set your customer information.
     // If you using SANDBOX you must use an email @sandbox.pagseguro.com.br
     $directPaymentRequest->setSender('João Comprador', '*****@*****.**', '11', '56273440', 'CPF', '156.009.442-76', true);
     $directPaymentRequest->setSenderHash("d94d002b6998ca9cd69092746518e50aded5a54aef64c4877ccea02573694986");
     // Set shipping information for this payment request
     $sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
     $directPaymentRequest->setShippingType($sedexCode);
     $directPaymentRequest->setShippingAddress('01452002', 'Av. Brig. Faria Lima', '1384', 'apto. 114', 'Jardim Paulistano', 'São Paulo', 'SP', 'BRA');
     // Set bank for this payment request
     $directPaymentRequest->setOnlineDebit(array("bankName" => 'ITAU'));
     try {
         /**
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         // seller authentication
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $return = $directPaymentRequest->register($credentials);
         self::printTransactionReturn($return);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
Esempio n. 5
0
 public static function main()
 {
     // Instantiate a new pre-approval request
     $preApprovalRequest = new PagSeguroPreApprovalRequest();
     // Set the currency
     $preApprovalRequest->setCurrency("BRL");
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $preApprovalRequest->setReference("REF123");
     // Set shipping information for this payment request
     $sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
     $preApprovalRequest->setShippingType($sedexCode);
     $preApprovalRequest->setShippingAddress('01452002', 'Av. Brig. Faria Lima', '1384', 'apto. 114', 'Jardim Paulistano', 'São Paulo', 'SP', 'BRA');
     // Set your customer information.
     $preApprovalRequest->setSender('João Comprador', '*****@*****.**', '11', '56273440', 'CPF', '156.009.442-76');
     /***
      * Pre Approval information
      */
     $preApprovalRequest->setPreApprovalCharge('manual');
     $preApprovalRequest->setPreApprovalName("Seguro contra roubo do Notebook Prata");
     $preApprovalRequest->setPreApprovalDetails("Todo dia 30 será cobrado o valor de R100,00 referente ao seguro contra\n            roubo do Notebook Prata.");
     $preApprovalRequest->setPreApprovalAmountPerPayment('100.00');
     $preApprovalRequest->setPreApprovalMaxAmountPerPeriod('200.00');
     $preApprovalRequest->setPreApprovalPeriod('Monthly');
     $preApprovalRequest->setPreApprovalMaxTotalAmount('2400.00');
     $preApprovalRequest->setPreApprovalInitialDate('2015-09-10T00:00:00');
     $preApprovalRequest->setPreApprovalFinalDate('2017-09-07T00:00:00');
     $preApprovalRequest->setRedirectURL("http://www.lojateste.com.br/redirect");
     $preApprovalRequest->setReviewURL("http://www.lojateste.com.br/review");
     try {
         /*
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         // seller authentication
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $url = $preApprovalRequest->register($credentials);
         self::printPreApprovalUrl($url);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 public static function main()
 {
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Sets the currency
     $paymentRequest->setCurrency("BRL");
     // Add an item for this payment request
     $paymentRequest->addItem('0001', 'Notebook prata', 2, 430.0);
     // Add another item for this payment request
     $paymentRequest->addItem('0002', 'Notebook rosa', 2, 560.0);
     // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
     $paymentRequest->setReference("REF123");
     // Sets shipping information for this payment request
     $CODIGO_SEDEX = PagSeguroShippingType::getCodeByType('SEDEX');
     $paymentRequest->setShippingType($CODIGO_SEDEX);
     $paymentRequest->setShippingAddress('01452002', 'Av. Brig. Faria Lima', '1384', 'apto. 114', 'Jardim Paulistano', 'São Paulo', 'SP', 'BRA');
     // Sets your customer information.
     $paymentRequest->setSender('João Comprador', '*****@*****.**', '11', '56273440', 'CPF', '156.009.442-76');
     // Sets the url used by PagSeguro for redirect user after ends checkout process
     $paymentRequest->setRedirectUrl("http://www.lojamodelo.com.br");
     // Add checkout metadata information
     $paymentRequest->addMetadata('PASSENGER_CPF', '15600944276', 1);
     $paymentRequest->addMetadata('GAME_NAME', 'DOTA');
     $paymentRequest->addMetadata('PASSENGER_PASSPORT', '23456', 1);
     // Another way to set checkout parameters
     $paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas');
     $paymentRequest->addIndexedParameter('itemId', '0003', 3);
     $paymentRequest->addIndexedParameter('itemDescription', 'Notebook Preto', 3);
     $paymentRequest->addIndexedParameter('itemQuantity', '1', 3);
     $paymentRequest->addIndexedParameter('itemAmount', '200.00', 3);
     try {
         /*
          * #### Crendencials #####
          * Substitute the parameters below with your credentials (e-mail and token)
          * You can also get your credentails from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "your_token_here");
         // Register this payment request in PagSeguro, to obtain the payment URL for redirect your customer.
         $url = $paymentRequest->register($credentials);
         self::printPaymentUrl($url);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 public static function createByType($type)
 {
     $ShippingType = new PagSeguroShippingType();
     $ShippingType->setByType($type);
     return $ShippingType;
 }
 public static function main()
 {
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Set the currency
     $paymentRequest->setCurrency("BRL");
     $finalPrice = (double) self::$productData->price - self::$productData->discount;
     // Add an item for this payment request
     $paymentRequest->addItem('0001', self::$productData->name, 1, $finalPrice);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $paymentRequest->setReference(self::$referenceID);
     // Set shipping information for this payment request
     // 1 = PAC
     // 2 = SEDEX
     $sedexCode = PagSeguroShippingType::getCodeByType('PAC');
     $paymentRequest->setShippingType($sedexCode);
     $paymentRequest->setShippingAddress(self::$orderData->zipcode, self::$orderData->street, self::$orderData->number, self::$orderData->complement, self::$orderData->local, self::$orderData->city, self::$orderData->state, 'BRA');
     //$paymentRequest->setShippingCost(new BigDecimal("23.30"));
     // Adapta nome ao padrão do PagSeguro ("Nome Sobrenome")
     $name = self::$accountData->name;
     $name = preg_replace('/\\d/', '', $name);
     $name = preg_replace('/[\\n\\t\\r]/', ' ', $name);
     $name = preg_replace('/\\s(?=\\s)/', '', $name);
     $name = trim($name);
     $name = explode(' ', $name);
     if (count($name) == 1) {
         $name[] = ' dos Santos';
     }
     $name = implode(' ', $name);
     // Set your customer information.
     $paymentRequest->setSender($name, self::$accountData->email, '11', '56273440', 'CPF', '156.009.442-76');
     $paymentRequest->addParameter('senderCPF', self::$accountData->cpf);
     $paymentRequest->addParameter('senderAreaCode', 11);
     $paymentRequest->addParameter('senderCPF', 36251520884);
     //self::$accountData->cpf);
     $paymentRequest->addParameter('senderPhone', 921231232);
     $paymentRequest->addParameter('senderBornDate', "11/11/2012");
     // Set the url used by PagSeguro to redirect user after checkout process ends
     $paymentRequest->setRedirectUrl($_SERVER['SERVER_NAME'] . Config::read('page.url.order.completed') . '/' . self::$referenceID);
     // Add checkout metadata information
     // $paymentRequest->addMetadata('PASSENGER_CPF', '15600944276', 1);
     // $paymentRequest->addMetadata('GAME_NAME', 'DOTA');
     // $paymentRequest->addMetadata('PASSENGER_PASSPORT', '23456', 1);
     // Another way to set checkout parameters
     $paymentRequest->addParameter('notificationURL', $_SERVER['SERVER_NAME'] . Config::read('page.url.order.notifications'));
     $paymentRequest->addParameter('senderBornDate', '07/05/1981');
     // $paymentRequest->addIndexedParameter('itemId', '0003', 3);
     // $paymentRequest->addIndexedParameter('itemDescription', 'Notebook Preto', 3);
     // $paymentRequest->addIndexedParameter('itemQuantity', '1', 3);
     // $paymentRequest->addIndexedParameter('itemAmount', '200.00', 3);
     // Add discount per payment method
     //$paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 1.00, 'DISCOUNT_PERCENT');
     //$paymentRequest->addPaymentMethodConfig('EFT', 2.90, 'DISCOUNT_PERCENT');
     //$paymentRequest->addPaymentMethodConfig('BOLETO', 10.00, 'DISCOUNT_PERCENT');
     //$paymentRequest->addPaymentMethodConfig('DEPOSIT', 3.45, 'DISCOUNT_PERCENT');
     //$paymentRequest->addPaymentMethodConfig('BALANCE', 0.01, 'DISCOUNT_PERCENT');
     // Add installment without addition per payment method
     $paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 6, 'MAX_INSTALLMENTS_NO_INTEREST');
     // Add installment limit per payment method
     $paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 8, 'MAX_INSTALLMENTS_LIMIT');
     // Add and remove a group and payment methods
     //$paymentRequest->acceptPaymentMethodGroup('CREDIT_CARD', 'DEBITO_ITAU');
     //$paymentRequest->excludePaymentMethodGroup('BOLETO', 'BOLETO');
     try {
         /*
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = new PagSeguroAccountCredentials("*****@*****.**",
          * "E231B2C9BCC8474DA2E260B6C8CF60D3");
          */
         // seller authentication
         $credentials = PagSeguroConfig::getAccountCredentials();
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $url = $paymentRequest->register($credentials);
         return $url;
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 public static function compraCreditos($idp, $idpct)
 {
     /**
      * Executa uma operação de compra de créditos
      *
      * @param int $idp ID do parceiro
      * @param int $idpct ID do pacote comprado
      * @param int $tipo transação : 2 = cartão (default) | 3 = boleto | 4 = depósito
      * @param string $obj objeto da operação
      */
     // As ações de compra e bônus possuem status = 0 (espera) e não atualiza o saldo de créditos
     // até que a operação de checkout retorne o valor como pago.
     $hoje = new ActiveRecord\DateTime(date('Y-m-d H:i:s'));
     $saldo = creditos_saldo_parceiro::find_by_parceiro_id('first', $idp);
     $parceiro = parceiro::find_by_id($idp);
     if (!$parceiro) {
         return self::ERRO_USUARIO_INVALIDO;
     }
     $ddd = (int) substr($parceiro->fone, 1, 2);
     $fone = (int) str_replace('-', '', substr($parceiro->fone, 4, 10));
     $options['conditions'] = array('parceiro_id = ? AND vencimento >= ? AND flag_ativo = ?', $idp, $hoje, 1);
     $bonusUnico = creditos_bonus_unico::first($options);
     // Pega os dados de créditos, custo e bonus do pacote
     $pacote = creditos_pacote::find_by_id($idpct);
     if (!$pacote || $pacote->flag_ativo == 0) {
         return self::ERRO_PACOTE_INVALIDO;
     }
     $titulo = $pacote->titulo;
     $creditos = $pacote->quant_creditos;
     $custo = $pacote->custo_pacote_reais;
     $referencia = $idp . '-SC-' . self::contaEventos($idp, self::SC, 1);
     // utilizado para rastrear todos as fases da operação
     $bonus_geral = 0;
     $bonus_unico = 0;
     // avalia bonus geral e único
     if ($pacote->creditos_bonus > 0 && strtotime($pacote->data_limite_bonus) >= strtotime($hoje)) {
         $bonus_geral = $pacote->creditos_bonus;
     }
     $buOptions['conditions'] = array('parceiro_id = ? AND vencimento >= ? AND flag_ativo = ?', $idp, $hoje, 1);
     $bu = creditos_bonus_unico::first($buOptions);
     if ($bu) {
         $bonus_unico = $bu->bonus;
     }
     // inicializa classe do pagseguro, inserindo dados de usuário
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->addItem($idpct, $titulo, 1, $custo);
     $paymentRequest->setSender($parceiro->responsavel . ' - ' . $parceiro->nome, $parceiro->email, $ddd, $fone);
     $paymentRequest->setCurrency('BRL');
     $paymentRequest->setReference($referencia);
     //$paymentRequest->addParameter('notificationURL', self::NOTIFICATION_URL);
     $sedexCode = PagSeguroShippingType::getCodeByType('NOT_SPECIFIED');
     $paymentRequest->setShippingType($sedexCode);
     $cidade = cidade::find_by_id($parceiro->cidade_id);
     $estado = estado::find_by_id($parceiro->estado_id);
     $postalCode = str_replace('-', '', $parceiro->cep);
     $postalCode = str_replace('.', '', $postalCode);
     $logradouro = explode(', ', $parceiro->logradouro);
     $paymentRequest->setShippingAddress($postalCode, $logradouro[0], $logradouro[1], $parceiro->complemento, $parceiro->bairro, $cidade->cidade, $estado->uf, 'BRA');
     // inicia o processo de transação enviando as credenciais e
     // solicitando o código da operação
     try {
         $credentials = PagSeguroConfig::getAccountCredentials();
         // getApplicationCredentials()
         $checkoutUrl = $paymentRequest->register($credentials);
         // FORMATO:  https://pagseguro.uol.com.br/v2/checkout/payment.html?code=1C9B0FD3AEAE0FF004A39F98B751B1E5
         $codigo = explode('=', $checkoutUrl);
         // grava os dados da operação antes inicar
         $dadosPagSeguro = array();
         $dadosPagSeguro['parceiro_id'] = $idp;
         $dadosPagSeguro['parceiro_nome'] = $parceiro->responsavel . ' - ' . $parceiro->nome;
         $dadosPagSeguro['parceiro_email'] = $parceiro->email;
         $dadosPagSeguro['parceiro_fone'] = $parceiro->fone;
         $dadosPagSeguro['bonus_geral'] = $bonus_geral;
         $dadosPagSeguro['bonus_unico'] = $bonus_unico;
         $dadosPagSeguro['pacote_id'] = $idpct;
         $dadosPagSeguro['pacote_titulo'] = $titulo;
         $dadosPagSeguro['pacote_creditos'] = $creditos;
         $dadosPagSeguro['flag_pacote_creditado'] = 0;
         $dadosPagSeguro['data_cadastro'] = $hoje;
         $dadosPagSeguro['data_atualizacao'] = $hoje;
         $dadosPagSeguro['codigo_link'] = $codigo[1];
         $dadosPagSeguro['referencia'] = $referencia;
         $dadosPagSeguro['tipo_transacao'] = 1;
         // 1 ==  compra | 11 == assinatura
         $dadosPagSeguro['status_transacao'] = 0;
         // inicia como 0
         $dadosPagSeguro['fases'] = 0;
         // registra todos os status retornados pelo pagseguro. Inicia como 0
         $dadosPagSeguro['valor_reais'] = $custo;
         $pagseguro = operacoes_pagseguro::create($dadosPagSeguro);
         $pagseguro->save();
         $observação = 'Solicitação de compra PagSeguro ' . $referencia . '(R$' . number_format($custo, 2, ',', '.') . ')';
         // registra o crédito adquirido como status EM ESPERA
         self::registraEvento($idp, self::SC, $saldo->saldo, $referencia, $crdt, $custo, 1, $observação);
         // descomentar esta linha na versão final
         // return $codigo[1];
         return self::ERRO_OPERACAO_TESTE_CANCELADA;
     } catch (PagSeguroServiceException $e) {
         // implementar retorno de erro personalizado
         die($e->getMessage());
     }
 }
 public function setTipoFrete($tipo = 'SEDEX')
 {
     $shipping_code = \PagSeguroShippingType::getCodeByType($tipo);
     $this->request_pg->setShippingType($shipping_code);
 }
 public static function main()
 {
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Set the currency
     $paymentRequest->setCurrency("BRL");
     // Add an item for this payment request
     $paymentRequest->addItem('0001', 'Notebook prata', 2, 430.0);
     // Add another item for this payment request
     $paymentRequest->addItem('0002', 'Notebook rosa', 2, 560.0);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $paymentRequest->setReference("REF123");
     // Set shipping information for this payment request
     $sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
     $paymentRequest->setShippingType($sedexCode);
     $paymentRequest->setShippingAddress('01452002', 'Av. Brig. Faria Lima', '1384', 'apto. 114', 'Jardim Paulistano', 'São Paulo', 'SP', 'BRA');
     // Set your customer information.
     $paymentRequest->setSender('João Comprador', '*****@*****.**', '11', '56273440', 'CPF', '156.009.442-76');
     // Set the url used by PagSeguro to redirect user after checkout process ends
     $paymentRequest->setRedirectUrl("http://www.lojamodelo.com.br");
     // Add checkout metadata information
     $paymentRequest->addMetadata('PASSENGER_CPF', '15600944276', 1);
     $paymentRequest->addMetadata('GAME_NAME', 'DOTA');
     $paymentRequest->addMetadata('PASSENGER_PASSPORT', '23456', 1);
     // Another way to set checkout parameters
     $paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas');
     $paymentRequest->addParameter('senderBornDate', '07/05/1981');
     $paymentRequest->addIndexedParameter('itemId', '0003', 3);
     $paymentRequest->addIndexedParameter('itemDescription', 'Notebook Preto', 3);
     $paymentRequest->addIndexedParameter('itemQuantity', '1', 3);
     $paymentRequest->addIndexedParameter('itemAmount', '200.00', 3);
     /***
      * Pre Approval information
      */
     $preApprovalRequest = new PagSeguroPreApprovalRequest();
     $preApprovalRequest->setPreApprovalCharge('manual');
     $preApprovalRequest->setPreApprovalName("Seguro contra roubo do Notebook Prata");
     $preApprovalRequest->setPreApprovalDetails("Todo dia 30 será cobrado o valor de R100,00 referente ao seguro contra\n            roubo do Notebook Prata.");
     $preApprovalRequest->setPreApprovalAmountPerPayment('100.00');
     $preApprovalRequest->setPreApprovalMaxAmountPerPeriod('200.00');
     $preApprovalRequest->setPreApprovalPeriod('Monthly');
     $preApprovalRequest->setPreApprovalMaxTotalAmount('2400.00');
     $preApprovalRequest->setPreApprovalInitialDate('2015-09-09T00:00:00');
     $preApprovalRequest->setPreApprovalFinalDate('2017-09-09T00:00:00');
     $preApprovalRequest->setReviewURL("http://www.lojateste.com.br/redirect");
     $paymentRequest->setPreApproval($preApprovalRequest);
     try {
         /*
          * #### Credentials #####
          * Replace the parameters below with your credentials
          * You can also get your credentials from a config file. See an example:
          * $credentials = PagSeguroConfig::getAccountCredentials();
          */
         // seller authentication
         $credentials = new PagSeguroAccountCredentials("*****@*****.**", "E231B2C9BCC8474DA2E260B6C8CF60D3");
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $url = $paymentRequest->register($credentials);
         self::printPaymentUrl($url);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
 public function paymentPagSeguro($products, $andress, $client, $total, $valor_frete, $id_venda)
 {
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Set the currency
     $paymentRequest->setCurrency("BRL");
     // Add an item for this payment request
     foreach ($products as $i => $item) {
         $paymentRequest->addItem('000' . $item['Produto']['id'], $item['Produto']['nome'] . '    Tamanho: ' . $item['Produto']['variacao'], $item['Produto']['quantidade'], number_format($item['Produto']['preco'], 2, '.', ''));
     }
     // Add an item for this payment request
     // $paymentRequest->addItem('0001', 'Notebook prata', 2, 430.00);
     // Add another item for this payment request
     // $paymentRequest->addItem('0002', 'Notebook rosa', 2, 560.00);
     // Set a reference code for this payment request. It is useful to identify this payment
     // in future notifications.
     $paymentRequest->setReference($id_venda);
     // Set shipping information for this payment request
     $sedexCode = PagSeguroShippingType::getCodeByType('PAC');
     $paymentRequest->setShippingCost($valor_frete);
     $paymentRequest->setShippingType($sedexCode);
     $paymentRequest->setShippingAddress($andress['cep'], $andress['endereco'], $andress['numero'], 'apto. 114', $andress['bairro'], $andress['cidade'], $andress['estado'], 'BRA');
     // Set your customer information.
     $paymentRequest->setSender($client['nome'], $client['email'], $client['ddd'], $client['telefone'], 'CPF', $client['cpf']);
     // Set the url used by PagSeguro to redirect user after checkout process ends
     $paymentRequest->setRedirectUrl("http://www.lojamodelo.com.br");
     // Add checkout metadata information
     // $paymentRequest->addMetadata('PASSENGER_CPF', '15600944276', 1);
     // $paymentRequest->addMetadata('GAME_NAME', 'DOTA');
     // $paymentRequest->addMetadata('PASSENGER_PASSPORT', '23456', 1);
     // Another way to set checkout parameters
     // $paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas');
     // $paymentRequest->addParameter('senderBornDate', '07/05/1981');
     // $paymentRequest->addIndexedParameter('itemId', '0003', 3);
     // $paymentRequest->addIndexedParameter('itemDescription', 'Notebook Preto', 3);
     // $paymentRequest->addIndexedParameter('itemQuantity', '1', 3);
     // $paymentRequest->addIndexedParameter('itemAmount', '200.00', 3);
     // Add discount per payment method
     $paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 1.0, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('EFT', 2.9, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('BOLETO', 10.0, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('DEPOSIT', 3.45, 'DISCOUNT_PERCENT');
     $paymentRequest->addPaymentMethodConfig('BALANCE', 0.01, 'DISCOUNT_PERCENT');
     try {
         /*
                      * #### Credentials #####
                      * Replace the parameters below with your credentials
                      * You can also get your credentials from a config file. See an example:
                      * $credentials = PagSeguroConfig::getAccountCredentials();
                     //  */
         // seller authentication
         $credentials = new PagSeguroAccountCredentials("email", "token");
         // application authentication
         //$credentials = PagSeguroConfig::getApplicationCredentials();
         //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
         // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
         $url = $paymentRequest->register($credentials);
         $this->redirect($url);
     } catch (PagSeguroServiceException $e) {
         die($e->getMessage());
     }
 }
Esempio n. 13
0
if (isset($_POST['submit'])) {
    if ($_POST['options'] == "PagSeguro") {
        require_once 'PagSeguroLibrary/PagSeguroLibrary.php';
        /** INICIO PROCESSO PAGSEGURO */
        $paymentRequest = new PagSeguroPaymentRequest();
        $data = array('id' => '01', 'description' => 'Presente de Casamento Jèssica e Rafael', 'quantity' => 1, 'amount' => $_POST['quantity'] . '.00');
        $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);
        $sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');
        $paymentRequest->setShippingType($sedexCode);
        $paymentRequest->setShippingAddress('30240440', 'Rua Professor Tancredo Martins', '59', 'apto. 201', 'São Lucas', 'Belo Horizonte', 'MG', 'BRA');
        //Url de redirecionamento
        $redirectURL = "http://www.jessicafaria.com.br/casamento_jr/casamento.php";
        $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);
        print "<script>\n\twindow.location.href = '" . $url . "';\n</script>";
    }
}
 public function setEnderecoClienteGateway()
 {
     if (empty($this->endereco)) {
         throw new Exception("Você precisa usar a função setar os dados do cliente!", 1);
     }
     $sedexCode = PagSeguroShippingType::getCodeByType('PAC');
     $paymentRequest->setShippingType($sedexCode);
     $paymentRequest->setShippingAddress($this->endereco['cep'], $this->endereco['endereco'], $this->endereco['numero'], $this->endereco['complemento'], $this->endereco['bairro'], $this->endereco['cidade'], $this->endereco['estado'], 'BRA');
     return $this->getEndereco();
 }
Esempio n. 15
0
 /**
  * Generate PagSeguro Shipping Type
  * @return \PagSeguroShippingTyp
  */
 private function _generatePagSeguroShippingTypeObject()
 {
     $shippingType = new PagSeguroShippingType();
     $shippingType->setByType('NOT_SPECIFIED');
     return $shippingType;
 }
Esempio n. 16
0
 /**
  * Use PagSeguroLibrary
  * 
  * @param type $order_id
  * @return type
  */
 public function payment($order)
 {
     global $woocommerce;
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Set cms version
     PagSeguroLibrary::setCMSVersion('woocommerce-v.' . $woocommerce->version);
     // Set plugin version
     PagSeguroLibrary::setModuleVersion('woocommerce-v.' . $this->plugin_version);
     // Set charset
     PagSeguroConfig::setApplicationCharset($this->charset);
     // Sets the currency
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName("REAL"));
     // Set a reference
     $paymentRequest->setReference($this->invoice_prefix . $order->id);
     //Sets shipping data
     $paymentRequest->setShippingAddress($order->billing_postcode, $order->billing_address_1, '', $order->billing_address_2, '', $order->billing_city, $order->billing_state, $order->billing_country);
     $paymentRequest->setShippingCost($order->order_shipping);
     $paymentRequest->setShippingType(PagSeguroShippingType::getCodeByType('NOT_SPECIFIED'));
     // Sets your customer information.
     $paymentRequest->setSender($order->billing_first_name . ' ' . $order->billing_last_name, $order->billing_email, substr($order->billing_phone, 0, 2), substr($order->billing_phone, 2));
     // Sets the url used by PagSeguro for redirect user after ends checkout process
     if (!empty($this->url_redirect)) {
         $paymentRequest->setRedirectUrl($this->url_redirect);
     } else {
         $paymentRequest->setRedirectUrl($this->get_return_url($order));
     }
     // Sets the url used by PagSeguro for redirect user after ends checkout process
     if (!empty($this->url_notification)) {
         $paymentRequest->setNotificationURL($this->url_notification);
     } else {
         $paymentRequest->setNotificationURL(home_url() . '/index.php?notificationurl=true');
     }
     //Sets Items
     if (sizeof($order->get_items()) > 0) {
         $paymentRequest->setItems($this->setItems($order));
     }
     // Sets the sum of discounts
     $paymentRequest->setExtraAmount(($order->order_discount + $order->cart_discount) * -1 + ($order->order_tax + $order->order_shipping_tax + $order->prices_include_tax));
     try {
         $credentials = new PagSeguroAccountCredentials($this->email, $this->token);
         return $paymentRequest->register($credentials);
     } catch (PagSeguroServiceException $e) {
         $woocommerce->add_error(__('Sorry, unfortunately there was an error during checkout. Please contact the store administrator if the problem persists.', 'wpwcpagseguro'));
         $woocommerce->show_messages();
         wp_die();
     }
 }
/**
 * 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;
}