[interchange-cvs] interchange - heins modified lib/Vend/Order.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Sat Dec 27 09:01:18 EST 2003


User:      heins
Date:      2003-12-27 14:01:17 GMT
Modified:  lib/Vend Order.pm
Log:
* Add the ability to create a transaction ID and later assign the order number.
  To use, you need to set in the main route:

	  counter_tid    etc/transaction.number

  At that point, in the current foundation, you would add this code to
  assign an order number *after* payment is taken.

	Set order number in values: [value
                        name=mv_order_number
                        set="[counter
                                name=`$Session->{current_route}{counter_name}
										|| 'etc/order.number'
									 `
                                sql=`$Session->{current_route}{sql_counter}`
                                start=`$Session->{current_route}{first_order_number}`
                                date=`$Session->{current_route}{date_counter}`
                            ]"
                    ]
	Set order number in session: [calc]
                        $Session->{mv_order_number} = $Values->{mv_order_number};
                    [/calc]

  This allows the order numbers to increment only after payment has been
  received, while still allowing the all-in-one transaction logging
  file located in a report file.

  If you use counter_tid, you *must* set set the order number in your
  logging file if you want it to be available.

  You will want to call [charge ... order_id="[value mv_transaction_id]"]
  to get full traceability of declined and failed charges.

* Add ability to use date-based order numbers with

		date_counter   1

  in the appropriate route.

* Allow setting a counter name without incrementing the counter itself, if

		increment   0

  is in the route. This is really how it should have been done in the
  first place.

* All tested with current foundation, and should be completely transparent
  and compatible.

Revision  Changes    Path
2.62      +59 -18    interchange/lib/Vend/Order.pm


rev 2.62, prev_rev 2.61
Index: Order.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Order.pm,v
retrieving revision 2.61
retrieving revision 2.62
diff -u -r2.61 -r2.62
--- Order.pm	25 Nov 2003 16:58:37 -0000	2.61
+++ Order.pm	27 Dec 2003 14:01:17 -0000	2.62
@@ -1,6 +1,6 @@
 # Vend::Order - Interchange order routing routines
 #
-# $Id: Order.pm,v 2.61 2003/11/25 16:58:37 mheins Exp $
+# $Id: Order.pm,v 2.62 2003/12/27 14:01:17 mheins Exp $
 #
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -29,7 +29,7 @@
 package Vend::Order;
 require Exporter;
 
-$VERSION = substr(q$Revision: 2.61 $, 10);
+$VERSION = substr(q$Revision: 2.62 $, 10);
 
 @ISA = qw(Exporter);
 
@@ -1468,7 +1468,15 @@
 	my $file = shift || $Vend::Cfg->{OrderCounter};
 	my $sql = shift;
 	my $start = shift || '000000';
-	return Vend::Interpolate::tag_counter($file, { sql => $sql, start => $start });
+	my $date = shift;
+	return Vend::Interpolate::tag_counter(
+											$file,
+											{
+												sql => $sql,
+												start => $start,
+												date => $date
+											}
+										);
 }
 
 sub update_order_number {
@@ -1587,26 +1595,29 @@
 	my @route_failed;
 	my @route_done;
 	my $route_checked;
-
-	### This used to be the check_only
-	# Here we return if it is only a check
-	#return route_profile_check(@routes) if $check_only;
+	$Vend::Session->{routes_run} = [];
 
 	# Careful! If you set it on one order and not on another,
 	# you must delete in between.
-	if(! $check_only and ! $main->{no_increment} and ! $Vend::Session->{mv_order_number}) {
+
+	my $no_increment = $check_only
+						|| $main->{no_increment}
+						|| $main->{counter_tid}
+						|| $Vend::Session->{mv_order_number};
+		
+	unless($no_increment) {
 		$::Values->{mv_order_number} = counter_number(
 											$main->{counter},
 											$main->{sql_counter},
 											$main->{first_order_number},
+											$main->{date_counter},
 										);
 	}
 
 	my $value_save = { %{$::Values} };
 
-	my @trans_tables;
-
-	# We aren't going to 
+	# We aren't going to allow encrypt_program setting from database as
+	# that is a security problem
 	my %override_key = qw/
 		encrypt_program 1
 	/;
@@ -1626,6 +1637,9 @@
 		$main = $route if $route->{master};
 		my $old;
 
+		## Record the routes run
+		push @{$Vend::Session->{routes_run}}, $c;
+
 #::logDebug("route $c is: " . ::uneval($route));
 		##### OK, can put variables in DB all the time. It can be dynamic
 		##### from the database if $main->{dynamic_routes} is set. ITL only if
@@ -1678,6 +1692,9 @@
 		#####
 		#####
 
+		## Make route available to subsidiary files
+		$Vend::Session->{current_route} = $route;
+
 		# Compatibility 
 		if($route->{cascade}) {
 			my @extra = grep /\S/, split /[\s,\0]+/, $route->{cascade};
@@ -1770,23 +1787,42 @@
 							);
 		}
 
-		if($Vend::Session->{mv_order_number}) {
-			$::Values->{mv_order_number} = $Vend::Session->{mv_order_number};
-		}
-		elsif($route->{counter}) {
-			$::Values->{mv_order_number} = counter_number(
-												$route->{counter},
+		if($route->{counter_tid}) {
+			## This is designed to allow order number setting in
+			## the report code file
+			$Vend::Session->{mv_transaction_id} = counter_number(
+												$route->{counter_tid},
 												$route->{sql_counter},
 												$route->{first_order_number},
+												$route->{date_counter},
 											);
 		}
-		elsif($route->{increment}) {
+		elsif($Vend::Session->{mv_order_number}) {
+			$::Values->{mv_order_number} = $Vend::Session->{mv_order_number};
+		}
+		elsif(defined $route->{increment}) {
 			$::Values->{mv_order_number} = counter_number(
 												$main->{counter},
 												$main->{sql_counter},
 												$main->{first_order_number},
+												$main->{date_counter},
+											)
+				if $route->{increment};
+		}
+		elsif($route->{counter}) {
+			$::Values->{mv_order_number} = counter_number(
+												$route->{counter},
+												$route->{sql_counter},
+												$route->{first_order_number},
+												$route->{date_counter},
 											);
 		}
+
+		# Pick up transaction ID if already set
+		if($Vend::Session->{mv_transaction_id}) {
+			$::Values->{mv_transaction_id} = $Vend::Session->{mv_transaction_id};
+		}
+
 		my $pagefile;
 		my $page;
 		if($route->{empty} and ! $route->{report}) {
@@ -2038,6 +2074,11 @@
 	# Get rid of this puppy
 	$::Values->{mv_credit_card_info}
 			=~ s/^(\s*\w+\s+)(\d\d)[\d ]+(\d\d\d\d)/$1$2 NEED ENCRYPTION $3/;
+
+	# Clear these, we are done with them
+	delete $Vend::Session->{mv_transaction_id};
+	delete $Vend::Session->{current_route};
+
 	# If we give a defined value, the regular mail_order routine will not
 	# be called
 #::logDebug("route errors=$errors supplant=$main->{supplant}");








More information about the interchange-cvs mailing list