Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234476
Change subject: Cancel subscriptions programatically
......................................................................
Cancel subscriptions programatically
Bug: T110367
Change-Id: I9bcee979fdab1210024bdf21b3fb4b06cd2d200d
---
M globalcollect_gateway/globalcollect.adapter.php
M globalcollect_gateway/scripts/refund.php
2 files changed, 53 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/76/234476/1
diff --git a/globalcollect_gateway/globalcollect.adapter.php
b/globalcollect_gateway/globalcollect.adapter.php
index bec0eca..dba8af5 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -726,6 +726,28 @@
'AUTHENTICATIONINDICATOR' => '0',
),
);
+
+ $this->transactions['CANCEL_ORDER'] = array(
+ 'request' => array(
+ 'REQUEST' => array(
+ 'ACTION',
+ 'META' => array(
+ 'MERCHANTID',
+ 'IPADDRESS',
+ 'VERSION',
+ ),
+ 'PARAMS' => array(
+ 'ORDER' => array(
+ 'ORDERID',
+ ),
+ )
+ )
+ ),
+ 'values' => array(
+ 'ACTION' => 'CANCEL_ORDER',
+ 'VERSION' => '1.0',
+ ),
+ );
}
/**
@@ -1640,6 +1662,23 @@
}
/**
+ * Cancel a subscription
+ *
+ * Uses the adapter's internal order ID.
+ *
+ * @return PaymentResult
+ */
+ public function cancelSubscription() {
+ $response = $this->do_transaction( 'CANCEL_ORDER' );
+
+ if ( !$response->getCommunicationStatus() ) {
+ return PaymentResult::fromResults( $response,
FinalStatus::FAILED );
+ }
+
+ return PaymentResult::fromResults( $response,
FinalStatus::COMPLETE );
+ }
+
+ /**
* Parse the response to get the status. Not sure if this should return
a bool, or something more... telling.
*
* @param DomDocument $response The response XML loaded into a
DomDocument
diff --git a/globalcollect_gateway/scripts/refund.php
b/globalcollect_gateway/scripts/refund.php
index cc15fa4..bb6a5e2 100644
--- a/globalcollect_gateway/scripts/refund.php
+++ b/globalcollect_gateway/scripts/refund.php
@@ -17,6 +17,8 @@
$this->addOption( 'file', 'Read refund detail in from a file',
true, true, 'f' );
+ $this->addOption( 'unsubscribe', 'Cancel the subscription this
charge is a part of',
+ false, false );
}
public function execute() {
@@ -24,6 +26,8 @@
// don't run fraud checks for refunds
$wgGlobalCollectGatewayEnableCustomFilters = false;
+
+ $isUnsubscribing = $this->getOption( 'unsubscribe' );
$filename = $this->getOption( 'file' );
if( !( $file = fopen( $filename, 'r' ) ) ){
@@ -57,6 +61,16 @@
} else {
$this->output( "Successfully refunded
transaction $oid\n" );
}
+
+ if ( $isUnsubscribing ) {
+ $result = $adapter->cancelSubscription();
+
+ if ( $result->isFailed() ) {
+ $this->error( "Failed cancelling
subscription $oid" );
+ } else {
+ $this->output( "Successfully cancelled
subscription $oid\n" );
+ }
+ }
}
fclose( $file );
}
--
To view, visit https://gerrit.wikimedia.org/r/234476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bcee979fdab1210024bdf21b3fb4b06cd2d200d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits