PearlJam: Ten Club Store
Final Order Processing
var:'timer'=(integer:_date_msec); Include:'html/setup.lasso'; Encode_Set:-EncodeNone; var: 'EmailAddress'=(action_param:'EmailAddress'), 'Phone1'=(action_param:'Phone1'); if:!$Phone1; $Phone1='206-555-1212'; /if; if:!(Variable_Defined:'VisitorID') || ((action_param:'VisitorID') != $VisitorID); $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Customer number not found. Please try again.'; else:!(Session_ID:-Name='pj'); $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Session not transferred. Please try again. Or report this error to the site admin'; else:!$BillAddressID; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Billing Address not found. Please try again.'; else:!$ShipAddressID; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Shipping Address not found missing. Please try again.'; else:!(Variable_Defined:'cart') || (($cart->size) == 0); $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Cart contents not found. Please try again.'; else:!$EmailAddress; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Your email address was not found. Please try again.'; else:(action_param:'CardNumber') == ''; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. No card number was entered. Please try again.'; else; var: 'BillingAddress'='', 'BillRegionID'=0, 'CCGatewayParams'=(array), 'CCGatewayResult'=(array), 'bPackList'='n', 'bForeignShipping'='y', 'bDoubleLabels'='y', 'bTaxable'='n', 'bEmail'='n', 'iPrintLabel'=0, 'iPackList'=0, 'countrycode'='', 'GrandTotal'=0, 'iCategory'=0, 'iEmail'=0, 'OrderArray'=(array), 'OrderId'='', 'Postal'='', 'Rmap'=(map), 'ShippingAddress'='', 'ShippingCost'=0, 'ShipRegionID'=0, 'SubTotal'=0, 'stateprov'='', 'sWLAddressSentTo'='None', 'Tax2Add'=0, 'temp'='', 'total4shipping'=0, 'total4Tax'=0; // Lookup Billing address details var:'STMT'=('SELECT AddressID, AddressLine1, AddressLine2, City, CountryID, NameFirstAddress, NameLastAddress, Postal, Region, RegionID ' + 'FROM ' + $Use4DB + '.Addresses WHERE VisitorID=' + $VisitorID + ' AND AddressID=' + $BillAddressID + ';'); Inline: -database=$Use4DB, -SQL=$STMT, -maxrecords=1; if:(found_count) == 0; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Billing Address not found. Please try again.'; else:(Field:'CountryID') == 0; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Billing Address does not contain country information. Please try again.'; else:$BillAddressID == (field:'AddressID'); $BillRegionID=(Field:'RegionID'); $Postal=(Field:'Postal'); $countrycode=(MCID2CountryCode:(Field:'CountryID')); if:(Field:'RegionID') == 0; $stateprov=(Field:'Region'); else; $stateprov=(String_GetField:-FieldNumber=1,-Delimiter=';',(MCID2Region:(Field:'RegionID'))); /if; if:$stateprov == ''; $stateprov='na'; /if; if:$Postal == ''; $Postal='na'; /if; $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_countrycode'=$countrycode)); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_postalcode'=$Postal)); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_stateprov'=$stateprov)); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_street_line1'=(Field:'AddressLine1'))); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_street_line2'=(Field:'AddressLine2'))); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_city'=(Field:'City'))); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_name_first'=(Field:'NameFirstAddress'))); $CCGatewayParams->(insert:(pair:'Shop_Billto_postal_name_last'=(Field:'NameLastAddress'))); $CCGatewayParams->(insert:(pair:'Shop_Payment_Card_Name'=((Field:'NameFirstAddress') + ' ' + (Field:'NameLastAddress')))); $BillingAddress=((field:'NameFirstAddress') + ' ' + (field:'NameLastAddress')); if:$BillingAddress && (! $BillingAddress->(EndsWith:'\n')); $BillingAddress += '\n'; /if; $BillingAddress += (field:'AddressLine1'); if:$BillingAddress && (! $BillingAddress->(EndsWith:'\n')); $BillingAddress += '\n'; /if; $BillingAddress += (field:'AddressLine2'); if:$BillingAddress && (! $BillingAddress->(EndsWith:'\n')); $BillingAddress += '\n'; /if; $BillingAddress += ((field:'City') + ' ' + (field:'Region') + ' ' + (String_GetField:-FieldNumber=1,-Delimiter=';',(MCID2Region:(Field:'RegionID'))) + ' ' + (field:'Postal')); if:$BillingAddress && (! $BillingAddress->(EndsWith:'\n')); $BillingAddress += '\n'; /if; $BillingAddress += (MCID2Country:(Field:'CountryID')); /if; /Inline; // Lookup shipping address details to store in order var:'STMT'=('SELECT AddressID, AddressLine1, AddressLine2, City, CountryID, NameFirstAddress, NameLastAddress, Postal, Region, RegionID, WLVisitorID ' + 'FROM ' + $Use4DB + '.Addresses WHERE VisitorID=' + $VisitorID + ' AND AddressID=' + $ShipAddressID + ';'); Inline: -database=$Use4DB, -SQL=$STMT; if:(found_count) > 0; if:(Field:'WLVisitorID') == 0; $ShipRegionID=(Field:'RegionID'); $ShippingAddress=((field:'NameFirstAddress') + ' ' + (field:'NameLastAddress')); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += (field:'AddressLine1'); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += (field:'AddressLine2'); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += ((field:'City') + ' ' + (field:'Region') + ' ' + (String_GetField:-FieldNumber=1,-Delimiter=';',(MCID2Region:(Field:'RegionID'))) + ' ' + (field:'Postal')); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += (MCID2Country:(Field:'CountryID')); else; $sWLAddressSentTo = 'Withheld'; // this address needs to be looked up from another visitor and is withheld from view by current user var:'STMT'=('SELECT AddressID, AddressLine1, AddressLine2, City, CountryID, NameFirstAddress, NameLastAddress, Postal, Region, RegionID, WLVisitorID ' + 'FROM ' + $Use4DB + '.Addresses WHERE VisitorID=' + (Field:'WLVisitorID') + ' AND bPrimary=\'y\';'); Inline: -database=$Use4DB, -SQL=$STMT; if:(found_count) > 0; $ShipRegionID=(Field:'RegionID'); $ShippingAddress=((field:'NameFirstAddress') + ' ' + (field:'NameLastAddress')); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += (field:'AddressLine1'); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += (field:'AddressLine2'); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += ((field:'City') + ' ' + (field:'Region') + ' ' + (String_GetField:-FieldNumber=1,-Delimiter=';',(MCID2Region:(Field:'RegionID'))) + ' ' + (field:'Postal')); if:$ShippingAddress && (! $ShippingAddress->(EndsWith:'\n')); $ShippingAddress += '\n'; /if; $ShippingAddress += (MCID2Country:(Field:'CountryID')); /if; if:((found_count) == 0) || ($ShippingAddress == ''); $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Shipping Address for the wish list recipient could not be found.'; /if; /inline; /if; else; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Shipping Address was not found.'; /if; /inline; if:!$errorFlag; // Convert Cart into Order List with all Details Loop:($cart->size); var: 'OrderItemMap'=(map), 'extended'='', 'UnitID'=($cart->(get:(loop_count))->name), 'cPrice'=($cart->(get:(loop_count))->value->(find:'up')), 'qty'=($cart->(get:(loop_count))->value->(find:'qty')); $OrderItemMap=(GetProductDetails:$UnitID,'other'); $OrderItemMap->(insert:'UnitID'=$UnitID); // The price is retrieved by GetProductDetails but over-ridden here to be the value as it was in the cart $OrderItemMap->(insert:'cPrice'=$cPrice); $OrderItemMap->(insert:'qty'=$qty); $OrderItemMap->(insert:'wl'=($cart->(get:(loop_count))->value->(find:'wl'))); $OrderItemMap->(insert:'p'=($cart->(get:(loop_count))->value->(find:'p'))); $extended=((integer:($OrderItemMap->(find:'cPrice'))) * (integer:$qty)); $SubTotal += $extended; if:($OrderItemMap->(find:'bShp')) == 'y'; $total4shipping += $extended; /if; if:($OrderItemMap->(find:'bTx')) == 'y'; $total4Tax += $extended; /if; if:($OrderItemMap->(find:'bWebLabel')) == 'y'; $iPrintLabel += (decimal:($OrderItemMap->(find:'fLabelRequired'))); /if; if:($OrderItemMap->(find:'wl')) > 0; $sWLAddressSentTo = 'Entered'; /if; $OrderArray->(insert:$OrderItemMap); if:(loop_count) == 1; $iCategory=(String_Extract:-StartPosition=1,-EndPosition=1,($OrderItemMap->(find:'pn'))); else; if:(String_Extract:-StartPosition=1,-EndPosition=1,($OrderItemMap->(find:'pn'))) != $iCategory; $iCategory=0; /if; /if; if:($OrderItemMap->(find:'MessageID')) > 0; $iEmail += 1; $bEmail = 'y'; /if; if:($OrderItemMap->(find:'bPackList')) == 'y'; $bPackList = 'y'; $iPackList = 1; /if; var:'iLimitQty'=(integer:($OrderItemMap->(find:'iLimitQty'))); if:$iLimitQty > 0; if:$iLimitQty < $qty; $errorFlag=true; $errorCode=7777; $errorMsg='ERROR: This product, #' + ($OrderItemMap->(find:'pn')) + ($OrderItemMap->(find:'sSize')) + ' ' + ($OrderItemMap->(find:'p')) + ', has a quantity limit of ' + $iLimitQty + '.'; else; // Verify that this item was not ordered in a previous order by this same VisitorID var:'TotPrev'=$qty,'STMT'=('SELECT iQtyOrder FROM ' + $Use4DB + '.Orders, ' + $Use4DB + '.OrderItems WHERE Orders.OrderID=OrderItems.OrderID AND Orders.VisitorID=' + $VisitorID + ' AND OrderItems.UnitID=' + $UnitID + ';'); Inline: -database=$Use4DB, -SQL=$STMT; records; $TotPrev += (integer:(field:'iQtyOrder')); /records; /Inline; if:$iLimitQty < $TotPrev; $errorFlag=true; $errorCode=7777; $errorMsg='ERROR: This product, #' + ($OrderItemMap->(find:'pn')) + ($OrderItemMap->(find:'sSize')) + ' ' + ($OrderItemMap->(find:'p')) + ', has a quantity limit of ' + $iLimitQty + '.'; /if; /if; /if; /Loop; If:$ShipRegionID > 0; Inline: -Database=$Use4DB, -SQL=('SELECT bUSShippingApplies, bDoubleShippingLabels FROM ' + $Use4DB + '.Regions WHERE RegionID=' + $ShipRegionID); if:(found_count) > 0; if:(field:'bUSShippingApplies') == 'y'; $bForeignShipping='n'; /if; $bDoubleLabels=(field:'bDoubleShippingLabels'); /if; /Inline; /if; $iPrintLabel = (math_ceil:$iPrintLabel); // Double the printlabel value if the Region indicates it should be done or is a foreign address if:$bDoubleLabels == 'y'; $iPrintLabel *= 2; /if; if:!$errorFlag; If:$total4shipping > 0; $ShippingCost=(ShippingCost:$total4shipping,$ShipRegionID); /if; if:$total4Tax > 0; $Tax2Add=(TaxAdd:($total4Tax + $ShippingCost),$ShipRegionID); /if; if:$Tax2Add > 0; $bTaxable = 'y'; /if; $GrandTotal=($SubTotal + $ShippingCost + $Tax2Add); $CCGatewayParams->(insert:(pair:'CCGateway_merchant_id'='TenClub')); $CCGatewayParams->(insert:(pair:'CCGateway_auto_settle_flag'='N')); $CCGatewayParams->(insert:(pair:'CCGateway_merchant_shopper_id'=$VisitorID)); $CCGatewayParams->(insert:(pair:'CCGateway_merchant_order_id'=(session_id:-name='pj'))); $CCGatewayParams->(insert:(pair:'Shop_Payment_Card_ExpDate_Month'=(action_param:'CardMonth'))); $CCGatewayParams->(insert:(pair:'Shop_Payment_Card_ExpDate_Year'=(action_param:'CardYear'))); $CCGatewayParams->(insert:(pair:'Shop_payment_card_number'=(action_param:'CardNumber'))); $CCGatewayParams->(insert:(pair:'Shop_Billto_telShop_phone_number'=$Phone1)); $CCGatewayParams->(insert:(pair:'Shop_Billto_online_email'=$EmailAddress)); $CCGatewayParams->(insert:(pair:'CCGateway_order_price_amount'=(Currency:$SubTotal))); $CCGatewayParams->(insert:(pair:'CCGateway_order_ship_amount'=(Currency:$ShippingCost))); $CCGatewayParams->(insert:(pair:'CCGateway_order_tax_amount'=(Currency:$Tax2Add))); $CCGatewayParams->(insert:(pair:'CCGateway_order_total_amount'=(Currency:$GrandTotal))); $CCGatewayResult=((Include_URL:'https://cart.bamart.com/payment.mart',-sendmimeheaders=(array:'Referer'='kapu.doublesecret.net'),-POSTParams=$CCGatewayParams)->(Split:'')); loop:$CCGatewayResult->(Size); $temp=($CCGatewayResult->(Get:(loop_count))); var: 'thisParam'=(String_GetField:-FieldNumber=1,-Delimiter='=',$temp), 'thisVal'=(String_GetField:-FieldNumber=2,-Delimiter='=',$temp); if:$thisParam && $thisVal; $Rmap->(insert:$thisParam=$thisVal); /if; /loop; if:(($Rmap->(find:'Shop_transaction_complete')) == 'False') || (($Rmap->(find:'Shop_transaction_complete')) == ''); $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. An unknown communication error occurred. Please try again.'; else:($Rmap->(find:'CCGateway_merchant_shopper_id')) != $VisitorID; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. The Customer ID for the transaction does not match the current Customer ID.'; else:($Rmap->(find:'CCGateway_merchant_order_id')) != (Session_ID:-Name='pj'); $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. The Session ID for the transaction does not match the current Session ID.'; else:((($Rmap->(find:'Shop_transaction_complete')) == 'True') && (($Rmap->(find:'CCGateway_response_code')) < 1) && (($Rmap->(find:'CCGateway_response_code')) > -1)); if:!$errorFlag; var:'cAuthorizationAmount'=(integer:((Decimal:($Rmap->(find:'CCGateway_authorization_amount'))) * 100)); Inline: -database=$Use4DB, -table='Orders', -keyfield='OrderID', 'VisitorID'=$VisitorID, 'AuthorizationCode'=($Rmap->(find:'CCGateway_authorization_code')), 'AVSResult'=($Rmap->(find:'CCGateway_avs_result')), 'BillingAddress'=$BillingAddress, 'CCGatewayShopperID'=($Rmap->(find:'CCGateway_shopper_id')), 'bEmail'=$bEmail, 'bForeignShipping'=$bForeignShipping, 'bPackList'=$bPackList, 'bTaxable'=$bTaxable, 'bWebOrder'='y', 'bDoubleLabels'=$bDoubleLabels, 'cAuthorizationAmount'=$cAuthorizationAmount, 'cOrderSettledAmount'=$cAuthorizationAmount, 'cOrderTotalAmount'=(integer:((Decimal:($Rmap->(find:'CCGateway_order_total_amount'))) * 100)), 'cShippingCost'=$ShippingCost, 'cTaxAdded'=$Tax2Add, 'iCCGatewayOrderID'=($Rmap->(find:'CCGateway_order_id')), 'iCategory'=$iCategory, 'iEmail'=$iEmail, 'iPackList'=$iPackList, 'iPrintLabel'=$iPrintLabel, 'ShippingAddress'=$ShippingAddress, 'sWLAddressSentTo'=$sWLAddressSentTo, 'dtCreated'=(Date_Format:(Date),-DateFormat='%Q %T'), -Add; $OrderId=(KeyField_Value); /inline; if:$OrderId; var:'allwlid'=(array); Loop:($OrderArray->size); var:'OrderItemMap'=($OrderArray->(get:(loop_count))); var: 'UnitID'=($OrderItemMap->(find:'UnitID')), 'qty'=($OrderItemMap->(find:'qty')), 'wlid'=($OrderItemMap->(find:'wl')); Inline: -database=$Use4DB, -table='OrderItems', -keyfield='OrderItemID', 'OrderID'=$OrderID, 'UnitID'=$UnitID, 'cSoldPrice'=(integer:($OrderItemMap->(find:'cPrice'))), 'cSoldCost'=(integer:($OrderItemMap->(find:'cCost'))), 'WLVisitorID'=(integer:($OrderItemMap->(find:'wl'))), 'iQtyShipped'=$qty, 'iQtyOrder'=$qty, 'dtCreated'=(Date_Format:(Date),-DateFormat='%Q %T'), -Add; /inline; // Wish List items total for the appropriate visitor need to be reduced by the quantity purchased (WishListQty:$wlid,$UnitID,$qty); // Units.iQty should be reduced by the quantity purchased (UnitInventoryReduce:$UnitID,$qty); if:($wlid != '') && ($wlid > 0); var:'t'=($allwlid->(find:$wlid)); if:($t->size) == 0; // Address for user wish list purchased for is deleted from list of addresses (WishListAddressDelete:$VisitorID,$wlid); /if; $allwlid->(insert:$wlid); /if; /Loop; // Send confirmation email to customer var:'Body'='Thank you for your order at PearlJam.com Ten Club.\n\n'; Loop:($OrderArray->size); var:'OrderItemMap'=($OrderArray->(get:(loop_count))); $Body += ($OrderItemMap->(find:'p'))+ '\t' + ($OrderItemMap->(find:'qty')) + '\t' + (Currency:($OrderItemMap->(find:'cPrice'))) + '\n'; /Loop; $Body += 'Subtotal: $' + (Currency:$SubTotal) + '\n'; $Body += 'Shipping Cost: $' + (currency:$ShippingCost) + '\n'; if:$Tax2Add; $Body += 'Tax: $' + (Currency:$Tax2Add) + '\n'; /if; $Body += 'Grand Total: $' + (Currency:$GrandTotal) + '\n\n'; $Body += 'You can view this order by signing on again at http://www.pearljam.com, and selecting Profile.'; (FinalOrderEmail:$CustName,$EmailAddress,$Body); // Empty cart Loop:($cart->size); $cart->(Remove:($cart->(get:1)->name)); /Loop; /if; /if; else; $errorFlag=true; $errorCode=7777; Select:$Rmap->(find:'CCGateway_response_code'); case:-1; $errorMsg='We\'re sorry. We\'re unable to process your request at this time due to temporary problem. Please retry this transaction.'; case:1; $errorMsg='We\'re sorry. We\'re unable to process your request at this time due to a communication issue with your card issuing company. Please retry this transaction or try using a different Credit Card for this purchase. Communication error requiring resubmission of authorization request.'; case:2; $errorMsg='We\'re sorry. We\'re unable to authorize your request. Please contact the company that issued this credit card or try using a different Credit Card for this purchase. Card issuing company declined to authorize transaction.'; case:3; $errorMsg='We\'re sorry. We\'re unable to process your request. Please try using a different credit card for this purchase.'; case:4; $errorMsg='We\'re sorry. We\'re unable to authorize your request. Please contact the company that issued this credit card or try using a different card for this purchase.'; case:6; $errorMsg='We\'re sorry. We\'re unable to process your request. Please try using a different credit card for this purchase.'; case:7; $errorMsg='We\'re sorry. We\'re unable to process your request. Please contact the company that issued this credit card or try using a different card for this purchase. Your card issuing company declined to authorize this transaction in full.'; case:8; $errorMsg='We\'re sorry. We\'re unable to process your request at this time due to a communication issue with your card issuing company. Please retry this transaction or try using a different credit card for this purchase. A communication error requiring resubmission of authorization request has occurred.'; case:9; $errorMsg='We\'re sorry. We\'re unable to process your request as the transaction appears to be a duplicate.'; case:10; $errorMsg='We\'re sorry. We\'re unable to process your request. Please try using a different credit card for this purchase.'; case; $errorMsg='We\'re sorry, but we are unable to process your request. Unknown error.'; /Select; /if; /if; else; $errorFlag=true; $errorCode=9999; $errorMsg='Transaction not completed. Some unknown error occurred.'; /if; /if; /Encode_Set; if:$errorFlag; var:'STMT'=('SELECT Addresses.AddressID, Addresses.bPrimary, Addresses.WLVisitorID, Addresses.NameFirstAddress, Addresses.NameLastAddress, Addresses.AddressLine1, Addresses.AddressLine2, Addresses.City, Addresses.CountryID, Addresses.Postal, Addresses.Region, Addresses.RegionID, Visitors.EmailAddress, Visitors.Phone1 ' + 'FROM ' + $Use4DB + '.Addresses LEFT JOIN ' + $Use4DB + '.Visitors ON Addresses.VisitorID=Visitors.VisitorID WHERE Addresses.VisitorID=' + $VisitorID + ' ORDER BY Addresses.bPrimary DESC, Addresses.NameLastAddress;'); Inline: -database=$Use4DB, -SQL=$STMT; include:'html/setbillingaddrdetails.lasso'; include:'html/FinishCartTot.inc'; Error_SetErrorCode:$errorCode; Error_SetErrorMessage:$errorMsg; Include:'html/OrderInvoice.html'; /Inline; else; Include:'html/Thanks.html'; log:'OrderLog.txt';(date) + '\t' + ((integer:_date_msec) - $timer) + '\t' + $OrderId + '\t' + ($Rmap->(find:'CCGateway_response_code')) + '\n';/log; /If;