NOTICE OF LICENSE Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Author: PagSeguro Internet Ltda. @copyright 2007-2014 PagSeguro Internet Ltda. @license http://www.apache.org/licenses/LICENSE-2.0
Exemplo n.º 1
0
 public static function init()
 {
     if (self::$library == null) {
         self::$library = new PagSeguroLibrary();
     }
     return self::$library;
 }
 private function addClass($dir, $class)
 {
     $file = PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $class . '.class.php';
     if (file_exists($file) && is_file($file)) {
         require_once $file;
     }
 }
Exemplo n.º 3
0
 public function install()
 {
     if (version_compare(PagSeguroLibrary::getVersion(), '2.1.8', '<=')) {
         if (!$this->validatePagSeguroRequirements()) {
             return false;
         }
     }
     if (!$this->validatePagSeguroId()) {
         return false;
     }
     if (!$this->validateOrderMessage()) {
         return false;
     }
     if (!$this->generatePagSeguroOrderStatus()) {
         return false;
     }
     if (!$this->createTables()) {
         return false;
     }
     if (!$this->modulo->installConfiguration()) {
         return false;
     }
     if (!parent::install() or !$this->registerHook('payment') or !$this->registerHook('paymentReturn') or !Configuration::updateValue('PAGSEGURO_EMAIL', '') or !Configuration::updateValue('PAGSEGURO_TOKEN', '') or !Configuration::updateValue('PAGSEGURO_URL_REDIRECT', '') or !Configuration::updateValue('PAGSEGURO_NOTIFICATION_URL', '') or !Configuration::updateValue('PAGSEGURO_CHARSET', PagSeguroConfig::getData('application', 'charset')) or !Configuration::updateValue('PAGSEGURO_LOG_ACTIVE', PagSeguroConfig::getData('log', 'active')) or !Configuration::updateValue('PAGSEGURO_RECOVERY_ACTIVE', false) or !Configuration::updateValue('PAGSEGURO_DAYS_RECOVERY', 1) or !Configuration::updateValue('PAGSEGURO_CHECKOUT', false) or !Configuration::updateValue('PAGSEGURO_LOG_FILELOCATION', PagSeguroConfig::getData('log', 'fileLocation'))) {
         return false;
     }
     return true;
 }
 private function curlConnection($method, $url, $timeout, $charset, array $data = null)
 {
     if (Tools::strtoupper($method) === 'POST') {
         $postFields = $data ? http_build_query($data, '', '&') : "";
         $contentLength = "Content-length: " . Tools::strlen($postFields);
         $methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields);
     } else {
         $contentLength = null;
         $methodOptions = array(CURLOPT_HTTPGET => true);
     }
     $options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength, 'lib-description: php:' . PagSeguroLibrary::getVersion(), 'language-engine-description: php:' . PagSeguroLibrary::getPHPVersion()), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout);
     if (!is_null(PagSeguroLibrary::getModuleVersion())) {
         array_push($options[CURLOPT_HTTPHEADER], 'module-description: ' . PagSeguroLibrary::getModuleVersion());
     }
     if (!is_null(PagSeguroLibrary::getCMSVersion())) {
         array_push($options[CURLOPT_HTTPHEADER], 'cms-description: ' . PagSeguroLibrary::getCMSVersion());
     }
     $options = $options + $methodOptions;
     $curl = curl_init();
     curl_setopt_array($curl, $options);
     $resp = curl_exec($curl);
     $info = curl_getinfo($curl);
     $error = curl_errno($curl);
     $errorMessage = curl_error($curl);
     curl_close($curl);
     $this->setStatus((int) $info['http_code']);
     $this->setResponse((string) $resp);
     if ($error) {
         throw new Exception("CURL can't connect: {$errorMessage}");
     } else {
         return true;
     }
 }
Exemplo n.º 5
0
 public static function init()
 {
     self::verifyDependencies();
     if (self::$library == null) {
         self::$library = new PagSeguroLibrary();
     }
     return self::$library;
 }
