Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/189153
Change subject: WIP doPayment()
......................................................................
WIP doPayment()
Change-Id: I3e542ad4b38fe294744084e15d46cb91010a2e6d
---
M adyen_gateway/adyen.adapter.php
M amazon_gateway/amazon.adapter.php
M amazon_gateway/amazon_gateway.body.php
M gateway_common/PaymentResult.php
M gateway_common/gateway.adapter.php
M globalcollect_gateway/globalcollect.adapter.php
M globalcollect_gateway/globalcollect_gateway.body.php
7 files changed, 103 insertions(+), 71 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/53/189153/1
diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php
index 007eaa7..2db5c6f 100644
--- a/adyen_gateway/adyen.adapter.php
+++ b/adyen_gateway/adyen.adapter.php
@@ -177,13 +177,14 @@
);
}
+ function doPayment() {
+ return PaymentResult::fromResultsArray(
+ $this->do_transaction( 'donate' )
+ );
+ }
+
/**
- * Because GC has some processes that involve more than one
do_transaction
- * chained together, we're catching those special ones in an overload
and
- * letting the rest behave normally.
- * @TODO: If this is a pattern we want to be able to reuse, it should be
- * represented in the base class.
- * I can't help but feel like it's bad that the parent's do_transaction
+ * FIXME: I can't help but feel like it's bad that the parent's
do_transaction
* is never used at all.
*/
function do_transaction( $transaction ) {
diff --git a/amazon_gateway/amazon.adapter.php
b/amazon_gateway/amazon.adapter.php
index ebab94b..d4162e4 100644
--- a/amazon_gateway/amazon.adapter.php
+++ b/amazon_gateway/amazon.adapter.php
@@ -200,6 +200,16 @@
return $queryparams;
}
+ public function doPayment() {
+ if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) {
+ $resultData = $this->do_transaction( 'DonateMonthly' );
+ } else {
+ $resultData = $this->do_transaction( 'Donate' );
+ }
+
+ return PaymentResult::fromResultsArray( $resultData );
+ }
+
function do_transaction( $transaction ) {
global $wgRequest, $wgOut;
$this->session_addDonorData();
diff --git a/amazon_gateway/amazon_gateway.body.php
b/amazon_gateway/amazon_gateway.body.php
index 785f4b9..6f356d9 100644
--- a/amazon_gateway/amazon_gateway.body.php
+++ b/amazon_gateway/amazon_gateway.body.php
@@ -43,13 +43,17 @@
if ( $this->getRequest()->getText( 'ffname',
'default' ) === 'amazon-recurring'
|| $this->getRequest()->getText(
'recurring', 0 )
) {
- $this->adapter->do_transaction(
'DonateMonthly' );
- } else {
- $this->adapter->do_transaction(
'Donate' );
+ // FIXME: do this in the form param
harvesting step
+ $this->adapter->addData( array(
+ 'recurring' => 1,
+ ) );
}
+ $this->adapter->doPayment();
+ // TODO: move redirect here.
return;
}
+ // TODO: move resultswitching out
$this->log( 'At gateway return with params: ' .
json_encode( $this->getRequest()->getValues() ), LOG_INFO );
if ( $this->adapter->checkTokens() &&
$this->getRequest()->getText( 'status' ) ) {
$this->adapter->do_transaction(
'ProcessAmazonReturn' );
diff --git a/gateway_common/PaymentResult.php b/gateway_common/PaymentResult.php
index 0f911f5..2e1067b 100644
--- a/gateway_common/PaymentResult.php
+++ b/gateway_common/PaymentResult.php
@@ -58,6 +58,11 @@
return $response;
}
+ static public function newSuccess() {
+ $response = new PaymentResult();
+ return $response;
+ }
+
public function getIframe() {
return $this->iframe;
}
@@ -77,4 +82,11 @@
public function getErrors() {
return $this->errors;
}
+
+ static public function fromResultsArray( $data ) {
+ if ( array_key_exists( 'redirect', $data ) ) {
+ return PaymentResult::newRedirect( $data['redirect'] );
+ }
+ return PaymentResult::newSuccess();
+ }
}
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 1c54064..23322ec 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -157,6 +157,14 @@
function setGatewayDefaults();
static function getCurrencies();
+
+ /**
+ * Attempt the default transaction for the current DonationData
+ *
+ * @return PaymentResult hints for the next donor interaction
+ */
+ function doPayment() {
+ }
}
/**
diff --git a/globalcollect_gateway/globalcollect.adapter.php
b/globalcollect_gateway/globalcollect.adapter.php
index 8fea4fd..66fec84 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -1067,6 +1067,65 @@
PaymentMethod::registerMethods( $this->payment_submethods );
}
+ public function doPayment() {
+ $payment_method = $this->getPaymentMethod();
+
+ // FIXME: this should happen during normalization, and before
validatation.
+ if ( $payment_method === 'dd'
+ and !$this->getPaymentSubmethod() ) {
+ // Synthesize a submethod based on the country.
+ $country_code = strtolower(
$this->getData_Unstaged_Escaped( 'country' ) );
+ $this->addData( array(
+ 'payment_submethod' => "dd_{$country_code}",
+ ) );
+ }
+
+ // Execute the proper transaction code:
+ switch ( $payment_method ) {
+ case 'cc':
+ // FIXME: we don't actually use this code path,
it's done from gc.cc.js instead.
+
+ $this->adapter->do_transaction(
'INSERT_ORDERWITHPAYMENT' );
+
+ // Display an iframe for credit cards
+ return PaymentResult::newIframe();
+ //if ( $this->executeIframeForCreditCard() ) {
+ FIXME: $this->displayResultsForDebug();
+ // Nothing left to process
+ return;
+ }
+ break;
+
+ case 'bt':
+ case 'obt':
+ $this->adapter->do_transaction(
'INSERT_ORDERWITHPAYMENT' );
+
+ if ( in_array(
$this->adapter->getFinalStatus(), $this->adapter->getGoToThankYouOn() ) ) {
+ return
$this->displayEndTransactionInfo( $payment_method );
+ }
+ break;
+
+ case 'dd':
+ $result =
$this->adapter->do_transaction('Direct_Debit');
+ break;
+
+ case 'ew':
+ case 'rtbt':
+ case 'cash':
+ $this->adapter->do_transaction(
'INSERT_ORDERWITHPAYMENT' );
+ $formAction =
$this->adapter->getTransactionDataFormAction();
+
+ // Redirect to the bank
+ if ( !empty( $formAction ) ) {
+ return $this->getOutput()->redirect(
$formAction );
+ }
+ break;
+
+ default:
+ $this->adapter->do_transaction(
'INSERT_ORDERWITHPAYMENT' );
+ }
+ }
+
/**
* Because GC has some processes that involve more than one
do_transaction
* chained together, we're catching those special ones in an overload
and
diff --git a/globalcollect_gateway/globalcollect_gateway.body.php
b/globalcollect_gateway/globalcollect_gateway.body.php
index 73a492c..9c8c86b 100644
--- a/globalcollect_gateway/globalcollect_gateway.body.php
+++ b/globalcollect_gateway/globalcollect_gateway.body.php
@@ -43,68 +43,6 @@
// dispatch forms/handling
if ( $this->adapter->checkTokens() ) {
if ( $this->adapter->posted ) {
- // The form was submitted and the payment
method has been set
- $payment_method =
$this->adapter->getPaymentMethod();
-
- if ( $payment_method === 'dd'
- and
!$this->adapter->getPaymentSubmethod() ) {
- // Synthesize a submethod based on the
country.
- $country_code = strtolower(
$this->adapter->getData_Unstaged_Escaped( 'country' ) );
- $this->adapter->addData( array(
- 'payment_submethod' =>
"dd_{$country_code}",
- ) );
- }
-
- // If there were errors, redisplay form,
otherwise proceed to next step
- if ( $this->validateForm() ) {
- $this->displayForm();
- } else { // The submitted form data is valid,
so process it
- // allow any external validators to
have their way with the data
- // Execute the proper transaction code:
-
- switch ( $payment_method ){
- case 'cc':
- // FIXME: we don't
actually use this code path, it's done from gc.cc.js instead.
-
-
$this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
-
- // Display an iframe
for credit cards
- if (
$this->executeIframeForCreditCard() ) {
-
$this->displayResultsForDebug();
- // Nothing left
to process
- return;
- }
- break;
-
- case 'bt':
- case 'obt':
-
$this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
-
- if ( in_array(
$this->adapter->getFinalStatus(), $this->adapter->getGoToThankYouOn() ) ) {
- return
$this->displayEndTransactionInfo( $payment_method );
- }
- break;
-
- case 'dd':
- $result =
$this->adapter->do_transaction('Direct_Debit');
- break;
-
- case 'ew':
- case 'rtbt':
- case 'cash':
-
$this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
- $formAction =
$this->adapter->getTransactionDataFormAction();
-
- // Redirect to the bank
- if ( !empty(
$formAction ) ) {
- return
$this->getOutput()->redirect( $formAction );
- }
- break;
-
- default:
-
$this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' );
- }
-
return $this->resultHandler();
}
--
To view, visit https://gerrit.wikimedia.org/r/189153
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e542ad4b38fe294744084e15d46cb91010a2e6d
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