Ejegg has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/345790 )
Change subject: WIP cache directory lookup 404s
......................................................................
WIP cache directory lookup 404s
These are legitimate responses in REST-ese. Don't failmail when
someone tries to pay with iDEAL in an unsupported currency.
We should still route them elsewhere in the frontend, tho!
TODO: test with 404
Bug: T161072
Change-Id: I28a1bc71ffc7a8982b686028ab53a558032de3c7
---
M Core/Http/HttpStatusValidator.php
M PaymentProviders/Ingenico/Api.php
M PaymentProviders/Ingenico/ApiException.php
M PaymentProviders/Ingenico/BankPaymentProvider.php
A PaymentProviders/Ingenico/RestResponseValidator.php
M SmashPig.yaml
6 files changed, 51 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig
refs/changes/90/345790/1
diff --git a/Core/Http/HttpStatusValidator.php
b/Core/Http/HttpStatusValidator.php
index a36230b..68c6859 100644
--- a/Core/Http/HttpStatusValidator.php
+++ b/Core/Http/HttpStatusValidator.php
@@ -12,16 +12,13 @@
public function shouldRetry( $parsedResponse ) {
$statusCode = $parsedResponse['status'];
+ if ( array_search( $statusCode, $this->getSuccessCodes() ) !==
false ) {
+ Logger::debug( "Successful request" );
+ return false;
+ }
$body = $parsedResponse['body'];
switch ( $statusCode ) {
- case 200: // Everything is AWESOME
- case 201: // Also fine, and we created a thing
- $continue = false;
-
- Logger::debug( "Successful request" );
- break;
-
case 400: // Oh noes! Bad request.. BAD CODE, BAD BAD
CODE!
$continue = false;
Logger::error( "Request returned (400) BAD
REQUEST: $body" );
@@ -39,4 +36,11 @@
}
return $continue;
}
+
+ protected function getSuccessCodes() {
+ return array(
+ 200, // Everything is AWESOME
+ 201 // Also fine, and we created a thing
+ );
+ }
}
diff --git a/PaymentProviders/Ingenico/Api.php
b/PaymentProviders/Ingenico/Api.php
index 5da77bb..3a7f0cc 100644
--- a/PaymentProviders/Ingenico/Api.php
+++ b/PaymentProviders/Ingenico/Api.php
@@ -84,7 +84,9 @@
$messages[] = "Error code {$error['code']}:
{$error['message']}.";
}
$concatenated = implode( ' ', $messages );
- throw new ApiException( $concatenated );
+ $ex = new ApiException( $concatenated );
+ $ex->setRawErrors( $decoded['errors'] );
+ throw $ex;
}
}
}
diff --git a/PaymentProviders/Ingenico/ApiException.php
b/PaymentProviders/Ingenico/ApiException.php
index 44af1fc..3f3ed73 100644
--- a/PaymentProviders/Ingenico/ApiException.php
+++ b/PaymentProviders/Ingenico/ApiException.php
@@ -6,4 +6,13 @@
class ApiException extends SmashPigException {
+ protected $rawErrors;
+
+ public function setRawErrors( $errors ) {
+ $this->rawErrors = $errors;
+ }
+
+ public function getRawErrors() {
+ return $this->rawErrors;
+ }
}
diff --git a/PaymentProviders/Ingenico/BankPaymentProvider.php
b/PaymentProviders/Ingenico/BankPaymentProvider.php
index 87c034d..5a479ce 100644
--- a/PaymentProviders/Ingenico/BankPaymentProvider.php
+++ b/PaymentProviders/Ingenico/BankPaymentProvider.php
@@ -50,12 +50,21 @@
'currencyCode' => $currency
);
$path = "products/$productId/directory";
- $response = $this->api->makeApiCall( $path, 'GET',
$query );
-
$banks = array();
- foreach ( $response['entries'] as $entry ) {
- $banks[$entry['issuerId']] =
$entry['issuerName'];
+ try {
+ $response = $this->api->makeApiCall( $path,
'GET', $query );
+
+ foreach ( $response['entries'] as $entry ) {
+ $banks[$entry['issuerId']] =
$entry['issuerName'];
+ }
+ } catch ( ApiException $ex ) {
+ $errors = $ex->getRawErrors();
+ if ( empty( $errors ) ||
$errors[0]['httpStatusCode'] !== 404 ) {
+ throw $ex;
+ }
+ // If there is a single 404 error, that means
there is no directory info for
+ // the country/currency/product. That's
legitimate, so cache the empty array
}
$duration = $this->cacheParameters['duration'];
$cacheItem->set( array(
diff --git a/PaymentProviders/Ingenico/RestResponseValidator.php
b/PaymentProviders/Ingenico/RestResponseValidator.php
new file mode 100644
index 0000000..0a74d33
--- /dev/null
+++ b/PaymentProviders/Ingenico/RestResponseValidator.php
@@ -0,0 +1,12 @@
+<?php
+namespace SmashPig\PaymentProviders\Ingenico;
+
+use SmashPig\Core\Http\HttpStatusValidator;
+
+class RestResponseValidator extends HttpStatusValidator {
+ protected function getSuccessCodes() {
+ $codes = parent::getSuccessCodes();
+ $codes[] = '404'; // also a valid response in REST-ese
+ return $codes;
+ }
+}
diff --git a/SmashPig.yaml b/SmashPig.yaml
index 19e2f1b..ac7159b 100644
--- a/SmashPig.yaml
+++ b/SmashPig.yaml
@@ -477,6 +477,9 @@
key: SMASHPIG_IDEAL_BANK_STATUS
availability-url:
https://availability.ideal.nl/api/api/GetIssuers
+ curl:
+ validator:
+ class: SmashPig\PaymentProviders\Ingenico\RestResponseValidator
# deprecated, delete when projects using SmashPig rename adaptors
globalcollect:
--
To view, visit https://gerrit.wikimedia.org/r/345790
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I28a1bc71ffc7a8982b686028ab53a558032de3c7
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