[guadec-web-regcfp] Execute separate



commit b70a3613ee9cd13b6e426058b88217e2bf40f4fe
Author: Patrick Uiterwijk <puiterwijk redhat com>
Date:   Fri Jun 19 15:18:01 2015 +0200

    Execute separate

 routes/registration.js                           |   25 +++++++---
 views/registration/pay_paypal.hbs                |   60 ++++++++++++++++++++++
 views/registration/payment_paypal_registered.hbs |    9 ---
 3 files changed, 78 insertions(+), 16 deletions(-)
---
diff --git a/routes/registration.js b/routes/registration.js
index 4d1c685..da03fc6 100644
--- a/routes/registration.js
+++ b/routes/registration.js
@@ -48,21 +48,28 @@ router.post('/pay', function(req, res, next) {
 router.all('/pay/paypal/return', utils.require_user);
 router.all('/pay/paypal/return', utils.require_permission('registration/pay_extra'));
 router.get('/pay/paypal/return', function(req, res, next) {
+  res.render('registration/pay_paypal', {regfee: req.session.regfee, payerId: req.query.PayerID, paymentId: 
req.query.paymentId});
+});
+
+router.all('/pay/paypal/execute', utils.require_user);
+router.all('/pay/paypal/execute', utils.require_permission('registration/pay_extra'));
+router.post('/pay/paypal/execute', function(req, res, next) {
   console.log("VERIFYING PAYMENT");
+  console.log('Payer: ' + req.body.payerId + ', paymentId: ' + req.body.paymentId);
   var execute_payment = {
-    'payer_id': req.query.PayerID,
+    'payer_id': req.body.payerId,
     'transactions': [{
       'amount': req.session.payment['request']['transactions'][0]['amount']
     }]
   };
   console.log('Request');
   console.log(JSON.stringify(execute_payment));
-  var paymentID = req.session.payment['response']['id'];
+  var paymentID = req.body.paymentId;
   paypal.payment.execute(paymentID, execute_payment, function(error, payment) {
     if(!!error) {
       console.log('ERROR');
       console.log(JSON.stringify(error));
-      res.status(500).send('Error authorizing payment');
+      res.status(500).send('authorization-failure');
     } else {
       console.log('Response: ');
       console.log(JSON.stringify(payment));
@@ -87,9 +94,13 @@ router.get('/pay/paypal/return', function(req, res, next) {
                   .complete(function(err) {
                     if(!!err) {
                       console.log('Error attaching payment to reg: ' + err);
-                      res.status(500).send('Error attaching payment');
+                      res.status(500).send('error');
                     } else {
-                      res.render('registration/payment_paypal_registered', {amount: info.amount, approved: 
info.paid});
+                      if(info.paid) {
+                        res.status(200).send('approved');
+                      } else {
+                        res.status(200).send('executed');
+                      }
                     }
                   });
               });
@@ -99,7 +110,7 @@ router.get('/pay/paypal/return', function(req, res, next) {
   });
 });
 
-function execute_paypal(req, res, next, amount) {
+function create_payment(req, res, next, amount) {
   var create_payment = {
     'intent': 'sale',
     'payer': {
@@ -182,7 +193,7 @@ router.post('/pay/do', function(req, res, next) {
       });
   } else if(method == 'paypal') {
     req.session.regfee = req.body.regfee;
-    execute_paypal(req, res, next, req.body.regfee);
+    create_payment(req, res, next, req.body.regfee);
   } else {
     res.status(402).send('Invalid payment method selected');
   }
diff --git a/views/registration/pay_paypal.hbs b/views/registration/pay_paypal.hbs
new file mode 100644
index 0000000..638b6fd
--- /dev/null
+++ b/views/registration/pay_paypal.hbs
@@ -0,0 +1,60 @@
+<script type="text/javascript">
+    var payerId = '{{payerId}}';
+    var paymentId = '{{paymentId}}';
+
+    function execute_payment() {
+        $('#confirm_payment').hide();
+        $('#confirming').show();
+        $.ajax({
+            type: 'POST',
+            url: '/registration/pay/paypal/execute',
+            data: {
+                payerId: payerId,
+                paymentId: paymentId
+            }
+        })
+        .done(function(data) {
+            $('#confirming').hide();
+            if(data == 'approved') {
+                $('#payment_approved').show();
+            } else {
+                $('#payment_delayed').show();
+            }
+        })
+        .fail(function(data) {
+            $('#confirming').hide();
+            $('#payment_error').show();
+        });
+    };
+</script>
+
+<div id="confirm_payment">
+Please confirm you want to pay {{config.registration.currency_symbol}}{{regfee}} via Paypal:
+<button value="Execute payment" onclick="execute_payment();">Execute payment</button>
+</div>
+
+<div id="confirming" style="display: none">
+Payment confirmation in progress.
+Please do not close this window!
+</div>
+
+<div id="payment_approved" style="display: none">
+Thank you!<br/>
+Your PayPal payment has come in and has been approved.
+See you in Sweden!<br />
+<a href="/">Return</a>
+</div>
+
+<div id="payment_delayed" style="display:none">
+Thank you!<br/>
+Your PayPal payment has come in, and will be processed.
+It can take some time for your payment to be verified.<br/>
+See you in Sweden!<br />
+<a href="/">Return</a>
+</div>
+
+<div id="payment_error" style="display:none">
+PayPal payment execution failed, please retry.
+If it fails multiple times, please contact the GUADEC team.<br />
+<a href="/">Return</a>
+</div>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]