Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/94465
Change subject: WmfTransaction accessor to retrieve the contribution
......................................................................
WmfTransaction accessor to retrieve the contribution
Change-Id: If498d768165329aa731973b166ba13f6ecdb080c
---
M sites/all/modules/wmf_common/WmfTransaction.php
1 file changed, 35 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/65/94465/1
diff --git a/sites/all/modules/wmf_common/WmfTransaction.php
b/sites/all/modules/wmf_common/WmfTransaction.php
index 93c9d98..3fd5c0f 100644
--- a/sites/all/modules/wmf_common/WmfTransaction.php
+++ b/sites/all/modules/wmf_common/WmfTransaction.php
@@ -111,4 +111,39 @@
return $transaction;
}
+
+ function exists() {
+ try {
+ $this->getContribution();
+ return true;
+ } catch ( WmfException $ex ) {
+ return false;
+ }
+ }
+
+ /**
+ * @return array of civicrm_contribution and wmf_contribution_extra db
values
+ */
+ function getContribution() {
+ $contributions = wmf_civicrm_get_contributions_from_gateway_id(
$this->gateway, $this->gateway_txn_id );
+ if ( !$contributions ) {
+ throw new NoTransactionExists( $this );
+ } elseif ( count( $contributions ) > 1 ) {
+ throw new NonUniqueTransaction( $this );
+ } else {
+ return array_shift( $contributions );
+ }
+ }
+}
+
+class NoTransactionExists extends WmfException {
+ function __construct( WmfTransaction $transaction ) {
+ parent::__construct( "GET_CONTRIBUTION", "No such transaction:
{$transaction->get_unique_id()}" );
+ }
+}
+
+class NonUniqueTransaction extends WmfException {
+ function __construct( WmfTransaction $transaction ) {
+ parent::__construct( "GET_CONTRIBUTION", "Transaction does not resolve
to a single contribution: {$transaction->get_unique_id()}" );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/94465
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If498d768165329aa731973b166ba13f6ecdb080c
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits