Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277554
Change subject: WIP mock Adyen API for tests
......................................................................
WIP mock Adyen API for tests
Change-Id: I4aae0d4fce2275920597867bf2e56d569ce6738d
TODO: write a test that uses it
---
M PaymentProviders/Adyen/AdyenPaymentsAPI.php
M PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
A PaymentProviders/Adyen/Tests/MockAdyenPaymentsAPI.php
M config_defaults.php
4 files changed, 52 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig
refs/changes/54/277554/1
diff --git a/PaymentProviders/Adyen/AdyenPaymentsAPI.php
b/PaymentProviders/Adyen/AdyenPaymentsAPI.php
index a61b43d..28c148e 100644
--- a/PaymentProviders/Adyen/AdyenPaymentsAPI.php
+++ b/PaymentProviders/Adyen/AdyenPaymentsAPI.php
@@ -10,7 +10,7 @@
protected $soapClient = null;
protected $account = '';
- public function __construct( $account ) {
+ public function setAccount( $account ) {
require_once( 'WSDL/Payment.php' );
$this->account = $account;
diff --git a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
index d0cc7e6..9fa605d 100644
--- a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
+++ b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
@@ -66,7 +66,7 @@
$pendingQueue->queueIgnoreObject();
// Attempt to capture the payment
- $api = new AdyenPaymentsAPI( $this->account );
+ $api = $this->getApi();
Logger::info(
"Attempting capture API call for currency
'{$this->currency}', " .
"amount '{$this->amount}', reference
'{$this->pspReference}'."
@@ -91,7 +91,7 @@
}
} else if ( $action == self::ACTION_REJECT ) {
Logger::debug( "Cancelling authorization with reference
'{$this->pspReference}'" );
- $api = new AdyenPaymentsAPI( $this->account );
+ $api = $api = $this->getApi();
$result = $api->cancel( $this->pspReference );
if ( $result ) {
Logger::debug( "Successfully cancelled
authorization" );
@@ -166,4 +166,9 @@
Logger::debug( "Sending antifraud message with risk score
$riskScore and action $action." );
Configuration::getDefaultConfig()->object(
'data-store/antifraud' )->addObject( $antifraudMessage );
}
+
+ protected function getApi() {
+ $api = Configuration::getDefaultConfig()->object(
'payment-provider/adyen/api' );
+ $api->setAccount( $this->account );
+ }
}
diff --git a/PaymentProviders/Adyen/Tests/MockAdyenPaymentsAPI.php
b/PaymentProviders/Adyen/Tests/MockAdyenPaymentsAPI.php
new file mode 100644
index 0000000..643b078
--- /dev/null
+++ b/PaymentProviders/Adyen/Tests/MockAdyenPaymentsAPI.php
@@ -0,0 +1,39 @@
+<?php namespace SmashPig\PaymentProviders\Adyen\Tests;
+
+class MockAdyenPaymentsAPI {
+
+ protected $account = '';
+ protected $returnCode = false;
+
+ public function __construct( $returnCode ) {
+ $this->returnCode = $returnCode;
+ }
+
+ public function setAccount( $account ) {
+ $this->account = $account;
+ }
+
+ /**
+ * Fakes a Capture modification to a given Adyen transaction.
+ *
+ * @param string $currency Original currency of the request
+ * @param int $amount Amount to be captured. Less than or
equal to the original request
+ * @param string $pspReference Original pspReference of the request
+ *
+ * @returns bool|string The return code set in the constructor.
+ */
+ public function capture( $currency, $amount, $pspReference ) {
+ return $this->returnCode;
+ }
+
+ /**
+ * Pretends to cancel an Adyen authorization
+ *
+ * @param string $pspReference Original pspReference of the request
+ *
+ * @returns bool|string The return code set in the constructor.
+ */
+ public function cancel( $pspReference ) {
+ return $this->returnCode;
+ }
+}
diff --git a/config_defaults.php b/config_defaults.php
index d21c326..5bbf536 100644
--- a/config_defaults.php
+++ b/config_defaults.php
@@ -117,6 +117,11 @@
'payment-provider' => array(
'adyen' => array(
+ 'api' => array(
+ 'class' =>
'SmashPig\PaymentProviders\Adyen\AdyenPaymentsAPI',
+ 'inst-args' => array(),
+ ),
+
'payments-wsdl' =>
'https://pal-live.adyen.com/pal/Payment.wsdl',
'accounts' => array(
--
To view, visit https://gerrit.wikimedia.org/r/277554
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4aae0d4fce2275920597867bf2e56d569ce6738d
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