Skip to content

Commit

Permalink
Correção notificação de retorno
Browse files Browse the repository at this point in the history
Agora usa a nova api do Pagseguro para alterar o status das transações
de pedidos.
  • Loading branch information
luizwbr committed Nov 25, 2015
1 parent 4d3e67c commit a9a8c6b
Show file tree
Hide file tree
Showing 103 changed files with 15,689 additions and 93 deletions.
119 changes: 119 additions & 0 deletions PagSeguroLibrary/PagSeguroLibrary.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?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
*/

class PagSeguroLibrary
{

const VERSION = "2.6.0";
public static $resources;
public static $config;
public static $log;
private static $path;
private static $library;
private static $module_version;
private static $cms_version;
private static $php_version;

public function __construct()
{
self::$path = (dirname(__FILE__));
PagSeguroAutoloader::init();
self::$resources = PagSeguroResources::init();
self::$config = PagSeguroConfig::init();
self::$log = LogPagSeguro::init();
}

public static function init()
{
if (self::$library == null) {
require_once "loader" . DIRECTORY_SEPARATOR . "PagSeguroAutoLoader.class.php";
self::verifyDependencies();
self::$library = new PagSeguroLibrary();
}
return self::$library;
}

private static function verifyDependencies()
{

$dependencies = true;

try {
if (!function_exists('curl_init')) {
$dependencies = false;
throw new Exception('PagSeguroLibrary: cURL library is required.');
}

if (!class_exists('DOMDocument')) {
$dependencies = false;
throw new Exception('PagSeguroLibrary: DOM XML extension is required.');
}

} catch (Exception $e) {
return $dependencies;
}

return $dependencies;

}

final public static function getVersion()
{
return self::VERSION;
}

final public static function getPath()
{
return self::$path;
}

final public static function getModuleVersion()
{
return self::$module_version;
}

final public static function setModuleVersion($version)
{
self::$module_version = $version;
}

final public static function getPHPVersion()
{
return self::$php_version = phpversion();
}

final public static function setPHPVersion($version)
{
self::$php_version = $version;
}

final public static function getCMSVersion()
{
return self::$cms_version;
}

final public static function setCMSVersion($version)
{
self::$cms_version = $version;
}
}
26 changes: 26 additions & 0 deletions PagSeguroLibrary/PagSeguroLibrary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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();
215 changes: 215 additions & 0 deletions PagSeguroLibrary/config/PagSeguroConfig.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?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
*/

/***
* Provides a means to retrieve configuration preferences.
* These preferences can come from the default config file (PagSeguroLibrary/config/PagSeguroConfigWrapper.php).
*/

class PagSeguroConfig
{

private static $config;
private static $data;

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.");
}
}

public static function init()
{
if (self::$config == null) {
self::$config = new PagSeguroConfig();
}

return self::$config;
}

public static function getData($key1, $key2 = null)
{
if ($key2 != null) {
if (isset(self::$data[$key1][$key2])) {
return self::$data[$key1][$key2];
} else {
throw new Exception("Keys {$key1}, {$key2} not found.");
}
} else {
if (isset(self::$data[$key1])) {
return self::$data[$key1];
} else {
throw new Exception("Config key {$key1} not found.");
}
}
}

public static function setData($key1, $key2, $value)
{
if (isset(self::$data[$key1][$key2])) {
self::$data[$key1][$key2] = $value;
} else {
throw new Exception("Keys {$key1}, {$key2} not found.");
}
}

public static function setEnvironment($value)
{
self::$data['environment'] = $value;
}

public static function getApplicationCredentials()
{
if (isset(self::$data['credentials']) &&
isset(self::$data['credentials']['appId'][self::$data['environment']]) &&
isset(self::$data['credentials']['appKey'][self::$data['environment']])
) {
return new PagSeguroApplicationCredentials(
self::$data['credentials']['appId'][self::$data['environment']],
self::$data['credentials']['appKey'][self::$data['environment']]
);
} else {
throw new Exception("Applications credentials not set.");
}
}

public static function getAccountCredentials()
{
if (isset(self::$data['credentials']) &&
isset(self::$data['credentials']['email']) &&
isset(self::$data['credentials']['token'][self::$data['environment']])
) {
return new PagSeguroAccountCredentials(
self::$data['credentials']['email'],
self::$data['credentials']['token'][self::$data['environment']]
);
} else {
throw new Exception("Credentials not set.");
}
}

public static function getPaymentRedirectUrl()
{
return PagSeguroResources::getPaymentUrl(self::$data['environment']);
}

public static function getStaticUrl()
{
return PagSeguroResources::getStaticUrl(self::$data['environment']);
}

public static function getEnvironment()
{
if (isset(self::$data['environment'])) {
return self::$data['environment'];
} else {
throw new Exception("Environment not set.");
}
}

public static function getApplicationCharset()
{
if (isset(self::$data['application']) && isset(self::$data['application']['charset'])) {
return self::$data['application']['charset'];
} else {
throw new Exception("Application charset not set.");
}
}

public static function setApplicationCharset($charset)
{
self::setData('application', 'charset', $charset);
}

public static function logIsActive()
{
if (isset(self::$data['log']) && isset(self::$data['log']['active'])) {
return (bool) self::$data['log']['active'];
} else {
throw new Exception("Log activation flag not set.");
}
}

public static function activeLog($fileName = null)
{
self::setData('log', 'active', true);
self::setData('log', 'fileLocation', $fileName ? $fileName : '');
LogPagSeguro::reLoad();
}

public static function getLogFileLocation()
{
if (isset(self::$data['log']) && isset(self::$data['log']['fileLocation'])) {
return self::$data['log']['fileLocation'];
} else {
throw new Exception("Log file location not set.");
}
}

/***
* Validate if the requirements are enable for use correct of the PagSeguro
* @return array
*/
public static function validateRequirements()
{

$requirements = array(
'version' => '',
'spl' => '',
'curl' => '',
'dom' => ''
);

$version = str_replace('.', '', phpversion());

if ($version < 5427) {
$requirements['version'] = 'PagSeguroLibrary: PHP version 5.4.27 or greater is required.';
}

if (!function_exists('spl_autoload_register')) {
$requirements['spl'] = 'PagSeguroLibrary: Standard PHP Library (SPL) is required.';
}

if (!function_exists('curl_init')) {
$requirements['curl'] = 'PagSeguroLibrary: cURL library is required.';
}

if (!class_exists('DOMDocument')) {
$requirements['dom'] = 'PagSeguroLibrary: DOM XML extension is required.';
}

return $requirements;
}
}
Loading

0 comments on commit a9a8c6b

Please sign in to comment.