[guadec-web] Changes to IPN: trial 1



commit 7fd7ad01b7e1afd36eff6eb2e3c986e69893507f
Author: Saumya Dwivedi <saumya zero gmail com>
Date:   Mon Jul 7 16:04:02 2014 +0530

    Changes to IPN: trial 1

 guadec/access-register.php |    4 ++--
 guadec/confirm-payment.php |   21 ++++++++++-----------
 guadec/ipn.php             |   33 ++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/guadec/access-register.php b/guadec/access-register.php
index 3156204..ea9d3b4 100644
--- a/guadec/access-register.php
+++ b/guadec/access-register.php
@@ -49,11 +49,11 @@ else{
 
        if(isset($_POST['viewtype']) && !empty($_POST['viewtype'])) {
            $action = $_POST['viewtype'];
-          // $table_name = $wpdb->prefix .'guadec2014_registration';
+           $table_name = $wpdb->prefix .'guadec2014_registrations';
            switch($action) {
 
                case 'showall' :
-                   $result = $wpdb->get_results('SELECT * FROM wp_guadec2014_registrations', ARRAY_A);
+                   $result = $wpdb->get_results('SELECT * FROM $wp_guadec2014_registrations', ARRAY_A);
                        echo display_result($result);
                        break;
                case 'showcomplete' :
diff --git a/guadec/confirm-payment.php b/guadec/confirm-payment.php
index 3e137c2..58ef716 100644
--- a/guadec/confirm-payment.php
+++ b/guadec/confirm-payment.php
@@ -83,17 +83,16 @@ if (!empty($_POST)) {
        if ($errors == false) {
                /* This variable not be changed: goes to a restricted field to Paypal API */
                $registerInfo = 
-               "Name: " . $name . "\n".
-               "Email: " . $obfuscated_email . "\n" .
-               "Arrive :  ". $arrive . "\n".
-               "Depart:  ". $depart . "\n".
-               "Sponsored: ". $sponsor_check . "\n".
-               "Lunch Days: ". $x. "\n".
-               "Entry Fee: ". $entry ."\n".
-               "Lunch Fee: ".$lamount."\n".
-               "Accom Fee: ".$aamount."\n".
-               "Total Fee: ".$tamount."\n"
-               ;
+               "name=" . $name . "&".
+               "email=" . $email . "&" .
+               "time=" . date("Y-m-d H:i:s"). "&".
+               "arrive=". $arrive . "&".
+               "depart=". $depart . "&".
+               "entryfee=". $entry ."&".
+               "lunchfee=".$lamount."&".
+               "accomfee=".$aamount."&".
+               "totalfee=".$tamount
+                               ;
                $mailContent .= $registerInfo;
                $subject = "From GUADEC 2014 Registration";
                $headers = "From: GUADEC 2014 Registration Script <some-address gnome org>";
diff --git a/guadec/ipn.php b/guadec/ipn.php
index db959b9..b8f8657 100755
--- a/guadec/ipn.php
+++ b/guadec/ipn.php
@@ -19,6 +19,9 @@ $listener = new IpnListener();
 // tell the IPN listener to use the PayPal test sandbox
 $listener->use_sandbox = true;
 
+//variable to update the database
+global $wpdb;
+
 // try to process the IPN POST
 try {
     $listener->requirePostMethod();
@@ -34,11 +37,27 @@ if ($verified) {
     // TODO: Implement additional fraud checks and MySQL storage
 
     $errmsg = '';   // stores errors from fraud checks
+    $customInfo = $_POST['custom'];     // access custom information
+    $csplit = explode('&',$customInfo);
+    $cvar = array(); $i = 0;
+
+    while(($i < 9) && ($csplit[$i] != null)){
+        $dsplit =  explode('=',$csplit[$i]);
+        $ckey = $dsplit[0];
+        $cvalue = ($dsplit[1] =='')?'0': $dsplit[1];
+        $cvar[$ckey] = $cvalue;
+        error_log("dsjnfsdjnfdjsjbsf\n");       
+        error_log($cvar[$ckey]);
+        error_log($ckey);
+//      error_log($cvalue);
+//      error_log($csplit[$i]);
+        $i = $i + 1;
+        } 
     
     // 1. Make sure the payment status is "Completed" 
     if ($_POST['payment_status'] != 'Completed') { 
         $errmsg .= "'Payment status' does not match: ";
-        $errmsg .= $_POST['receiver_email']."\n";
+        $errmsg .= $_POST['payment_status']."\n";
         // simply ignore any IPN that is not completed
         exit(0); 
     }
@@ -79,6 +98,18 @@ if ($verified) {
         
         
     } else {
+        $reg_email = $cvar['email'];
+        $table_name = $wpdb->prefix .'guadec2014_registration';
+        
+        $wpdb->update(
+        $table_name,
+        array(
+            'payment' => 'Completed'
+            ),
+        array(
+            'email' => $reg_email
+            ) 
+        );
         $body .= $listener->getTextReport();
         $body .= "Registration Payment Successful for ";
         $body .= $_POST['custom'];


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