locked
Please Help RRS feed

  • Question

  • User763091057 posted

    I need some help with this code if possible. This is an online store. When someone makes a pre-order, it is supposed to send the total price over to Authorize.net, but for some reason it is only sending over the shipping amount. Can you tell if there's a problem with the calculation? 

      Dim sbItemsOrdered As New StringBuilder
                    hidOrderTotal.Value = "0.00"
                    sbItemsOrdered.AppendLine("<table cellpadding=""3"">")
                    Dim dt As DataTable = EcomOrderItem.ViewCart(Request.Cookies("CartID").Value)
                    hidHasRegularItems.Value = False
                    hidHasPreorderItems.Value = False
    
                    Dim preordertotal As Decimal = 0
    
    
                    For Each dr As DataRow In dt.Rows
                        If dr("ReleaseDate") < Today Then
                            'Regular item
                            hidHasRegularItems.Value = True
                            'CUSTOM - used Custom1 instead of SKU here
                            sbItemsOrdered.AppendLine("<tr><td>" & dr("Quantity") & " x " & dr("ProductName") & " (" & dr("Custom1") & ")</td><td>$" & Format(dr("Subtotal"), "0.00") & "</td></tr>")
                            'Add item to total
                            hidOrderTotal.Value = CDbl(hidOrderTotal.Value) + CDbl(dr("Subtotal"))
                        Else
                            'Preorder item
                            hidHasPreorderItems.Value = True
                            'CUSTOM - used Custom1 instead of SKU here
                            preordertotal = preordertotal + CDbl(hidOrderTotal.Value)
                            sbItemsOrdered.AppendLine("<tr><td>" & dr("Quantity") & " x " & dr("ProductName") & " (" & dr("Custom1") & ")</td><td><em>$" & Format(dr("Subtotal"), "0.00") & " *</em></td></tr>")
                        End If
                    Next
                    sbItemsOrdered.AppendLine("<tr><td>Subtotal</td><td>$" & Format(CDbl(hidOrderTotal.Value), "0.00") & "</td></tr>")
                    If hidHasPreorderItems.Value = True Then sbItemsOrdered.AppendLine("<tr><td colspan=""2""></em>* Preorder items are not billed immediately &amp;<br />are not counted in the subtotal above.</td></tr>")
    
                    'State taxes
                    Dim dtTaxes As DataTable = EcomTaxRate.SelectAll
                    hidTaxTotal.Value = "0.000"
                    For Each dr As DataRow In dtTaxes.Rows
                        If txtBillState.Text.Trim = dr("State") Then
                            hidTaxTotal.Value = Format((CDbl(hidOrderTotal.Value) + preordertotal) * (CDbl(dr("TaxRate")) / 100), "0.00")
                            Exit For
                        End If
                    Next
    
                    'Display total after discount
                    If Not IsNothing(Request.Cookies("UserID")) Then
                        'Load account
                        Dim objEcomAccount As New EcomAccount(Request.Cookies("UserID").Value)
                        If objEcomAccount.Discount <> 0 Then
                            'Display total less discount
                            hidOrderTotal.Value = CDbl(hidOrderTotal.Value) * (1 - (objEcomAccount.Discount / 100))
                            sbItemsOrdered.AppendLine("<tr><td>Subtotal (after discount)</td><td>$" & Format(CDbl(hidOrderTotal.Value), "0.00") & "</td></tr>")
                        Else
                        End If
                    End If
    
                    ' If hidOrderTotal.Value <> "0.00" Then
                    'Tax
                    sbItemsOrdered.AppendLine("<tr><td>Tax</td><td>$" & hidTaxTotal.Value & "</td></tr>")
                    'Add tax to total
                    hidOrderTotal.Value = Format(CDbl(hidOrderTotal.Value) + CDbl(hidTaxTotal.Value), "0.00")
    
                    'Shipping
                    sbItemsOrdered.AppendLine("<tr><td>Shipping & Handling</td><td>" & rblShipping.SelectedItem.Text & "</td></tr>")
                    'Add shipping to total
                    hidOrderTotal.Value = CDbl(hidOrderTotal.Value) + CDbl(rblShipping.SelectedValue)
                    'End If
    
                    'Display total
                    sbItemsOrdered.AppendLine("<tr><td><strong>TOTAL</strong></td><td><strong>$" & Format(CDbl(hidOrderTotal.Value), "0.00") & " USD</strong></td></tr>")
    
                    sbItemsOrdered.AppendLine("</table>")
    
                    lblItemsOrdered.Text = sbItemsOrdered.ToString
    
                    lblPaymentInfo.Text = _
                        "<table>" & _
                        "<tr><td width=""150"">Type</td><td>" & rblCardType.SelectedItem.Text & "</td></tr>" & _
                        "<tr><td>Card Number</td><td>XXXXXXXXXXXX" & txtCCNumber.Text.Substring(txtCCNumber.Text.Length - 4, 4) & "</td></tr>" & _
                        "<tr><td>Expiration Date</td><td>" & ddlCCMonth.SelectedValue & "/" & ddlCCYear.SelectedValue & "</td></tr>"
    
                    'exclude the CVV info from the Order Completed form
                    lblPaymentInfoCompleted.Text = lblPaymentInfo.Text & "</table>"
    
                    lblPaymentInfo.Text = lblPaymentInfo.Text & "<tr><td>CVV Code</td><td>" & txtCCCVV.Text & "</td></tr></table>"
    
    
    
                Case 4 'Order Completed
                    'Make sure a valid shipping option was selected
                    If IsNothing(rblShipping.SelectedItem.Text) Then wizCheckout.ActiveStepIndex = 3
    
                    'Check to ensure that all items in their cart are still in stock.
                    'CUSTOM - COMMENT THIS OUT IF THE CUSTOMER IS NOT INTERESTED IN KEEPING ACCURATE QUANTITY ON HAND
                    'Dim dt As DataTable = SQLExec.Query("sp_Order_FinalStockCheck", "@OrderID", Session("Order_ID"))
                    'If dt.Rows.Count > 0 Then
                    '    wizCheckout.ActiveStepIndex = 2
                    '    lblStatus.Text = "Some items are out of stock!<br/>One or more of the items on your order were in stock when you added them to cart, but are now out of stock.<br/>The following items are out of stock:<br />" & vbCrLf
                    '    For Each dr In dt.Rows
                    '        lblStatus.Text &= dr("Name") & "<br />"
                    '    Next
                    '    Exit Sub
                    'End If
    
                    'Authorize.net - Process card
                    Dim objCC As New AuthorizeNet
                    'objCC.CustomerID = hidAccountID.Value
                    objCC.FirstName = txtFirstName.Text.Trim
                    objCC.LastName = txtLastName.Text.Trim
                    objCC.Address = txtBillAddress.Text.Trim
                    objCC.ZipCode = txtBillZIP.Text.Trim
                    objCC.Email = txtEmail.Text.Trim
    
                    objCC.CardNumber = txtCCNumber.Text.Trim
                    objCC.CVV = txtCCCVV.Text.Trim
                    objCC.ExpirationDate = CDate(ddlCCMonth.SelectedValue & "/1/" & ddlCCYear.SelectedValue)
                    objCC.OrderAmount = CSng(hidOrderTotal.Value)
    
                    objCC.Company = txtCompany.Text.Trim
                    objCC.City = txtBillCity.Text.Trim
                    objCC.State = txtBillState.Text.Trim
                    objCC.PhoneNumber = txtHomePhone.Text.Trim
                    objCC.OrderID = Request.Cookies("CartID").Value
                    objCC.CustomerID = hidAccountID.Value
    
                    'AUTH_ONLY()
    
                    'Process order
                    Dim objOrder As New EcomOrder(Request.Cookies("CartID").Value)
    
                    Dim pass As Boolean
    
    
                    If hidHasPreorderItems.Value = True Then
                        ' Order has pre-order items so do not capture
                        pass = objCC.Process("AUTH_ONLY")
                    Else
                        'normal items only go ahead and capture
                        pass = objCC.Process()
                    End If
    
    
                    If pass Then
                        'Credit card authorized
                        lblCompleted.Text = "Transaction ID: " & objCC.TransactionID & "<br/>" & _
                                            "Approval Code: " & objCC.ApprovalCode
                        objOrder.Status = "P"
                    Else
                        'Credit card not authorized
                        wizCheckout.ActiveStepIndex = 3
                        lblStatus.Text = "Credit card not authorized!<br/>Please correct the following issues and try again:<br/>" & _
                                         "<strong>" & objCC.ResultMessage.Replace(vbCrLf, "<br/>") & "</strong><br/>" & _
                                         "Address Result (if any): " & objCC.AddressResult & "<br/>" & _
                                         "CVV Result (if any): " & objCC.CVVResult & "<br/>"
                        Exit Sub
                    End If
    
    
                    If hidHasPreorderItems.Value = True Then
                        objCC.AddToCIM() 'Add to to Authorize.net customer information manager.  Comment this out if customer does not use CIM.
                    End If
    
                    lblCompleted.Text = "Your order has been accepted at " & Now.ToString & ".<br />Order Number: <strong>" & Request.Cookies("CartID").Value & "</strong><br />We have received your order and will notify you via email when your order has been shipped.<br />Thank you from all of us at Basic Enterprise – Bob & Don, LLC.<br />Click the print button to print this page."
    
                    lblPersonalCompleted.Text = Me.lblPersonal.Text
                    lblBillingAddressCompleted.Text = Me.lblBillingAddress.Text
                    lblShippingAddressCompleted.Text = Me.lblShippingAddress.Text
                    lblItemsOrderedCompleted.Text = Me.lblItemsOrdered.Text
    Tuesday, October 25, 2011 11:27 AM

Answers

  • User-952121411 posted

    A few recommendations

    1. In my experience reusing a hidden field which will always be of type 'String' is cumbersome when continually working with numeric values. All of the casting each time introduces potential for error. I recommend using a local variable of type Decimal that takes the value of the hidden field 1 time, casts it a single time and then uses the local variable.
    2. Even using the hidden field value 'hidOrderTotal' you are casting it sometimes to double via CDbl and sometimes to CSng. At least keep the casting consistent.
    3. I can not immediately see reassignment of a shipping value to the 'hidOrderTotal' value. To figure this out (shouldn't be too difficult), place a breakpoint at the beginning of the method with the value is "0.00" and walk debugging the code to see when it changes to the unwanted value before the final assignment to: objCC.OrderAmount.
    4. Lastly, make sure you don't just have some weired anomaly where the shipping price is equal to the order price and the values are actually correct. (i.e. shipping is $15.50 and so is the total order amount).

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 26, 2011 11:43 AM