<%args> $c => 'default' <%init> use Data::Dumper; #my @bob = ( {'item_name' => 'Diana', # 'item_quantity' => '1', # 'item_image_path' => 'images/lrg-diana-sm.jpg', # 'item_price' => '125'}, # # {'item_name' => 'Isus', # 'item_quantity' => '2', # 'item_image_path' => 'images/lrg-isis-sm.jpg', # 'item_price' => '150'}); my @bob; #my $response = $m->comp('parse_response'); #$m->session->{cart_array} = \@bob; <& $c &> <%def default>
ChaliceArt Receipt
Please print this page. This is your official receipt.

<& list_cart_contents&>







<%def display_billing_info> <%init> my $response = $m->comp('get_response'); #use Data::Dumper; #print "
";
#print Dumper($response);
#$m->flush_buffer;
#$m->abort;

 
 
 
Customer Billing Information
 
First Name: 
<%$response->{'x_first_name'}%>
Last Name: 
<%$response->{'x_last_name'}%>
Address: 
<%$response->{'x_address'}%>
City: 
<%$response->{'x_city'}%>
State: 
<%$response->{'x_state'}%>
Zip Code: 
<%$response->{'x_zip'}%>
Phone: 
<%$response->{'x_phone'}%>
E-Mail: 
<%$response->{'x_email'}%>
 
   
Customer Shipping Information
 
First Name: 
%if($response->{'x_ship_to_first_name'}){ <%$response->{'x_ship_to_first_name'}%> %}else{ <%$response->{'x_first_name'}%> %}
Last Name: 
%if($response->{'x_ship_to_last_name'}){ <%$response->{'x_ship_to_last_name'}%> %}else{ <%$response->{'x_last_name'}%> %}
Address: 
%if($response->{'x_ship_to_address'}){ <%$response->{'x_ship_to_address'}%> %}else{ <%$response->{'x_address'}%> %}
City: 
%if($response->{'x_ship_to_city'}){ <%$response->{'x_ship_to_city'}%> %}else{ <%$response->{'x_city'}%> %}
State: 
%if($response->{'x_ship_to_state'}){ <%$response->{'x_ship_to_state'}%> %}else{ <%$response->{'x_state'}%> %}
Zip: 
%if($response->{'x_ship_to_zip'}){ <%$response->{'x_ship_to_zip'}%> %}else{ <%$response->{'x_zip'}%> %}
  <%def get_response> <%init> use DBI; my $x_invoice_num = $m->session->{'x_invoice_num'}; my $dbh;# = DBI->connect('DBI:mysql:CCS_Shopping_Carts', 'ccscart', 'cwebcomm'); #$dbh->disconnect; my $Table = 'Transactions'; $dbh = DBI->connect('DBI:mysql:Chaliceart', 'chaliceart', 'chaliceart'); my $response = $dbh->selectrow_hashref("select * from Transactions where x_invoice_num=?",undef,$x_invoice_num); $dbh->disconnect; return $response; <%def list_cart_contents> <%init> $m->comp('send_emails', 'response' => $m->comp('get_response')); my $list = $m->session->{cart_array}; my $subtotal = 0; my $shipping = 0; my $total = 0; % foreach my $item (@$list) { % $subtotal += ($item->{item_price} * $item->{item_quantity}); % $shipping += ($item->{item_quantity} * $item->{item_shipping}); %} <&'display_billing_info'&>
Image
Item
Quantity
Price
<%$item->{item_title}%>
<%$item->{item_name}%>
<%$item->{item_extra}%>
<%$item->{item_quantity}%>
$<%$item->{item_price} * $item->{item_quantity}%>
 
