[MediaWiki-commits] [Gerrit] mediawiki...DonationInterface[master]: PayPal EC: use ajax to get redirect URL

2017-07-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/364825 )

Change subject: PayPal EC: use ajax to get redirect URL
..


PayPal EC: use ajax to get redirect URL

Act like Adyen or Ingenico, showing the form and using and AJAX call to do
the server-to-server setup in the background and return a formaction URL.

Slightly different from Adyen and Ingenico, this will submit instantly and
redirect instead of showing an iframe.

This might solve our dead session errors.

Bug: T167923
Change-Id: Ifad296dbd09dc6935ecd8799278e411ef3b14548
---
M extension.json
M gateway_common/donation.api.php
A paypal_gateway/express_checkout/forms/js/paypal.js
M paypal_gateway/express_checkout/paypal_express.adapter.php
M paypal_gateway/express_checkout/paypal_express_gateway.body.php
5 files changed, 25 insertions(+), 11 deletions(-)

Approvals:
  Mepps: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index d6367ad..ca62edd 100644
--- a/extension.json
+++ b/extension.json
@@ -203,6 +203,10 @@
"scripts": "globalcollect_gateway/forms/js/ingenico.js",
"dependencies": "ext.donationInterface.forms"
},
+   "ext.donationinterface.paypal.scripts": {
+   "scripts": 
"paypal_gateway/express_checkout/forms/js/paypal.js",
+   "dependencies": "ext.donationInterface.forms"
+   },
"ext.donationinterface.amazon.styles": {
"styles": "amazon_gateway/amazon.css"
},
diff --git a/gateway_common/donation.api.php b/gateway_common/donation.api.php
index 5d38d3c..7ad1075 100644
--- a/gateway_common/donation.api.php
+++ b/gateway_common/donation.api.php
@@ -48,6 +48,9 @@
}
} elseif ( $this->gateway == 'adyen' ) {
$result = $gatewayObj->do_transaction( 'donate' );
+   } elseif ( $this->gateway === 'paypal_ec' ) {
+   $gatewayObj->doPayment();
+   $result = $gatewayObj->getTransactionResponse();
}
 
// $normalizedData = $gatewayObj->getData_Unstaged_Escaped();
diff --git a/paypal_gateway/express_checkout/forms/js/paypal.js 
b/paypal_gateway/express_checkout/forms/js/paypal.js
new file mode 100644
index 000..9f41454
--- /dev/null
+++ b/paypal_gateway/express_checkout/forms/js/paypal.js
@@ -0,0 +1,12 @@
+( function ( $, mw ) {
+   var di = mw.donationInterface;
+
+   function redirect( result ) {
+   top.location.href = result.formaction;
+   }
+
+   di.forms.submit = function () {
+   di.forms.callDonateApi( redirect );
+   };
+   di.forms.submit();
+} )( jQuery, mediaWiki );
diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index c614407..f40e39b 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -420,8 +420,11 @@
case 'SetExpressCheckout_recurring':
$this->checkResponseAck( $response );
$this->addResponseData( $this->unstageKeys( 
$response ) );
-   $this->transaction_response->setRedirect(
-   $this->account_config['RedirectURL'] . 
$response['TOKEN'] );
+   $redirectUrl = 
$this->account_config['RedirectURL'] . $response['TOKEN'];
+   $this->transaction_response->setRedirect( 
$redirectUrl );
+   $this->transaction_response->setData( array(
+   'FORMACTION' => $redirectUrl
+   ) );
break;
case 'GetExpressCheckoutDetails':
$this->checkResponseAck( $response );
diff --git a/paypal_gateway/express_checkout/paypal_express_gateway.body.php 
b/paypal_gateway/express_checkout/paypal_express_gateway.body.php
index 2d7e4ce..8f624ba 100644
--- a/paypal_gateway/express_checkout/paypal_express_gateway.body.php
+++ b/paypal_gateway/express_checkout/paypal_express_gateway.body.php
@@ -8,17 +8,9 @@
 */
protected function handleRequest() {
$this->getOutput()->allowClickjacking();
-   $this->getOutput()->addModules( 'ext.donationInterface.forms' );
+   $this->getOutput()->addModules( 
'ext.donationinterface.paypal.scripts' );
 
$this->handleDonationRequest();
}
 
-   /**
-* Always attempt to pass through transparently.
-*
-* @see GatewayPage::isProcessImmediate()
-*/
- 

[MediaWiki-commits] [Gerrit] mediawiki...DonationInterface[master]: PayPal EC: use ajax to get redirect URL

