Calculation Problem

Discussion in 'ASP General' started by BaWork, Oct 4, 2005.

  1. BaWork

    BaWork Guest

    I'm using the following code to calculate order amount in a payment form
    for Authorize.net:

    (Assume book_copies = 1 and ship_country = United States)

    book_copies = request ("book_copies")
    product_price = 16.95

    If ship_country = "United States" then
    ship_amount = 3.99
    Elseif ship_country = "Canada" then
    ship_amount = 3.99
    Else
    ship_amount = 7.99
    End if

    order_amount = product_price * book_copies
    total_amount = (product_price * book_copies) + ship_amount

    I then set the values for authorize.net as follows:

    <%

    Dim sequence
    Dim amount
    Dim ret

    amount = (product_price * book_copies) + ship_amount

    ....... unrelated code ......

    %>

    NOW, my question is:

    What could be the difference between the following:

    amount = (product_price * book_copies) + ship_amount

    (this generates an error)

    and

    amount = 20.94

    (this works if I set the value directly)

    Thanks.

    Brett
     
    BaWork, Oct 4, 2005
    #1
    1. Advertising

  2. "BaWork" <> wrote in message
    news:%...
    > I'm using the following code to calculate order amount in a payment form
    > for Authorize.net:
    >
    > (Assume book_copies = 1 and ship_country = United States)
    >
    > book_copies = request ("book_copies")
    > product_price = 16.95
    >
    > If ship_country = "United States" then
    > ship_amount = 3.99
    > Elseif ship_country = "Canada" then
    > ship_amount = 3.99
    > Else
    > ship_amount = 7.99
    > End if
    >
    > order_amount = product_price * book_copies
    > total_amount = (product_price * book_copies) + ship_amount
    >
    > I then set the values for authorize.net as follows:
    >
    > <%
    >
    > Dim sequence
    > Dim amount
    > Dim ret
    >
    > amount = (product_price * book_copies) + ship_amount
    >
    > ...... unrelated code ......
    >
    > %>
    >
    > NOW, my question is:
    >
    > What could be the difference between the following:
    >
    > amount = (product_price * book_copies) + ship_amount
    >
    > (this generates an error)
    >
    > and
    >
    > amount = 20.94
    >
    > (this works if I set the value directly)
    >


    book_copies is a string

    use clng() to convert to a numeric


    --
    John Blessing

    http://www.LbeHelpdesk.com - Help Desk software priced to suit all
    businesses
    http://www.room-booking-software.com - Schedule rooms & equipment bookings
    for your meeting/class over the web.
    http://www.lbetoolbox.com - Remove Duplicates from MS Outlook
    http://www.outlook-find-replace.com - Find & Replace in Emails, Contacts,
    Appointments, Tasks and Notes
     
    John Blessing, Oct 4, 2005
    #2
    1. Advertising

  3. BaWork

    BaWork Guest

    Thanks for the response. That didn't fix it though. As far as the
    generated code is concerned, this calculates the correct value:

    amount = (product_price * book_copies) + ship_amount

    but here is where it gets stupid. If the quantity is 2 or 5, it works,
    if it 1,3 or 4, it doesn't.

    Here is the page example:

    http://www.vantagepoints.net/buy1.asp

    Keeping all other values the same, changing only the number of books
    determines if it works or not

    If you chose 2 or 5, fill in dummy text and click "Continue", confirm
    your order on the next page and click "Submit Order", it works. If you
    use any the other possible values for book quantity, it doesn't.

    Any ideas? Authorize.net won't help.

    Thanks

    Brett




    John Blessing wrote:
    > "BaWork" <> wrote in message
    > news:%...
    >
    >>I'm using the following code to calculate order amount in a payment form
    >>for Authorize.net:
    >>
    >>(Assume book_copies = 1 and ship_country = United States)
    >>
    >>book_copies = request ("book_copies")
    >>product_price = 16.95
    >>
    >>If ship_country = "United States" then
    >>ship_amount = 3.99
    >>Elseif ship_country = "Canada" then
    >>ship_amount = 3.99
    >>Else
    >>ship_amount = 7.99
    >>End if
    >>
    >>order_amount = product_price * book_copies
    >>total_amount = (product_price * book_copies) + ship_amount
    >>
    >>I then set the values for authorize.net as follows:
    >>
    >><%
    >>
    >>Dim sequence
    >>Dim amount
    >>Dim ret
    >>
    >>amount = (product_price * book_copies) + ship_amount
    >>
    >>...... unrelated code ......
    >>
    >>%>
    >>
    >>NOW, my question is:
    >>
    >>What could be the difference between the following:
    >>
    >>amount = (product_price * book_copies) + ship_amount
    >>
    >>(this generates an error)
    >>
    >>and
    >>
    >>amount = 20.94
    >>
    >>(this works if I set the value directly)
    >>

    >
    >
    > book_copies is a string
    >
    > use clng() to convert to a numeric
    >
    >
     
    BaWork, Oct 4, 2005
    #3
  4. BaWork wrote:

    > amount = (product_price * book_copies) + ship_amount
    >
    > (this generates an error)
    >

    What error?
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 4, 2005
    #4
  5. BaWork

    BaWork Guest

    Bob,

    I'm sorry for not being more clear, Authorize.net generates an error
    when calculating the hash value where the amount is one of the values
    used in the hash calculation. But it isn't consistent, it works for
    some values and not for others.

    See my response to John's, I think I was better at explaining the issue.

    I don't know how a value of 1 causes an error where a value of 2 does not...

    Thanks for the response.

    Brett


    Bob Barrows [MVP] wrote:
    > BaWork wrote:
    >
    >
    >>amount = (product_price * book_copies) + ship_amount
    >>
    >>(this generates an error)
    >>

    >
    > What error?
     
    BaWork, Oct 4, 2005
    #5
  6. What error? There must be some error message ...

    BaWork wrote:
    > Bob,
    >
    > I'm sorry for not being more clear, Authorize.net generates an error
    > when calculating the hash value where the amount is one of the values
    > used in the hash calculation. But it isn't consistent, it works for
    > some values and not for others.
    >
    > See my response to John's, I think I was better at explaining the
    > issue.
    >
    > I don't know how a value of 1 causes an error where a value of 2 does
    > not...
    >
    > Thanks for the response.
    >
    > Brett
    >
    >
    > Bob Barrows [MVP] wrote:
    >> BaWork wrote:
    >>
    >>
    >>> amount = (product_price * book_copies) + ship_amount
    >>>
    >>> (this generates an error)
    >>>

    >>
    >> What error?


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 4, 2005
    #6
  7. BaWork

    BaWork Guest

    Bob,

    It is an Authorize.net generated error that relates to the calculated
    hash value not matching the server generated hash value. If you visit
    http://vantagepoints.net/buy1.asp and run through the process using all
    5 available quantities, you see the error for some and not for others.

    In a nutshell, this code works as long as the quantity is 2 or 5.

    amount = (product_price * book_copies) + ship_amount

    If it is 1,3 or 4, it doesn't. For these values, if I hard-code the
    total order amount, it works though.

    So that is why I'm left thinking there is something wrong with my code
    (even though I can't understand how it works for some values and not for
    others...)

    Thanks for your continued help. Authorize.net has offered zero
    assistance on this.

    Brett



    Bob Barrows [MVP] wrote:
    > What error? There must be some error message ...
    >
    > BaWork wrote:
    >
    >>Bob,
    >>
    >>I'm sorry for not being more clear, Authorize.net generates an error
    >>when calculating the hash value where the amount is one of the values
    >>used in the hash calculation. But it isn't consistent, it works for
    >>some values and not for others.
    >>
    >>See my response to John's, I think I was better at explaining the
    >>issue.
    >>
    >>I don't know how a value of 1 causes an error where a value of 2 does
    >>not...
    >>
    >>Thanks for the response.
    >>
    >>Brett
    >>
    >>
    >>Bob Barrows [MVP] wrote:
    >>
    >>>BaWork wrote:
    >>>
    >>>
    >>>
    >>>>amount = (product_price * book_copies) + ship_amount
    >>>>
    >>>>(this generates an error)
    >>>>
    >>>
    >>>What error?

    >
    >
     
    BaWork, Oct 4, 2005
    #7
  8. BaWork wrote:
    > Bob,
    >
    > It is an Authorize.net generated error that relates to the calculated
    > hash value not matching the server generated hash value.


    So the error says that the "calculated hash value does not match the
    server-generated hash value"? OK, now we know it's not a vbscript error.

    > If you visit
    > http://vantagepoints.net/buy1.asp and run through the process using
    > all 5 available quantities, you see the error for some and not for
    > others.


    Sorry, but I'm not going to do that: I'm at work.

    >
    > In a nutshell, this code works as long as the quantity is 2 or 5.


    Whose code is breaking? Yours or theirs? It sounds as if their code is
    breaking...

    >
    > amount = (product_price * book_copies) + ship_amount


    Have you done:
    Response.Write amount

    and

    Response.Write typename(amount)

    ? If not, do so. Perhaps you need to be more explicit, as John suggested.
    Maybe:

    amount=CDbl((product_price * CLng(book_copies)) + ship_amount)

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 4, 2005
    #8
  9. BaWork

    BaWork Guest

    Bob,

    I don't believe my code is breaking since it works for some values and
    not for others. I use Authorize.net for payment processing on 3 other
    sites, but this is first time doing something like this. Your
    suggestion did not work, it still fails for values of 1,3 and 4 and
    works for values of 2 and 5.

    This code "amount = (product_price * book_copies) + ship_amount" returns
    "Double" for Response.Write typename(amount)

    This code "CDbl((product_price * CLng(book_copies)) + ship_amount)"
    returns "Double for for Response.Write typename(amount)

    "Response.Write amount" returns a value like "54.84"

    I just don't know.

    Thanks....

    Brett




    Bob Barrows [MVP] wrote:
    > BaWork wrote:
    >
    >>Bob,
    >>
    >>It is an Authorize.net generated error that relates to the calculated
    >>hash value not matching the server generated hash value.

    >
    >
    > So the error says that the "calculated hash value does not match the
    > server-generated hash value"? OK, now we know it's not a vbscript error.
    >
    >
    >>If you visit
    >>http://vantagepoints.net/buy1.asp and run through the process using
    >>all 5 available quantities, you see the error for some and not for
    >>others.

    >
    >
    > Sorry, but I'm not going to do that: I'm at work.
    >
    >
    >>In a nutshell, this code works as long as the quantity is 2 or 5.

    >
    >
    > Whose code is breaking? Yours or theirs? It sounds as if their code is
    > breaking...
    >
    >
    >>amount = (product_price * book_copies) + ship_amount

    >
    >
    > Have you done:
    > Response.Write amount
    >
    > and
    >
    > Response.Write typename(amount)
    >
    > ? If not, do so. Perhaps you need to be more explicit, as John suggested.
    > Maybe:
    >
    > amount=CDbl((product_price * CLng(book_copies)) + ship_amount)
    >
    > Bob Barrows
    >
     
    BaWork, Oct 4, 2005
    #9
  10. BaWork wrote:
    > Bob,
    >
    > I don't believe my code is breaking since it works for some values and
    > not for others. I use Authorize.net for payment processing on 3 other
    > sites, but this is first time doing something like this. Your
    > suggestion did not work, it still fails for values of 1,3 and 4 and
    > works for values of 2 and 5.
    >
    > This code "amount = (product_price * book_copies) + ship_amount"
    > returns "Double" for Response.Write typename(amount)
    >


    For all values? If so, your code is doing nothing wrong.

    > This code "CDbl((product_price * CLng(book_copies)) + ship_amount)"
    > returns "Double for for Response.Write typename(amount)
    >
    > "Response.Write amount" returns a value like "54.84"
    >
    > I just don't know.
    >

    Sorry, neither do I. It's probably got something to do with their hash
    algorithm

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Oct 4, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael G

    problem with a calculation

    Michael G, Apr 27, 2004, in forum: C++
    Replies:
    10
    Views:
    1,005
    Michael G
    Apr 28, 2004
  2. Replies:
    2
    Views:
    380
    Steven D'Aprano
    Mar 4, 2007
  3. harryos

    matrix calculation problem..

    harryos, Aug 25, 2008, in forum: Java
    Replies:
    0
    Views:
    299
    harryos
    Aug 25, 2008
  4. bei
    Replies:
    0
    Views:
    242
  5. bei
    Replies:
    4
    Views:
    391
Loading...

Share This Page