Country specific codes?

2 views
Skip to first unread message

Dangermouse

unread,
Oct 31, 2007, 4:40:55 AM10/31/07
to Google Checkout Mod for OSC Community Support Forum
Hi

Another small problem I am having is that when a customer has
transferred over to GC and filled in their card details etc, when they
come back to the store the prices are suddenly displayed without tax,
and checking their accounts they are set to GB instead of United
Kingdom (even though they filled out as united kingdom at GC).

This means that their invoice is wrong as it has a tax of 0% on each
product line, even though the total price is correct.

Is this something specific to my OSC installation? Its always worked
perfectly before when Ive taken card payments and paypal payments etc,
but with GC integration this happens.

Any help would be really appreciated.

regards

Tony

Dangermouse

unread,
Oct 31, 2007, 5:12:22 AM10/31/07
to Google Checkout Mod for OSC Community Support Forum
In actual fact, the individuals account is always set to Afghanistan.

is there some way of stopping this?

Dangermouse

unread,
Oct 31, 2007, 8:04:11 AM10/31/07
to Google Checkout Mod for OSC Community Support Forum
Further to this, looking at the mysql DB the users address book is not
being populated with a country. looking at DB > address_book the
field "entry_country_id" is set to 0 .

Note: when doing this whole ordering process without taking the user
off site (ie using the default credit card checkout routine) the
address is populated just fine, so why with GC does it not populate
the country_id?

> > Tony- Hide quoted text -
>
> - Show quoted text -

Dangermouse

unread,
Nov 7, 2007, 5:44:33 AM11/7/07
to Google Checkout Mod for OSC Community Support Forum
Anyone?

Is this project still alive? I have not received any replies to any
of the questions I have posed at all.

Tony

> > - Show quoted text -- Hide quoted text -

Ropu

unread,
Nov 7, 2007, 8:28:03 AM11/7/07
to google-checkout-f...@googlegroups.com
Hi, yes, we are still here.

I cannot fully understand ur issue.

you are saying that the address is competes correctly? but the country is wrong?

anything else?

ropu
--
.-. --- .--. ..-
R  o  p  u

Dangermouse

unread,
Nov 7, 2007, 8:45:41 AM11/7/07
to Google Checkout Mod for OSC Community Support Forum
Hi ropu

Thats right... the users address comes across just fine apart from the
country.

in OSC admin if you look at the customer order it gives the customer,
shipping and billing address correctly, but the country is set to GB
(presumably this is the ISO code for the country which OSC interprets
to GB?).

I wouldnt have a problem with that if it werent for the fact that tax
on each individual item ordered is then set to 0%, and tax is shown
for the whole order... this means that the invoice is wrong as price
(inc) and price (exc) are both the same, albeit the total amount is
correct.

Further, if you find the customer in the OSC admin area and edit it,
the country is set to Afghanistan, and this is what leads me to
believe this is where its getting its 0% tax, but I may be wrong
here. What I do know is that the newly created user is set to 0 in
entry_country_id

> R o p u- Hide quoted text -

Ropu

unread,
Nov 7, 2007, 8:54:44 AM11/7/07
to google-checkout-f...@googlegroups.com
is weird that the addr is set to afg., and it could be the issue there.

could u please send me the snippet of the new order notification, specially the whole buyer-shipping-address section?

since i think there is the issue... i use the region to determine the country and zone for the buyer address.

thx

Dangermouse

unread,
Nov 7, 2007, 9:50:36 AM11/7/07
to Google Checkout Mod for OSC Community Support Forum
Cheers for taking a look.

Here is the snippet:-

<buyer-shipping-address>

<contact-name>Tony Gman</contact-name>

<company-name></company-name>

<email>t...@something.com</email>

<phone></phone>

<fax></fax>

<address1>6 Something Close</address1>

<address2></address2>

<city>SomeTown</city>

<country-code>GB</country-code>

<region>NORTHANTS</region>

<postal-code>NN11 000</postal-code>

</buyer-shipping-address>

> R o p u- Hide quoted text -

Dangermouse

unread,
Nov 7, 2007, 9:52:00 AM11/7/07
to Google Checkout Mod for OSC Community Support Forum
The shipping address shows GB, although in googlecheckout admin it
shows the address as UNITED KINGDOM.

Is that correct?

On Nov 7, 1:54 pm, Ropu <rovagn...@gmail.com> wrote:

> R o p u- Hide quoted text -

Dangermouse

unread,
Nov 7, 2007, 10:09:29 AM11/7/07
to Google Checkout Mod for OSC Community Support Forum
This is odd... I just did a the cart decode which you suggested to
someone else and this is what it came back with:-

<tax-tables merchant-calculated="false">
<default-tax-table>
<tax-rules>
<default-tax-rule>
<shipping-taxed>true</shipping-taxed>
<rate>0.175</rate>
<tax-area>
<postal-area>
<country-code>AF</country-code>
</postal-area>
</tax-area>
</default-tax-rule>
<default-tax-rule>
<shipping-taxed>true</shipping-taxed>
<rate>0.175</rate>
<tax-area>
<postal-area>
<country-code>GB</country-code>
</postal-area>
</tax-area>
</default-tax-rule>
<default-tax-rule>
<shipping-taxed>true</shipping-taxed>
<rate>0.175</rate>
<tax-area>
<postal-area>
<country-code>GB</country-code>
</postal-area>
</tax-area>
</default-tax-rule>
</tax-rules>
</default-tax-table>
<alternate-tax-tables>
<alternate-tax-table standalone="false" name="Taxable
Goods">
<alternate-tax-rules>
<alternate-tax-rule>
<rate>0.175</rate>
<tax-area>
<postal-area>
<country-code>AF</country-code>
</postal-area>
</tax-area>
</alternate-tax-rule>
<alternate-tax-rule>
<rate>0.175</rate>
<tax-area>
<postal-area>
<country-code>GB</country-code>
</postal-area>
</tax-area>
</alternate-tax-rule>
<alternate-tax-rule>
<rate>0.175</rate>
<tax-area>
<postal-area>
<country-code>GB</country-code>
</postal-area>
</tax-area>
</alternate-tax-rule>
</alternate-tax-rules>
</alternate-tax-table>
</alternate-tax-tables>
</tax-tables>

Where is it getting the AF from?

Ropu

unread,
Nov 7, 2007, 11:15:01 AM11/7/07
to google-checkout-f...@googlegroups.com
yes yes

as i said, i use <region>NORTHANTS</region> to determine the country
responsehandler.php line 264

        $buyer_state = $gc_data[$root]['buyer-shipping-address']['region']['VALUE'];
        $zone_answer = tep_db_fetch_array(tep_db_query("select zone_id, zone_country_id from " .
        TABLE_ZONES . " where zone_code = '" . $buyer_state . "'"));


check in ur TABLE_ZONES to which country is mapped the NORTHANTS zone. (it should be UK) Thats an OSC config

Ropu

unread,
Nov 7, 2007, 11:21:08 AM11/7/07
to google-checkout-f...@googlegroups.com

Hi, double check ur Tax Table class zone restriction definition, seems u have something wrong there.

Can u please send me also the item section, to see if items match to the Taxable goods tax table...

check that the products have the correct tax table. since tax table definitions are ok

also try adding the distinct to the sql queries in line 624 and 664

"select distinct countries_name, ..."

Dangermouse

unread,
Nov 8, 2007, 5:14:09 AM11/8/07
to Google Checkout Mod for OSC Community Support Forum
OK, checked the database and the following is how the zones are set
for all my UK regions:-

363 222 NHAM Northamptonshire

(222 being UK and NORTHANTS being Northamptonshire)

I presumed this is where the error came in as what happens if someone
has their region set to Northants and our cart only looks for
Northamptonshire? Same with Bucks and Buckinghamshire and loads of
other UK counties?

Having said that, I just changed the delivery address on my
Googlecheckout account to Northamptonshire and placed a test order and
the same thing happened, 0% tax, although tax as always is added to
the order. Here is the XML:-

<merchant-calculation-successful>false</merchant-calculation-
successful>
<merchant-codes />
<total-tax currency="GBP">4.31</total-tax>
<shipping>
<merchant-calculated-shipping-adjustment>
<shipping-name>Delivery: Table Rate</shipping-name>
<shipping-cost currency="GBP">5.06</shipping-cost>
</merchant-calculated-shipping-adjustment>
</shipping>
<adjustment-total currency="GBP">9.37</adjustment-total>
</order-adjustment>
<buyer-id>900829598240334</buyer-id>
<google-order-number>866634798437810</google-order-number>
<buyer-shipping-address>
<contact-name>Tony G</contact-name>


<company-name></company-name>
<email>t...@something.com</email>
<phone></phone>
<fax></fax>

<address1>4 Something Close</address1>
<address2></address2>
<city>Daventry</city>
<country-code>GB</country-code>
<region>NORTHAMPTONSHIRE</region>


<postal-code>NN11 000</postal-code>
</buyer-shipping-address>

<buyer-billing-address>
<contact-name>Tony G</contact-name>


<company-name></company-name>
<email>t...@something.com</email>

<phone>01327 111 2222</phone>
<fax></fax>
<address1>4 Something Close</address1>
<address2></address2>
<city>Daventry</city>


<country-code>GB</country-code>
<region>NORTHANTS</region>
<postal-code>NN11 000</postal-code>

</buyer-billing-address>

And here is the item data:-

<shopping-cart>
<items>
<item>
<item-weight value="1.6" unit="LB" />
<tax-table-selector>Taxable Goods</tax-table-selector>
<merchant-item-id>91</merchant-item-id>
<item-name>Jtalk Digital Bathroom Scales</item-name>
<item-description>The J-Talk Scale is a high capacity, highly
accurate bathroom weighing scale. This scale is so new, we are the
first to introduce this to the UK Market
Some of its features include:-
Reads in Pounds, Kilograms &amp;amp; Stones (something very unique
with digital bathroom scales)
Capacity: 440lb/2...</item-description>
<unit-price currency="GBP">19.5319</unit-price>
<quantity>1</quantity>
<merchant-private-item-data>

<item>YTo5OntzOjM6InF0eSI7aToxO3M6NDoibmFtZSI7czoyOToiSnRhbGsgRGlnaXRhbCBCYXRocm9vbSBTY2FsZXMiO3M6NToibW9kZWwiO3M6NToiSlRhbGsiO3M6MzoidGF4IjtpOjA7czoxNToidGF4X2Rlc2NyaXB0aW9uIjtzOjE2OiJVbmtub3duIHRheCByYXRlIjtzOjU6InByaWNlIjtzOjc6IjE5LjUzMTkiO3M6MTE6ImZpbmFsX3ByaWNlIjtkOjE5LjUzMTkwMDAwMDAwMDAwMDI2MTQ3OTcyNjc1OTcxNjg2ODQwMDU3MzczMDQ2ODc1O3M6Njoid2VpZ2h0IjtzOjQ6IjEuNjAiO3M6MjoiaWQiO2k6OTE7fQ==</
item>

</merchant-private-item-data>
</item>
</items>
<merchant-private-data>

> R o p u- Hide quoted text -

Message has been deleted

Ropu

unread,
Nov 12, 2007, 8:07:21 AM11/12/07
to google-checkout-f...@googlegroups.com
yeap, i see the issue.

UK addr are handled different from US ones...

a fix could be this one

responsehandler.php line 265

replacer

        $zone_answer = tep_db_fetch_array(tep_db_query("select zone_id, zone_country_id from " .
        TABLE_ZONES . " where zone_code = '" . $buyer_state . "'"));
with

        $zone_answer = tep_db_fetch_array(tep_db_query("select zone_id, zone_country_id from " .
        TABLE_ZONES . " where zone_code = '" . $buyer_state . "' or zone_name = '" . $buyer_state . "'"));


this way u will also check the zone by its name. Hopefully will work with all your zone definitions...

let me know the result,

thx

ropu

btw, i'll apply this patch to next version




On Nov 8, 2007 7:23 AM, Dangermouse < sa...@scalesonline.co.uk> wrote:

To see this order in my admin please see the screen captures:-

http://scalesonline.co.uk/images/Admin_Order.jpg
&
http://scalesonline.co.uk/images/Admin_Customer.jpg

hope this helps

Tony
> R  o  p  u- Hide quoted text -

>
> - Show quoted text -


Dangermouse

unread,
Nov 12, 2007, 8:07:32 AM11/12/07
to Google Checkout Mod for OSC Community Support Forum
Any chance you could cast your expert eye over this problem? Thanks

Tony

On Nov 8, 10:23 am, Dangermouse <sa...@scalesonline.co.uk> wrote:
> To see this order in my admin please see the screen captures:-
>
> http://scalesonline.co.uk/images/Admin_Order.jpg

> &http://scalesonline.co.uk/images/Admin_Customer.jpg
>
> hope this helps
>
> Tony

