コード例 #1
1
ファイル: pagseguro.php プロジェクト: dlanileonardo/pagseguro
 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;
 }
コード例 #2
0
 public function requestPayment($items, $client, $reference = null, $shipping = null, $redirect = '/', $currency = 'BRL')
 {
     $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();
         }
     }
 }
コード例 #3
0
ファイル: wpwcpagseguro.php プロジェクト: moterra/woocommerce
 /**
  * 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();
     }
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 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());
     }
 }