jenkins-bot has submitted this change and it was merged. Change subject: Cancel subscriptions programatically ......................................................................
Cancel subscriptions programatically Try CANCEL_ORDER, then if it doesn't work try END_ORDER Bug: T110367 Change-Id: I9bcee979fdab1210024bdf21b3fb4b06cd2d200d --- M globalcollect_gateway/globalcollect.adapter.php M globalcollect_gateway/scripts/refund.php 2 files changed, 83 insertions(+), 0 deletions(-) Approvals: Ejegg: Looks good to me, approved jenkins-bot: Verified diff --git a/globalcollect_gateway/globalcollect.adapter.php b/globalcollect_gateway/globalcollect.adapter.php index c02c1c7..405cf18 100644 --- a/globalcollect_gateway/globalcollect.adapter.php +++ b/globalcollect_gateway/globalcollect.adapter.php @@ -728,6 +728,52 @@ 'AUTHENTICATIONINDICATOR' => '0', ), ); + + // Cancel a recurring transaction if all payment attempts can be canceled + $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', + ), + ); + + // End a recurring transaction, disallowing further payment attempts + $this->transactions['END_ORDER'] = array( + 'request' => array( + 'REQUEST' => array( + 'ACTION', + 'META' => array( + 'MERCHANTID', + 'IPADDRESS', + 'VERSION', + ), + 'PARAMS' => array( + 'ORDER' => array( + 'ORDERID', + ), + ) + ) + ), + 'values' => array( + 'ACTION' => 'END_ORDER', + 'VERSION' => '1.0', + ), + ); } /** @@ -1642,6 +1688,29 @@ } /** + * Cancel a subscription + * + * Uses the adapter's internal order ID. + * + * @return PaymentResult + */ + public function cancelSubscription() { + // Try to cancel, in case no payment attempts have been made or all + // payment attempts can be canceled + $response = $this->do_transaction( 'CANCEL_ORDER' ); + + if ( !$response->getCommunicationStatus() ) { + // If we can't cancel, end it to disallow future attempts + $response = $this->do_transaction( 'END_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: merged Gerrit-Change-Id: I9bcee979fdab1210024bdf21b3fb4b06cd2d200d Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits