[LON-CAPA-cvs] cvs: modules /raeburn/register register.pm

raeburn raeburn@source.lon-capa.org
Fri, 08 Apr 2011 22:51:34 -0000


This is a MIME encoded message

--raeburn1302303094
Content-Type: text/plain

raeburn		Fri Apr  8 22:51:34 2011 EDT

  Modified files:              
    /modules/raeburn/register	register.pm 
  Log:
  - Payment handling switched from WebCredit to CASHNet.
  - Remove debugging to test support for subsidies for participants from
    hosting institution.   
  
  
--raeburn1302303094
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20110408225134.txt"

Index: modules/raeburn/register/register.pm
diff -u modules/raeburn/register/register.pm:1.18 modules/raeburn/register/register.pm:1.19
--- modules/raeburn/register/register.pm:1.18	Fri Apr  8 22:22:04 2011
+++ modules/raeburn/register/register.pm	Fri Apr  8 22:51:34 2011
@@ -3,7 +3,7 @@
 # Session-based registration for conferences/workshops
 # Data read/written from MySQL database.
 #
-# $Id: register.pm,v 1.18 2011/04/08 22:22:04 raeburn Exp $
+# $Id: register.pm,v 1.19 2011/04/08 22:51:34 raeburn Exp $
 #
 # Stuart P Raeburn
 #
@@ -93,7 +93,61 @@
     my $domain = $params{'domain'};
     my %feeinfo;
     my @consortium;
-    my ($page,$year,$event,$portal,$returnpage,$event_id,$webpath,$year_quoted,$event_quoted,$fees,$condmail,$feesmsg,$localfeesmsg);
+    my $command = $params{'go'};
+    my $page = $params{'page'};
+
+    my ($event,$year,$event_id);
+    my $merchant = $params{'merchant'};
+    if ($merchant eq '3420') {
+        my ($wid,$user_id,$order,$paymentstate);
+        my %cashnet = &cashnet_itemcodes();
+        my @itemcodes = values(%cashnet);
+        foreach my $key (sort(keys(%params))) {
+            unless ($wid) {
+                if ($key =~ /^ref(\d+)type(\d+)$/) {
+                    my $refcode = $1;
+                    my $itemcode = $2;  
+                    if ($params{$key} eq 'FKEY') {
+                        $wid = $params{'ref'.$refcode.'val'.$itemcode};
+                    }
+                } elsif ($key =~ /^amount(\d+)$/) {
+                    my $itemcode = $1;
+                    if ($params{'itemcode'.$itemcode} =~ /^\Q$merchant\E\-(\w+)$/) {
+                        my $item = $1;
+                        if (grep(/^\Q$item\E$/,@itemcodes)) {
+                            $order += $params{$key}; 
+                        }
+                    }
+                }
+            }
+        }
+        if ($wid) {
+            my $quoted_wid = $dbh->quote( $wid );
+            my $statement = "SELECT p.event_id, p.user_id, w.state FROM purchaser p, webcredit w WHERE w.wid = $quoted_wid AND w.pid = p.pid";
+            ($event_id,$user_id,$paymentstate) = $dbh->selectrow_array($statement);
+            if (($user_id eq $user) && ($event_id)) {
+                $statement = "SELECT event, year FROM event_config WHERE event_id = '$event_id'";
+                ($event,$year) = $dbh->selectrow_array($statement);
+                if ($event && $year) {
+                    $command = 'NextPage';
+                    $params{'year'} = $year;
+                    $params{'event'} = $event;
+# Next line modified from production for security reasons. 
+                    my $done = 1;
+                    if ($done) {
+                        $page = '2';
+                        if ($paymentstate eq '') {
+                            $dbh->do("UPDATE webcredit SET amount='$order',modified=NOW(), state = 'D' WHERE wid = $quoted_wid");
+                        }
+                    } else {
+                        $page = '0'; 
+                    }
+                }
+            }
+        }
+    }
+
+    my ($portal,$returnpage,$webpath,$year_quoted,$event_quoted,$fees,$condmail,$feesmsg,$localfeesmsg);
     if (exists $params{'return'}) {
         $returnpage = $params{'return'};
     }
@@ -114,22 +168,22 @@
         $event_quoted = $dbh->quote( $event );
     }
     if ($year && $event) {
-        my $sth = $dbh->prepare("SELECT name,url,image_path,orientation FROM event_sponsors WHERE event_id = '$event_id' ORDER BY position");
-        $sth->execute();
-        while (my ($name,$url,$image_path,$orientation) = $sth->fetchrow_array) {
-            push @sponsors, $name;
-            %{$sponsorinfo{$name}} = ();
-            $sponsorinfo{$name}{url} = $url;
-            $sponsorinfo{$name}{image_path} = $image_path;
-            $sponsorinfo{$name}{orientation} = $orientation;
-        }
-        $sth->finish;
         ($event_id,$webpath,$fees,$condmail,$feesmsg,$localfeesmsg) = $dbh->selectrow_array("SELECT event_id,webpath,fees,condmail,feesmsg,localfeesmsg FROM event_config WHERE year=$year_quoted AND event=$event_quoted");
         $portal = $webpath.$returnpage;
         if ($event_id eq '') {
             &invalid_event($r,$dbh,$page,$year,$event,$portal,$returnpage,$exitpage,\@sponsors,\%sponsorinfo,$domain);
             return OK;
         } else {
+            my $sth = $dbh->prepare("SELECT name,url,image_path,orientation FROM event_sponsors WHERE event_id = '$event_id' ORDER BY position");
+            $sth->execute();
+            while (my ($name,$url,$image_path,$orientation) = $sth->fetchrow_array) {
+                push @sponsors, $name;
+                %{$sponsorinfo{$name}} = ();
+                $sponsorinfo{$name}{url} = $url;
+                $sponsorinfo{$name}{image_path} = $image_path;
+                $sponsorinfo{$name}{orientation} = $orientation;
+            }
+            $sth->finish;
 # check for fees
             if ($fees) {
                 $sth = $dbh->prepare("SELECT iid,description,cost,required,longdesc,type,waiver,infotext,displayorder,dependency,displayoptional,localdiscount FROM products WHERE event_id = '$event_id'");
@@ -255,8 +309,6 @@
     my $contact_name = "MSU LON-CAPA group";
 
 # figure out what page we're on and where we're heading.
-    $page = $params{'page'};
-    my $command = $params{'go'};
     my $current_page = &calculate_page($page,$command);
     if ($current_page == 3) {
          my $status = $dbh->selectrow_array("SELECT status FROM event_registration WHERE user_id = $quoted_user AND event_id = '$event_id'");
@@ -1719,7 +1771,7 @@
                             } elsif ($feehash{$key}{'type'} eq 'attendancedays') {
                                 $payinfo .= 'As your attendance plans have changed, a credit of $'.$ccard{$key}.' will be credited to you.<br />';
                             } else {
-                                $payinfo .= 'As you will not be attending the '.$key.' a credit of $'.$ccard{$key}.' will be credited to you.<br />';
+                                $payinfo .= 'As you will not be attending the '.$$feeinfo{$feehash{$key}{'iid'}}{'longdesc'}..' a credit of $'.$ccard{$key}.' will be credited to you.<br />';
                             }
                         }
                     } elsif ($currstatus eq 'cancel') {
@@ -2086,13 +2138,13 @@
     <table border="0" width="100%">
      <tr>
       <td>&nbsp;</td>
-      <td><h3>WebCredit Transaction</h3>
+      <td><h3>CASHNet Transaction</h3>
       </td>
      </tr>
      <tr>
       <td>&nbsp;</td>
       <td>
-       Thank you for paying through MSU's secure webCredit site.
+       Thank you for using the MSU CASHNet site to make your credit card payment.
       </td>
      </tr>
      <tr>
@@ -2198,26 +2250,18 @@
     my $citystate = $finaldat->{'citystate'};
     $citystate =~ s/\s+$//;
     my ($city,$state) = ($citystate =~ /^(.+)\s+([^\s]+)$/);
-    my $action = 'https://payments.msu.edu/process/';
+    $city =~ s/,$//;
+    my $country = $finaldat->{'country'};
+    my $action = 'https://commerce.CASHNet.com/msu_3420';
     my $output .= <<END_A;
 <form name="webcredit" action="$action" method="post">
-<input type="hidden" name="Identifier" Value="32546LON">
-<input type="hidden" name="Version" Value="3.2">
-<input type="hidden" name="Order_Comment" value="$redirect">
-<input type="hidden" name="Card_Email" Value="$finaldat->{'email'}">
-<input type="hidden" name="Card_Name" Value="$name">
-<input type="hidden" name="Ship_Name" Value="$name">
-<input type="hidden" name="Ship_Address1" Value="$address">
-<input type="hidden" name="Ship_City" Value="$city">
-<input type="hidden" name="Ship_State" Value="$state">
-<input type="hidden" name="Ship_Country" Value="">
-<input type="hidden" name="Ship_Zip" Value="$finaldat->{'zip'}">
-<input type="hidden" name="Ship_Phone1" Value="$finaldat->{'phone'}">
-<input type="hidden" name="Order_Fkey" Value="$wid">
-<input type="hidden" name="Order_Price" Value="$order">
-<input type="hidden" name="Order_Checksum1" Value="$checksum1">
-<input type="hidden" name="Order_Checksum2" Value="$checksum2">
-<input type="hidden" name="Order_Items" Value="$paynum">
+<input type="hidden" name="Email_g" Value="$finaldat->{'email'}">
+<input type="hidden" name="Name_g" Value="$name">
+<input type="hidden" name="Addr_g" Value="$address">
+<input type="hidden" name="City_g" Value="$city">
+<input type="hidden" name="State_g" Value="$state">
+<input type="hidden" name="Country_g" Value="$country">
+<input type="hidden" name="Zip_g" Value="$finaldat->{'zip'}">
 END_A
     my $n = 0;
     foreach my $item (keys(%{$ccard})) {
@@ -2225,23 +2269,25 @@
             $sort_by_id{$feehash->{$item}{'iid'}} = $item;
         }
     }
+    my %cashnet = &cashnet_itemcodes();
     foreach my $iid (sort(keys(%sort_by_id))) {
-        my $item = $sort_by_id{$iid}; 
+        my $item = $sort_by_id{$iid};
         $n ++;
         my $debt = -1 * $ccard->{$item};
         $debt = sprintf("%.2f",$debt);
-        my $prodprice = $feehash->{$item}{'cost'};
-        $prodprice = sprintf("%.2f",$prodprice);
         my $quant = $quantities->{$item} - $total->{$feehash->{$item}{'iid'}};
+        my $itemcode = '3420-'.$cashnet{$item};
         $output .= <<END_B;
-<input type="hidden" NAME="Prod_SKU$n" Value="$iid">
-<input type="hidden" NAME="Prod_Qty$n" Value="$quant">
-<input type="hidden" NAME="Prod_Name$n" Value="$feehash->{$item}{'longdesc'}">
-<input type="hidden" NAME="Prod_Price$n" Value="$prodprice">
-<input type="hidden" NAME="Prod_TotalPrice$n" Value="$debt">
+<input type="hidden" name="itemcode$n" value="$itemcode">
+<input type="hidden" name="Itemcnt$n" value="$quant">
+<input type="hidden" name="Amount$n" value="$debt">
+<input  name="ref1Type$n" type="hidden" value="FKEY">
+<input  name="ref1val$n" type="hidden" value="$wid">
 END_B
     }
+
     $output .= <<END_C;
+<input type="hidden" name="itemcnt" value="$n" \>
 <input type="button" class="buttoncolored" value="Proceed to secure payment site" onClick="submit()" />
 </form>
 END_C
@@ -2319,6 +2365,16 @@
     return %remnants;
 }
 
+sub cashnet_itemcodes {
+    my %cashnet = (
+                    preworkshop         => 'PRECONF',
+                    registration        => 'CONFREG',
+                    thursday            => 'CONFONE',
+                    virtualregistration => 'VIRTREG',
+                  );
+    return %cashnet;
+}
+
 sub error_exit() {
     my ($r,$page,$year,$event,$error_msg,$contact_name,$contact_email,$sponsors,$sponsorinfo,$domain) = @_;
     $r->print(<<"END_OF_TOP");
@@ -2800,17 +2856,13 @@
             $count = 1; 
         } elsif ($user =~ /^([^@]+)\@(acadiau|dal)\.ca$/) {
             $count = 1;
-        } elsif ($user eq 'raeburn@educog.com') {
+        }
+    } elsif ($event_id eq '17') {
+        if ($user =~ /^([^@]+):(vcu)$/i) {
+            $count = 1;
+        } elsif ($user =~ /^([^@]+)\@vcu\.edu$/i) {
             $count = 1;
         }
-     } elsif ($event_id eq '17') {
-         if ($user =~ /^([^@]+):(vcu)$/i) {
-             $count = 1;
-         } elsif ($user =~ /^([^@]+)\@vcu\.edu$/i) {
-             $count = 1;
-         } elsif ($user eq 'raeburn@educog.com') {
-             $count = 1;
-         }
     }
     return $count;
 }

--raeburn1302303094--