Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234474
Change subject: Tweak the cancel/refund logic
......................................................................
Tweak the cancel/refund logic
Try cancelling first, it's the only way to stop a charge that hasn't settled
yet.
Do some sketchy stuff with the status code mapping, we're busting DI's rivets,
we'll have to redesign the way data and state are handled to be more
appropriate for workflows other than normal payment.
Bug: T110367
Change-Id: I8848fe6542f46f8284ff8b05bbab401dd0af35a4
---
M gateway_common/FinalStatus.php
M globalcollect_gateway/globalcollect.adapter.php
M globalcollect_gateway/scripts/refund.php
3 files changed, 41 insertions(+), 17 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/74/234474/1
diff --git a/gateway_common/FinalStatus.php b/gateway_common/FinalStatus.php
index 062d080..2ae09cf 100644
--- a/gateway_common/FinalStatus.php
+++ b/gateway_common/FinalStatus.php
@@ -9,4 +9,6 @@
const PENDING = 'pending';
const PENDING_POKE = 'pending-poke';
const REVISED = 'revised';
+ const REFUNDED = 'refunded';
+ const CANCELLED = 'cancelled';
}
diff --git a/globalcollect_gateway/globalcollect.adapter.php
b/globalcollect_gateway/globalcollect.adapter.php
index e81f7d9..bec0eca 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -383,9 +383,11 @@
$this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::COMPLETE, 800, 975 ); //these are all post-authorized, but
technically pre-settled...
$this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::COMPLETE, 1000, 1050 );
$this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::FAILED, 1100, 1520 );
- $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::COMPLETE, 1800 ); // Refunded
- $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::FAILED, 1810, 999999 ); // 102020 - ACTION 130 IS NOT ALLOWED FOR
MERCHANT NNN, IPADDRESS NNN.NNN.NNN.NNN
-
+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::REFUNDED, 1800 );
+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::FAILED, 1810, 2220 );
+ // FIXME: not sure what this comment is about:
+ // 102020 - ACTION 130 IS NOT ALLOWED FOR MERCHANT NNN,
IPADDRESS NNN.NNN.NNN.NNN
+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID',
FinalStatus::CANCELLED, 99999 );
$this->defineGoToThankYouOn();
}
@@ -1592,29 +1594,49 @@
// don't want to use standard ct_id staging
$this->var_map['MERCHANTREFERENCE'] = 'merchant_reference';
+ // Try cancelling first, it's fast and cheap.
+ // TODO: Look into AUTHORIZATIONREVERSALINDICATOR
+ $cancel_payment_response = $this->do_transaction(
'CANCEL_PAYMENT' );
+
+ if ( $cancel_payment_response->getCommunicationStatus() ) {
+ // That's all we need!
+ return PaymentResult::fromResults(
$cancel_payment_response, FinalStatus::COMPLETE );
+ }
+
$this->do_transaction( 'DO_REFUND' );
// So get the status and see what we've accomplished so far.
$get_orderstatus_response = $this->do_transaction(
'GET_ORDERSTATUS' );
$data = $this->getTransactionData();
- // If can't even get the status, fail.
- if ( !$get_orderstatus_response->getCommunicationStatus() ) {
- return PaymentResult::fromResults(
$get_orderstatus_response, FinalStatus::FAILED );
- }
-
- // I think DO_REFUND should have moved the order back into
status 600
- if ( !isset( $data['STATUSID'] )
- || $this->findCodeAction( 'GET_ORDERSTATUS',
'STATUSID', $data['STATUSID'] ) !== FinalStatus::PENDING_POKE
+ // If we can't even get the status, fail.
+ if ( !$get_orderstatus_response->getCommunicationStatus()
+ || !isset( $data['STATUSID'] )
) {
return PaymentResult::fromResults(
$get_orderstatus_response, FinalStatus::FAILED );
}
- // Settle.
- $this->transactions['SET_REFUND']['values']['PAYMENTPRODUCTID']
= $data['PAYMENTPRODUCTID'];
- $set_refund_response = $this->do_transaction('SET_REFUND');
+ $final_status = $this->findCodeAction( 'GET_ORDERSTATUS',
'STATUSID', $data['STATUSID'] );
- return PaymentResult::fromResults( $set_refund_response,
FinalStatus::COMPLETE );
+ // If it's already cancelled or refunded, pat own back.
+ if ( $final_status === FinalStatus::CANCELLED
+ || $final_status === FinalStatus::REFUNDED
+ ) {
+ return PaymentResult::fromResults(
$get_orderstatus_response, FinalStatus::COMPLETE );
+ }
+
+ // If DO_REFUND moved the order back into status 600, settle
the refund.
+ if ( $final_status === FinalStatus::PENDING_POKE ) {
+ // Settle the refund.
+
$this->transactions['SET_REFUND']['values']['PAYMENTPRODUCTID'] =
$data['PAYMENTPRODUCTID'];
+ $set_refund_response =
$this->do_transaction('SET_REFUND');
+
+ if ( !$set_refund_response->getCommunicationStatus() ) {
+ return PaymentResult::fromResults(
$set_refund_response, FinalStatus::FAILED );
+ }
+
+ return PaymentResult::fromResults(
$set_refund_response, FinalStatus::COMPLETE );
+ }
}
/**
diff --git a/globalcollect_gateway/scripts/refund.php
b/globalcollect_gateway/scripts/refund.php
index 52e36b1..cc15fa4 100644
--- a/globalcollect_gateway/scripts/refund.php
+++ b/globalcollect_gateway/scripts/refund.php
@@ -48,14 +48,14 @@
),
);
- $this->output( "Refunding transaction $oid" );
+ $this->output( "Refunding transaction $oid\n" );
$adapter = new GlobalCollectAdapter( $gateway_opts );
$result = $adapter->doRefund();
if ( $result->isFailed() ) {
$this->error( "Failed refunding transaction
$oid" );
} else {
- $this->output( "Successfully refunded
transaction $oid" );
+ $this->output( "Successfully refunded
transaction $oid\n" );
}
}
fclose( $file );
--
To view, visit https://gerrit.wikimedia.org/r/234474
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8848fe6542f46f8284ff8b05bbab401dd0af35a4
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