2017-07-12 Thread Ejegg (Code Review)
Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364825 )

Change subject: PayPal EC: use ajax to get redirect URL
..

PayPal EC: use ajax to get redirect URL

Act like Adyen or Ingenico, showing the form and using and AJAX call to do
the server-to-server setup in the background and return a formaction URL.

Slightly different from Adyen and Ingenico, this will submit instantly and
redirect instead of showing an iframe.

This might solve our dead session errors.

Bug: T167923
Change-Id: Ifad296dbd09dc6935ecd8799278e411ef3b14548
---
M extension.json
M gateway_common/donation.api.php
A paypal_gateway/express_checkout/forms/js/paypal.js
M paypal_gateway/express_checkout/paypal_express.adapter.php
M paypal_gateway/express_checkout/paypal_express_gateway.body.php
5 files changed, 25 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/25/364825/1

diff --git a/extension.json b/extension.json
index d6367ad..ca62edd 100644
--- a/extension.json
+++ b/extension.json
@@ -203,6 +203,10 @@
"scripts": "globalcollect_gateway/forms/js/ingenico.js",
"dependencies": "ext.donationInterface.forms"
},
+   "ext.donationinterface.paypal.scripts": {
+   "scripts": 
"paypal_gateway/express_checkout/forms/js/paypal.js",
+   "dependencies": "ext.donationInterface.forms"
+   },
"ext.donationinterface.amazon.styles": {
"styles": "amazon_gateway/amazon.css"
},
diff --git a/gateway_common/donation.api.php b/gateway_common/donation.api.php
index 5d38d3c..7ad1075 100644
--- a/gateway_common/donation.api.php
+++ b/gateway_common/donation.api.php
@@ -48,6 +48,9 @@
}
} elseif ( $this->gateway == 'adyen' ) {
$result = $gatewayObj->do_transaction( 'donate' );
+   } elseif ( $this->gateway === 'paypal_ec' ) {
+   $gatewayObj->doPayment();
+   $result = $gatewayObj->getTransactionResponse();
}
 
// $normalizedData = $gatewayObj->getData_Unstaged_Escaped();
diff --git a/paypal_gateway/express_checkout/forms/js/paypal.js 
b/paypal_gateway/express_checkout/forms/js/paypal.js
new file mode 100644
index 000..9f41454
--- /dev/null
+++ b/paypal_gateway/express_checkout/forms/js/paypal.js
@@ -0,0 +1,12 @@
+( function ( $, mw ) {
+   var di = mw.donationInterface;
+
+   function redirect( result ) {
+   top.location.href = result.formaction;
+   }
+
+   di.forms.submit = function () {
+   di.forms.callDonateApi( redirect );
+   };
+   di.forms.submit();
+} )( jQuery, mediaWiki );
diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php 
b/paypal_gateway/express_checkout/paypal_express.adapter.php
index c614407..f40e39b 100644
--- a/paypal_gateway/express_checkout/paypal_express.adapter.php
+++ b/paypal_gateway/express_checkout/paypal_express.adapter.php
@@ -420,8 +420,11 @@
case 'SetExpressCheckout_recurring':
$this->checkResponseAck( $response );
$this->addResponseData( $this->unstageKeys( 
$response ) );
-   $this->transaction_response->setRedirect(
-   $this->account_config['RedirectURL'] . 
$response['TOKEN'] );
+   $redirectUrl = 
$this->account_config['RedirectURL'] . $response['TOKEN'];
+   $this->transaction_response->setRedirect( 
$redirectUrl );
+   $this->transaction_response->setData( array(
+   'FORMACTION' => $redirectUrl
+   ) );
break;
case 'GetExpressCheckoutDetails':
$this->checkResponseAck( $response );
diff --git a/paypal_gateway/express_checkout/paypal_express_gateway.body.php 
b/paypal_gateway/express_checkout/paypal_express_gateway.body.php
index 2d7e4ce..8f624ba 100644
--- a/paypal_gateway/express_checkout/paypal_express_gateway.body.php
+++ b/paypal_gateway/express_checkout/paypal_express_gateway.body.php
@@ -8,17 +8,9 @@
 */
protected function handleRequest() {
$this->getOutput()->allowClickjacking();
-   $this->getOutput()->addModules( 'ext.donationInterface.forms' );
+   $this->getOutput()->addModules( 
'ext.donationinterface.paypal.scripts' );
 
$this->handleDonationRequest();
}
 
-   /**
-* Always attempt to pass through transparently.
-*
-* @see