Ejegg has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/338306 )
Change subject: Reduce Configuration use in BankPaymentProvider
......................................................................
Reduce Configuration use in BankPaymentProvider
Provide cache params as constructor arguments
Bug: T158374
Change-Id: Ib0f5d0c1e67517c7331a2fb1bccc8dac612d603e
---
M PaymentProviders/Ingenico/BankPaymentProvider.php
M PaymentProviders/Ingenico/IngenicoPaymentProvider.php
M PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
M SmashPig.yaml
4 files changed, 46 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig
refs/changes/06/338306/1
diff --git a/PaymentProviders/Ingenico/BankPaymentProvider.php
b/PaymentProviders/Ingenico/BankPaymentProvider.php
index 8803ae9..9bd376b 100644
--- a/PaymentProviders/Ingenico/BankPaymentProvider.php
+++ b/PaymentProviders/Ingenico/BankPaymentProvider.php
@@ -2,6 +2,9 @@
namespace SmashPig\PaymentProviders\Ingenico;
+use SmashPig\Core\Context;
+use Psr\Cache\CacheItemPoolInterface;
+
/**
* Handle bank payments via Ingenico
* Will eventually implement PaymentProvider, but right now just looks
@@ -9,6 +12,24 @@
* config key 'cache'.
*/
class BankPaymentProvider extends IngenicoPaymentProvider {
+
+ /**
+ * @var array()
+ */
+ protected $cacheParameters;
+
+ /**
+ * @var CacheItemPoolInterface
+ */
+ protected $cache;
+
+ public function __construct( array $options = array() ) {
+ parent::__construct( $options );
+ $this->cacheParameters = $options['cache-parameters'];
+ // FIXME: provide objects in constructor
+ $config = Context::get()->getConfiguration();
+ $this->cache = $config->object( 'cache' );
+ }
/**
* Look up banks
@@ -21,8 +42,7 @@
*/
public function getBankList( $country, $currency, $productId = 809 ) {
$cacheKey = $this->makeCacheKey( $country, $currency,
$productId );
- $cache = $this->config->object( 'cache' );
- $cacheItem = $cache->getItem( $cacheKey );
+ $cacheItem = $this->cache->getItem( $cacheKey );
if ( !$cacheItem->isHit() ) {
$query = array(
@@ -32,7 +52,7 @@
$path = "products/$productId/directory";
$response = $this->makeApiCall( $path, 'GET', $query );
- // TODO: base class should probably decode
+ // TODO: api class should probably decode
$decoded = json_decode( $response['body'] );
$banks = array();
@@ -41,15 +61,15 @@
$banks[$entry->issuerId] = $entry->issuerName;
}
$cacheItem->set( $banks );
- $duration = $this->config->val( 'bank-cache/duration' );
+ $duration = $this->cacheParameters['duration'];
$cacheItem->expiresAfter( $duration );
- $cache->save( $cacheItem );
+ $this->cache->save( $cacheItem );
}
return $cacheItem->get();
}
protected function makeCacheKey( $country, $currency, $productId ) {
- $base = $this->config->val( 'bank-cache/key' );
+ $base = $this->cacheParameters['key-base'];
return "{$base}_{$country}_{$currency}_{$productId}";
}
}
diff --git a/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
b/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
index 3ad939a..85e2c9a 100644
--- a/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
+++ b/PaymentProviders/Ingenico/IngenicoPaymentProvider.php
@@ -21,7 +21,7 @@
*/
protected $config;
- public function __construct() {
+ public function __construct( $options = array() ) {
$this->config = Context::get()->getConfiguration();
}
diff --git
a/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
b/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
index bf3d702..1edfe84 100644
--- a/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
+++ b/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
@@ -16,18 +16,28 @@
*/
protected $curlWrapper;
+ /**
+ * @var BankPaymentProvider
+ */
+ protected $provider;
+
public function setUp() {
$config = $this->setConfig( 'ingenico' );
$this->curlWrapper = $this->getMock(
'\SmashPig\Core\Http\CurlWrapper' );
$config->overrideObjectInstance( 'curl/wrapper',
$this->curlWrapper );
$config->object( 'cache' )->clear();
+ $this->provider = new BankPaymentProvider( array(
+ 'cache-parameters' => array(
+ 'duration' => 10,
+ 'key-base' => 'BLAH_BLAH'
+ )
+ ) );
parent::setUp();
}
public function testGetBankList() {
$this->setUpResponse( 'productDirectory', 200 );
- $provider = new BankPaymentProvider();
- $results = $provider->getBankList( 'NL', 'EUR' );
+ $results = $this->provider->getBankList( 'NL', 'EUR' );
$this->assertEquals(
array(
'INGBNL2A' => 'Issuer Simulation V3 - ING'
@@ -40,15 +50,14 @@
$this->setUpResponse( 'productDirectory', 200 );
$this->curlWrapper->expects( $this->once() )
->method( 'execute' );
- $provider = new BankPaymentProvider();
- $results = $provider->getBankList( 'NL', 'EUR' );
+ $results = $this->provider->getBankList( 'NL', 'EUR' );
$this->assertEquals(
array(
'INGBNL2A' => 'Issuer Simulation V3 - ING'
),
$results
);
- $cachedResults = $provider->getBankList( 'NL', 'EUR' );
+ $cachedResults = $this->provider->getBankList( 'NL', 'EUR' );
$this->assertEquals( $results, $cachedResults );
}
diff --git a/SmashPig.yaml b/SmashPig.yaml
index 70655f0..40e98e1 100644
--- a/SmashPig.yaml
+++ b/SmashPig.yaml
@@ -455,13 +455,14 @@
class: SmashPig\PaymentProviders\Ingenico\Authenticator
constructor-parameters: []
- bank-cache:
- key: SMASHPIG_INGENICO_IDEAL_BANK_LIST
- duration: 300
-
payment-provider:
rtbt:
class: SmashPig\PaymentProviders\Ingenico\BankPaymentProvider
+ constructor-parameters:
+ -
+ cache-parameters:
+ duration: 300
+ key-base: SMASHPIG_INGENICO_IDEAL_BANK_LIST
# deprecated, delete when projects using SmashPig rename adaptors
globalcollect:
--
To view, visit https://gerrit.wikimedia.org/r/338306
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib0f5d0c1e67517c7331a2fb1bccc8dac612d603e
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits