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, 10000000 ),
+ 'action' => 'di_amazon_bill',
+ );
+ $session = array(
+ 'Donor' => array(
+ 'amount' => '1.55',
+ 'currency' => 'USD',
+ 'recurring' => '0',
+ 'contribution_tracking_id' => mt_rand( 0,
10000000 ),
+ 'country' => 'US',
+ ),
+ 'amazonEditToken' => 'kjaskdjahsdkjsad',
+ );
+ $mockClient = $this->providerConfig->object( 'payments-client'
);
+ $mockClient->returns['authorize'][] = 'InvalidPaymentMethod';
+
+ $apiResult = $this->doApiRequest( $params, $session );
+ $errors = $apiResult[0]['errors'];
+ $this->assertNotEmpty( $errors['general'] );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/399659
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie8c92e14431a7fd1113112d396928dbc2f5652b2
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits