[MediaWiki-commits] [Gerrit] mediawiki...DonationInterface[master]: Properly serialize Amazon error messages

2017-12-22 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399659 )

Change subject: Properly serialize Amazon error messages
..


Properly serialize Amazon error messages

Need to break 'em down into simple hashes to feed to javascript

Bug: T183477
Change-Id: Ie8c92e14431a7fd1113112d396928dbc2f5652b2
---
M amazon_gateway/amazon.api.php
M gateway_common/donation.api.php
M tests/phpunit/Adapter/Amazon/AmazonApiTest.php
3 files changed, 42 insertions(+), 5 deletions(-)

Approvals:
  Mepps: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/amazon_gateway/amazon.api.php b/amazon_gateway/amazon.api.php
index ca0b80e..1b5b8b9 100644
--- a/amazon_gateway/amazon.api.php
+++ b/amazon_gateway/amazon.api.php
@@ -32,7 +32,10 @@
$output->addValue(
null,
'errors',
-   $adapter->getErrorState()->getErrors()
+   DonationApi::serializeErrors(
+   $adapter->getErrorState()->getErrors(),
+   $adapter
+   )
);
} elseif ( $token && $adapter->checkTokens() ) {
if ( $recurring ) {
@@ -55,7 +58,10 @@
$output->addValue(
null,
'errors',
-   $result->getErrors()
+   DonationApi::serializeErrors(
+   $result->getErrors(),
+   $adapter
+   )
);
} else {
$output->addValue(
diff --git a/gateway_common/donation.api.php b/gateway_common/donation.api.php
index 71e8545..7b98148 100644
--- a/gateway_common/donation.api.php
+++ b/gateway_common/donation.api.php
@@ -30,7 +30,7 @@
$validated_ok = $gatewayObj->validatedOK();
if ( !$validated_ok ) {
$errors = $gatewayObj->getErrorState()->getErrors();
-   $outputResult['errors'] = $this->serializeErrors( 
$errors, $gatewayObj );
+   $outputResult['errors'] = self::serializeErrors( 
$errors, $gatewayObj );
// FIXME: What is this junk?  Smaller API, like 
getResult()->addErrors
$this->getResult()->setIndexedTagName( 
$outputResult['errors'], 'error' );
$this->getResult()->addValue( null, 'result', 
$outputResult );
@@ -94,7 +94,7 @@
}
}
if ( !empty( $errors ) ) {
-   $outputResult['errors'] = $this->serializeErrors( 
$errors, $gatewayObj );
+   $outputResult['errors'] = self::serializeErrors( 
$errors, $gatewayObj );
$this->getResult()->setIndexedTagName( 
$outputResult['errors'], 'error' );
}
 
@@ -104,7 +104,7 @@
$this->getResult()->addValue( null, 'result', $outputResult );
}
 
-   protected function serializeErrors( $errors, GatewayAdapter $adapter ) {
+   public static function serializeErrors( $errors, GatewayAdapter 
$adapter ) {
$serializedErrors = array();
foreach ( $errors as $error ) {
if ( $error instanceof ValidationError ) {
diff --git a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
index acff8af..80f8f01 100644
--- a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
+++ b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
@@ -54,4 +54,35 @@
$this->assertNotNull( $message, 'Not sending a message to the 
donations queue' );
$this->assertEquals( 'S01-0391295-0674065-C095112', 
$message['gateway_txn_id'], 'Queue message has wrong txn ID' );
}
+
+   /**
+* InvalidPaymentMethod error should show an error message in the
+* 'general' section.
+*/
+   public function testDoPaymentErrors() {
+   $params = array(
+   'amount' => '1.55',
+   'currency' => 'USD',
+   'recurring' => '0',
+   'wmf_token' => 'e601502632e5e51dc2a17a0045162272+\\',
+   'orderReferenceId' => mt_rand( 0, 1000 ),
+   'action' => 'di_amazon_bill',
+   );
+   $session = array(
+   'Donor' => array(
+   'amount' => '1.55',
+   'currency' => 'USD',
+   

[MediaWiki-commits] [Gerrit] mediawiki...DonationInterface[master]: Properly serialize Amazon error messages

2017-12-21 Thread Ejegg (Code Review)
Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399659 )

Change subject: Properly serialize Amazon error messages
..

Properly serialize Amazon error messages

Need to break 'em down into simple hashes to feed to javascript

Bug: T183477
Change-Id: Ie8c92e14431a7fd1113112d396928dbc2f5652b2
---
M amazon_gateway/amazon.api.php
M gateway_common/donation.api.php
M tests/phpunit/Adapter/Amazon/AmazonApiTest.php
3 files changed, 42 insertions(+), 5 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/59/399659/1

diff --git a/amazon_gateway/amazon.api.php b/amazon_gateway/amazon.api.php
index ca0b80e..1b5b8b9 100644
--- a/amazon_gateway/amazon.api.php
+++ b/amazon_gateway/amazon.api.php
@@ -32,7 +32,10 @@
$output->addValue(
null,
'errors',
-   $adapter->getErrorState()->getErrors()
+   DonationApi::serializeErrors(
+   $adapter->getErrorState()->getErrors(),
+   $adapter
+   )
);
} elseif ( $token && $adapter->checkTokens() ) {
if ( $recurring ) {
@@ -55,7 +58,10 @@
$output->addValue(
null,
'errors',
-   $result->getErrors()
+   DonationApi::serializeErrors(
+   $result->getErrors(),
+   $adapter
+   )
);
} else {
$output->addValue(
diff --git a/gateway_common/donation.api.php b/gateway_common/donation.api.php
index 71e8545..7b98148 100644
--- a/gateway_common/donation.api.php
+++ b/gateway_common/donation.api.php
@@ -30,7 +30,7 @@
$validated_ok = $gatewayObj->validatedOK();
if ( !$validated_ok ) {
$errors = $gatewayObj->getErrorState()->getErrors();
-   $outputResult['errors'] = $this->serializeErrors( 
$errors, $gatewayObj );
+   $outputResult['errors'] = self::serializeErrors( 
$errors, $gatewayObj );
// FIXME: What is this junk?  Smaller API, like 
getResult()->addErrors
$this->getResult()->setIndexedTagName( 
$outputResult['errors'], 'error' );
$this->getResult()->addValue( null, 'result', 
$outputResult );
@@ -94,7 +94,7 @@
}
}
if ( !empty( $errors ) ) {
-   $outputResult['errors'] = $this->serializeErrors( 
$errors, $gatewayObj );
+   $outputResult['errors'] = self::serializeErrors( 
$errors, $gatewayObj );
$this->getResult()->setIndexedTagName( 
$outputResult['errors'], 'error' );
}
 
@@ -104,7 +104,7 @@
$this->getResult()->addValue( null, 'result', $outputResult );
}
 
-   protected function serializeErrors( $errors, GatewayAdapter $adapter ) {
+   public static function serializeErrors( $errors, GatewayAdapter 
$adapter ) {
$serializedErrors = array();
foreach ( $errors as $error ) {
if ( $error instanceof ValidationError ) {
diff --git a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
index acff8af..80f8f01 100644
--- a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
+++ b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
@@ -54,4 +54,35 @@
$this->assertNotNull( $message, 'Not sending a message to the 
donations queue' );
$this->assertEquals( 'S01-0391295-0674065-C095112', 
$message['gateway_txn_id'], 'Queue message has wrong txn ID' );
}
+
+   /**
+* InvalidPaymentMethod error should show an error message in the
+* 'general' section.
+*/
+   public function testDoPaymentErrors() {
+   $params = array(
+   'amount' => '1.55',
+   'currency' => 'USD',
+   'recurring' => '0',
+   'wmf_token' => 'e601502632e5e51dc2a17a0045162272+\\',
+   'orderReferenceId' => mt_rand( 0, 1000 ),
+   'action' => 'di_amazon_bill',
+   );
+   $session = array(
+   'Donor' => array(
+   'amount' => '1.55',
+   'currency' => 'USD',
+