Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35 from pmclain/hotfix/logging
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
pmclain authored Mar 31, 2018
2 parents c78a839 + fb5f1cf commit 9122028
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 19 deletions.
8 changes: 8 additions & 0 deletions Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
const KEY_USE_CCV = 'useccv';
const KEY_ALLOW_SPECIFIC = 'allowspecific';
const KEY_SPECIFIC_COUNTRY = 'specificcountry';
const KEY_DEBUG = 'debug';

/**
* @return array
Expand Down Expand Up @@ -105,4 +106,11 @@ public function getSecretKey() {
public function isTestMode() {
return (bool) $this->getValue(self::KEY_ENVIRONMENT);
}

/**
* @return bool
*/
public function isDebugOn() {
return (bool) $this->getValue(self::KEY_DEBUG);
}
}
23 changes: 20 additions & 3 deletions Gateway/Http/Client/AbstractTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Magento\Payment\Gateway\Http\TransferInterface;
use Magento\Payment\Model\Method\Logger;
use Psr\Log\LoggerInterface;
use Pmclain\Stripe\Gateway\Config\Config;
use Magento\Framework\App\ObjectManager;

abstract class AbstractTransaction implements ClientInterface
{
Expand All @@ -30,14 +32,18 @@ abstract class AbstractTransaction implements ClientInterface

protected $adapter;

protected $config;

public function __construct(
LoggerInterface $logger,
Logger $customLogger,
StripeAdapter $adapter
StripeAdapter $adapter,
Config $config = null
) {
$this->logger = $logger;
$this->customLogger = $customLogger;
$this->adapter = $adapter;
$this->config = $config ?: ObjectManager::getInstance()->get(Config::class);
}

public function placeRequest(
Expand All @@ -54,10 +60,21 @@ public function placeRequest(
$response['object'] = $this->process($data);
}catch (\Exception $e) {
$message = __($e->getMessage() ?: 'Sorry, but something went wrong.');
$this->logger->critical($message);
$this->logger->critical($e);
throw new ClientException($message);
}finally {
$log['response'] = (array) $response['object'];
if ($response['object'] instanceof \Stripe\Error\Base
|| $response['object'] instanceof \Stripe\StripeObject
) {
$log['response'] = $response['object']->__toString();
} else {
$log['response'] = $response['object'];
}

if ($this->config->isDebugOn()) {
$this->logger->warning(var_export($log, true));
}

$this->customLogger->debug($log);
}

Expand Down
10 changes: 9 additions & 1 deletion Gateway/Request/PaymentDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Magento\Customer\Model\Session;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Stripe\Customer;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\ObjectManager;

class PaymentDataBuilder implements BuilderInterface
{
Expand All @@ -47,24 +49,29 @@ class PaymentDataBuilder implements BuilderInterface
/** @var CustomerRepositoryInterface */
protected $customerRepository;

/** @var LoggerInterface */
protected $logger;

/**
* PaymentDataBuilder constructor.
* @param Config $config
* @param SubjectReader $subjectReader
* @param Session $customerSession
* @param CustomerRepositoryInterface $customerRepository
* @param LoggerInterface $logger
*/
public function __construct(
Config $config,
SubjectReader $subjectReader,
Session $customerSession,
CustomerRepositoryInterface $customerRepository
CustomerRepositoryInterface $customerRepository,
LoggerInterface $logger = null
) {
$this->config = $config;
$this->subjectReader = $subjectReader;
$this->customerSession = $customerSession;
$this->customerRepository = $customerRepository;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
}

/**
Expand Down Expand Up @@ -126,6 +133,7 @@ protected function createNewStripeCustomer($email) {
'description' => 'Customer for ' . $email,
]);
}catch (\Exception $e) {
$this->logger->critical($e);
throw new \Magento\Framework\Validator\Exception(__($e->getMessage()));
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In your Magento 2 root directory run
| ------- | --------------- |
| 1.x.x | 2.2.x |
| 1.x.x   | 2.1.x           |
| 0.0.3 | 2.0.x |
| None | 2.0.x |

## Configuration
The configuration can be found in the Magento 2 admin panel under
Expand Down
6 changes: 1 addition & 5 deletions Test/Unit/Gateway/Http/Client/TransactionSaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function testPlaceRequestSuccess() {

$actualResult = $this->model->placeRequest($this->getTransferObjectMock());

$this->assertTrue(is_object($actualResult['object']));
$this->assertEquals(['object' => $response], $actualResult);
}

Expand All @@ -110,9 +109,6 @@ private function getTransferObjectMock() {
}

private function getResponseObject() {
$object = new \stdClass();
$object->success = true;

return $object;
return ['success' => true];
}
}
4 changes: 4 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<label>Credit Card Verification</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="debug" translate="label" type="select" sortOrder="115" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Debug</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Applicable Countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<useccv>1</useccv>
<cctypes_stripe_mapper><![CDATA[{"american-express":"AE","discover":"DI","jcb":"JCB","mastercard":"MC","master-card":"MC","visa":"VI","maestro":"MI","diners-club":"DN","unionpay":"CUP"}]]></cctypes_stripe_mapper>
<order_status>processing</order_status>
<debug>0</debug>
</pmclain_stripe>
<pmclain_stripe_vault>
<model>StripeCreditCardVaultFacade</model>
Expand Down
15 changes: 14 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,18 @@
</arguments>
</type>

<!-- Settlement Reqports?? -->
<type name="Magento\Config\Model\Config\TypePool">
<arguments>
<argument name="sensitive" xsi:type="array">
<item name="payment/pmclain_stripe/test_secret_key" xsi:type="string">1</item>
<item name="payment/pmclain_stripe/test_publishable_key" xsi:type="string">1</item>
<item name="payment/pmclain_stripe/live_secret_key" xsi:type="string">1</item>
<item name="payment/pmclain_stripe/live_publishable_key" xsi:type="string">1</item>
</argument>
<argument name="environment" xsi:type="array">
<item name="payment/pmclain_stripe/debug" xsi:type="string">1</item>
<item name="payment/pmclain_stripe/test_mode" xsi:type="string">1</item>
</argument>
</arguments>
</type>
</config>
7 changes: 0 additions & 7 deletions view/frontend/requirejs-config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(
'Magento_Checkout/js/action/redirect-on-success',
'Magento_Vault/js/view/payment/vault-enabler',
'Magento_Checkout/js/model/quote',
'stripejs'
'https://js.stripe.com/v3/'
],
function (
$,
Expand Down

0 comments on commit 9122028

Please sign in to comment.