Description
Subtotal
$<%$subtotal%>
Shipping
$<%$shipping%>
Total
$<%$subtotal + $shipping%>
<%def send_emails> <%init> use MIME::Lite; my $response = $ARGS{'response'}; my $list = $m->session->{cart_array}; my $subtotal = 0; my $shipping = 0; my $total = 0; my $body_header = " Chalice Art Order Conformation "; my $body = ''; my $auth_net = "Authorize.net Information Invoice Number: ".$response->{'x_invoice_num'}." Transaction Id: ".$response->{'x_trans_id'}." Credit Card Number(last 5 didgits): ".$response->{'x_card_num'}." "; #$body .= $auth_net; #$response->{'x_response_code'} #$response->{'x_response_subcode'} #$response->{'x_response_reason_code'} #$response->{'x_response_reason_text'} #$response->{'x_auth_code'} #$response->{'x_avs_code'} #$response->{'x_trans_id'} #$response->{'x_invoice_num'} #$response->{'x_description'} #$response->{'x_amount'} #$response->{'x_method'} #$response->{'x_type'} #$response->{'x_cust_id'} #$response->{'x_first_name'} #$response->{'x_last_name'} #$response->{'x_company'} #$response->{'x_address'} #$response->{'x_city'} #$response->{'x_state'} #$response->{'x_zip'} #$response->{'x_country'} #$response->{'x_phone'} #$response->{'x_fax'} #$response->{'x_email'} #$response->{'x_ship_to_first_name'} #$response->{'x_ship_to_last_name'} #$response->{'x_ship_to_company'} #$response->{'x_ship_to_address'} #$response->{'x_ship_to_city'} #$response->{'x_ship_to_state'} #$response->{'x_ship_to_zip'} #$response->{'x_ship_to_country'} #$response->{'x_tax'} #$response->{'x_duty'} #$response->{'x_freight'} #$response->{'x_tax_exempt'} #$response->{'x_po_num'} #$response->{'x_MD5_Hash'} #$response->{'x_avs_code'} #$response->{'x_cvv2_resp_code'} $body .= "Order Information "; foreach my $item (@$list) { $subtotal += ($item->{item_price} * $item->{item_quantity}); $shipping += ($item->{item_quantity} * $item->{item_shipping}); $body .= " Item Title: ".$item->{item_title}." "; $body .= " Item Name: ".$item->{item_name}." "; $body .= " Item Extra: ".$item->{item_extra}." "; $body .= " Item Quantity: ".$item->{item_quantity}." "; $body .= " Item Subtotal: ".sprintf("%.2f",$subtotal)." "; } $body .= " Shipping: ".sprintf("%.2f",$shipping)." "; if($response->{'x_tax'}){ $body .= " Tax: ".sprintf("%.2f",$response->{'x_tax'})." "; }else{ $body .= " Tax: 0.00 "; } $body .= " Total: ".sprintf("%.2f",$response->{'x_amount'})." "; $body .= "Customer Billing Information "; $body .= " First Name: ".$response->{'x_first_name'}." "; $body .= " Last Name: ".$response->{'x_last_name'}." "; $body .= " Address: ".$response->{'x_address'}." "; $body .= " City: ".$response->{'x_city'}." "; $body .= " State: ".$response->{'x_state'}." "; $body .= " Zip: ".$response->{'x_zip'}." "; $body .= " Phone: ".$response->{'x_phone'}." "; $body .= " Email: ".$response->{'x_email'}." "; $body .= "Customer Shipping Information "; if($response->{'x_ship_to_first_name'}){ $body .= " First Name: ".$response->{'x_ship_to_first_name'}." "; }else{ $body .= " First Name: ".$response->{'x_first_name'}." "; } if($response->{'x_ship_to_last_name'}){ $body .= " Last Name: ".$response->{'x_ship_to_last_name'}." "; }else{ $body .= " Last Name: ".$response->{'x_last_name'}." "; } if($response->{'x_ship_to_address'}){ $body .= " Address: ".$response->{'x_ship_to_address'}." "; }else{ $body .= " Address: ".$response->{'x_address'}." "; } if($response->{'x_ship_to_city'}){ $body .= " City: ".$response->{'x_ship_to_city'}." "; }else{ $body .= " City: ".$response->{'x_city'}." "; } if($response->{'x_ship_to_state'}){ $body .= " State: ".$response->{'x_ship_to_state'}." "; }else{ $body .= " State: ".$response->{'x_state'}." "; } if($response->{'x_ship_to_zip'}){ $body .= " Zip: ".$response->{'x_ship_to_zip'}." "; }else{ $body .= " Zip: ".$response->{'x_zip'}." "; } #use Data::Dumper; #print "
";
#print Dumper($body,$response,$m->session);
#$m->flush_buffer;
#$m->abort;
my $body_data = $body_header.$auth_net.$body;
my $email = MIME::Lite->new(
                                To      => 'hugh@ccs-coporate.com',
                                Subject => 'Chalice Art Order Conformation',
                                From    => 'Order_Conformation@chaliceart.com',
                                Type    => 'TEXT',
Data    => $body_data) || die "foo";

$email->send;
use Data::Dumper;
print "
";
print Dumper($body,$response,$m->session);
$m->flush_buffer;
$m->abort;



<%def add_to_cart>
<%init>
my $current_cart = $m->session->{cart_array};

my $item_name = $m->request_args->{name};
my $item_extra = $m->request_args->{extra};
my $item_title = $m->request_args->{item_name};

#
# Check to see if we already have this item.  If so, then increment its quantity.

foreach (@$current_cart) {
 if ( ( $_->{item_name} eq $item_name ) 
&&    ($_->{item_extra} eq $item_extra) 
&&    ($_->{item_title} eq $item_title) ) {
   $_->{item_quantity} += 1;
   $m->redirect("cart.htm");
  }
}

#
# Add to cart
push(@$current_cart,
{   'item_title' => $m->request_args->{item_name},
    'item_name' => $m->request_args->{name},
    'item_extra' => $m->request_args->{extra},
    'item_quantity' => 1,
    'item_image_path' => $m->request_args->{image_path},
    'item_price' => $m->request_args->{price},
    'item_shipping' => $m->request_args->{shipping} } );

$m->session->{cart_array} = $current_cart;
$m->redirect("cart.htm");



<%def clear_cart>
<%init>
my @bob;
$m->session->{cart_array} = \@bob;
delete $m->session->{'x_invoice_num'};
$m->redirect("http://www.chaliceart.com");



<%def email>
<%init>
use MIME::Lite;
my $response = $ARGS{'response'};
my $email = MIME::Lite->new(
                                To      => $ARGS{'to'},
                                Subject => $ARGS{'subject'},
                                From    => $ARGS{'from'},
                                Type    => 'TEXT',
Data    =>
"
 last name:     ".$m->request_args->{lname}."
 first name:    ".$m->request_args->{fname}."
 address:       ".$m->request_args->{address}."
 city:          ".$m->request_args->{city}."
 state:         ".$m->request_args->{state}."
 zip:           ".$m->request_args->{zip}."
 phone:         ".$m->request_args->{phone}."
 date of birth: ".$m->request_args->{birth}."
 height:        ".$m->request_args->{height}."
 weight:        ".$m->request_args->{weight}."
 age:           ".$m->request_args->{age}."
 box1:          ".$m->request_args->{box1}."
 box2:          ".$m->request_args->{box2}."
 how_many:      ".$m->request_args->{how_many}."
 money1:        ".$m->request_args->{money1}."
 money2:        ".$m->request_args->{money2} );

$email->send;