Exemplo n.º 6
0
 public function __construct()
 {
     $this->ci =& get_instance();
     $this->ci->load->config('pagseguro');
     PagSeguroLibrary::init();
     self::$pgEmail = $this->ci->config->item('pagseguroAccount');
     self::$pgToken = $this->ci->config->item('pagseguroToken');
 }
 public function __construct()
 {
     $this->ci =& get_instance();
     $this->ci->load->config('pagseguro');
     PagSeguroLibrary::init();
     self::$config = $this->ci->config->item('pagseguro');
     self::$environment = self::$config['environment'];
     self::$email = self::$config[self::$environment]['pagseguroAccount'];
     self::$token = self::$config[self::$environment]['pagseguroToken'];
 }
Exemplo n.º 8
0
 private function __construct()
 {
     define('ALLOW_PAGSEGURO_CONFIG', true);
     require_once PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "PagSeguroConfig.php";
     $varName = self::VARNAME;
     if (isset(${$varName})) {
         self::$data = ${$varName};
         unset(${$varName});
     } else {
         throw new Exception("Config is undefined.");
     }
 }
 private function __construct()
 {
     define('ALLOW_PAGSEGURO_RESOURCES', true);
     require_once PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . "PagSeguroResources.php";
     $varName = self::VAR_NAME;
     if (isset(${$varName})) {
         self::$data = ${$varName};
         unset(${$varName});
     } else {
         throw new Exception("Resources is undefined.");
     }
 }
Exemplo n.º 10
0
 function __autoload($class)
 {
     $dirs = array('domain', 'exception', 'parser', 'service', 'utils', 'helper', 'config', 'resources', 'log');
     foreach ($dirs as $d) {
         $file = PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . $d . DIRECTORY_SEPARATOR . $class . '.class.php';
         if (file_exists($file) && is_file($file)) {
             require_once $file;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 11
0
 private function __construct()
 {
     define('ALLOW_PAGSEGURO_CONFIG', true);
     if (!class_exists('PagSeguroConfigWrapper')) {
         require_once PagSeguroLibrary::getPath() . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "PagSeguroConfigWrapper.php";
     }
     $wrapper = new PagSeguroConfigWrapper();
     if (method_exists($wrapper, 'getConfig')) {
         self::$data = $wrapper->getConfig();
     } else {
         throw new Exception("Config is undefined.");
     }
 }
Exemplo n.º 12
0
 /**
  * Creates the log file
  * @throws Exception
  * @return boolean
  */
 public static function createFile()
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro.log';
     self::$fileLocation = $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     if ($f = @fopen(self::$fileLocation, "a")) {
         fclose($f);
     } else {
         throw new Exception("Can't create log file. Permission denied. File location: " . self::$fileLocation);
     }
 }
Exemplo n.º 13
0
 /**
  * Creates the log file
  * @throws Exception
  * @return boolean
  */
 public static function createFile()
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro.log';
     self::$fileLocation = $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     try {
         $f = fopen(self::$fileLocation, "a");
         fclose($f);
     } catch (Exception $e) {
         echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . self::$fileLocation;
     }
 }
 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());
     }
 }
Exemplo n.º 15
0
 public static function createFile($logFile = false)
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro.log';
     self::$fileLocation = $logFile ? $logFile : $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     try {
         $f = fopen(self::$fileLocation, "a");
         if (!$f) {
             throw new Exception('Unable to open the input file');
         }
         fclose($f);
         return true;
     } catch (Exception $e) {
         echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . self::$fileLocation;
         return false;
     }
 }
Exemplo n.º 16
0
 public static function createFile()
 {
     if (!self::$active) {
         return false;
     }
     $defaultPath = PagSeguroLibrary::getPath();
     $defaultName = 'PagSeguro' . mt_rand() . '.log';
     self::$fileLocation = $defaultPath . DIRECTORY_SEPARATOR . $defaultName;
     Configuration::updateValue('PAGSEGURO_LOG_FILELOCATION', "/modules/pagseguro/features/PagSeguroLibrary/" . $defaultName);
     try {
         $f = fopen(self::$fileLocation, "a");
         if (!$f) {
             throw new Exception('Unable to open the input file');
         }
         fclose($f);
         return true;
     } catch (Exception $e) {
         echo $e->getMessage() . " - Can't create log file. Permission denied. File location: " . self::$fileLocation;
         return false;
     }
 }
 public static final function setCMSVersion($version)
 {
     self::$cms_version = $version;
 }
Exemplo n.º 18
0
 public function testDependencies()
 {
     $this->assertInstanceOf('PagSeguroLibrary', PagSeguroLibrary::init());
 }
 public function __construct()
 {
     PagSeguroLibrary::init();
 }
Exemplo n.º 20
0
 function __construct($file)
 {
     PagSeguroLibrary::init();
     $this->pg = new PagSeguroPaymentRequest();
     $this->init($file);
 }
Exemplo n.º 21
0
 /**
  * Sets VirtueMart version
  */
 private function _setPagSeguroCMSVersion()
 {
     PagSeguroLibrary::setCMSVersion('virtuemart' . ':' . vmVersion::$RELEASE);
 }
Exemplo n.º 22
0
 public function __construct($dadosCliente)
 {
     $this->dados_cliente = $dadosCliente;
     $this->pagseguroConfig = new \PagSeguroPaymentRequest();
     \PagSeguroLibrary::init();
 }
Exemplo n.º 23
0
<?php

/**
 * 2007-2014 [PagSeguro Internet Ltda.]
 *
 * NOTICE OF LICENSE
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 *http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
 *
 *  @author    PagSeguro Internet Ltda.
 *  @copyright 2007-2014 PagSeguro Internet Ltda.
 *  @license   http://www.apache.org/licenses/LICENSE-2.0
 */
require_once dirname(__FILE__) . '/PagSeguroLibrary.class.php';
PagSeguroLibrary::init();
Exemplo n.º 24
0
 /**
  * Set version CMS
  */
 private function _setCmsVersion()
 {
     PagSeguroLibrary::setCMSVersion('opencart' . ':' . VERSION);
 }
 /**
  * Sets VirtueMart version
  */
 private function _setPagSeguroCMSVersion()
 {
     PagSeguroLibrary::setCMSVersion('hikashop' . ':2.1.0');
 }
Exemplo n.º 26
0
 public function __contruct()
 {
     parent::__contruct();
 }
Exemplo n.º 27
0
 /**
  * Set PagSeguro CMS version
  */
 private function _setPagSeguroCMSVersion()
 {
     PagSeguroLibrary::setCMSVersion('prestashop-v.' . _PS_VERSION_);
 }
 /**
  * Set Config's to PagSeguro API
  */
 private function setPagSeguroConfig()
 {
     $activeLog = $this->getConfigData('log');
     $charset = $this->getConfigData('charset');
     //Module version
     PagSeguroLibrary::setModuleVersion('magento' . ':' . Mage::helper('pagseguro')->getVersion());
     //CMS version
     PagSeguroLibrary::setCMSVersion('magento' . ':' . Mage::getVersion());
     //Setup Charset
     if ($charset != null and !empty($charset)) {
         PagSeguroConfig::setApplicationCharset($charset);
     }
     //Setup Log
     if ($activeLog == 1) {
         $logFile = $this->getConfigData('log_file');
         if (self::checkFile(Mage::getBaseDir() . '/' . $logFile)) {
             PagSeguroConfig::activeLog(Mage::getBaseDir() . '/' . $logFile);
         } else {
             PagSeguroConfig::activeLog();
             //Default Log
         }
     }
 }
Exemplo n.º 29
0
 /**
  * Set Config's to PagSeguro API
  *
  */
 private function setPagSeguroConfig()
 {
     $_activeLog = $this->getConfigData('log');
     $_charset = $this->getConfigData('charset');
     Mage::getSingleton('PagSeguro_PagSeguro_Helper_Data')->saveAllStatusPagSeguro();
     //Module version
     PagSeguroLibrary::setModuleVersion('magento' . ':' . $this->Module_Version);
     //CMS version
     PagSeguroLibrary::setCMSVersion('magento' . ':' . Mage::getVersion());
     //Setup Charset
     if ($_charset != null and !empty($_charset)) {
         PagSeguroConfig::setApplicationCharset($_charset);
     }
     //Setup Log
     if ($_activeLog == 1) {
         $_log_file = $this->getConfigData('log_file');
         if (self::checkFile(Mage::getBaseDir() . '/' . $_log_file)) {
             PagSeguroConfig::activeLog(Mage::getBaseDir() . '/' . $_log_file);
         } else {
             PagSeguroConfig::activeLog();
             //Default Log
         }
     }
 }
Exemplo n.º 30
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();
     }
 }