Skip to content

Commit

Permalink
Merge pull request #24 from roadster31/revamping
Browse files Browse the repository at this point in the history
Complete module revamping
  • Loading branch information
bibich committed Jan 14, 2016
2 parents 546715b + ae0b9f0 commit 113b131
Show file tree
Hide file tree
Showing 45 changed files with 1,527 additions and 3,568 deletions.
113 changes: 0 additions & 113 deletions AdminIncludes/module_configuration.html

This file was deleted.

71 changes: 32 additions & 39 deletions Classes/API/PaypalApiCredentials.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
<?php
/**
* Class PaypalApiCredentials
* Store PayPal API Credentials
*
* Created by JetBrains PhpStorm.
* Date: 8/5/13
* Time: 5:37 PM
*
* @author Guillaume MOREL <[email protected]>
*/
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/

namespace Paypal\Classes\API;

use Paypal\Model\ConfigInterface;
use Paypal\Paypal;
use Thelia\Core\Translation\Translator;

Expand All @@ -28,26 +38,19 @@ class PaypalApiCredentials
/** @var string PayPal API signature (Three Token Authentication) */
protected $apiSignature = null;

/*
* @var ConfigInterface
*/
protected $config;

/**
* Create a NVP Credentials
*
* @param ConfigInterface $config Variable
* @param string $user PayPal API username
* @param string $password PayPal API password
* @param string $signature PayPal API signature (3T)
*
* @throws \InvalidArgumentException
*/
public function __construct(ConfigInterface $config, $user = null, $password = null, $signature = null)
public function __construct($user = null, $password = null, $signature = null)
{
$this->config=$config;
if ($user === null && $password === null && $signature === null) {
$this->setDefaultCredentials($config);
$this->setDefaultCredentials();
} else {
if (empty($user) || empty($password) || empty($signature)) {
throw new \InvalidArgumentException(
Expand All @@ -61,32 +64,23 @@ public function __construct(ConfigInterface $config, $user = null, $password = n
}
}

/**
* @return \Paypal\Model\ConfigInterface
*/
public function getConfig()
{
return $this->config;
}

/**
* Set credentials from database according to SandBox Mode
*
* @param ConfigInterface $config Variable
*
* @throws \InvalidArgumentException
*/
protected function setDefaultCredentials(ConfigInterface $config)
protected function setDefaultCredentials()
{
$paypalApiManager = new PaypalApiManager($config);
$paypalApiManager = new PaypalApiManager();

if ($paypalApiManager->isModeSandbox()) {
$username = $config->getLoginSandbox() != null?$config->getLoginSandbox():"";
$password = $config->getPasswordSandbox() != null? $config->getPasswordSandbox():"";
$signature = $config->getSignatureSandbox() != null? $config->getSignatureSandbox():"";
$username = Paypal::getConfigValue('sandbox_login', '');
$password = Paypal::getConfigValue('sandbox_password', '');
$signature = Paypal::getConfigValue('sandbox_signature', '');
} else {
$username = $config->getLogin() != null?$config->getLogin():"";
$password = $config->getPassword() != null?$config->getPassword():"";
$signature = $config->getSignature() != null?$config->getSignature():"";
$username = Paypal::getConfigValue('login', '');
$password = Paypal::getConfigValue('password', '');
$signature = Paypal::getConfigValue('signature', '');
}

if (empty($username)) {
Expand Down Expand Up @@ -133,5 +127,4 @@ public function getApiUsername()
{
return $this->apiUsername;
}

}
123 changes: 57 additions & 66 deletions Classes/API/PaypalApiLogManager.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: Quentin Dufour
* Date: 08/08/13
* Time: 11:22
*/
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/

namespace Paypal\Classes\API;

use Thelia\Log\Tlog;

/**
Expand All @@ -16,86 +32,61 @@
*/
class PaypalApiLogManager
{
const EMERGENCY = 'EMERGENCY';
const ALERT = 'ALERT';
const CRITICAL = 'CRITICAL';
const ERROR = 'ERROR';
const WARNING = 'WARNING';
const NOTICE = 'NOTICE';
const INFO = 'INFO';
const DEBUG = 'DEBUG';

const LOGCLASS = "\\Thelia\\Log\\Destination\\TlogDestinationFile";

/** @var Tlog $log */
protected $log;
protected static $logger;

/**
* Parse and log the return of the Paypal NVP API
*
* @param string $transaction A special string returned by the NVP API
*/
public function logTransaction($transaction)
public function logTransaction($parsedTransaction)
{
$this->setTLogPaypal();
/*
* Then write
*/
$logLine = '';
$parsedTransaction = PaypalApiManager::nvpToArray($transaction);
$date = new \DateTime($parsedTransaction['TIMESTAMP']);
if ($parsedTransaction) {
/*
* Then write
*/
$logLine = '';
$date = new \DateTime($parsedTransaction['TIMESTAMP']);

$logLine .= $date->format('Y-m-d H:i:s') . ' ';
$logLine .= 'Transaction ' . $parsedTransaction['ACK'] . ' ';
$logLine .= 'correlationId: ' . $parsedTransaction['CORRELATIONID'] . ' ';
$logLine .= $date->format('Y-m-d H:i:s') . ' ';
$logLine .= 'Transaction ' . $parsedTransaction['ACK'] . ' ';
$logLine .= 'correlationId: ' . $parsedTransaction['CORRELATIONID'] . ' ';

if ($parsedTransaction !== null && array_key_exists('L_ERRORCODE0', $parsedTransaction)) {
$logLine .= 'error: ';
$logLine .= '[' . $parsedTransaction['L_ERRORCODE0'] . '] ';
$logLine .= '<' . $parsedTransaction['L_SHORTMESSAGE0'] . '> ';
$logLine .= $parsedTransaction['L_LONGMESSAGE0'] . ' ';
}
if ($parsedTransaction !== null && array_key_exists('L_ERRORCODE0', $parsedTransaction)) {
$logLine .= 'error: ';
$logLine .= '[' . $parsedTransaction['L_ERRORCODE0'] . '] ';
$logLine .= '<' . $parsedTransaction['L_SHORTMESSAGE0'] . '> ';
$logLine .= $parsedTransaction['L_LONGMESSAGE0'] . ' ';
}

$this->log->info($logLine);
$this->getBackToPreviousState();
$this->getLogger()->info($logLine);
} else {
$this->getLogger()->info('No transaction was created.');
}
}

/**
* Log a message
*
* @param string $message Message
* @param string $severity EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG
* @param string $category Category
*/

public function logText($message, $severity = 'INFO', $category = 'paypal')
public static function getLogFilePath()
{
$this->setTLogPaypal();

$now = date('Y-m-d h:i:s');
$msg = "[$now] $category.$severity: $message.";
$this->log->info($msg);

// Back to previous state
$this->getBackToPreviousState();
return THELIA_LOG_DIR . DS . "log-paypal.txt";
}

/**
* @return Tlog
*/
protected function setTLogPaypal()
public function getLogger()
{
/*
* Write Log
*/
$this->log = Tlog::getInstance();
$this->log->setDestinations(self::LOGCLASS);
$this->log->setConfig(self::LOGCLASS, 0, THELIA_ROOT . "log" . DS . "log-paypal.txt");
}
if (self::$logger == null) {
self::$logger = Tlog::getNewInstance();

protected function getBackToPreviousState()
{
$this->log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
}
$logFilePath = self::getLogFilePath();

self::$logger->setPrefix("#LEVEL: #DATE #HOUR: ");
self::$logger->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
self::$logger->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile", 0, $logFilePath);
self::$logger->setLevel(Tlog::INFO);
}

return self::$logger;
}
}
Loading

0 comments on commit 113b131

Please sign in to comment.