[MediaWiki-commits] [Gerrit] wikimedia...SmashPig[master]: Batch cancel Amazon payments

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

Change subject: Batch cancel Amazon payments
..


Batch cancel Amazon payments

Change-Id: Ia08d21fdffd005b8ec6212fa61dfa1e57a0a845f
---
M PaymentProviders/Amazon/AmazonApi.php
A PaymentProviders/Amazon/Maintenance/Cancel.php
2 files changed, 65 insertions(+), 0 deletions(-)

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



diff --git a/PaymentProviders/Amazon/AmazonApi.php 
b/PaymentProviders/Amazon/AmazonApi.php
index c6bc771..c93cb0f 100644
--- a/PaymentProviders/Amazon/AmazonApi.php
+++ b/PaymentProviders/Amazon/AmazonApi.php
@@ -145,4 +145,17 @@
}
return 
$authorizeResult['AuthorizeResult']['AuthorizationDetails'];
}
+
+   public function cancelOrderReference( $orderReferenceId, $reason = null 
) {
+   $params = array(
+   'amazon_order_reference_id' => $orderReferenceId
+   );
+   if( $reason ) {
+   $params['cancelation_reason'] = $reason;
+   }
+   $result = $this->client->cancelOrderReference( $params 
)->toArray();
+   if ( !empty( $result['Error'] ) ) {
+   throw new SmashPigException( 
$result['Error']['Message'] );
+   }
+   }
 }
diff --git a/PaymentProviders/Amazon/Maintenance/Cancel.php 
b/PaymentProviders/Amazon/Maintenance/Cancel.php
new file mode 100644
index 000..f94eae7
--- /dev/null
+++ b/PaymentProviders/Amazon/Maintenance/Cancel.php
@@ -0,0 +1,52 @@
+addOption( 'reason', 'Reason for cancellation', '' );
+   $this->addArgument(
+   'file',
+   'File with one order reference ID per line',
+   true
+   );
+   $this->desiredOptions['config-node']['default'] = 'amazon';
+   }
+
+   public function execute() {
+   $api = AmazonApi::get();
+
+   $filename = $this->getArgument( 'file' );
+   $reason = $this->getOption( 'reason' );
+
+   $f = fopen( $filename, 'r' );
+   if ( !$f ) {
+   $this->error( "Could not open $filename for read", true 
);
+   }
+
+   // Do the loop!
+   while ( ( $line = fgets( $f ) ) !== false ) {
+   $orderRef = trim( $line );
+   try {
+   $api->cancelOrderReference( $orderRef, $reason 
);
+   print "Canceled $orderRef\n";
+   } catch ( \Exception $ex ) {
+   print(
+   "Canceling $orderRef had an error: " . 
$ex->getMessage() . "\n"
+   );
+   }
+   }
+   }
+}
+
+require ( RUN_MAINTENANCE_IF_MAIN );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia08d21fdffd005b8ec6212fa61dfa1e57a0a845f
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg 
Gerrit-Reviewer: AndyRussG 
Gerrit-Reviewer: Awight 
Gerrit-Reviewer: Cdentinger 
Gerrit-Reviewer: Eileen 
Gerrit-Reviewer: Katie Horn 
Gerrit-Reviewer: Mepps 
Gerrit-Reviewer: XenoRyet 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] wikimedia...SmashPig[master]: Batch cancel Amazon payments

2017-06-02 Thread Ejegg (Code Review)
Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356979 )

Change subject: Batch cancel Amazon payments
..

Batch cancel Amazon payments

Change-Id: Ia08d21fdffd005b8ec6212fa61dfa1e57a0a845f
---
M PaymentProviders/Amazon/AmazonApi.php
A PaymentProviders/Amazon/Maintenance/Cancel.php
2 files changed, 60 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/79/356979/1

diff --git a/PaymentProviders/Amazon/AmazonApi.php 
b/PaymentProviders/Amazon/AmazonApi.php
index 4e0e47e..46d6fb4 100644
--- a/PaymentProviders/Amazon/AmazonApi.php
+++ b/PaymentProviders/Amazon/AmazonApi.php
@@ -145,4 +145,14 @@
}
return 
$authorizeResult['AuthorizeResult']['AuthorizationDetails'];
}
+
+   public function cancelOrderReference( $orderReferenceId, $reason = null 
) {
+   $params = array(
+   'amazon_order_reference_id' => $orderReferenceId
+   );
+   if( $reason ) {
+   $params['cancelation_reason'] = $reason;
+   }
+   $this->client->cancelOrderReference( $params );
+   }
 }
diff --git a/PaymentProviders/Amazon/Maintenance/Cancel.php 
b/PaymentProviders/Amazon/Maintenance/Cancel.php
new file mode 100644
index 000..1cbdafd
--- /dev/null
+++ b/PaymentProviders/Amazon/Maintenance/Cancel.php
@@ -0,0 +1,50 @@
+addOption( 'reason', 'Reason for cancellation', '' );
+   $this->addArgument(
+   'file',
+   'File with one order reference ID per line',
+   true
+   );
+   $this->desiredOptions['config-node']['default'] = 'amazon';
+   }
+
+   public function execute() {
+   $api = AmazonApi::get();
+
+   $filename = $this->getArgument( 'file' );
+   $reason = $this->getOption( 'reason' );
+
+   $f = fopen( $filename, 'r' );
+   if ( !$f ) {
+   $this->error( "Could not open $filename for read", true 
);
+   }
+
+   // Do the loop!
+   while ( ( $line = fgets( $f ) ) !== false ) {
+   $orderRef = trim( $line );
+   try {
+   $api->cancelOrderReference( $orderRef, $reason 
);
+   print "Canceled $orderRef";
+   } catch ( \Exception $ex ) {
+   print( $ex->getMessage() );
+   }
+   }
+   }
+}
+
+require ( RUN_MAINTENANCE_IF_MAIN );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia08d21fdffd005b8ec6212fa61dfa1e57a0a845f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg 

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