Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344272 )

Change subject: Hack to get availability straight from iDEAL
......................................................................

Hack to get availability straight from iDEAL

If noone vetoes this, maybe put it in a different class.

Bug: T161153
Change-Id: I0d24f86a0ca2bd89337e5d3acec723db05cb69f0
---
M PaymentProviders/Ingenico/BankPaymentProvider.php
A PaymentProviders/Ingenico/Tests/Data/availability.response
M PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
M SmashPig.yaml
4 files changed, 57 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/72/344272/1

diff --git a/PaymentProviders/Ingenico/BankPaymentProvider.php 
b/PaymentProviders/Ingenico/BankPaymentProvider.php
index 87c034d..4844bbc 100644
--- a/PaymentProviders/Ingenico/BankPaymentProvider.php
+++ b/PaymentProviders/Ingenico/BankPaymentProvider.php
@@ -4,6 +4,7 @@
 
 use SmashPig\Core\Context;
 use Psr\Cache\CacheItemPoolInterface;
+use SmashPig\Core\Http\OutboundRequest;
 
 /**
  * Handle bank payments via Ingenico
@@ -23,9 +24,15 @@
         */
        protected $cache;
 
+       /**
+        * @var array()
+        */
+       protected $availabilityParameters;
+
        public function __construct( array $options = array() ) {
                parent::__construct( $options );
                $this->cacheParameters = $options['cache-parameters'];
+               $this->availabilityParameters = 
$options['availability-parameters'];
                // FIXME: provide objects in constructor
                $config = Context::get()->getConfiguration();
                $this->cache = $config->object( 'cache' );
@@ -45,7 +52,7 @@
                $cacheItem = $this->cache->getItem( $cacheKey );
 
                if ( !$cacheItem->isHit() || $this->shouldBeExpired( $cacheItem 
) ) {
-                       $query = array(
+                       /*$query = array(
                                'countryCode' => $country,
                                'currencyCode' => $currency
                        );
@@ -56,7 +63,28 @@
 
                        foreach ( $response['entries'] as $entry ) {
                                $banks[$entry['issuerId']] = 
$entry['issuerName'];
+                       }*/
+
+                       $banks = array();
+
+                       // HAAACK!
+                       // Use undocumented API to get availability straight 
from iDEAL,
+                       // until Ingenico can incorporate this into their 
directory
+                       if ( $country === 'NL' && $currency === 'EUR' ) {
+                               $url = $this->availabilityParameters['url'];
+                               $threshold = 
$this->availabilityParameters['threshold'];
+
+                               $request = new OutboundRequest( $url );
+                               $rawResponse = $request->execute();
+                               $response = json_decode( $rawResponse['body'], 
true );
+
+                               foreach ( $response['Issuers'] as $issuer ) {
+                                       if ( $issuer['Percent'] >= $threshold ) 
{
+                                               $banks[$issuer['BankId']] = 
$issuer['BankName'];
+                                       }
+                               }
                        }
+
                        $duration = $this->cacheParameters['duration'];
                        $cacheItem->set( array(
                                'value' => $banks,
diff --git a/PaymentProviders/Ingenico/Tests/Data/availability.response 
b/PaymentProviders/Ingenico/Tests/Data/availability.response
new file mode 100644
index 0000000..74f0def
--- /dev/null
+++ b/PaymentProviders/Ingenico/Tests/Data/availability.response
@@ -0,0 +1,14 @@
+HTTP/1.1 200 OK
+Cache-Control: no-cache
+Pragma: no-cache
+Content-Length: 656
+Content-Type: application/json; charset=utf-8
+Content-Encoding: gzip
+Expires: -1
+Vary: Accept-Encoding
+Server: Microsoft-IIS/8.0
+X-AspNet-Version: 4.0.30319
+X-Powered-By: ASP.NET
+Date: Wed, 22 Mar 2017 22:42:05 GMT
+
+{"Issuers":[{"BankId":"ABNANL2A","BankName":"ABN 
AMRO","LogoPath":"/Content/icons/banks/abn.png","Status":"Green","Percent":"40","Details":"","MoreDetails":"","LogoStatus":"/Content/icons/green.png","URL":"/History?bank=ABN_AMRO"},{"BankId":"INGBNL2A","BankName":"Issuer
 Simulation V3 - 
ING","LogoPath":"/Content/icons/banks/sim.png","Status":"Green","Percent":"100","Details":"","MoreDetails":"","LogoStatus":"/Content/icons/green.png","URL":"/History?bank=Simulated_Bank"}],"Message":"","IssuerMessageCalculationFailed":false,"LastUpdate":"22-3-2017,
 23:40","AllGreen":true}
diff --git 
a/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php 
b/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
index d9a2e3e..18ef9e7 100644
--- a/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
+++ b/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php
@@ -38,13 +38,18 @@
                        'cache-parameters' => array(
                                'duration' => 10,
                                'key-base' => 'BLAH_BLAH'
+                       ),
+                       'availability-parameters' => array(
+                               'url' => 
'http://example.org/undocumented/api/GetIssuers',
+                               'threshold' => 60
                        )
                ) );
                parent::setUp();
        }
 
        public function testGetBankList() {
-               $this->setUpResponse( 'productDirectory', 200 );
+               //$this->setUpResponse( 'productDirectory', 200 );
+               $this->setUpResponse( 'availability', 200 );
                $results = $this->provider->getBankList( 'NL', 'EUR' );
                $this->assertEquals(
                        array(
@@ -55,7 +60,8 @@
        }
 
        public function testCacheBankList() {
-               $this->setUpResponse( 'productDirectory', 200 );
+               //$this->setUpResponse( 'productDirectory', 200 );
+               $this->setUpResponse( 'availability', 200 );
                $this->curlWrapper->expects( $this->once() )
                        ->method( 'execute' );
                $results = $this->provider->getBankList( 'NL', 'EUR' );
@@ -79,7 +85,8 @@
                        true
                );
                $this->cache->save( $cacheItem );
-               $this->setUpResponse( 'productDirectory', 200 );
+               //$this->setUpResponse( 'productDirectory', 200 );
+               $this->setUpResponse( 'availability', 200 );
                $this->curlWrapper->expects( $this->once() )
                        ->method( 'execute' );
                $results = $this->provider->getBankList( 'NL', 'EUR' );
diff --git a/SmashPig.yaml b/SmashPig.yaml
index 2ce8de1..28e7333 100644
--- a/SmashPig.yaml
+++ b/SmashPig.yaml
@@ -467,6 +467,10 @@
                     cache-parameters:
                         duration: 300
                         key-base: SMASHPIG_INGENICO_IDEAL_BANK_LIST
+                    availability-parameters:
+                        url: http://availability.ideal.nl/api/api/GetIssuers
+                        # percentage availability below which issuers are 
omitted
+                        threshold: 50
 
 # deprecated, delete when projects using SmashPig rename adaptors
 globalcollect:

-- 
To view, visit https://gerrit.wikimedia.org/r/344272
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d24f86a0ca2bd89337e5d3acec723db05cb69f0
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to