"; $ipaddress_w = $_SERVER['REMOTE_ADDR']; //echo "ipaddress = $ipaddress_w
"; $orderdate_w = date("Y:m:d H:i:s"); //echo "orderdate = $orderdate_w
"; $product_w = $_SESSION['cart']; //echo "products = $product_w
"; $tmp_w = explode(',',$product_w); $items_w = count($tmp_w); //echo "items = $items_w
"; //$items = explode(',',$cart); //set expiration date for creating b_id software keys to 90 days for now $expires = date('Y-m-d', strtotime($orderdate_w.' + 90 days')); $os_w = mysqli_real_escape_string($dbi, $_POST['os']); $tos_w = mysqli_real_escape_string($dbi, $_POST['tos']); $first_w = mysqli_real_escape_string($dbi, $_POST['first']); $last_w = mysqli_real_escape_string($dbi, $_POST['last']); $shipstreet_w = mysqli_real_escape_string($dbi, $_POST['shipstreet']); $shipcity_w = mysqli_real_escape_string($dbi, $_POST['shipcity']); $shipstate_w = mysqli_real_escape_string($dbi, $_POST['shipstate']); $shipcountry_w = mysqli_real_escape_string($dbi, $_POST['shipcountry']); $shipzip_w = mysqli_real_escape_string($dbi, $_POST['shipzip']); $billstreet_w = mysqli_real_escape_string($dbi, $_POST['billstreet']); $billcity_w = mysqli_real_escape_string($dbi, $_POST['billcity']); $billstate_w = mysqli_real_escape_string($dbi, $_POST['billstate']); $billcountry_w = mysqli_real_escape_string($dbi, $_POST['billcountry']); $billzip_w = mysqli_real_escape_string($dbi, $_POST['billzip']); $email_w = mysqli_real_escape_string($dbi, $_POST['email']); $referrer_w = mysqli_real_escape_string($dbi, $_POST['referrer']); $referralcode_w = mysqli_real_escape_string($dbi, $_POST['referralcode']); $shippingmethod_w = mysqli_real_escape_string($dbi, $_POST['deliverymethod']); $submit = mysqli_real_escape_string($dbi, $_POST['submit']); $paymentmethod_w = mysqli_real_escape_string($dbi, $_POST['paymentmethod']); $ccnumber_w = mysqli_real_escape_string($dbi, $_POST['ccnumber']); $creditcode_w = mysqli_real_escape_string($dbi, $_POST['creditcode']); $ccexpiration_w = mysqli_real_escape_string($dbi, $_POST['ccexpiration']); $nameoncard_w = mysqli_real_escape_string($dbi, $_POST['nameoncard']); $cvcnumber_w = mysqli_real_escape_string($dbi, $_POST['cvcnumber']); $price_w = ""; $tax_w = ""; //set shipping method permanently to internet delivery $shippingmethod_w = 0; $total_w = ""; $serialnumber_w = ""; $productkey_w = ""; $registrationcode_w = ""; $productid_w = ""; $username_w = mysqli_real_escape_string($dbi, $_POST['username']); $password_w = mysqli_real_escape_string($dbi, $_POST['password']); $currentaction = $_GET['action']; $currentaction = mysqli_real_escape_string($dbi, $currentaction); $txn = $_GET['tx']; if (strpos($currentaction, "pp2")>0){ $paypal = 1; $currentaction = str_replace("pp2", "", $currentaction); } switch ($currentaction) { ////////////////////////////////////////////////////////////////// //Start the checkout process with billing info // ////////////////////////////////////////////////////////////////// case 'showcart': $sql1 = "SELECT * FROM purchaser_db where sessionid = '$session_w'"; $result = $dbi->query($sql1); $row = $result->fetch_assoc(); $nav = "
\"\"
"; //extract($row); $tmp2 = $row['sessionid']; $first = $row['first']; $last = $row['last']; $email = $row['email']; $billstreet = $row['billstreet']; $billcity = $row['billcity']; $billzip = $row['billzip']; $billstate = $row['billstate']; //get products and check their type $productsarray = explode(",",$product_w); $issoftware = 0; $isgoods = 0; while ($productsarray){ $productnumber = array_pop($productsarray); $tmpsql = "SELECT * FROM products where productid = '$productnumber'"; $result = $dbi->query($tmpsql); $row = $result->fetch_assoc(); $ptype = $row['Type']; if ($ptype == "1" || $ptype == "3"){ $issoftware = 1; } else if ($ptype == "2"){ $isgoods = 1; } } //check to see if record exists, update or add as necessary if ($tmp2) { $sql11 = "UPDATE purchaser_db SET sessionid = '$session_w', ipaddress = '$ipaddress_w', orderdate = '$orderdate_w' WHERE sessionid = '$session_w'"; } else { $sql11 = "INSERT INTO purchaser_db (sessionid, ipaddress, orderdate) VALUES ('$session_w', '$ipaddress_w', '$orderdate_w')"; } //echo $sql11; $result2 = $dbi->query($sql11); $code = "

  Purchaser Information

"; if ($issoftware){ $code .= " "; } $code .= ""; if ($billstate){ $code .= ""; } else { $code .= ""; } $code .= "
"; /*if ($issoftware){ $code .=""; }*/ $code .= "
Please confirm your Operating System is Windows 10, 8, or 7
Please confirm that you accept the Twigs Software License User Agreement
First Name:
Last Name:
Email:
A valid email address must be provided to complete all software purchases!

Billing Information:

Street:
City:
State:
State:
Zip Code:
Software Delivery Method:


Referred By:


Discount Code:
 
 



"; break; //////////////////////////////////////////////////////////////////// //Part 2 of the checkout process, REMOVED // //////////////////////////////////////////////////////////////////// //case 'enter1': ////////////////////////////////////////////////////////////////////// //Part 3 of the checkout process, payment info // ////////////////////////////////////////////////////////////////////// case 'enter2': $sql1 = "SELECT * FROM purchaser_db where sessionid = '$session_w'"; $result = $dbi->query($sql1); $row = $result->fetch_assoc(); //extract($row); $tmp2 = $row['sessionid']; $os = $row['os']; $tos = $row['tos']; $email = $row['email']; if ($os == 1 && !$os_w){$os_w = 1;} if ($tos == 1 && !$tos_w){$tos_w=1;} if (strlen($email)>5 && !$email_w){$email_w=$email;} if ($referralcode_w){ $refnote = "
Discount Code: Please note that your discounted pricing for Twigs will be reflected on the final checkout screen.

"; if ($referralcode_w == "Artisan2012" || $referralcode_w == "artisan2012" || $referralcode_w == "ARTISAN2012"){ $cart = "5"; $_SESSION['cart'] = $cart; } } $nav = "
\"\"
"; if ((filter_var($email_w, FILTER_VALIDATE_EMAIL))==False){$email_w="";} if (!$os_w || !$tos_w || !$email_w){ //echo "os $os_w tos $tos_w email $email_w session $session_w"; $code = "

  Purchaser Information


Error: You must confirm your operating system, agree to the Twigs Software Terms of Service, and submit a valid email address to purchase software!

Please return to step one.





"; } else if ($shippingmethod_w == "0"){ if ($submit){ $sql2 = "UPDATE purchaser_db set items='$items_w', product='$product_w', os='$os_w', tos='$tos_w', first='$first_w', last='$last_w', billstreet='$billstreet_w', billcity='$billcity_w', billstate='$billstate_w', billzip='$billzip_w', email='$email_w', isgoods='0', referrer='$referrer_w', referralcode='$referralcode_w', shippingmethod='0' WHERE sessionid='$session_w'"; $result = $dbi->query($sql2); } $code = '

OR

'; $code .= "

  Payment Information

Notice: Twigs Software purchases are available for immediate download after purchasing.  Your software download link and product key will be emailed to you at $email_w upon completion of your purchase.  Please confirm this address is correct before continuing.

Payment Type:
Card Number:
Card Expiration: (MMYY)
Cardholder Name:
Security Code: (CVC code) What is this?
Store Credit Code:
(if paying with store credit)
 
 



"; } //chose delivery method, calculate total and verify sale break; ////////////////////////////////////////////////////////////////////// //Confirm payment details and finalize order // ////////////////////////////////////////////////////////////////////// case 'enter3': $nav = "
\"\"
"; if ($submit){ $sql2 = "UPDATE purchaser_db set paymentmethod='$paymentmethod_w', ccnumber='$ccnumber_w', ccexpiration='$ccexpiration_w', nameoncard='$nameoncard_w', cvcnumber='$cvcnumber_w', creditcode='$creditcode_w' WHERE sessionid='$session_w'"; $result = $dbi->query($sql2); //capture cc information and process transaction } $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); $shippingitems = 0; $sql9 = "SELECT * FROM purchaser_db where sessionid = '$session_w'"; $result9 = $dbi->query($sql9); $row9 = $result9->fetch_assoc(); $shippingmethod_w = $row9['shippingmethod']; //set variable to ensure there aren't a large amount of items in the cart $overflow = 0; //calculate total software price $softwaretotal = 0; foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output = '

Finalize Shopping Cart

'; $output .= ''; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM products WHERE productid = '.$id; $result = $dbi->query($sql); $row = $result->fetch_array(); extract($row); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $total += $productprice * $qty; $output .= ''; //calculate the number of total items. $overflow += $qty; //if the item is software, check to see if we are shipping it if ($id <= 10){ if ($shippingmethod_w == "1"){ $shippingitems += 1*$qty; } $softwaretotal += $productprice * $qty; } //if the product id is greater than 10 we know it's not software so we must add it to shipping else { $shippingitems += 1*$qty;; } } if ($shippingitems >= 1){ $shippingcost = 6.95 + ($shippingitems-1)*1.11; } //evaluate discount code or store credit!!! // pr = percentage discount on entire cart, dp = discount price for a copy of twigs, cr = store credit in dollars $referralcodeactive = $row9['referralcode']; $creditcodeactive = $row9['creditcode']; //check to see if a referral code was entered (specific pr code) if ($referralcodeactive){ $codetype = substr($referralcodeactive, 0, 2); //check to see if it was an affiliate code if ($referralcodeactive == "A5DV0010" || $referralcodeactive == "a5dv0010"){ //set discount percentage based on affiliate relationship $crpercentage = .1; //calculate discount for software only $creditamount = $crpercentage * $softwaretotal; } else if ($referralcodeactive == "Artisan2012" || $referralcodeactive == "artisan2012" || $referralcodeactive == "ARTISAN2012"){ //set discount percentage based on affiliate relationship $crpercentage = .15; //if it is a valid discount price code, set the cart to a single copy of twigs full version //set the price to dp, set shipping and shipping method to internet delivery. //calculate discount for software only $creditamount = $crpercentage * $softwaretotal; $dpnote = "
Software Discount Applied: Your discounted pricing for Twigs Artist Edition is reflected on the final checkout screen (below).

"; } //otherwise check to see if it is a general pr code else if ($codetype == "ds" || $codetype == "DS") { $sqlcr = "SELECT * FROM discount where code = '$referralcodeactive' and expiration >= CURDATE() AND dateused = '0000-00-00'"; $resultcr = $dbi->query($sqlcr); $rowcr = $resultcr->fetch_assoc(); $crpercentage = $rowcr['percentage']; if (!$crpercentage){ $creditamount = 0; $errormssg = "
Discount Code Error: There seems to have been a problem with your discount code. Please confirm it was entered correctly, has not expired, and has not already been used in conjunction with a previous order.

"; } else { $creditamount = $crpercentage * $softwaretotal; } } // check to see if it is a discount price code else if ($codetype == "sp" || $codetype == "SP"){ $sqlcr = "SELECT * FROM discount where code = '$referralcodeactive' and expiration >= CURDATE() AND dateused = '0000-00-00'"; $resultcr = $dbi->query($sqlcr); $rowcr = $resultcr->fetch_assoc(); $discountprice = $rowcr['setprice']; if (!$discountprice){ $creditamount = 0; $errormessg = "
Discount Error: There seems to have been a problem with your discount code. Please confirm it was entered correctly, has not expired, and has not already been used in conjunction with a previous order.

"; } else { //if it is a valid discount price code, set the cart to a single copy of twigs full version //set the price to dp, set shipping and shipping method to internet delivery. $sql2 = "UPDATE purchaser_db set items='1', product='3', shippingmethod='0' WHERE sessionid='$session_w'"; $result2 = $dbi->query($sql2); $total = $discountprice; $shippingcost = 0; $creditamount = 0; $dpnote = "
Software Discount Applied: Your discount pricing for Twigs is reflected on the final checkout screen (below). You will receive one copy of Twigs and it will be available via internet download.

"; } } } //check to see if a valid credit code has been entered if ($creditcodeactive) { $sqlcr = "SELECT * FROM discount where code = '$creditcodeactive' and expiration >= CURDATE() AND dateused = '0000-00-00'"; $resultcr = $dbi->query($sqlcr); $rowcr = $resultcr->fetch_assoc(); $cramount = $rowcr['credit']; if (!$cramount){ $creditamount = 0; $errormssg = "
Store Credit Error: There seems to have been a problem with your store credit code. Please confirm it was entered correctly, has not expired, and has not already been used in conjunction with a previous order.

"; } else { $creditamount = $cramount; } } $sql_c = "SELECT * FROM purchaser_db where sessionid = '$session_w'"; $result_c = $dbi->query($sql_c); $row_c = $result_c->fetch_assoc(); //extract($row); $state1 = $row_c['shipstate']; $state2 = $row_c['billstate']; if ($state1 == "Tx" || $state1 == "tx" || $state1 == "Texas"){ $state1 = "TX"; } if ($state2 == "Tx" || $state2 == "tx" || $state2 == "Texas"){ $state2 = "TX"; } if ($state1 == "TX" || $state2 == "TX"){ $salestax = ($total - $creditamount) * 0.0825; } else { $salestax = 0; } if ($salestax < 0){$salestax = 0;} $finaltotal = $total - $creditamount + $salestax + $shippingcost; $sql2 = "UPDATE purchaser_db set price='$total', credit='$creditamount', tax='$salestax', shipping='$shippingcost', total='$finaltotal' WHERE sessionid='$session_w'"; $result2 = $dbi->query($sql2); $total = sprintf("%01.2f",$total); if ($creditamount){ $creditamount = sprintf("%01.2f",$creditamount); } $salestax = sprintf("%01.2f",$salestax); $shippingcost = sprintf("%01.2f",$shippingcost); $finaltotal = sprintf("%01.2f",$finaltotal); $output .= '
Remove'.$productname.' version '.$productversion.' Item Price: $'.$productprice.' Item Quantity: Item Total: $'.sprintf("%01.2f",$productprice * $qty).'
'; $output .= $dpnote; $output .=$errormssg; $output .= '

Total: $'.$total.'

'; if ($creditamount){ $output .= 'Software Discount Applied: $'.$creditamount.'

'; } $output .= 'Tax (Texas State Sales Tax if applicable): $'.$salestax.'

'; //$output .= 'Shipping (UPS GROUND): $'.$shippingcost.'

'; if ($finaltotal < 0){ $output .= 'Grand Total: $0.00

';} else { $output .= 'Grand Total: $'.$finaltotal.'

';} $output .= '
'; $output .= '
'; } else { $output .= '

Your shopping cart is empty.

'; } if ($overflow > 25){ $code = "

  Order Placement Error


TwigsSoftware.com is not currently accepting bulk orders online.

If you are interesting in ordering Twigs software or items from the Twigs shop in bulk, please email sales for more information and current inventories. Otherwise, please return to the shopping cart and reduce the number of items you are attempting to purchase.




"; } else { if ($paypal==1){ $code = "

  Order Placement


Please confirm the details of your order above.

Click the Check Out button only if you are satisfied and ready to submit your order for final processing.

".'
'."



"; } else { $code = "

  Order Placement


Please confirm the details of your order above.

Click the Place Order button only if you are satisfied and ready to submit your order for final processing.




"; } } break; /////////////////////////////////////////////////////////////// //Process transaction and finalize or abort // /////////////////////////////////////////////////////////////// case 'finalize': $nav = "
\"\"
"; $sql1 = "SELECT * FROM purchaser_db where sessionid = '$session_w'"; $result = $dbi->query($sql1); $row = $result->fetch_assoc(); $ccnumber = $row['ccnumber']; $ccexpiration = $row['ccexpiration']; $total = $row['total']; $first = $row['first']; $last = $row['last']; $billstreet = $row['billstreet']; $billcity = $row['billcity']; $billstate = $row['billstate']; $billzip = $row['billzip']; $cvcnumber = $row['cvcnumber']; //if total is negative or zero due to a store credit, proceed if ($total <= 0){ header('Location: https://www.twigssoftware.com/checkout.html?action=confirmation1'); echo "Total cannot be negative...aborting..."; } //$ccexpiration = substr($ccexpiration, 0, 2)."20".substr($ccexpiration,2,2); //echo $ccexpiration; //return $DEBUGGING = 0; # Display additional information to track down problems $TESTING = 0; # Set the testing flag so that transactions are not live $ERROR_RETRIES = 2; # Number of transactions to post if soft errors occur $auth_net_login_id = "74hYHqEUg76"; $auth_net_tran_key = "5rz5mBAP633K673E"; //$auth_net_url = "https://secure.authorize.net/gateway/transact.dll"; # Uncomment the line ABOVE for test accounts or BELOW for live merchant accounts $auth_net_url = "https://secure.authorize.net/gateway/transact.dll"; $authnet_values = array ( "x_login" => $auth_net_login_id, "x_version" => "3.1", "x_delim_char" => "|", "x_delim_data" => "TRUE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_tran_key" => $auth_net_tran_key, "x_relay_response" => "FALSE", "x_card_num" => $ccnumber, "x_exp_date" => $ccexpiration, "x_amount" => $total, "x_first_name" => $first, "x_last_name" => $last, "x_address" => $billstreet, "x_city" => $billcity, "x_state" => $billstate, "x_zip" => $billzip, "x_card_code" => $cvcnumber, "x_test_request" => "FALSE", ); $fields = ""; foreach( $authnet_values as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&"; //echo "
"; /////////////////////////////////////////////////////////// //echo "01: Post the transaction (see the code for specific information):
"; ### $ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); ### Uncomment the line ABOVE for test accounts or BELOW for live merchant accounts $ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); // use HTTP POST to send form data ### curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ### $resp = curl_exec($ch); //execute post and get results curl_close ($ch); //echo "
"; /////////////////////////////////////////////////////////// //echo "02: Get post results:
"; //echo $resp; //echo "
"; //echo "
"; /////////////////////////////////////////////////////////// //echo "03: Parse post results (simple approach)
"; $text = $resp; //echo ""; //echo ""; //echo ""; //echo ""; //echo "
"; $tok = strtok($text,"|"); while(!($tok === FALSE)){ //while ($tok) { //echo "     ".$tok."
"; $tok = strtok("|"); } //echo "
"; //echo "
"; /////////////////////////////////////////////////////////// //echo "04: Parse the results string into individual, meaningful segments:
"; //echo ""; /////////////////////////////////////////////////////////// // STATISTICAL USE ONLY: // /////////////////////////////////////////////////////////// //echo ""; //echo ""; //echo ""; //echo ""; $howMany = substr_count($resp, "|"); //echo ""; //echo ""; //echo ""; //echo ""; /////////////////////////////////////////////////////////// $text = $resp; $h = substr_count($text, "|"); $h++; for($j=1; $j <= $h; $j++){ $p = strpos($text, "|"); if ($p === false) { // note: three equal signs //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; }else{ $p++; // We found the x_delim_char and accounted for it . . . now do something with it // get one portion of the response at a time $pstr = substr($text, 0, $p); // this prepares the text and returns one value of the submitted // and processed name/value pairs at a time // for AIM-specific interpretations of the responses // please consult the AIM Guide and look up // the section called Gateway Response API $pstr_trimmed = substr($pstr, 0, -1); // removes "|" at the end if($pstr_trimmed==""){ $pstr_trimmed="NO VALUE RETURNED"; } //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; //echo ""; // remove the part that we identified and work with the rest of the string $text = substr($text, $p); } } //echo "
"; //echo "Length of the returned string from Authorize.Net:"; //echo ""; //echo strlen($resp); //echo "
"; //echo "Number of delimiter characters in the returned string:"; //echo ""; //echo $howMany; //echo "
"; // x_delim_char is obviously not found in the last go-around if($j>=39){ //echo "Merchant-defined (".$j."): "; //echo ": "; //echo ""; //echo $text; //echo "
"; } else { //echo $j; //echo ": "; //echo "
"; // echo $text; //echo "
"; } //echo "
"; switch($j){ case 1: //echo "Response Code: "; //echo ""; $fval=""; if($pstr_trimmed=="1"){ $response="Approved"; $setresponse = "1"; }elseif($pstr_trimmed=="2"){ $response="Declined"; $setresponse = "2"; }elseif($pstr_trimmed=="3"){ $setresponse = "3"; $response="Error"; } //echo $fval; //echo "
"; break; case 2: //echo "Response Subcode: "; //echo "
"; $responsesub = $pstr_trimmed; //echo "
"; break; case 3: //echo "Response Reason Code: "; //echo "
"; $responsereason = $pstr_trimmed; //echo "
"; break; case 4: //echo "Response Reason Text: "; //echo "
"; $responsereasontext = $pstr_trimmed; //echo "
"; break; case 5: //echo "Approval Code: "; //echo "
"; $approvalcd = $pstr_trimmed; //echo "
"; break; case 6: //echo "AVS Result Code: "; //echo "
"; $avscd = $pstr_trimmed; //echo "
"; break; case 7: //echo "Transaction ID: "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 8: //echo "Invoice Number (x_invoice_num): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 9: //echo "Description (x_description): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 10: //echo "Amount (x_amount): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 11: //echo "Method (x_method): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 12: //echo "Transaction Type (x_type): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 13: //echo "Customer ID (x_cust_id): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 14: //echo "Cardholder First Name (x_first_name): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 15: //echo "Cardholder Last Name (x_last_name): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 16: //echo "Company (x_company): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 17: //echo "Billing Address (x_address): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 18: //echo "City (x_city): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 19: //echo "State (x_state): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 20: //echo "ZIP (x_zip): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 21: //echo "Country (x_country): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 22: //echo "Phone (x_phone): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 23: //echo "Fax (x_fax): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 24: //echo "E-Mail Address (x_email): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 25: //echo "Ship to First Name (x_ship_to_first_name): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 26: //echo "Ship to Last Name (x_ship_to_last_name): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 27: //echo "Ship to Company (x_ship_to_company): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 28: //echo "Ship to Address (x_ship_to_address): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 29: //echo "Ship to City (x_ship_to_city): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 30: //echo "Ship to State (x_ship_to_state): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 31: //echo "Ship to ZIP (x_ship_to_zip): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 32: //echo "Ship to Country (x_ship_to_country): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 33: //echo "Tax Amount (x_tax): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 34: //echo "Duty Amount (x_duty): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 35: //echo "Freight Amount (x_freight): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 36: //echo "Tax Exempt Flag (x_tax_exempt): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 37: //echo "PO Number (x_po_num): "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 38: //echo "MD5 Hash: "; //echo "
"; //echo $pstr_trimmed; //echo "
"; break; case 39: //echo "Card Code Response: "; //echo "
"; $fval=""; if($pstr_trimmed=="M"){ $fval="M = Match"; }elseif($pstr_trimmed=="N"){ $fval="N = No Match"; }elseif($pstr_trimmed=="P"){ $fval="P = Not Processed"; }elseif($pstr_trimmed=="S"){ $fval="S = Should have been present"; }elseif($pstr_trimmed=="U"){ $fval="U = Issuer unable to process request"; }else{ $fval="NO VALUE RETURNED"; } $_SESSION['response'] = $response; $_SESSION['responsesub'] = $responsesub; $_SESSION['responsereason'] = $responsereason; $_SESSION['responsereasontext'] = $responsereasontext; $_SESSION['approvalcd'] = $approvalcd; $_SESSION['avscd'] = $avscd; if ($setresponse == "1"){ header('Location: https://www.twigssoftware.com/checkout.html?action=confirmation1'); } else if ($setresponse == "2"){ header('Location: https://www.twigssoftware.com/checkout.html?action=confirmation2'); } else { header('Location: https://www.twigssoftware.com/checkout.html?action=confirmation3'); } //echo $fval; //echo "
"; break; default: if($j>=39){ //echo "Merchant-defined (".$j."): "; //echo ": "; //echo "
"; //echo $pstr_trimmed; //echo "
"; } else { //echo $j; //echo ": "; //echo "
"; //echo $pstr_trimmed; //echo "
"; } break; } //echo "
"; //echo "
"; //echo "
"; //echo "04: Done.
"; $code = ""; break; //////////////////////////////////////////////////////////////////////// //Get Results from a paypal payment and record// //////////////////////////////////////////////////////////////////////// case 'confirmationpay': //echo $txn; //Returns// /*46139571YH140421P