> > R o p u- Hide quoted text -

Dangermouse

unread,
Nov 12, 2007, 8:15:53 AM11/12/07
to Google Checkout Mod for OSC Community Support Forum
Sorry, posted at the same time as you...

This fix didnt work, still exactly the same.

Anything else I can try?

Ropu

unread,
Nov 12, 2007, 8:43:48 AM11/12/07
to google-checkout-f...@googlegroups.com
sure?

weird, it worked for me with london

try querying ur db with this:

select zone_id, zone_country_id from                              
        zones where zone_code = 'NORTHAMPTONSHIRE' or zone_name = 'NORTHAMPTONSHIRE'

(this should be the parsed query from the shipping address u sent as example
        $buyer_state = $gc_data[$root]['buyer-shipping-address']['region']['VALUE'];
        $zone_answer = tep_db_fetch_array(tep_db_query("select zone_id, zone_country_id from " .
        TABLE_ZONES . " where zone_code = '" . $buyer_state . "' or zone_name = '" . $buyer_state . "'"));
)
and from the dumped row u sent me
363     222     NHAM    Northamptonshire

the zone_name should match (since is not case sensitive)

if u see a result, the patch should work...

u may also try debuging it using this tool

https://demo.globant.com/~brovagnati/tools -> responsehandler test

let me know the results.

ropu

Dangermouse

unread,
Nov 12, 2007, 9:10:04 AM11/12/07
to Google Checkout Mod for OSC Community Support Forum
Thats odd as the SQL you gave as an example resulted in

zone_id zone_country_id
363 222

The new user created also has the correct country associated with it,
however the order still comes through as 0% tax and when I edit the
order the country is set to AFGHANISTAN. where the hell is it getting
that from??

Also, what happens if someone has their state set to Northants instead
of Northamptonshire, or Bucks instead of Buckinghamshire? This will
surely result in 0 tax again as it wont match anything in the zone
db? Currently OSC asks the user to clarify what zone they are in if
it doesnt first match it, but from what I gather here it will simply
send it anyway and then result in an incorrect zone.

On Nov 12, 1:43 pm, Ropu <rovagn...@gmail.com> wrote:
> sure?
>
> weird, it worked for me with london
>
> try querying ur db with this:
>
> select zone_id, zone_country_id from
> zones where zone_code = 'NORTHAMPTONSHIRE' or zone_name =
> 'NORTHAMPTONSHIRE'
>
> (this should be the parsed query from the shipping address u sent as example
> $buyer_state =
> $gc_data[$root]['buyer-shipping-address']['region']['VALUE'];
> $zone_answer = tep_db_fetch_array(tep_db_query("select zone_id,
> zone_country_id from " .
> TABLE_ZONES . " where zone_code = '" . $buyer_state . "' or
> zone_name = '" . $buyer_state . "'"));
> )
> and from the dumped row u sent me
> 363 222 NHAM Northamptonshire
>

> the *zone_name* should match (since is not case sensitive)


>
> if u see a result, the patch should work...
>
> u may also try debuging it using this tool
>

> https://demo.globant.com/~brovagnati/tools-> responsehandler test

> ...
>
> read more »- Hide quoted text -

Ropu

unread,
Nov 12, 2007, 9:22:09 AM11/12/07
to google-checkout-f...@googlegroups.com
HI

the tax is calculated in the google server, and is "hardcoded" in the NewOrderNotification..

changing the order country wont affect the tax.

Right now google ONLY applies tax to the whole UK as a one big zone, u cannot differentiate UK regions. To do that, u will need to implement merchant calculated tax. Which the module doesnt offer right now.

You will need to process tax in the merchant calculations. Right now max
granularity for tax in ZC is at State level.

To do this u must add the logic in the googlecheckout/responsehandler.php (
v1.4.5) line 933 and 951
and in gcheckout.php line 594 set merchant_calculated tax to true

$Gcart->SetMerchantCalculations($url, 'true', 'false', 'false');




hope this helps

ropu

Dangermouse

unread,
Nov 12, 2007, 9:38:40 AM11/12/07
to Google Checkout Mod for OSC Community Support Forum
No, I think you are misunderstanding me again...

I dont want different taxes for different UK zones, I just want A
tax... ie anything in the UK to be taxed at 17.5%, which currently it
is not.

What my question was referring to is that if you identify what tax to
give someone dependant on what country their zone is in (which is what
I am presuming going by your description two or three posts before)
then what happens if OSC doesnt recognize the zone passed back from
GC? will it return a 0% tax which will be wrong.

Currently OSC asks the user to clarify what zone it is in if it doesnt
recognise their address first time round by means of a drop down
box... because GC is bypassing the normal account creation in OSC then
what kind of fallback is there if OSC doesnt recognize the zone first
time round?

> > >https://demo.globant.com/~brovagnati/tools-<https://demo.globant.com/%7Ebrovagnati/tools->>

Dangermouse

unread,
Nov 12, 2007, 9:58:14 AM11/12/07
to Google Checkout Mod for OSC Community Support Forum
When I say its not being taxed, thats not entirely true as tax is
being added to the order as a whole, but each individual product is
showing a tax of 0%

On Nov 12, 2:22 pm, Ropu <rovagn...@gmail.com> wrote:

> > >https://demo.globant.com/~brovagnati/tools-<https://demo.globant.com/%7Ebrovagnati/tools->>

Jon Cooper :: Business IT Solutions

unread,
Nov 12, 2007, 3:20:45 PM11/12/07
to google-checkout-f...@googlegroups.com
I had this same issue, but fixed it by resetting the uk zones file.

I followed this and google then worked for me.

http://oscart.seiretto.com/oscommerce_VAT_tutorial.html

Thought I had it setup ok as osc worked fine with paypal and credit cards
with VAT, but with GC I had no vat.

Thanks to above, all works now.

Try it, see if it helps you.

Jon Cooper

Dangermouse

unread,
Nov 13, 2007, 10:34:37 AM11/13/07
to Google Checkout Mod for OSC Community Support Forum
Hi Jon

Thanks for the suggestion... Just tried this however and it still is
exactly the same.

I am quite willing to accept that this is probably something quirky
about my setup in OSC, but for the life of me I can not find it.

Ive deleted my own tax zones and gone through the tutorial you linked
to and its still exactly the same.

::Scratches head::

On Nov 12, 8:20 pm, "Jon Cooper :: Business IT Solutions"

Message has been deleted

Dangermouse

unread,
Nov 26, 2007, 4:01:02 AM11/26/07
to Google Checkout Mod for OSC Community Support Forum
I could really do with a fix for this please, or a pointer in the
right direction as to why its doing it.

Ive since installed the paypal IPN mod which surely must be similar in
that it takes the user off the site to pay and then back on again and
this works flawlessly, so why doesnt the GC one work as its supposed
to? Surely this eliminates my settings being wrong?

I am currently having to edit each order with the mod found at
http://www.oscommerce.com/community/contributions,1435 to include tax
after the customer has paid. Its not ideal, but it makes the invoice
correct.

On Nov 13, 3:42 pm, Dangermouse <sa...@scalesonline.co.uk> wrote:
> Just to update so I know exactly where we are now... the new user
> created after paying through GC now has the correct country set for
> them in the client information, however the product tax is still
> showing as 0% thus making the price (inc) and price (exc) wrong,
> although tax is being added on to the order afterwards... please see
> the linked GIF athttp://scalesonline.co.uk/images/sanbox_problem.gif
>
> Thanks
>
> Tony
>
> On Nov 12, 8:20 pm, "Jon Cooper :: Business IT Solutions"
>
>
>
> <jon.coo...@jwcgroup.co.uk> wrote:

Dangermouse

unread,
Dec 3, 2007, 11:50:20 AM12/3/07
to Google Checkout Mod for OSC Community Support Forum
Anybody? Please?

Dont know if it helps, but all my store prices are shown including
VAT... when a user places the order and pays via GC, then comes back
to the store it shows them prices without VAT... quite confusing to
the customer as I have it say at the bottom of the page that prices
include VAT.

What am I missing?

Tony

On Nov 26, 9:01 am, Dangermouse <sa...@scalesonline.co.uk> wrote:
> I could really do with a fix for this please, or a pointer in the
> right direction as to why its doing it.
>
> Ive since installed the paypal IPN mod which surely must be similar in
> that it takes the user off the site to pay and then back on again and
> this works flawlessly, so why doesnt the GC one work as its supposed
> to? Surely this eliminates my settings being wrong?
>
> I am currently having to edit each order with the mod found athttp://www.oscommerce.com/community/contributions,1435to includetax
> after the customer has paid. Its not ideal, but it makes the invoice
> correct.
>
> On Nov 13, 3:42 pm, Dangermouse <sa...@scalesonline.co.uk> wrote:
>
>
>
> > Just to update so I know exactly where we are now... the new user
> > created after paying through GC now has the correct country set for
> > them in the client information, however the producttaxis still
> > showing as 0% thus making the price (inc) and price (exc) wrong,
> > althoughtaxis being added on to the order afterwards... please see
> > > GC? will it return a 0%taxwhich will be wrong.
>
> > > Currently OSC asks the user to clarify what zone it is in if it doesnt
> > > recognise their address first time round by means of a drop down
> > > box... because GC is bypassing the normal account creation in OSC then
> > > what kind of fallback is there if OSC doesnt recognize the zone first
> > > time round?
>
> > > On Nov 12, 2:22 pm, Ropu <rovagn...@gmail.com> wrote:
> > > > HI
>
> > > > thetaxis calculated in the google server, and is "hardcoded" in the
> > > > NewOrderNotification..
>
> > > > changing the order country wont affect thetax.
>
> > > > Right now google ONLY appliestaxto the whole UK as a one big zone, u
> > > > cannot differentiate UK regions. To do that, u will need to implement
> > > > merchant calculatedtax. Which the module doesnt offer right now.
>
> > > > You will need to processtaxin the merchant calculations. Right now max
> > > > granularity fortaxin ZC is at State level.
>
> > > > To do this u must add the logic in the googlecheckout/responsehandler.php
> > > (
> > > > v1.4.5) line 933 and 951
> > > > and in gcheckout.php line 594 set merchant_calculatedtaxto true
>
> > > > $Gcart->SetMerchantCalculations($url, 'true', 'false', 'false');
>
> > > > hope this helps
>
> > > > ropu
> > > > On Nov 12, 2007 11:10 AM, Dangermouse <sa...@scalesonline.co.uk> wrote:
>
> > > > > Thats odd as the SQL you gave as an example resulted in
>
> > > > > zone_id zone_country_id
> > > > > 363 222
>
> > > > > The new user created also has the correct country associated with it,
> > > > > however the order still comes through as 0%taxand when I edit the
> > > > > order the country is set to AFGHANISTAN. where the hell is it getting
> > > > > that from??
>
> > > > > Also, what happens if someone has their state set to Northants instead
> > > > > of Northamptonshire, or Bucks instead of Buckinghamshire? This will
> > > > > surely result in 0taxagain as it wont match anything in the zone
> > > > > > > > > > Hi, double check urTaxTable class zone restriction
> > - Show quoted text -- Hide quoted text -

Dangermouse

unread,
Dec 4, 2007, 8:52:36 AM12/4/07
to Google Checkout Mod for OSC Community Support Forum
OK, well I have installed a fresh copy of OSC and set it up for the UK
as per http://oscart.seiretto.com/oscommerce_VAT_tutorial.html .

Added UK zones as per http://www.oscommerce.com/community/contributions,1300/category,all/search,uk_counties+1.2
.

Set the store location to UK and the zone to our county and Google
checkout orders are still coming in with 0% tax on the item line and
the correct tax on the order total, which is incorrect.

Interestingly, the fix ropu have me earlier for responsehandler as
per:-

$zone_answer = tep_db_fetch_array(tep_db_query("select
zone_id, zone_country_id from " .
TABLE_ZONES . " where zone_code = '" . $buyer_state . "' or
zone_name = '" . $buyer_state . "'"));

makes the newly created customer account come through as UK instead of
afghanistan, however the order still has 0% tax.

Its only when using the order editor/creator mod on my live install
that I can see that the orders country is set to afghanistan (not the
accounts address which is correctly set to United Kingdom)

So, is there a fix similar to the one above for the order itself, not
just for the account address?

Hope that makes sense, please let me know if it doesnt.

Dangermouse

unread,
Dec 5, 2007, 8:50:23 AM12/5/07
to Google Checkout Mod for OSC Community Support Forum
This is really beginning to do my head in.

Before I went out on lunch I thought I had this fixed on my test
cart. An order was placed and it included tax on the product line,
exactly as it should be... But when I came back from lunch I placed a
second order to confirm my happiness and guess what, it no longer
works??!?!!

To get it to work in the first place all I did was install a new order
total module: http://www.oscommerce.com/community/contributions,4618/category,all/search,subtotal+ex+vat

Dont know if this was just fluke, but it now doesnt seem to hold any
fix.

Whats the difference between these 2 following items?

YTo5OntzOjM6InF0eSI7aToxO3M6NDoibmFtZSI7czoyNjoiTWljcm9zb2Z0IEludGVsbGlNb3VzZSBQcm8iO3M6NToibW9kZWwiO3M6NzoiTVNJTVBSTyI7czozOiJ0YXgiO2Q6MTcuNTAwMDAwMDAwMDAwMDAzNTUyNzEzNjc4ODAwNTAwOTI5MzU1NjIxMzM3ODkwNjI1O3M6MTU6InRheF9kZXNjcmlwdGlvbiI7czoyMjoiVkFUIEV4ZW1wdCArIFZBVCAxNy41JSI7czo1OiJwcmljZSI7czo3OiIzOS45OTAwIjtzOjExOiJmaW5hbF9wcmljZSI7ZDozOS45OTAwMDAwMDAwMDAwMDE5ODk1MTk2NjAxMjgyODA1MjA0MzkxNDc5NDkyMTg3NTtzOjY6IndlaWdodCI7czo0OiI3LjAwIjtzOjI6ImlkIjtpOjM7fQ==

YTo5OntzOjM6InF0eSI7aToxO3M6NDoibmFtZSI7czoyNjoiTWljcm9zb2Z0IEludGVsbGlNb3VzZSBQcm8iO3M6NToibW9kZWwiO3M6NzoiTVNJTVBSTyI7czozOiJ0YXgiO2Q6MDtzOjE1OiJ0YXhfZGVzY3JpcHRpb24iO3M6MTA6IlZBVCBFeGVtcHQiO3M6NToicHJpY2UiO3M6NzoiMzkuOTkwMCI7czoxMToiZmluYWxfcHJpY2UiO2Q6MzkuOTkwMDAwMDAwMDAwMDAxOTg5NTE5NjYwMTI4MjgwNTIwNDM5MTQ3OTQ5MjE4NzU7czo2OiJ3ZWlnaHQiO3M6NDoiNy4wMCI7czoyOiJpZCI7aTozO30=

Help Please?

Dangermouse

unread,
Dec 6, 2007, 11:18:50 AM12/6/07
to Google Checkout Mod for OSC Community Support Forum
Ive discovered that the way to "fix" this is to add "all countries" to
the european tax zone and remove it from the Rest of the World tax
zone, however this means that everybody in every country gets charged
VAT which is obviously incorrect.

Come on guys, I dont mean to pester, but the lack of support from the
creators of this script is nothing short of amazing. I have now spent
several weeks on this off and on and am no further on...

ropu

unread,
Dec 7, 2007, 9:04:11 AM12/7/07
to Google Checkout Mod for OSC Community Support Forum
Yeap

i see the issue

could you please send me how WITH THE EXACT SAME CART; SAME ADDRESS
but a different payment method, the order should look?

thx

ropu

On Nov 13, 12:42 pm, Dangermouse <sa...@scalesonline.co.uk> wrote:
> Just to update so I know exactly where we are now... the new user
> created after paying through GC now has the correct country set for
> them in the client information, however the product tax is still
> showing as 0% thus making the price (inc) and price (exc) wrong,
> although tax is being added on to the order afterwards... please see
> the linked GIF athttp://scalesonline.co.uk/images/sanbox_problem.gif
>
> Thanks
>
> Tony
>
> On Nov 12, 8:20 pm, "Jon Cooper :: Business IT Solutions"
>
> <jon.coo...@jwcgroup.co.uk> wrote:
> ...
>
> read more >>

Dangermouse

unread,
Dec 7, 2007, 9:29:15 AM12/7/07
to Google Checkout Mod for OSC Community Support Forum
Thank you for getting back to me...

This is how it looks with using google checkout:-

http://charlie.superior-servers.net/~scales/images/incorrect.gif

This is how it looks when I use any other payment method (in this case
cash):-

http://charlie.superior-servers.net/~scales/images/correct.gif

Notice the 17.5% tax on the product line as well as the VAT 17.5% on
the subtotal/totals line.

Ropu

unread,
Dec 10, 2007, 10:12:33 AM12/10/07
to google-checkout-f...@googlegroups.com
Thx for the info, i'll try to reproduce it and find the error.


ropu

Dangermouse

unread,
Jan 14, 2008, 10:58:51 AM1/14/08
to Google Checkout Mod for OSC Community Support Forum
Is there any chance we could get a fix on this?

It has now officially lost me an order due to confusion caused by this
problem.

thanks

On Dec 10 2007, 3:12 pm, Ropu <rovagn...@gmail.com> wrote:
> Thx for the info, i'll try to reproduce it and find the error.
>
> ropu
>
> On Dec 7, 2007 11:29 AM, Dangermouse <sa...@scalesonline.co.uk> wrote:
>
>
>
>
>
>
>
> > Thank you for getting back to me...
>
> > This is how it looks with using google checkout:-
>
> >http://charlie.superior-servers.net/~scales/images/incorrect.gif<http://charlie.superior-servers.net/%7Escales/images/incorrect.gif>
>
> > This is how it looks when I use any other payment method (in this case
> > cash):-
>
> >http://charlie.superior-servers.net/~scales/images/correct.gif<http://charlie.superior-servers.net/%7Escales/images/correct.gif>
>
> > Notice the 17.5% tax on the product line as well as the VAT 17.5% on
> > the subtotal/totals line.
>
> --
> .-. --- .--. ..-
> R  o  p  u- Hide quoted text -

Dangermouse

unread,
Jan 24, 2008, 11:26:00 AM1/24/08
to Google Checkout Mod for OSC Community Support Forum
Is this project still alive? I last received a response from you on
Dec 10th 2007, over 7 weeks ago.
> > - Show quoted text -- Hide quoted text -

Dangermouse

unread,
Jan 25, 2008, 5:41:49 AM1/25/08
to Google Checkout Mod for OSC Community Support Forum
Has anybody in the UK got googlecheckout working and successfully
adding in VAT at 17.5% to the OSC admin orders?

I cant believe I am the only one with this problem??

pablof

unread,
Jan 29, 2008, 9:33:54 AM1/29/08
to Google Checkout Mod for OSC Community Support Forum
try this:

replace these lines (around line 397):

foreach ($items as $item) {
if (isset ($item['merchant-private-item-data']['item']
['VALUE'])) {
$order->products[] =
unserialize(base64_decode($item['merchant-private-item-data']['item']
['VALUE']));
} else
if ($item['merchant-private-item-data']['order_total']
['VALUE']) {
$ot = unserialize(base64_decode($item['merchant-private-
item-data']['order_total']['VALUE']));
$ot_customs[] = $ot;
$ot_value = $ot['value'] * (strrpos($ot['text'], '-') ===
false ? 1 : -1);
$ot_customs_total += $currencies->get_value($gc_data[$root]
['order-total']['currency']) * $ot_value;
} else {
// For Invoices!
// Happy BDay ropu, 07/03
$order->products[] = array (
'qty' => $item['quantity']['VALUE'],
'name' => $item['item-name']['VALUE'],
'model' => $item['item-description']['VALUE'],
'tax' => 0,
'tax_description' => @$item['tax-table-selector']
['VALUE'],
'price' => $item['unit-price']['VALUE'],
'final_price' => $item['unit-price']['VALUE'],
'onetime_charges' => 0,
'weight' => 0,
'products_priced_by_attribute' => 0,
'product_is_free' => 0,
'products_discount_type' => 0,
'products_discount_type_from' => 0,
'id' => @$item['merchant-item-id']['VALUE']
);
}
}

with these:

foreach ($items as $item) {
if(isset($item['tax-table-selector']['VALUE'])) {
$query = "select tax_rate from ".TABLE_TAX_RATES.
" where tax_description = '" .
$item['tax-table-selector']['VALUE']."'";
$tax_rate_result = tep_db_query($query);
$tax_res = tep_db_fetch_array($tax_rate_result);
$tax_rate = floatval($tax_res['tax_rate']);
} else {
$tax_rate = 0;
}

if (isset ($item['merchant-private-item-data']['item']
['VALUE'])) {
$p = unserialize(base64_decode($item['merchant-private-item-
data']['item']['VALUE']));
$p['tax'] = $tax_rate;
$p['tax_description'] = $item['tax-table-selector']
['VALUE'];
$order->products[] = $p;
} else
if ($item['merchant-private-item-data']['order_total']
['VALUE']) {
$ot = unserialize(base64_decode($item['merchant-private-
item-data']['order_total']['VALUE']));
$ot_customs[] = $ot;
$ot_value = $ot['value'] * (strrpos($ot['text'], '-') ===
false ? 1 : -1);
$ot_customs_total += $currencies->get_value($gc_data[$root]
['order-total']['currency']) * $ot_value;
} else {
// For Invoices!
// Happy BDay ropu, 07/03
$order->products[] = array (
'qty' => $item['quantity']['VALUE'],
'name' => $item['item-name']['VALUE'],
'model' => $item['item-description']['VALUE'],
'tax' => $tax_rate,
'tax_description' => @$item['tax-table-selector']
['VALUE'],
'price' => $item['unit-price']['VALUE'],
'final_price' => $item['unit-price']['VALUE'],
'onetime_charges' => 0,
'weight' => 0,
'products_priced_by_attribute' => 0,
'product_is_free' => 0,
'products_discount_type' => 0,
'products_discount_type_from' => 0,
'id' => @$item['merchant-item-id']['VALUE']
);
}
}

make sure the Tax Class Title (admin > location / taxes > tax classes)
of the uk tax is the exact same as the Tax Rate Description (admin >
location / taxes > tax rates) that uses that tax class.

the tax setup i used is at https://demo.globant.com/~brovagnati/osc_demo2/catalog/admin/tax_classes.php
it's a demo site so you can play with it all you want.

let me know if it works
cheers,
> ...
>
> read more »

Dangermouse

unread,
Jan 29, 2008, 11:02:11 AM1/29/08
to Google Checkout Mod for OSC Community Support Forum
Thanks for the response...

I tried editing responsehandler.php with the alterations you suggested
but it gave me a completely empty product line as can be seen at
http://scaleserver.co.uk/~scales/sandbox/images/googlecheckoutwrong.gif

Im just about to go through the tax zone settings as per your demo
cart, but I am fairly sure they are correct because all the other
payment modules work correctly.

Tax is being taken by googlecheckout correctly, and the right price is
being paid for the product, its just not being displayed when it comes
back to OSC and this makes the invoice incorrect.
> the tax setup i used is athttps://demo.globant.com/~brovagnati/osc_demo2/catalog/admin/tax_clas...

Dangermouse

unread,
Jan 29, 2008, 11:10:16 AM1/29/08
to Google Checkout Mod for OSC Community Support Forum
There is something I have noticed with your demo cart also...

You only have 1 zone set up, London - UK, which has united kingdom and
all zones inside it. This setup will cause the tax to be calculated
and displayed correctly... the problem I have is that I have 2 zones,
Europe (which only contains United Kindom and all zones at the moment)
and RoW (for rest of the world) which has All Countries in it.

If I take all countries out of RoW and put it into the Europe tax
zone, tax is displayed correctly on the product line. This is,
however, incorrect as then everyone in the world is charged 17.5% vat.

Can i place a test order on your demo account? Im hoping this will
confirm what I am seeing in my installation.


On Jan 29, 2:33 pm, pablof <pab...@gmail.com> wrote:
> the tax setup i used is athttps://demo.globant.com/~brovagnati/osc_demo2/catalog/admin/tax_clas...

Dangermouse

unread,
Jan 29, 2008, 11:23:15 AM1/29/08
to Google Checkout Mod for OSC Community Support Forum
ok, thats mad... It works on your store... vat was passed back to the
OSC admin area on the product line correctly.

What am I missing?

pablof, is it possible I can give you login details to my demo store
privately so you can take a look? I have it setup the same as my live
store so if I have got something setup wrong it should be obvious but
I, for the life of me, cant find it and its screwing my head up!

Thanks

Tony

On Jan 29, 2:33 pm, pablof <pab...@gmail.com> wrote:
> the tax setup i used is athttps://demo.globant.com/~brovagnati/osc_demo2/catalog/admin/tax_clas...

pablof

unread,
Jan 29, 2008, 11:40:52 AM1/29/08
to google-checkout-f...@googlegroups.com
if you modified the code correctly and the tax class being applied is
the correct one there shouldn't be any problems.
if the tax is being calculated correctly and you only have 2 tax
classes that would mean it's applying the correct one so i don't think
it's a tax config issue, the problem must be in the code.

did you make sure the Tax Class Title of the uk tax is the exact same
as the Tax Rate Description?
this is sort of a quick fix but is necessary for the responsehandler
script to find the tax class that was applied to the item in the osc
DB.

please re-check the code you modified, or send me the modified part of
the file to me privately so i can review it.

cheers,

--
pablof

Dangermouse

unread,
Jan 29, 2008, 12:06:08 PM1/29/08
to Google Checkout Mod for OSC Community Support Forum
OK, re-edited the code and checked the zones. I even modified the
name of the zone so there was no chance of it being wrong and it was
the same result as previously posted with the empty product line (just
0 x) as the product name.

Here is the responsehandler.php file in full:-

<?php
/*
Copyright (C) 2007 Google Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

/* **GOOGLE CHECKOUT ** v1.4.5
* @version $Id: responsehandler.php 6952 2007-09-27 14:58:57Z ropu $
* Script invoked for any callback notfications from the Checkout
server
* Can be used to process new order notifications, order state changes
and risk notifications
*/

// 1. Setup the log file
// 2. Parse the http header to verify the source
// 3. Parse the XML message
// 4. Trasfer control to appropriate function

// Error handler function
// Used to handle errors and log them in the GC log files
//function ErrorHandler($errno, $errstr, $errfile, $errline){
// global $Gresponse;
// switch ($errno) {
// case E_USER_ERROR:
// $err = "USER ERROR: [$errno] $errstr\n"
// . " Fatal error on line $errline in file $errfile
\n"
// . "Process aborted\n";
// $Gresponse->log->logError($err);
// $Gresponse->SendServerErrorStatus($err);
// break;
//
// case E_USER_WARNING:
// $err = "WARNING: [$errno] $errstr\n"
// . " Error on line $errline in file $errfile\n"
// . "Process aborted\n";
// $Gresponse->log->logError($err);
// $Gresponse->SendServerErrorStatus($err);
// break;
//
// case E_USER_NOTICE:
// $err = "NOTICE: [$errno] $errstr\n"
// . " Error on line $errline in file $errfile\n"
// . "Process continues.\n";
// $Gresponse->log->logError($err);
//// $Gresponse->SendServerErrorStatus($err);
// break;
//
// default:
// $err = "Unknown error type: [$errno] $errstr\n"
// . " Error on line $errline in file $errfile\n"
// . "Process continues.\n";
// $Gresponse->log->logError($err);
//// $Gresponse->SendServerErrorStatus($err);
// break;
// }
//
// /* Don't execute PHP internal error handler */
// return true;
//}
error_reporting(E_ALL);

// temporal disable of multisocket
define('MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET', 'False');


define('GC_STATE_NEW', 100);
define('GC_STATE_PROCESSING', 101);
define('GC_STATE_SHIPPED', 102);
define('GC_STATE_REFUNDED', 103);
define('GC_STATE_SHIPPED_REFUNDED', 104);
define('GC_STATE_CANCELED', 105);


chdir('./..');
$curr_dir = getcwd();
define('API_CALLBACK_ERROR_LOG', $curr_dir."/googlecheckout/logs/
response_error.log");
define('API_CALLBACK_MESSAGE_LOG', $curr_dir."/googlecheckout/logs/
response_message.log");

require_once($curr_dir.'/googlecheckout/library/
googlemerchantcalculations.php');
require_once($curr_dir.'/googlecheckout/library/googleresult.php');
require_once ($curr_dir . '/googlecheckout/library/
googlerequest.php');
require_once($curr_dir.'/googlecheckout/library/googleresponse.php');

$Gresponse = new GoogleResponse();
//Setup the log files
$Gresponse->SetLogFiles(API_CALLBACK_ERROR_LOG,
API_CALLBACK_MESSAGE_LOG, L_ALL);
//set_error_handler("ErrorHandler");
// Retrieve the XML sent in the HTTP POST request to the
ResponseHandler
$xml_response = isset($HTTP_RAW_POST_DATA)?
$HTTP_RAW_POST_DATA:file_get_contents("php://
input");
if (get_magic_quotes_gpc()) {
$xml_response = stripslashes($xml_response);
}
list($root, $gc_data) = $Gresponse->GetParsedXML($xml_response);
if(isset($gc_data[$root]['shopping-cart']['merchant-private-data']
['session-data']['VALUE'])) {
list ($sess_id, $sess_name) =
explode(";", $gc_data[$root]['shopping-cart']['merchant-private-
data']['session-data']['VALUE']);
//If session management is supported by this PHP version
if(function_exists('session_id'))
session_id($sess_id);
if(function_exists('session_name'))
session_name($sess_name);
}

include('includes/application_top.php');
include('includes/modules/payment/googlecheckout.php');

if(tep_session_is_registered('cart') && is_object($cart)) {
$cart->restore_contents();
} else {
$Gresponse->SendServerErrorStatus("Shopping cart not obtained from
session.");
}

$googlepayment = new googlecheckout();
$Gresponse->SetMerchantAuthentication($googlepayment->merchantid,
$googlepayment->merchantkey);

// Check if is CGI install, if so .htaccess is needed
if(MODULE_PAYMENT_GOOGLECHECKOUT_CGI != 'True') {
$Gresponse->HttpAuthentication();
}

switch ($root) {
case "request-received": {
process_request_received_response($Gresponse);
break;
}
case "error": {
process_error_response($Gresponse);
break;
}
case "diagnosis": {
process_diagnosis_response($Gresponse);
break;
}
case "checkout-redirect": {
process_checkout_redirect($Gresponse);
break;
}
case "merchant-calculation-callback" :
{
// if (MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET == 'True') {
// include_once ($curr_dir . '/googlecheckout/
multisocket.php');
// process_merchant_calculation_callback($Gresponse, 2.7,
false);
// break;
// }
// }
// case "merchant-calculation-callback-single" :
// {
// set_time_limit(5);
process_merchant_calculation_callback_single($Gresponse);
break;
}

case "new-order-notification": {

/*
* 1. check if the users email exists
* 1.a if not, create the user, and log in
* 2. Check if exists as a GC user
* 2.aAdd it the the google_checkout table to match buyer_id
customer_id
*
* 2. add the order to the logged user
*
*/
// Check if the order was already processed
$google_order = tep_db_fetch_array(tep_db_query("select
orders_id ".
" from " . $googlepayment-
>table_order . " " .
" where google_order_number = " .
$gc_data[$root]['google-order-number']
['VALUE'] ));
if($google_order['orders_id'] != '') {
// Order already processed, send ACK http 200 to avoid
notification resend
$Gresponse->log-
>logError(sprintf(GOOGLECHECKOUT_ERR_DUPLICATED_ORDER,
$gc_data[$root]['google-order-
number']['VALUE'],
$google_order['orders_id']));
$Gresponse->SendAck();
}

// Check if the email exists
$customer_exists = tep_db_fetch_array(tep_db_query("select
customers_id from " .
TABLE_CUSTOMERS . " where customers_email_address = '" .
gc_makeSqlString($gc_data[$root]['buyer-billing-address']
['email']['VALUE']) . "'"));

// Check if the GC buyer id exists
$customer_info = tep_db_fetch_array(tep_db_query("select
gct.customers_id from " .
$googlepayment->table_name . " gct " .
" inner join " .TABLE_CUSTOMERS . " tc on gct.customers_id =
tc.customers_id ".
" where gct.buyer_id = " .
gc_makeSqlString($gc_data[$root]['buyer-id']['VALUE'])));

$new_user = false;
// Ignore session to avoid mix of Cart-GC sessions/emails
// GC email is the most important one
if ($customer_exists['customers_id'] != '') {
$customer_id = $customer_exists['customers_id'];
tep_session_register('customer_id');
}
else if($customer_info['customers_id'] != ''){
$customer_id = $customer_info['customers_id'];
tep_session_register('customer_id');
}
else {
list ($firstname, $lastname) =
explode(' ', gc_makeSqlString($gc_data[$root]['buyer-
billing-address']['contact-name']['VALUE']), 2);
$sql_data_array = array (
'customers_firstname' => $firstname,
'customers_lastname' => $lastname,
'customers_email_address' => $gc_data[$root]['buyer-billing-
address']['email']['VALUE'],
'customers_telephone' => $gc_data[$root]['buyer-billing-
address']['phone']['VALUE'],
'customers_fax' => $gc_data[$root]['buyer-billing-address']
['fax']['VALUE'],
'customers_default_address_id' => 0,
'customers_password' =>
tep_encrypt_password(gc_makeSqlString($gc_data[$root]['buyer-id']
['VALUE'])),
'customers_newsletter' => $gc_data[$root]['buyer-marketing-
preferences']['email-allowed']['VALUE']=='true'?1:0
);
if (ACCOUNT_DOB == 'true') {
$sql_data_array['customers_dob'] = 'now()';
}
tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);
$customer_id = tep_db_insert_id();
tep_session_register('customer_id');
tep_db_query("insert into " . TABLE_CUSTOMERS_INFO . "
(customers_info_id,
customers_info_number_of_logons,

customers_info_date_account_created)
values ('" . (int) $customer_id . "',
'0', now())");
tep_db_query("insert into " . $googlepayment->table_name . "
" .
" values ( " . $customer_id . ", " .
$gc_data[$root]['buyer-id']['VALUE'] . ")");
$new_user = true;
}
// The user exists and is logged in
// Check database to see if the address exist.
$address_book = tep_db_query("select address_book_id,
entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . "
where customers_id = '" . $customer_id . "'
and entry_street_address = '" .
gc_makeSqlString($gc_data[$root]['buyer-shipping-address']['address1']
['VALUE']) . "'
and entry_suburb = '" .
gc_makeSqlString($gc_data[$root]['buyer-shipping-address']['address2']
['VALUE']) . "'
and entry_postcode = '" .
gc_makeSqlString($gc_data[$root]['buyer-shipping-address']['postal-
code']['VALUE']) . "'
and entry_city = '" .
gc_makeSqlString($gc_data[$root]['buyer-shipping-address']['city']
['VALUE']) . "'
");
// If not, add the addr as default one
if (!tep_db_num_rows($address_book)) {
$buyer_state = $gc_data[$root]['buyer-shipping-address']
['region']['VALUE'];
$zone_answer = tep_db_fetch_array(tep_db_query("select
zone_id, zone_country_id from " .
TABLE_ZONES . " where zone_code = '" . $buyer_state . "' or
zone_name = '" . $buyer_state . "'"));
list ($firstname, $lastname) =
explode(' ', gc_makeSqlString($gc_data[$root]['buyer-
shipping-address']['contact-name']['VALUE']), 2);
$sql_data_array = array (
'customers_id' => $customer_id,
'entry_gender' => '',
'entry_company' => $gc_data[$root]['buyer-shipping-address']
['company-name']['VALUE'],
'entry_firstname' => $firstname,
'entry_lastname' => $lastname,
'entry_street_address' => $gc_data[$root]['buyer-shipping-
address']['address1']['VALUE'],
'entry_suburb' => $gc_data[$root]['buyer-shipping-address']
['address2']['VALUE'],
'entry_postcode' => $gc_data[$root]['buyer-shipping-address']
['postal-code']['VALUE'],
'entry_city' => $gc_data[$root]['buyer-shipping-address']
['city']['VALUE'],
'entry_state' => $buyer_state,
'entry_country_id' => $zone_answer['zone_country_id'],
'entry_zone_id' => $zone_answer['zone_id']
);
tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);

$address_id = tep_db_insert_id();
tep_db_query("update " . TABLE_CUSTOMERS . "
set customers_default_address_id =
'" . (int) $address_id . "'
where customers_id = '" . (int)
$customer_id . "'");
$customer_default_address_id = $address_id;
$customer_country_id = $zone_answer['zone_country_id'];
$customer_zone_id = $zone_answer['zone_id'];
} else {
$customer_default_address_id =
$address_book['address_book_id'];
$customer_country_id = $address_book['entry_country_id'];
$customer_zone_id = $address_book['entry_zone_id'];
}
$customer_first_name = $gc_data[$root]['buyer-billing-address']
['contact-name']['VALUE'];
tep_session_register('customer_default_address_id');
tep_session_register('customer_country_id');
tep_session_register('customer_zone_id');
tep_session_register('customer_first_name');
// Customer exists, is logged and address book is up to date

// Create the order
if (isset ($gc_data[$root]['order-adjustment']['shipping']
['merchant-calculated-shipping-adjustment']['shipping-name']
['VALUE'])) {
$shipping = $gc_data[$root]['order-adjustment']['shipping']
['merchant-calculated-shipping-adjustment']['shipping-name']['VALUE'];
$ship_cost = $gc_data[$root]['order-adjustment']['shipping']
['merchant-calculated-shipping-adjustment']['shipping-cost']['VALUE'];
$methods_hash = $googlepayment->getMethods();
list ($a, $method_name) = explode(': ', $shipping, 2);
$shipping_name = $methods_hash[$method_name][0];//name
$shipping_code = $methods_hash[$method_name][2];//code
} else if (isset ($gc_data[$root]['order-adjustment']['shipping']
['flat-rate-shipping-adjustment']['shipping-name']['VALUE'])) {
$shipping = $gc_data[$root]['order-adjustment']['shipping']
['flat-rate-shipping-adjustment']['shipping-name']['VALUE'];
$ship_cost = $gc_data[$root]['order-adjustment']['shipping']
['flat-rate-shipping-adjustment']['shipping-cost']['VALUE'];
$methods_hash = $googlepayment->getMethods();
list ($a, $method_name) = explode(': ', $shipping, 2);
$shipping_name = $methods_hash[$method_name][0];//name
$shipping_code = $methods_hash[$method_name][2];//code
} else if (isset ($gc_data[$root]['order-adjustment']['shipping']
['carrier-calculated-shipping-adjustment']['shipping-name']['VALUE']))
{
$shipping = $gc_data[$root]['order-adjustment']['shipping']
['carrier-calculated-shipping-adjustment']['shipping-name']['VALUE'];
$ship_cost = $gc_data[$root]['order-adjustment']['shipping']
['carrier-calculated-shipping-adjustment']['shipping-cost']['VALUE'];
$shipping_name = $shipping;
$shipping_code = 'GCCarrierCalculated';//code
} else {
$shipping = 'GC Digital Delivery';
$ship_cost = 0;
$shipping_name = $shipping;//name
$shipping_code = 'FreeGCDigital';//code
}
$tax_amt = $gc_data[$root]['order-adjustment']['total-tax']
['VALUE'];
// $order_total = $gc_data[$root]['order-total']['VALUE'];

require (DIR_WS_CLASSES . 'order.php');
$order = new order();
// load the selected shipping module
$payment_method = $googlepayment->title;
if(MODULE_PAYMENT_GOOGLECHECKOUT_MODE=='https://
sandbox.google.com/checkout/'){
$payment_method .= " - SANDBOX";
}
// $method_name = '';
// if (!empty ($shipping)) {
// require (DIR_WS_CLASSES . 'shipping.php');
// $shipping_modules = new shipping($shipping);
// list ($a, $method_name) = explode(': ', $shipping, 2);
// }
// Set up order info
list ($order->customer['firstname'], $order-
>customer['lastname']) =
explode(' ', $gc_data[$root]['buyer-billing-address']
['contact-name']['VALUE'], 2);
$order->customer['company'] = $gc_data[$root]['buyer-billing-
address']['company-name']['VALUE'];
$order->customer['street_address'] = $gc_data[$root]['buyer-
billing-address']['address1']['VALUE'];
$order->customer['suburb'] = $gc_data[$root]['buyer-billing-
address']['address2']['VALUE'];
$order->customer['city'] = $gc_data[$root]['buyer-billing-
address']['city']['VALUE'];
$order->customer['postcode'] = $gc_data[$root]['buyer-billing-
address']['postal-code']['VALUE'];
$order->customer['state'] = $gc_data[$root]['buyer-billing-
address']['region']['VALUE'];
$order->customer['country']['title'] = $gc_data[$root]['buyer-
billing-address']['country-code']['VALUE'];
$order->customer['telephone'] = $gc_data[$root]['buyer-billing-
address']['phone']['VALUE'];
$order->customer['email_address'] = $gc_data[$root]['buyer-
billing-address']['email']['VALUE'];
$order->customer['format_id'] = 2;
list ($order->delivery['firstname'], $order-
>delivery['lastname']) =
explode(' ', $gc_data[$root]['buyer-shipping-address']
['contact-name']['VALUE'], 2);
$order->delivery['company'] = $gc_data[$root]['buyer-shipping-
address']['company-name']['VALUE'];
$order->delivery['street_address'] = $gc_data[$root]['buyer-
shipping-address']['address1']['VALUE'];
$order->delivery['suburb'] = $gc_data[$root]['buyer-shipping-
address']['address2']['VALUE'];
$order->delivery['city'] = $gc_data[$root]['buyer-shipping-
address']['city']['VALUE'];
$order->delivery['postcode'] = $gc_data[$root]['buyer-shipping-
address']['postal-code']['VALUE'];
$order->delivery['state'] = $gc_data[$root]['buyer-shipping-
address']['region']['VALUE'];
$order->delivery['country']['title'] = $gc_data[$root]['buyer-
shipping-address']['country-code']['VALUE'];
$order->delivery['format_id'] = 2;
list ($order->billing['firstname'], $order->billing['lastname'])
=
explode(' ', $gc_data[$root]['buyer-billing-address']
['contact-name']['VALUE'], 2);
$order->billing['company'] = $gc_data[$root]['buyer-billing-
address']['company-name']['VALUE'];
$order->billing['street_address'] = $gc_data[$root]['buyer-
billing-address']['address1']['VALUE'];
$order->billing['suburb'] = $gc_data[$root]['buyer-billing-
address']['address2']['VALUE'];
$order->billing['city'] = $gc_data[$root]['buyer-billing-
address']['city']['VALUE'];
$order->billing['postcode'] = $gc_data[$root]['buyer-billing-
address']['postal-code']['VALUE'];
$order->billing['state'] = $gc_data[$root]['buyer-billing-
address']['region']['VALUE'];
$order->billing['country']['title'] = $gc_data[$root]['buyer-
billing-address']['country-code']['VALUE'];
$order->billing['format_id'] = 2;
$order->info['payment_method'] = $payment_method;
$order->info['payment_module_code'] = $googlepayment->code;
$order->info['shipping_method'] = $shipping_name;
$order->info['shipping_module_code'] = $shipping_code;
$order->info['cc_type'] = '';
$order->info['cc_owner'] = '';
$order->info['cc_number'] = '';
$order->info['cc_expires'] = '';
$order->info['order_status'] = GC_STATE_NEW;
$order->info['tax'] = $tax_amt;
$order->info['currency'] = $gc_data[$root]['order-total']
['currency'];
$order->info['currency_value'] = 1;
// $customers_ip_address'] = $gc_data[$root]['shopping-cart']
['merchant-private-data']['ip-address']['VALUE'];
$order->info['comments'] = GOOGLECHECKOUT_STATE_NEW_ORDER_NUM .
$gc_data[$root]['google-order-number']['VALUE'] . "\n" .
GOOGLECHECKOUT_STATE_NEW_ORDER_MC_USED .
((@$gc_data[$root]['order-adjustment']['merchant-calculation-
successful']['VALUE'] == 'true')?'True':'False') .
($new_user ? ("\n" .
GOOGLECHECKOUT_STATE_NEW_ORDER_BUYER_USER .
$gc_data[$root]['buyer-billing-address']['email']['VALUE'] .
"\n" .
GOOGLECHECKOUT_STATE_NEW_ORDER_BUYER_PASS . $gc_data[$root]
['buyer-id']['VALUE']):'');

$coupons = gc_get_arr_result(@$gc_data[$root]['order-adjustment']
['merchant-codes']['coupon-adjustment']);
// $gift_cert = get_arr_result(@$gc_data[$root]['order-
adjustment']['merchant-codes']['gift-certificate-adjustment']);
$items = gc_get_arr_result($gc_data[$root]['shopping-cart']
['items']['item']);

// Get Coustoms OT
$ot_customs_total = 0;
$ot_customs = array();
$order->products = array();
$cart = new shoppingCart();
$prod_attr = gc_get_prattr($order->products);

foreach($prod_attr as $product_id => $item_data){
//$products_id, $qty = '1', $attributes = '
$cart->add_cart($product_id, $item_data['qty'] ,
$item_data['attr']);
}
// Update values so that order_total modules get the correct
values
$order->info['total'] = $gc_data[$root]['order-total']['VALUE'];
$order->info['subtotal'] = $gc_data[$root]['order-total']
['VALUE'] -
($ship_cost + $tax_amt) +
@$coupons[0]['applied-amount']
['VALUE'] -
$ot_customs_total;
$order->info['coupon_code'] = @$coupons[0]['code']['VALUE'];
$order->info['shipping_method'] = $shipping;
$order->info['shipping_cost'] = $ship_cost;
$order->info['tax_groups']['Tax'] = $tax_amt;
$order->info['currency'] = $gc_data[$root]['order-total']
['currency'];
$order->info['currency_value'] = 1;

require (DIR_WS_CLASSES . 'order_total.php');
$order_total_modules = new order_total();
// Disable OT sent as items in the GC cart
foreach ($order_total_modules->modules as $ot_code =>
$order_total) {
if (!in_array(substr($order_total, 0, strrpos($order_total,
'.')), $googlepayment->ot_ignore)) {
unset ($order_total_modules->modules[$ot_code]);
}
}
$order_totals = $order_total_modules->process();
// Not necessary, OT already disabled
// foreach($order_totals as $ot_code => $order_total){
// if(!in_array($order_total['code'], $googlepayment-
>ot_ignore)){
// unset($order_totals[$ot_code]);
// }
// }

// Merge all OT
$order_totals = array_merge($order_totals, $ot_customs);
if (isset ($gc_data[$root]['order-adjustment']['merchant-codes']
['coupon-adjustment'])) {
$order_totals[] = array (
'code' => 'ot_coupon',
'title' => "<b>" . MODULE_ORDER_TOTAL_COUPON_TITLE .
" " . @$coupons[0]['code']['VALUE'] . ":</b>",
'text' => $currencies->format(@$coupons[0]['applied-amount']
['VALUE']*-1,
false,@$coupons[0]['applied-amount']
['currency'])
,
'value' => @$coupons[0]['applied-amount']['VALUE'],
'sort_order' => 280
);
}

function OT_cmp($a, $b) {
if ($a['sort_order'] == $b['sort_order'])
return 0;
return ($a['sort_order'] < $b['sort_order']) ? -1 : 1;
}
usort($order_totals, "OT_cmp");

$sql_data_array = array('customers_id' => $customer_id,
'customers_name' => $order-
>customer['firstname'] . ' ' . $order->customer['lastname'],
'customers_company' => $order-
>customer['company'],
'customers_street_address' => $order-
>customer['street_address'],
'customers_suburb' => $order-
>customer['suburb'],
'customers_city' => $order-
>customer['city'],
'customers_postcode' => $order-
>customer['postcode'],
'customers_state' => $order-
>customer['state'],
'customers_country' => $order-
>customer['country']['title'],
'customers_telephone' => $order-
>customer['telephone'],
'customers_email_address' => $order-
>customer['email_address'],
'customers_address_format_id' => $order-
>customer['format_id'],
'delivery_name' => $order-
>delivery['firstname'] . ' ' . $order->delivery['lastname'],
'delivery_company' => $order-
>delivery['company'],
'delivery_street_address' => $order-
>delivery['street_address'],
'delivery_suburb' => $order-
>delivery['suburb'],
'delivery_city' => $order-
>delivery['city'],
'delivery_postcode' => $order-
>delivery['postcode'],
'delivery_state' => $order-
>delivery['state'],
'delivery_country' => $order-
>delivery['country']['title'],
'delivery_address_format_id' => $order-
>delivery['format_id'],
'billing_name' => $order-
>billing['firstname'] . ' ' . $order->billing['lastname'],
'billing_company' => $order-
>billing['company'],
'billing_street_address' => $order-
>billing['street_address'],
'billing_suburb' => $order-
>billing['suburb'],
'billing_city' => $order-
>billing['city'],
'billing_postcode' => $order-
>billing['postcode'],
'billing_state' => $order-
>billing['state'],
'billing_country' => $order-
>billing['country']['title'],
'billing_address_format_id' => $order-
>billing['format_id'],
'payment_method' => $order-
>info['payment_method'],
'cc_type' => $order->info['cc_type'],
'cc_owner' => $order->info['cc_owner'],
'cc_number' => $order-
>info['cc_number'],
'cc_expires' => $order-
>info['cc_expires'],
'date_purchased' => 'now()',
'orders_status' => $order-
>info['order_status'],
'currency' => $order->info['currency'],
'currency_value' => $order-
>info['currency_value']);
tep_db_perform(TABLE_ORDERS, $sql_data_array);
$insert_id = tep_db_insert_id();
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
$sql_data_array = array('orders_id' => $insert_id,
'title' => $order_totals[$i]['title'],
'text' => $order_totals[$i]['text'],
'value' => $order_totals[$i]
['value'],
'class' => $order_totals[$i]['code'],
'sort_order' => $order_totals[$i]
['sort_order']);
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
}

$customer_notification = (SEND_EMAILS == 'true') ? '1' : '0';
$sql_data_array = array('orders_id' => $insert_id,
'orders_status_id' => $order-
>info['order_status'],
'date_added' => 'now()',
'customer_notified' =>
$customer_notification,
'comments' => $order->info['comments']);
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);

// initialized for the email confirmation
$products_ordered = '';
$subtotal = 0;
$total_tax = 0;
$total_weight = 0;
$total_products_price = 0;
$products_tax = 0;
$total_cost = 0;


for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {
if (DOWNLOAD_ENABLED == 'true') {
$stock_query_raw = "SELECT products_quantity,
pad.products_attributes_filename
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " .
TABLE_PRODUCTS_ATTRIBUTES . " pa
ON p.products_id=pa.products_id
LEFT JOIN " .
TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
ON
pa.products_attributes_id=pad.products_attributes_id
WHERE p.products_id = '" .
tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
$products_attributes = @$order->products[$i]
['attributes'];
if (is_array($products_attributes)) {
$stock_query_raw .= " AND pa.options_id = '" .
$products_attributes[0]['option_id'] . "' AND pa.options_values_id =
'" . $products_attributes[0]['value_id'] . "'";
}
$stock_query = tep_db_query($stock_query_raw);
} else {
$stock_query = tep_db_query("select products_quantity from
" . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order-
>products[$i]['id']) . "'");
}
if (tep_db_num_rows($stock_query) > 0) {
$stock_values = tep_db_fetch_array($stock_query);
// do not decrement quantities if products_attributes_filename
exists
if ((DOWNLOAD_ENABLED != 'true') || (!
$stock_values['products_attributes_filename'])) {
$stock_left = $stock_values['products_quantity'] -
$order->products[$i]['qty'];
} else {
$stock_left = $stock_values['products_quantity'];
}
tep_db_query("update " . TABLE_PRODUCTS . " set
products_quantity = '" . $stock_left . "' where products_id = '" .
tep_get_prid($order->products[$i]['id']) . "'");
if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT ==
'false') ) {
tep_db_query("update " . TABLE_PRODUCTS . " set
products_status = '0' where products_id = '" . tep_get_prid($order-
>products[$i]['id']) . "'");
}
}
}

// Update products_ordered (for bestsellers list)
tep_db_query("update " . TABLE_PRODUCTS . " set
products_ordered = products_ordered + " . sprintf('%d', $order-
>products[$i]['qty']) . " where products_id = '" . tep_get_prid($order-
>products[$i]['id']) . "'");

$sql_data_array = array('orders_id' => $insert_id,
'products_id' => tep_get_prid($order-
>products[$i]['id']),
'products_model' => $order-
>products[$i]['model'],
'products_name' => $order->products[$i]
['name'],
'products_price' => $order-
>products[$i]['price'],
'final_price' => $order->products[$i]
['final_price'],
'products_tax' => $order->products[$i]
['tax'],
'products_quantity' => $order-
>products[$i]['qty']);
tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
$order_products_id = tep_db_insert_id();

//------insert customer choosen option to order--------
$attributes_exist = '0';
$products_ordered_attributes = '';
if (isset($order->products[$i]['attributes'])) {
$attributes_exist = '1';
for ($j=0, $n2=sizeof($order->products[$i]['attributes']);
$j<$n2; $j++) {
if (DOWNLOAD_ENABLED == 'true') {
$attributes_query = "select popt.products_options_name,
poval.products_options_values_name, pa.options_values_price,
pa.price_prefix, pad.products_attributes_maxdays,
pad.products_attributes_maxcount , pad.products_attributes_filename
from " . TABLE_PRODUCTS_OPTIONS . "
popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " .
TABLE_PRODUCTS_ATTRIBUTES . " pa
left join " .
TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
on
pa.products_attributes_id=pad.products_attributes_id
where pa.products_id = '" . $order-
>products[$i]['id'] . "'
and pa.options_id = '" . $order-
>products[$i]['attributes'][$j]['option_id'] . "'
and pa.options_id =
popt.products_options_id
and pa.options_values_id = '" .
$order->products[$i]['attributes'][$j]['value_id'] . "'
and pa.options_values_id =
poval.products_options_values_id
and popt.language_id = '" .
$languages_id . "'
and poval.language_id = '" .
$languages_id . "'";
$attributes = tep_db_query($attributes_query);
} else {
$attributes = tep_db_query("select
popt.products_options_name, poval.products_options_values_name,
pa.options_values_price, pa.price_prefix from " .
TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . "
poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id =
'" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order-
>products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id =
popt.products_options_id and pa.options_values_id = '" . $order-
>products[$i]['attributes'][$j]['value_id'] . "' and
pa.options_values_id = poval.products_options_values_id and
popt.language_id = '" . $languages_id . "' and poval.language_id =
'" . $languages_id . "'");
}
$attributes_values = tep_db_fetch_array($attributes);

$sql_data_array = array('orders_id' => $insert_id,
'orders_products_id' =>
$order_products_id,
'products_options' =>
$attributes_values['products_options_name'],
'products_options_values' =>
$attributes_values['products_options_values_name'],
'options_values_price' =>
$attributes_values['options_values_price'],
'price_prefix' =>
$attributes_values['price_prefix']);
tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES,
$sql_data_array);

if ((DOWNLOAD_ENABLED == 'true') &&
isset($attributes_values['products_attributes_filename']) &&
tep_not_null($attributes_values['products_attributes_filename'])) {
$sql_data_array = array('orders_id' => $insert_id,
'orders_products_id' =>
$order_products_id,
'orders_products_filename' =>
$attributes_values['products_attributes_filename'],
'download_maxdays' =>
$attributes_values['products_attributes_maxdays'],
'download_count' =>
$attributes_values['products_attributes_maxcount']);
tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD,
$sql_data_array);
}
$products_ordered_attributes .= "\n\t" .
$attributes_values['products_options_name'] . ' ' .
$attributes_values['products_options_values_name'];
}
}
//------insert customer choosen option eof ----
$total_weight += ($order->products[$i]['qty'] * $order-
>products[$i]['weight']);
$total_tax += tep_calculate_tax($total_products_price,
$products_tax) * $order->products[$i]['qty'];
$total_cost += $total_products_price;

$products_ordered .= $order->products[$i]['qty'] . ' x ' .
$order->products[$i]['name'] . ' (' . $order->products[$i]['model'] .
') = ' . $currencies->display_price($order->products[$i]
['final_price'], $order->products[$i]['tax'], $order->products[$i]
['qty']) . $products_ordered_attributes . "\n";
}







// FOR COUPON SUPPORT
// $insert_id = $order->create($order_totals, 2);
//// $order_total_modules = new order_total();
// // store the product info to the order
// $order->create_add_products($insert_id);
//// $order_number_created'] = $insert_id;
// // Add coupon to redeem track
// if (isset ($gc_data[$root]['order-adjustment']['merchant-
codes']['coupon-adjustment'])) {
// $sql = "select coupon_id
// from " . TABLE_COUPONS . "
// where
coupon_code= :couponCodeEntered
// and coupon_active='Y'";
// $sql = $db->bindVars($sql, ':couponCodeEntered', $coupons[0]
['code']['VALUE'], 'string');
//
// $coupon_result = tep_db_query($sql);
// $cc_id = $coupon_result['coupon_id'];
//
// tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . "
// (coupon_id, redeem_date,
redeem_ip, customer_id, order_id)
// values ('" . (int) $cc_id . "',
now(), '" .
// $gc_data[$root]['shopping-cart']['merchant-private-data']
['ip-address']['VALUE'] .
// "', '" . (int) $customer_id . "', '" . (int) $insert_id .
"')");
// $cc_id = "";
// }

//Add the order details to the table
// This table could be modified to hold the merchant id and key
if required
// so that different mids and mkeys can be used for different
orders
tep_db_query("insert into " . $googlepayment->table_order . "
values (" . $insert_id . ", " .
gc_makeSqlString($gc_data[$root]['google-order-number']
['VALUE']) . ", " .
gc_makeSqlFloat($gc_data[$root]['order-total']['VALUE']) . ")");

$cart->reset(TRUE);
tep_session_unregister('sendto');
tep_session_unregister('billto');
tep_session_unregister('shipping');
tep_session_unregister('payment');
tep_session_unregister('comments');
$Gresponse->SendAck();
break;
}
case "order-state-change-notification": {
process_order_state_change_notification($Gresponse, $googlepayment);
break;
}
case "charge-amount-notification": {
process_charge_amount_notification($Gresponse, $googlepayment);
break;
}
case "chargeback-amount-notification": {
process_chargeback_amount_notification($Gresponse);
break;
}
case "refund-amount-notification": {
process_refund_amount_notification($Gresponse, $googlepayment);
break;
}
case "risk-information-notification": {
process_risk_information_notification($Gresponse, $googlepayment);
break;
}
default: {
$Gresponse->SendBadRequestStatus("Invalid or not supported
Message");
break;
}
}
exit(0);

function process_request_received_response($Gresponse) {
}
function process_error_response($Gresponse) {
}
function process_diagnosis_response($Gresponse) {
}
function process_checkout_redirect($Gresponse) {
}

function process_merchant_calculation_callback_single($Gresponse) {
global $googlepayment, $order, $cart, $total_weight, $total_count;
list($root, $gc_data) = $Gresponse->GetParsedXML();
$currencies = new currencies();

// Get a hash array with the description of each shipping method
$methods_hash = $googlepayment->getMethods();

require(DIR_WS_CLASSES .'order.php');
$order = new order;

$items = gc_get_arr_result($gc_data[$root]['shopping-cart']['items']
['item']);

// Get Coustoms OT
$ot_customs_total = 0;
$ot_customs = array();
$order->products = array();
foreach ($items as $item) {
if (isset ($item['merchant-private-item-data']['item']['VALUE']))
{
$order->products[] = unserialize(base64_decode($item['merchant-
private-item-data']['item']['VALUE']));
$ex_cart = $cart;
$cart = new shoppingCart();

$prod_attr = gc_get_prattr($order->products);

foreach($prod_attr as $product_id => $item_data){
//$products_id, $qty = '1', $attributes = '
$cart->add_cart($product_id, $item_data['qty'] ,
$item_data['attr']);
}

// Register a random ID in the session to check throughout the
checkout procedure
// against alterations in the shopping cart contents.
// if (!tep_session_is_registered('cartID')) {
// tep_session_register('cartID');
// }
// $cartID = $cart->cartID;

$total_weight = $cart->show_weight();
$total_count = $cart->count_contents();

// Create the results and send it
$merchant_calc = new GoogleMerchantCalculations(DEFAULT_CURRENCY);

// Loop through the list of address ids from the callback.
$addresses = gc_get_arr_result($gc_data[$root]['calculate']
['addresses']['anonymous-address']);
// Get all the enabled shipping methods.
require(DIR_WS_CLASSES .'shipping.php');

// Required for some shipping methods (ie. USPS).
require_once('includes/classes/http_client.php');
foreach($addresses as $curr_address) {
// Set up the order address.
$curr_id = $curr_address['id'];
$country = $curr_address['country-code']['VALUE'];
$city = $curr_address['city']['VALUE'];
$region = $curr_address['region']['VALUE'];
$postal_code = $curr_address['postal-code']['VALUE'];

$row = tep_db_fetch_array(tep_db_query("select * from ".
TABLE_COUNTRIES ." where countries_iso_code_2 = '".
gc_makeSqlString($country) ."'"));
$order->delivery['country'] = array('id' => $row['countries_id'],
'title' =>
$row['countries_name'],
'iso_code_2' => $country,
'iso_code_3' =>
$row['countries_iso_code_3']);
$order->delivery['country_id'] = $row['countries_id'];
$order->delivery['format_id'] = $row['address_format_id'];

$row = tep_db_fetch_array(tep_db_query("select * from ".
TABLE_ZONES ." where zone_code = '" .
gc_makeSqlString($region) ."'"));
$order->delivery['zone_id'] = $row['zone_id'];
$order->delivery['state'] = $row['zone_name'];

$order->delivery['city'] = $city;
$order->delivery['postcode'] = $postal_code;
// print_r($order);
$shipping_modules = new shipping();

// Loop through each shipping method if merchant-calculated
shipping
// support is to be provided
//print_r($gc_data[$root]['calculate']['shipping']['method']);
if(isset($gc_data[$root]['calculate']['shipping'])) {
$shipping = gc_get_arr_result($gc_data[$root]['calculate']
['shipping']['method']);


if(MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET == 'True') {
// Single
// i get all the enabled shipping methods
$name = $shipping[0]['name'];
// Compute the price for this shipping method and address
id
list($a, $method_name) = explode(': ',$name);
if((($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY)
&& ($methods_hash[$method_name][1] == 'domestic_types'))
||
(($order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY)
&& ($methods_hash[$method_name][1] == 'international_types'))){
// reset the shipping class to set the new address
if (class_exists($methods_hash[$method_name][2])) {
$GLOBALS[$methods_hash[$method_name][2]] = new
$methods_hash[$method_name][2];
}
}
$quotes = $shipping_modules->quote('',
$methods_hash[$method_name][2]);
}
else {
// Standard
foreach($shipping as $curr_ship) {
$name = $curr_ship['name'];
// Compute the price for this shipping method and address
id
list($a, $method_name) = explode(': ',$name);
if((($order->delivery['country']['id'] ==
SHIPPING_ORIGIN_COUNTRY)
&& ($methods_hash[$method_name][1] == 'domestic_types'))
||
(($order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY)
&& ($methods_hash[$method_name][1] ==
'international_types'))){
// reset the shipping class to set the new address
if (class_exists($methods_hash[$method_name][2])) {
$GLOBALS[$methods_hash[$method_name][2]] = new
$methods_hash[$method_name][2];
}
}
}
$quotes = $shipping_modules->quote();
}
reset($shipping);
foreach($shipping as $curr_ship) {
$name = $curr_ship['name'];
// Compute the price for this shipping method and address
id
list($a, $method_name) = explode(': ',$name);
unset($quote_povider);
unset($quote_method);
if((($order->delivery['country']['id'] ==
SHIPPING_ORIGIN_COUNTRY)
&& ($methods_hash[$method_name][1] == 'domestic_types'))
||
(($order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY)
&& ($methods_hash[$method_name][1] ==
'international_types'))) {
foreach($quotes as $key_provider => $shipping_provider) {
// privider name (class)
if($shipping_provider['id'] == $methods_hash[$method_name][2]) {
// method name
$quote_povider = $key_provider;
if(is_array($shipping_provider['methods']))
foreach($shipping_provider['methods'] as $key_method =>
$shipping_method) {
if($shipping_method['id'] == $methods_hash[$method_name][0]){
$quote_method = $key_method;
break;
}
}
break;
}
}
}
//if there is a problem with the method, i mark it as non-
shippable
if( isset($quotes[$quote_povider]['error']) ||
!isset($quotes[$quote_povider]['methods'][$quote_method]
['cost'])) {
$price = "9999.09";
$shippable = "false";
} else {
$price = $quotes[$quote_povider]['methods'][$quote_method]
['cost'];
$shippable = "true";
}
$merchant_result = new GoogleResult($curr_id);
$merchant_result->SetShippingDetails($name, $currencies-
>get_value(DEFAULT_CURRENCY) * $price, $shippable);

if($gc_data[$root]['calculate']['tax']['VALUE'] == "true") {
//Compute tax for this address id and shipping type
$amount = 17.5; // Modify this to the actual tax value
$merchant_result->SetTaxDetails($currencies-
>get_value(DEFAULT_CURRENCY) * $amount);
}

if(isset($gc_data[$root]['calculate']['merchant-code-strings']
['merchant-code-string'])){
$codes = gc_get_arr_result($gc_data[$root]['calculate']
['merchant-code-strings']['merchant-code-string']);
foreach($codes as $curr_code) {
//Update this data as required to set whether the coupon
is valid, the code and the amount
$coupons = new GoogleCoupons("true", $curr_code['code'],
$currencies->get_value(DEFAULT_CURRENCY) * 5, "test2");
$merchant_result->AddCoupons($coupons);
}
}
$merchant_calc->AddResult($merchant_result);
}
} else {
$merchant_result = new GoogleResult($curr_id);
if($gc_data[$root]['calculate']['tax']['VALUE'] == "true") {
//Compute tax for this address id and shipping type
$amount = 17.5; // Modify this to the actual tax value
$merchant_result->SetTaxDetails($currencies-
>get_value(DEFAULT_CURRENCY) * $amount);
}
// calculate_coupons($Gresponse, $merchant_result);
$merchant_calc->AddResult($merchant_result);
}
}
$cart = $ex_cart;

$Gresponse->ProcessMerchantCalculations($merchant_calc);
}

function process_order_state_change_notification($Gresponse,
$googlepayment) {
list($root, $gc_data) = $Gresponse->GetParsedXML();
$new_financial_state = $gc_data[$root]['new-financial-order-state']
['VALUE'];
$new_fulfillment_order = $gc_data[$root]['new-fulfillment-order-
state']['VALUE'];

$previous_financial_state = $gc_data[$root]['previous-financial-
order-state']['VALUE'];
$previous_fulfillment_order = $gc_data[$root]['previous-fulfillment-
order-state']['VALUE'];

$google_order_number = $gc_data[$root]['google-order-number']
['VALUE'];

$google_order = tep_db_fetch_array(tep_db_query("select orders_id
from ".
$googlepayment->table_order ." where
google_order_number = '".
gc_makeSqlString($google_order_number) ."'"));


$update = false;
if ($previous_financial_state != $new_financial_state) {
switch($new_financial_state) {
case 'REVIEWING':
{
break;
}
case 'CHARGEABLE':
{
$update = true;
$orders_status_id = GC_STATE_NEW;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]
['timestamp']['VALUE']. "\n".
GOOGLECHECKOUT_STATE_STRING_NEW_STATE.
$new_financial_state."\n".
GOOGLECHECKOUT_STATE_STRING_ORDER_READY_CHARGE;
$customer_notified = 0;
break;
}
case 'CHARGING':
{
break;
}
case 'CHARGED':
{
$update = true;
$orders_status_id = GC_STATE_PROCESSING;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]
['timestamp']['VALUE']. "\n".
GOOGLECHECKOUT_STATE_STRING_NEW_STATE.
$new_financial_state ;
$customer_notified = 0;
break;
}


case 'PAYMENT-DECLINED':
{
$update = true;
$orders_status_id = GC_STATE_NEW;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]
['timestamp']['VALUE']. "\n".
GOOGLECHECKOUT_STATE_STRING_NEW_STATE.
$new_financial_state .
GOOGLECHECKOUT_STATE_STRING_PAYMENT_DECLINED;
$customer_notified = 1;
break;
}
case 'CANCELLED':
{
$update = true;
$orders_status_id = GC_STATE_CANCELED;
$customer_notified = 1;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]
['timestamp']['VALUE']. "\n".
GOOGLECHECKOUT_STATE_STRING_NEW_STATE.
$new_financial_state ."\n".
GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED;
break;
}
case 'CANCELLED_BY_GOOGLE':
{
$update = true;
$orders_status_id = GC_STATE_CANCELED;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]
['timestamp']['VALUE']. "\n".
GOOGLECHECKOUT_STATE_STRING_NEW_STATE.
$new_financial_state ."\n".
GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED_BY_GOOG;
$customer_notified = 1;
break;
}
default:
break;
}
}

if($update) {
$sql_data_array = array('orders_id' => $google_order['orders_id'],
'orders_status_id' => $orders_status_id,
'date_added' => 'now()',
'customer_notified' => $customer_notified,
'comments' => $comments);
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
tep_db_query("update ". TABLE_ORDERS . " set orders_status = '".
$orders_status_id."' where orders_id = '".
gc_makeSqlInteger($google_order['orders_id']) ."'");
}

$update = false;

if($previous_fulfillment_order != $new_fulfillment_order) {
switch($new_fulfillment_order) {
case 'NEW':
{
break;
}
case 'PROCESSING' :
{
// $Gresponse->SendAck(false);
$Grequest = new GoogleRequest($googlepayment->merchantid,
$googlepayment->merchantkey,

MODULE_PAYMENT_GOOGLECHECKOUT_MODE==
'https://sandbox.google.com/
checkout/'
?"sandbox":"production",
DEFAULT_CURRENCY);
$Grequest->SetLogFiles(API_CALLBACK_ERROR_LOG,
API_CALLBACK_MESSAGE_LOG);
$google_answer = tep_db_fetch_array(tep_db_query("SELECT
go.google_order_number, go.order_amount, o.customers_email_address,
gc.buyer_id, o.customers_id
FROM " . $googlepayment-
>table_order . " go
inner join " .
TABLE_ORDERS . " o on go.orders_id = o.orders_id
inner join " .
$googlepayment->table_name . " gc on gc.customers_id = o.customers_id
WHERE go.orders_id = '" .
(int)$google_order['orders_id'] ."'
group by o.customers_id
order by o.orders_id desc"));

$first_order = tep_db_fetch_array(tep_db_query("SELECT
customers_id, count(*) cant_orders
FROM " . TABLE_ORDERS . "
WHERE customers_id = '".
$google_answer['customers_id']."'
group by customers_id"));
// Send buyers email and password if new user and first buy with
GC in the site
if($first_order['cant_orders'] == 1) {
list($status,) = $Grequest-
>sendBuyerMessage($google_answer['google_order_number'],

sprintf(GOOGLECHECKOUT_NEW_CREDENTIALS_MESSAGE,
STORE_NAME,

$google_answer['customers_email_address'],

$google_answer['buyer_id']), "true", 2);

$comments = GOOGLECHECKOUT_STATE_STRING_TIME .
$gc_data[$root]['timestamp']['VALUE'] . "\n" .
GOOGLECHECKOUT_STATE_STRING_NEW_STATE .
$new_fulfillment_order. "\n";

if($status != 200) {
$comments .= "\n" .
GOOGLECHECKOUT_ERR_SEND_NEW_USER_CREDENTIALS . "\n";
$customer_notified = '0';
}
else {
$comments .=
GOOGLECHECKOUT_SUCCESS_SEND_NEW_USER_CREDENTIALS . "\n";
$customer_notified = '1';
}
$comments .= "Messsage:\n" .
sprintf(GOOGLECHECKOUT_NEW_CREDENTIALS_MESSAGE,
STORE_NAME,

$google_answer['customers_email_address'],
$google_answer['buyer_id']);

$update = true;
$orders_status_id = GC_STATE_PROCESSING;
}

// Tell google witch is the Zencart's internal order
Number
$Grequest-
>SendMerchantOrderNumber($google_answer['google_order_number'],

$google_order['orders_id'],
2);
break;
}
case 'DELIVERED' :
{
$check_status = tep_db_fetch_array(tep_db_query("select
orders_status from " . TABLE_ORDERS . "
where orders_id = '" .
$google_order['orders_id'] . "'"));

switch($check_status['orders_status']){
case GC_STATE_REFUNDED:
$orders_status_id = GC_STATE_SHIPPED_REFUNDED;
break;
case GC_STATE_PROCESSING:
default;
$orders_status_id = GC_STATE_SHIPPED;
break;
}

$update = true;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME . $gc_data[$root]
['timestamp']['VALUE']. "\n".
GOOGLECHECKOUT_STATE_STRING_NEW_STATE.
$new_fulfillment_order ."\n".
GOOGLECHECKOUT_STATE_STRING_ORDER_DELIVERED."\n";
$customer_notified = 1;
break;
}
case 'WILL_NOT_DELIVER':
{
$update = false;
$orders_status_id = GC_STATE_CANCELED;
$customer_notified = 1;
$comments = GOOGLECHECKOUT_STATE_STRING_TIME .
$gc_data[$root]['timestamp']['VALUE'] . "\n" .
GOOGLECHECKOUT_STATE_STRING_NEW_STATE .
$new_fulfillment_order . "\n" .
GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED;
break;
}
default:
break;
}
}

if($update) {
$sql_data_array = array('orders_id' => $google_order['orders_id'],
'orders_status_id' => $orders_status_id,
'date_added' => 'now()',
'customer_notified' => $customer_notified,
'comments' => $comments);
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
tep_db_query("update ". TABLE_ORDERS ." set orders_status = '".
$orders_status_id ."' WHERE orders_id = '".

gc_makeSqlInteger($google_order['orders_id']) ."'");
}

$Gresponse->SendAck();
}

// Update the order status upon completion of payment.
function process_charge_amount_notification($Gresponse,
$googlepayment) {
list($root, $gc_data) = $Gresponse->GetParsedXML();
$google_order_number = $gc_data[$root]['google-order-number']
['VALUE'];
$google_order = tep_db_fetch_array(tep_db_query("select orders_id
from ".
$googlepayment->table_order ." where
google_order_number = '".
gc_makeSqlString($google_order_number) ."'"));

$sql_data_array = array('orders_id' => $google_order['orders_id'],
'orders_status_id' => GC_STATE_PROCESSING,
'date_added' => 'now()',
'customer_notified' => 0,
'comments' =>
GOOGLECHECKOUT_STATE_STRING_LATEST_CHARGE .
$gc_data[$root]['latest-charge-amount']
['currency'].
' ' .$gc_data[$root]['latest-charge-amount']
['VALUE']."\n".
GOOGLECHECKOUT_STATE_STRING_TOTAL_CHARGE .
$gc_data[$root]['latest-charge-amount']
['currency'].' ' .
$gc_data[$root]['total-charge-amount']
['VALUE']);
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
// Adjust the orders_status value here if you need it to move to a
different status upon payment.
tep_db_query("update ". TABLE_ORDERS ." set orders_status = " .
GC_STATE_PROCESSING . " where orders_id = '".

gc_makeSqlInteger($google_order['orders_id']) ."'");

$Gresponse->SendAck();
}

function process_chargeback_amount_notification($Gresponse) {
$Gresponse->SendAck();
}
function process_refund_amount_notification($Gresponse,
$googlepayment) {
global $currencies;
list ($root, $gc_data) = $Gresponse->GetParsedXML();
$google_order_number = $gc_data[$root]['google-order-number']
['VALUE'];
$google_order = tep_db_fetch_array(tep_db_query("SELECT orders_id
from " .
"" . $googlepayment->table_order . " where google_order_number = " .
"'" . gc_makeSqlString($google_order_number) . "'"));

// fwrite($message_log,sprintf("\n%s\n",
$google_order['orders_id']));
$check_status = tep_db_fetch_array(tep_db_query("select
orders_status from " . TABLE_ORDERS . "
where orders_id = '" .
$google_order['orders_id'] . "'"));

switch($check_status['orders_status']){
case GC_STATE_PROCESSING:
case GC_STATE_REFUNDED:
$orders_status_id = GC_STATE_REFUNDED;
break;
case GC_STATE_SHIPPED:
case GC_STATE_SHIPPED_REFUNDED:
default;
$orders_status_id = GC_STATE_SHIPPED_REFUNDED;
break;
}

$sql_data_array = array (
'orders_id' => $google_order['orders_id'],
'orders_status_id' => GC_STATE_PROCESSING,
'date_added' => 'now()',
'customer_notified' => 1,
'comments' => GOOGLECHECKOUT_STATE_STRING_TIME .
$gc_data[$root]['timestamp']['VALUE'] . "\n" .
GOOGLECHECKOUT_STATE_STRING_LATEST_REFUND .
$currencies->format($gc_data[$root]['latest-refund-amount']
['VALUE'],
false, $gc_data[$root]['latest-refund-amount']
['currency']). "\n".
GOOGLECHECKOUT_STATE_STRING_TOTAL_REFUND .
$currencies->format($gc_data[$root]['total-refund-amount']
['VALUE'],
false, $gc_data[$root]['total-refund-amount']
['currency'])
);
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);

$sql_data_array = array (
'orders_id' => $google_order['orders_id'],
'title' => GOOGLECHECKOUT_STATE_STRING_GOOGLE_REFUND,
'text' => '<font color="#800000">' .
$currencies->format($gc_data[$root]['latest-refund-amount']
['VALUE'] * -1,
false, $gc_data[$root]['latest-refund-amount']
['currency']). "\n".
'</font>',
'value' => $gc_data[$root]['latest-refund-amount']['VALUE'],
'class' => 'ot_goog_refund',
'sort_order' => 1001
);

tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);

$total = tep_db_fetch_array(tep_db_query("SELECT orders_total_id,
text, value from " .
"" . TABLE_ORDERS_TOTAL . " where orders_id = " .
"'" . $google_order['orders_id'] . "' AND class = 'ot_total'"));

$net_rev = tep_db_fetch_array(tep_db_query("SELECT orders_total_id,
text, value from " .
"" . TABLE_ORDERS_TOTAL . " where orders_id = " .
"'" . $google_order['orders_id'] . "' AND class =
'ot_goog_net_rev'"));
$sql_data_array = array (
'orders_id' => $google_order['orders_id'],
'title' => '<b>' . GOOGLECHECKOUT_STATE_STRING_NET_REVENUE . '</
b>',
'text' => '<b>' .
$currencies->format(($total['value'] -
((double) $gc_data[$root]['total-refund-amount']
['VALUE'])),
false, $gc_data[$root]['total-refund-amount']
['currency']).
'</b>', 'value' => ($total['value'] -
((double) $gc_data[$root]['total-refund-amount']['VALUE'])),
'class' => 'ot_goog_net_rev',
'sort_order' => 1010);

if ($net_rev['orders_total_id'] == '') {
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
} else {
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array, 'update',
"orders_total_id = '" .
$net_rev['orders_total_id'] . "'");
}

$Gresponse->SendAck();
}

// Set an order back to pending if there's a problem with payment.
function process_risk_information_notification($Gresponse,
$googlepayment) {
list($root, $gc_data) = $Gresponse->GetParsedXML();
$google_order_number = $gc_data[$root]['google-order-number']
['VALUE'];
$google_order = tep_db_fetch_array(tep_db_query("select orders_id
from ".
$googlepayment->table_order ." where
google_order_number = '".
gc_makeSqlString($google_order_number) ."'"));



$sql_data_array = array('orders_id' => $google_order['orders_id'],
'orders_status_id' => GC_STATE_NEW,
'date_added' => 'now()',
'customer_notified' => 0,
'comments' =>
GOOGLECHECKOUT_STATE_STRING_RISK_INFO ."\n" .
GOOGLECHECKOUT_STATE_STRING_RISK_ELEGIBLE.
$gc_data[$root]['risk-information']['eligible-for-protection']
['VALUE']."\n" .
GOOGLECHECKOUT_STATE_STRING_RISK_AVS.
$gc_data[$root]['risk-information']['avs-response']
['VALUE']."\n" .
GOOGLECHECKOUT_STATE_STRING_RISK_CVN.
$gc_data[$root]['risk-information']['cvn-response']
['VALUE']."\n" .
GOOGLECHECKOUT_STATE_STRING_RISK_CC_NUM.
$gc_data[$root]['risk-information']['partial-cc-number']
['VALUE']."\n" .
GOOGLECHECKOUT_STATE_STRING_RISK_ACC_AGE.
$gc_data[$root]['risk-information']['buyer-account-age']
['VALUE']."\n"
);
tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
tep_db_query("update ". TABLE_ORDERS ." set orders_status = '".
GC_STATE_NEW .
"' WHERE orders_id = '".

gc_makeSqlInteger($google_order['orders_id'])."'");

$Gresponse->SendAck();
}

//Functions to prevent SQL injection attacks
function gc_makeSqlString($str) {
return tep_db_input($str);
// return addcslashes(stripcslashes($str), "'\"\\\0..\37!@\@
\177..\377");
}

function gc_makeSqlInteger($val) {
return ((settype($val, 'integer'))?($val):0);
}

function gc_makeSqlFloat($val) {
return ((settype($val, 'float'))?($val):0);
}
/* In case the XML API contains multiple open tags
with the same value, then invoke this function and
perform a foreach on the resultant array.
This takes care of cases when there is only one unique tag
or multiple tags.
Examples of this are "anonymous-address", "merchant-code-string"
from the merchant-calculations-callback API
*/
function gc_get_arr_result($child_node) {
$result = array();
if(isset($child_node)) {
if(gc_is_associative_array($child_node)) {
$result[] = $child_node;
}
else {
foreach($child_node as $curr_node){
$result[] = $curr_node;
}
}
}

return $result;
}

// Returns true if a given variable represents an associative array
function gc_is_associative_array($var) {
return is_array($var) && !is_numeric(implode('', array_keys($var)));
}

function gc_get_prattr($order_items) {
$rta = array();
foreach($order_items as $item) {
$tmp = array();
$pieces = explode('{', $item['id']);
for($i=1,$n=count($pieces); $i<$n; $i++){
list($opt, $val) = explode('}', $pieces[$i]);
$tmp[$opt] = $val;
}
$rta[$pieces[0]] = array('attr' => $tmp,
'qty' => $item['qty']);
}
return $rta;
}


?>

pablof

unread,
Jan 29, 2008, 12:42:10 PM1/29/08
to google-checkout-f...@googlegroups.com
the code seems to be alright, very puzzling.

does it work in a clean install?

--
pablof

Dangermouse

unread,
Jan 29, 2008, 2:34:30 PM1/29/08
to Google Checkout Mod for OSC Community Support Forum
My demo site practically is a fresh install other than the UK zones
being imported into the database as they are in my live site and
obviously googlecheckout.

Dangermouse

unread,
Jan 29, 2008, 4:34:16 PM1/29/08
to Google Checkout Mod for OSC Community Support Forum
OK, this evening I have installed a completely fresh install of OSC
and googlecheckout... added no other addons and set up the store to be
in the UK and given it 2 tax classes, taxable goods and tax exempt.

Ive also gone through the settings in your demo cart and copied over
the ones I feel are relevant.

All of this and its still doing exactly the same.

What else can I try?

Dangermouse

unread,
Jan 30, 2008, 6:06:34 AM1/30/08
to Google Checkout Mod for OSC Community Support Forum
OK, we have progress!!!

I took the code you had previously posted a few posts ago and re-laid
it out as this forum had munged it a little (line breaks etc). Made
sure the tax class and tax rate description were the same and sure
enough the VAT is now displayed on the product line! Wahoo!

One thing is still happening which is a slight annoyance is that when
the customer has come back to the shop from paying, prices are
displayed in the shop excluding VAT which is contrary to how I have
the shop set up. I even have a small amount of text after the price
saying inc.vat... so this can cause a little confusion to someone who
has just paid for an item only to believe that they have paid VAT
twice.

Closing down the browser and opening it again cures this... but just
for those moments after an order has been placed it displays prices
incorrectly.

Anything that can be done about this?

Thanks

Dangermouse

unread,
Feb 1, 2008, 8:51:53 AM2/1/08
to Google Checkout Mod for OSC Community Support Forum
Please can you help with the returning customer tax issue?

When the customer returns to the website from GC their prices are
shown excluding VAT. If the customer closes their browser and then
goes back to the site the prices are then inclusive of VAT, until they
log in to their account where by they are displayed excluding VAT.

The customer has to go into their address book in their account and
change the country from from "Please Select" to United Kingdom for tax
to be displayed properly.

For some reason it seems that Google Checkout is not populating the
customers country in properly on return.


On Jan 29, 5:42 pm, pablof <pab...@gmail.com> wrote:

Dangermouse

unread,
Feb 1, 2008, 11:55:16 AM2/1/08
to Google Checkout Mod for OSC Community Support Forum
In fact this behaviour can be seen on your demo cart at
http://200.69.205.154/~brovagnati/osc_demo2/catalog/admin/customers.php?

However this only seems to be happening for UK customers...

Dangermouse

unread,
Feb 7, 2008, 4:24:12 AM2/7/08
to Google Checkout Mod for OSC Community Support Forum
What seems to be the problem is that the SQL is not getting inserted
correctly. Unfortunately my PHP skills are limited, but even I can
see that the table address_book > entry_country_id is being set to 0
instead of the countries actual value.

This causes tax to not be displayed upon the customers return back to
the store.

On Feb 1, 4:55 pm, Dangermouse <sa...@scalesonline.co.uk> wrote:
> In fact this behaviour can be seen on your demo cart athttp://200.69.205.154/~brovagnati/osc_demo2/catalog/admin/customers.php?

parksey

unread,
Feb 24, 2008, 12:19:49 PM2/24/08
to Google Checkout Mod for OSC Community Support Forum
Their is a quick fix to this problem providing your customers are all
located in the UK

In sql Admin modify the address_book tavle layout set
entry_country_code to have a default value of 222 this is the OSC
value for UK, if your customer is eu then it appears that the
checkouthandler.php does write the correct value for their country
code.

good luck

regards

Rhys
www.calibraweighing.co.uk
> ...
>
> read more »

parksey

unread,
Feb 24, 2008, 10:15:04 PM2/24/08
to Google Checkout Mod for OSC Community Support Forum
Here is the final solution for this updated responsehandler.php posted
on OSC site

Open /googlecheckout/responcehandler.php

Find about line 252

if (!tep_db_num_rows($address_book)) {
$buyer_state = $gc_data[$root]['buyer-shipping-address']
['region']['VALUE'];
$zone_answer = tep_db_fetch_array(tep_db_query("select
zone_id, zone_country_id from " .
TABLE_ZONES . " where zone_code = '" . $buyer_state . "'"));

Replace with:
if (!tep_db_num_rows($address_book)) {
$buyer_country = $gc_data[$root]['buyer-shipping-address']['country-
code']['VALUE'];
$buyer_state = $gc_data[$root]['buyer-shipping-address']
['region']['VALUE'];
$zone_answer = tep_db_fetch_array(tep_db_query("SELECT
zone_id, zone_country_id from " .
TABLE_ZONES . " where zone_code = '" . $buyer_state . "'"));
//Update to get correct country code
$countries_answer = tep_db_fetch_array(tep_db_query("SELECT
countries_iso_code_2, countries_id FROM " .
TABLE_COUNTRIES . " WHERE countries_iso_code_2 = '" .
$buyer_country . "'"));
$country_new = $countries_answer['countries_id'];

Then find line 269
'entry_country_id' => $zone_answer['zone_country_id'],
replace with
'entry_country_id' => $country_new,

Find line 279
$customer_country_id = $zone_answer['zone_country_id'];

replace with

$customer_country_id = $country_new;

And that's it.

Now your code looks directly at the google code for Country and looks
it up in the database to set the correct country for the customer.
And the tax is correct when they return to the shop, works with UK and
other countries that Google send the ISO_2 code for !!!

Enjoy
any problems drop me a line

rh...@calibraweighing.co.uk
Reply all
Reply to author
Forward
0 new messages