Calculation Problem

B

BaWork

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
(e-mail address removed)
 
J

John Blessing

BaWork said:
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
 
B

BaWork

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
(e-mail address removed)
 
B

BaWork

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
(e-mail address removed)
 
B

Bob Barrows [MVP]

What error? There must be some error message ...
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
(e-mail address removed)
 
B

BaWork

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
(e-mail address removed)
 
B

Bob Barrows [MVP]

BaWork said:
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
 
B

BaWork

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
(e-mail address removed)
 
B

Bob Barrows [MVP]

BaWork said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top