Thank you for your purchase!

Payment Details
  • Name: Keith Downing
  • Item: Twigs Software Order
  • Amount: 1.50
  • */ $pp_hostname = "www.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-synch'; $tx_token = $_GET['tx']; $auth_token = "8ihhdwyn536maxJvZllqINxFQZ6MAlBUsp0iLJAz2MFCHVQqiFKymwTqTTO"; $req .= "&tx=$tx_token&at=$auth_token"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); //set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here, //if your server does not bundled with default verisign certificates. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname")); $res = curl_exec($ch); curl_close($ch); if(!$res){ //HTTP ERROR } else{ // parse the data $lines = explode("\n", $res); $keyarray = array(); if (strcmp ($lines[0], "SUCCESS") == 0) { for ($i=1; $i

    Thank you for your purchase!

    "); echo ("Payment Details
    \n"); echo ("
  • Name: $firstname $lastname
  • \n"); echo ("
  • Item: $itemname
  • \n"); echo ("
  • Amount: $amount
  • \n"); echo ("");*/ $paypalinfo = "Success: ".$firstname." ".$lastname.", ".$itemname.", ".$amount.", ".$txn." : ".$res; $paypl = "UPDATE purchaser_db set paymentmethod='paypal', paypalinfo='$paypalinfo' WHERE sessionid = '$session_w'"; $resultpaypl = $dbi->query($paypl); //set order processed amount for paypal receipt $_SESSION['paypalamount'] = $amount; header('Location: https://www.twigssoftware.com/checkout.html?action=confirmation1'); } else if (strcmp ($lines[0], "FAIL") == 0) { // log for manual investigation $paypl = "UPDATE purchaser_db set paypalinfo='$res' WHERE sessionid = '$session_w'"; $resultpaypl = $dbi->query($paypl); $code = "

    Order Error:

    There has been an error with your order.
    Paypal Returned an Invalid Response

    Please return to the shopping cart and make the necessary changes in order for us to complete processing.


    "; } } break; /////////////////////////////////////////////////////////////////////////////////////////// //Return results and send keys if Approved or amount due <0 // /////////////////////////////////////////////////////////////////////////////////////////// case 'confirmation1': //Confirm total charged $sql1 = "SELECT * FROM purchaser_db where sessionid = '$session_w'"; $result = $dbi->query($sql1); $row = $result->fetch_assoc(); $price = $row['price']; $tax = $row['tax']; $shipping = $row['shipping']; $creditamount = $row['credit']; $creditcode = $row['creditcode']; $discountcode = $row['referralcode']; $total = $row['total']; $email = $row['email']; $first = $row['first']; $last = $row['last']; $shipstreet = $row['shipstreet']; $shipcity = $row['shipcity']; $shipstate = $row['shipstate']; $shipzip = $row['shipzip']; $items = $row['items']; $product = $row['product']; $shippingmethod = $row['shippingmethod']; $purchaserid = $row['purchaserid']; $paypalamount = $_SESSION['paypalamount']; session_regenerate_id(); $session_w = session_id(); unset($_SESSION['cart']); if ($paypalamount == $total){ $response="Paypal"; } if ($total<=0 || $response=="Approved" || $response=="Paypal"){ //echo "Total $total Response $response"; //this area needs refinement //* //* //if a credit code was entered, enter it into the discount db if ($creditcode && $creditamount){ if ($creditcode != "A5DV0010" && $creditcode != "a5dv0010" && $creditcode != "Artisan2012" && $creditcode != "artisan2012" && $creditcode != "ARTISAN2012"){ //get remaining credit, which is the total //get credit amount //confirm credit still exists //update discount table with new credit and amounts spent //if credit still exists, set dateused to 0000-00-00 $actualtotal = $price+$tax+$shipping; $sqlcr = "SELECT * FROM discount where code = '$creditcode' and expiration >= CURDATE() "; $resultcr = $dbi->query($sqlcr); $rowcr = $resultcr->fetch_assoc(); $cramount = $rowcr['credit']; //check to see if credit available is greater or equal to what we have already included if ($cramount >= $creditamount){ //if so, check to see if there is a remaining credit if ($total < 0){ $newcredit = $cramount - $actualtotal; $sqlcredit = "UPDATE discount set purchaserid='$purchaserid', credit='$newcredit', amount=amount+$actualtotal, dateused='0000-00-00' WHERE code='$creditcode'"; //echo $sqlcredit; $resultcredit = $dbi->query($sqlcredit); } else { $sqlcredit = "UPDATE discount set purchaserid='$purchaserid', credit='0', amount=amount+$creditamount, dateused='$orderdate_w' WHERE code='$creditcode'"; $resultcredit = $dbi->query($sqlcredit); } } else {$Code ="There was a problem processing your store credit. Please try starting the process again.";goto end;} } } //* //* //* //if a discount/referrall code was entered, enter it into the discount db if ($discountcode && $creditamount){ if ($discountcode != "A5DV0010" && $discountcode != "a5dv0010" && $discountcode != "Artisan2012" && $discountcode != "artisan2012" && $discountcode != "ARTISAN2012"){ $sqlcredit = "UPDATE discount set purchaserid='$purchaserid', amount='$creditamount', dateused='$orderdate_w' WHERE code='$discountcode'"; $resultcredit = $dbi->query($sqlcredit); } } //* //* //* //get products and check their type $productsarray = explode(",",$product); $issoftware = 0; $isgoods = 0; $itemshere = 0; //find number of lite keys to generate $litekeys_n = 0; //find number of full keys to generate $fullkeys_n = 0; $b_id = []; while ($productsarray){ $productnumber = array_pop($productsarray); if ($productnumber == "1"){ $litekeys_n += 1; } if ($productnumber == "2" || $productnumber == "3" || $productnumber == "5"|| $productnumber == "8"|| $productnumber == "9"){ $fullkeys_n += 1; } $tmpsql = "SELECT * FROM products where productid = '$productnumber'"; $result = $dbi->query($tmpsql); $row = $result->fetch_assoc(); $ptype = $row['Type']; if ($ptype == "1"){ $issoftware = 1; } else if ($ptype == "2"){ $isgoods = 1; if ($itemshere){ $goodstoship = $goodstoship.",".$productnumber; } else { $goodstoship = $productnumber; $itemshere = 1; } } else if ($ptype == "3"){ $issoftware = 1; $isnottwigs = 1; array_push($b_id, $productnumber); } } // // //check to see if software is being sold if ($issoftware) { //enter the order into the orders database //check to see if we are shipping the software (and thus all items) if ($shippingmethod){ $sql11 = "INSERT INTO orders (purchaser, orderdate, p_id, p_id_tobeshipped) VALUES ('$purchaserid', '$orderdate_w', '$product', '$product')"; } //check to see if we are shipping goods but not software else if ($isgoods){ $sql11 = "INSERT INTO orders (purchaser, orderdate, p_id, p_id_tobeshipped) VALUES ('$purchaserid', '$orderdate_w', '$product', '$goodstoship')"; } //else, there is nothing to ship else { $sql11 = "INSERT INTO orders (purchaser, orderdate, filldate, p_id, filled) VALUES ('$purchaserid', '$orderdate_w', '$orderdate_w', '$product', '1')"; } $result = $dbi->query($sql11); //loop to find the next lite product keys that are not expiring within 30 days $i = $litekeys_n; $litekeys; $fullkeys; while ($i >= 1){ $sqlkey = "SELECT * FROM `p_id` WHERE `assigned` = 0 and `keytype` = 1 and `expiration` >= DATE_ADD(CURDATE(), INTERVAL 31 DAY)"; $resultkey = $dbi->query($sqlkey); $rowkey = $resultkey->fetch_assoc(); $productkey = $rowkey['productkey']; $litekeys .= $productkey."\n"; //assign product key to purchaser_db and set purchaser, assigned, and dateassigned in p_id database $sqlpid = "UPDATE p_id set assigned=1, purchaser='$purchaserid', dateassigned=CURDATE() WHERE productkey='$productkey'"; $resultpid = $dbi->query($sqlpid); $i--; } //loop to find next product keys that are not expiring within 30 days $j = $fullkeys_n; while ($j >= 1){ $sqlkey = "SELECT * FROM `p_id` WHERE `assigned` = 0 and `keytype` = 3 and `expiration` >= DATE_ADD(CURDATE(), INTERVAL 31 DAY)"; $resultkey = $dbi->query($sqlkey); $rowkey = $resultkey->fetch_assoc(); $fullkeys .= $rowkey['productkey']."\n"; $productkey = $rowkey['productkey']; //assign product key to purchaser_db and set purchaser, assigned, and dateassigned in p_id database $sqlpid = "UPDATE p_id set assigned=1, purchaser='$purchaserid', dateassigned=CURDATE() WHERE productkey='$productkey'"; $resultpid = $dbi->query($sqlpid); $j--; } $keyn = $litekeys_n + $fullkeys_n; //set processed = 1, set order date $sqlpd = "UPDATE purchaser_db set processed=1, productkey='$keyn' WHERE purchaserid='$purchaserid'"; $resultpd = $dbi->query($sqlpd); //if we are downloading software this will be the result if ($shippingmethod == "0"){ //email confirmation (product link and product key if online delivery requested) $message = $first.", thank you for your order from TwigsSoftware.com. \n\n"; if ($litekeys_n == 1){ $message .= "Twigs Lite Personal Knowledge Base\nSingle User License\n\n"; $keytext = "Your Twigs Lite product key is ".$litekeys."\nPlease be sure to have this key available when you install the software.\n\n"; } if ($litekeys_n > 1){ $message .= "Twigs Lite Personal Knowledge Base\n".$litekeys_n." Licenses\n\n"; $keytext = "\n\nYour Twigs Lite product keys are:\n".$litekeys."\nPlease distribute these keys with each licensed download and make sure that end users have their key available during installation."; } if ($fullkeys_n == 1){ $message .= "Twigs Personal Knowledge Base\nSingle User License\n\n"; $keytext .= "Your Twigs product key is ".$fullkeys."\nPlease be sure to have this key available when you install the software.\n\n"; } if ($fullkeys_n > 1){ $message .= "Twigs Personal Knowledge Base\n".$fullkeys_n." Licenses\n\n"; $keytext .= "\n\nYour Twigs product keys are:\n".$fullkeys."\nPlease distribute these keys with each licensed download and make sure that end users have their key available during installation."; } if ($isnottwigs == 1){ $software_packages = array_unique($b_id); if (array_unique($b_id) == $b_id){$thissize=1;$alreadyentered=1;} foreach ($software_packages as $s){ $sql2 = "Select productname from products where productid = $s"; $result2 = $dbi->query($sql2); $row2 = $result2->fetch_row(); $packagename = $row2[0]; if ($thissize==1){ $key = decryptkey($email, $s); $keytext .= "\n\nYour $packagename installation key is ".$key.".\nPlease be sure to have this key available when you install the software.\n\n"; $message .= "$packagename Licenses\n\n"; $thisid = array_pop($b_id); $sql111 = "INSERT INTO b_id (purchaser, keytype, expiration, email, productkey, assigned, dateassigned) VALUES ('$purchaserid', '$s', '$expires', '$email', '$key', '1', '$orderdate_w' )"; $result = $dbi->query($sql111); } else {$message .= "$packagename Licenses\n\n";} } } //determinine if discount should be included in pricing if($creditamount){ if ($total < 0){$total = "0.00"; $tax="0.00";} $message .= "Order Price: ".$price."\nDiscount Applied: ".$creditamount."\nTax: ".$tax."\nTotal Charges: ".$total."\n\nSoftware Shipping Method: Internet Download\n\n".$keytext."\n\nTo download your software package, please visit: http://www.TwigsSoftware.com/download.html?action=".$purchaserid."\n\nThank you for your purchase!\n\nTwigSoft Support\nsupport@twigssoftware.com"; } else { $message .= "Order Price: ".$price."\nTax: ".$tax."\nTotal Charges: ".$total."\n\nSoftware Shipping Method: Internet Download\n\n".$keytext."\n\nTo download your software package, please visit: http://www.TwigsSoftware.com/download.html?action=".$purchaserid."\n\nTwigSoft Support\nsupport@twigssoftware.com"; } $message = wordwrap($message, 70); $headers = 'From: orders@twigssoftware.com' . "\r\n" . 'Reply-To: support@twigssoftware.com' . "\r\n"; mail ( $email, 'Order Completed', $message, $headers); //email order confirmation to us (owners) $message = "A new order for Twigs Software has been placed!\n\nTo view the order details, please visit http://www.Twigssoftware.com/orderprocess.html?action=".$purchaserid."\n"; $message = wordwrap($message, 70); $headers = 'From: orders@twigssoftware.com' . "\r\n" . 'Reply-To: support@twigssoftware.com' . "\r\n"; mail ( 'orders@twigssoftware.com', 'Order Confirmation', $message, $headers); $output = "
    \"\"


    "; $code = "

      Order Completed


    Your transaction has been approved!

    A confirmation email with your order details and instructions on how to complete product downloads has been sent to you at ".$email.".

    Thank you for your purchase!

    Note: Some email and spam filters may attempt to filter this email. Please make sure you check those folders and settings if you have problems receiving the confirmation message.




    "; session_unset(); session_regenerate_id(); } else { //email confirmation product key and shipping information $message = $first.", thank you for your order from TwigsSoftware.com. \n\n"; if ($litekeys_n == 1){ $message .= "Twigs Lite Personal Knowledge Base\nSingle User License\n\n"; $keytext = "Your Twigs Lite product key is ".$litekeys."\nPlease be sure to have this key available when you install the software.\n\n"; } if ($litekeys_n > 1){ $message .= "Twigs Lite Personal Knowledge Base\n".$litekeys_n." Licenses\n\n"; $keytext = "\n\nYour Twigs Lite product keys are:\n".$litekeys."\nPlease distribute these keys with each licensed download and make sure that end users have their key available during installation."; } if ($fullkeys_n == 1){ $message .= "Twigs Personal Knowledge Base\nSingle User License\n\n"; $keytext .= "Your Twigs product key is ".$fullkeys."\nPlease be sure to have this key available when you install the software.\n\n"; } if ($fullkeys_n > 1){ $message .= "Twigs Personal Knowledge Base\n".$fullkeys_n." Licenses\n\n"; $keytext .= "\n\nYour Twigs product keys are:\n".$fullkeys."\nPlease distribute these keys with each licensed download and make sure that end users have their key available during installation."; } if($creditamount){ $message .= "Order Price: ".$price."\nDiscount Applied: ".$creditamount."\nTax: ".$tax."\nTotal Charges: ".$total."\n\nSoftware Shipping Method: UPS Ground\n\n".$keytext."\n\nOnce your order has been processed and shipped you will receive an additional email which will include your UPS tracking code.\n\nThank you for your purchase!\n\nTwigSoft Support\nsupport@twigssoftware.com"; } else { $message .= "Order Price: ".$price."\nTax: ".$tax."\nTotal Charges: ".$total."\n\nSoftware Shipping Method: UPS Ground\n".$keytext."\n\nOnce your order has been processed and shipped you will receive an additional email which will include your UPS tracking code.\n\nThank you for your purchase!\n\nTwigSoft Support\nsupport@twigssoftware.com"; } $message = wordwrap($message, 70); $headers = 'From: orders@twigssoftware.com' . "\r\n" . 'Reply-To: support@twigssoftware.com' . "\r\n"; mail ( $email, 'Order Completed', $message, $headers); //email order confirmation to us (owners) $message = "A new order for Twigs Software has been placed!\n\nTo view the order details, please visit http://www.Twigssoftware.com/orderprocess.html?action=".$purchaserid."\n"; $message = wordwrap($message, 70); $headers = 'From: orders@twigssoftware.com' . "\r\n" . 'Reply-To: support@twigssoftware.com' . "\r\n"; mail ( 'orders@twigssoftware.com', 'Order Confirmation', $message, $headers); $output = "
    \"\"


    "; $code = "

      Order Completed


    Your transaction has been approved!

    A confirmation email with your order details and software download information has been sent to you at ".$email.".

    Thank you for your purchase!




    "; session_unset(); session_regenerate_id(); } //insert software that are not twigs into the b_id table to allow multiple keys to be generated if (sizeof($b_id)>0 && $alreadyentered !=1){ while ($b_id){ $thisid = array_pop($b_id); $sql111 = "INSERT INTO b_id (purchaser, keytype, expiration, email) VALUES ('$purchaserid', '$thisid', '$expires', '$email')"; $result = $dbi->query($sql111); } } } // // //if we are shipping only goods this will be the result //////////////////////////////////////////////////////////////////////////// //SECTION REMOVED; see checkout.html.OLD // /////////////////////////////////////////////////////////////////////////// } else { $nav = "
    \"\"
    "; $code = "

      Order Status

    Order Error:

    There has been an error with your order.
    Authorization Code Invalid

    Please return to the shopping cart and make the necessary changes in order for us to complete processing.



    "; $code .= $total." ".$paypalamount; } break; ////////////////////////////////////////////////////////////////////// //Return Error for Declined Credit Card // ////////////////////////////////////////////////////////////////////// case 'confirmation2': $nav = "
    \"\"
    "; $code = "

      Order Status

    Order Error:

    Your transaction has been declined.

    $response -- $responsereasontext

    Please return to the payment information section of the checkout process and correct your payment information.




    "; break; ////////////////////////////////////////////////////////////////////// //Return Error for cc code verification failure // ////////////////////////////////////////////////////////////////////// case 'confirmation3': $nav = "
    \"\"
    "; $code = "

      Order Status

    Order Error:

    There has been an error with your order.
    $responsereasontext

    Please return to the shopping cart and make the necessary changes in order for us to complete processing.



    "; break; } end: echo $head; if ($output) { echo $output; } else { echo "

    Shopping Cart:

    "; echo writeShoppingCart(); echo showCart(); echo "

    "; } echo $refnote; echo $nav; echo "
    "; echo $code; echo "
    "; echo $foot; ?>