---
name: "Vend::Payment::GoogleCheckout"
section: "3pm"
platform: "linux"
package: "interchange"
version: "5.7.7-2"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/Vend::Payment::GoogleCheckout"
---

# Vend::Payment::GoogleCheckout(3pm)

## Interchange GoogleCheckout support

```
 http://kiwi.zolotek.net is the home page with the latest version. Also to be found on
 Kevin Walsh's excellent Interchange site,  http://interchange.rtfm.info.
```

## AUTHORS

```
 Lyn St George <info@zolotek.net>
```

## CREDITS

```
 Steve Graham, mrlock.com, debugging and documentation
 Andy Smith, tvcables.co.uk, debugging and documentation
```

## PREREQUISITES

XML::Simple and any of its prerequisites (eg XML::Parser or XML::SAX) MIME::Base64 these should be found anyway on any well-used perl installation. This version was built especially  without the Google libraries, so as to work on old machines with perl 5.6.1 and similarly vintaged OSes, and only need XML::Simple.

Interchange.cfg should contain this line, with args extra to 'rand' for current UTF8 problems: SafeUntrap  rand require caller dofile print entereval

## DESCRIPTION

This integrates Google Checkout quite tightly into Interchange - it is expected that all coupons, gift certificates, discounts, tax routines and shipping will be processed by Interchange before sending the customer to Google. The customer will see the basket, tax, shipping and total cost when he arrives there. The shipping is sent as a final value, while the tax is sent as a rate for Google to calculate with. The total cost is calculated by Google, and there is the possibility of penny differences due to rounding errors or different rounding methods employed in different countries. As Google won't accept final tax or total cost figures this cannot be helped.

This module will authorise and optionally charge the customer's card for the purchase. It will handle all IPNs (notifications sent back by Google of various events in the process) and both log the results and send emails to the merchant and customer as appropriate. IPNs relating to chargebacks, refunds and cancellations are included in this. It can handle commands sent through an admin panel - though the current IC panel is not set up to send these. Commands relating to 'charge', 'refund', 'cancel' etc would normally be sent through the Google admin panel, but the resulting IPNs are handled by this module.

In the interests of tighter integration and simplicity, the consensus of opinion has been to allow shipping to only the address taken by Interchange. This means that the shipping charge and tax rate will be correct, but also means that the customer cannot choose another address which he may have on file at Google - if he does then the system will tell him that "Merchant xx does not ship to this address". He of course has the option of clicking "edit basket" and changing his address at Interchange to suit. You may want to display some sort of note to this effect prior to sending the customer to Google. If delivery is to a US address then the restriction is to the state and the first 3 digits of the zip code; if to anywhere else in the world then the restriction is to that country and the first 3 characters of the postal code (or fewer characters if fewer were entered - if no postal code was entered then the whole country is allowed).

It is likely that I will build another version which does allow the customer to change his address whilst at Google, as this limitation is a little too harsh and not at all helpful for good customer relations.

### NOTE ########################################################################################################## # While you can send &amp; and have it returned safely, you cannot send &lt;, &gt; or similar in the # # description field, as it will cause IC to throw an error when Google returns the XML. Even if you send # # these as &#x3c; and similar UTF-8 entities, Google will return them in the &lt; format. # # # # Note also that you can only send the currency that is "associated with your seller account", as # # defined by Google. There is no option to configure this, and they select it according to the country # # you registered in your sign-up account. Nor can you do recurring/subscription billing. # # ##########################################################################################################

## SYNOPSIS

Go to http://checkout.google.com and set up a seller's account. They will give you a merchantid and a merchantkey, which you need to enter into the payment route as described below. While there, go to the "Settings" tab, then the "Integration" left menu item, and set the radio button for "XML call back", and enter the URL to your callback page -  https://your\_site/ord/gcoipn.

Place this module in your Vend/Payment/ directory, and call it in interchange.cfg with: Require module Vend::Payment::GoogleCheckout

Add these configuration options to the new Google payment route in catalog.cfg: Route googlecheckout merchantid  (as given to you by Google at sign-up) Route googlecheckout merchantkey (as given to you by Google at sign-up) Route googlecheckout googlehost  'https://checkout.google.com/cws/v2/Merchant' # live Route googlecheckout gcoipn\_url http://your\_url/cgi\_link/ord/gcoipn (replace 'your\_url' and 'cgi\_link' with yours) Route googlecheckout currency    'GBP'  (or USD, or any other ISO code accepted by Google) Route googlecheckout edit\_basket\_url (eg 'http://your\_url/cgi\_link/ord/basket') Route googlecheckout continue\_shopping\_url (eg, http://your\_url/cgi\_link/index) Route googlecheckout bypass\_authorization  (1 to bypass, empty to use. See below for details) Route googlecheckout default\_taxrate (a decimal, eg '0.06', in case the calculation fails) Route googlecheckout sender\_email (email address appearing in the 'from' and 'reply-to' fields) Route googlecheckout merchant\_email (email address to which the order should be sent) Route googlecheckout receipt\_from\_merchant (1 to send an email receipt to the customer) Route googlecheckout email\_auth\_charge ('charge' to send receipt after card has been charged, 'auth' after card has been authorised) Route googlecheckout html\_mail ('1' to send HTML instead of plain text mail) Route googlecheckout avs\_match\_accepted ('full' for full match where AVS is available, 'partial' for partial match, 'none' for no match required. Default is 'partial') Route googlecheckout cv2\_match\_accepted ('yes' for match required, 'none' for no match required. Default is 'yes') Route googlecheckout default\_country (2 letter ISO country code; use if not taking a delivery country at checkout, otherwise omit) Route googlecheckout default\_state (\* if you want to allow all states within a country, or omit) Route googlecheckout gco\_diagnose (1 if you want to return diagnostics, empty otherwise) Variable	MV\_HTTP\_CHARSET	UTF-8 The last is essential, otherwise GCO will repeat the 'new\_order\_notification' message ad infinitum and never proceed any further. You will be given no clue as to why this is happening.

NB:/ Apache is not built by default to make the HTTP\_AUTHORIZATION header available to the environment, and so you will either need to rebuild it or set 'bypass\_authorization' to 1 - this latter will not check the returned header to see that it contains your merchantid and merchantkey. Google recommend that you make this check, but it's your choice.

Add these order routes to catalog.cfg Route googlecheckout \<\<EOF\
 	attach            0\
 	empty             1\
 	default           1\
 	supplant          1\
 	no\_receipt        1\
 	report            etc/log\_transaction\
 	track             logs/tracking.asc\
 	counter\_tid       logs/tid.counter EOF

Route gco\_final master 1 Route gco\_final cascade "copy\_user main\_entry" Route gco\_final empty 	1 Route gco\_final supplant 1 Route gco\_final no\_receipt 1 Route gco\_final email \_\_ORDERS\_TO\_\_

The 'edit basket' URL is available to customers when they are at Google, and lets them change either the basket contents or the delivery address.

Create a GoogleCheckout button on your checkout page, including the order profile and route like so:\
   \[button\
     mv\_click=google\
     text="GoogleCheckout"\
     hidetext=1\
     form=checkout\
    \]\
    mv\_order\_profile=googlecheckout\
    mv\_order\_route=googlecheckout\
    mv\_todo=submit\
   \[/button\]

Create a page in pages/ord/ called gcoipn.html, consisting of this: \[charge route="googlecheckout" gcorequest="callback"\] This page is the target of all IPN callbacks from Google, and will call the payment module in the correct mode.

To have GoogleCheckout co-operate with your normal payment service provider, eg Authorizenet, do the following:

Add to etc/profiles.order:

\_\_NAME\_\_                            googlecheckout \_\_COMMON\_ORDER\_PROFILE\_\_ &fatal = yes email=required email=email &set=mv\_payment GCO &set=psp GCO &set=mv\_payment\_route googlecheckout &set=mv\_order\_route googlecheckout &final = yes &setcheck = payment\_method googlecheckout \_\_END\_\_ or, if you want to use GCO as a 'Buy now' button without taking any customer details, then omit the \_\_COMMON\_ORDER\_PROFILE\_\_ and the two 'email=...' lines above. Google are in fact quite finicky about you not taking your customer's details, so you have the option of complying with Google or complying with your own policy.

You must have MV\_PAYMENT\_MODE set in products/variable.txt to either your standard payment processor or to 'googlecheckout'; though you may instead set this in catalog.cfg rather than variable txt as: Variable MV\_PAYMENT\_MODE googlecheckout

Within the 'credit\_card' section of etc/profiles.order leave "MV\_PAYMENT\_MODE"  as set and add &set=psp \_\_MV\_PAYMENT\_PSP\_\_ &set=mv\_payment\_route authorizenet (or your preferred gateway) as the last entries in the section.

and then add Variable MV\_PAYMENT\_PSP "foo" to catalog.cfg, where "foo" is the name of your gateway or acquirer, formatted as you want it to appear on the receipt. Eg, "Bank of America" (rather than boa), "AuthorizeNet" (rather than authorizenet).

Run the following at a MySQL prompt to add the requisite fields to your transactions table: (with thanks to Steve Graham)

ALTER TABLE \`transactions\` ADD \`gco\_order\_number\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci , ADD \`gco\_buyers\_id\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_fulfillment\_state\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_serial\_number\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_avs\_response\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_cvn\_response\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_protection\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_cc\_number\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_timestamp\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_reason\` TEXT CHARACTER SET utf8 COLLATE utf8\_general\_ci , ADD \`gco\_latest\_charge\_amount\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_total\_charge\_amount\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_latest\_chargeback\_amount\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_total\_chargeback\_amount\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci , ADD \`gco\_total\_refund\_amount\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`gco\_latest\_refund\_amount\` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`lead\_source\` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`referring\_url\` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`locale\` *VARCHAR*(6) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`currency\_locale\` *VARCHAR*(6) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`txtype\` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8\_general\_ci, ADD \`cart\` BLOB;

And run these to allow for temporary order numbers of greater than the default 14 character field type ALTER TABLE \`transactions\` MODIFY \`order\_number\` varchar(32); ALTER TABLE \`orderline\` MODIFY \`order\_number\` varchar(32);

In etc/log\_transction, immediately after the \[elsif variable MV\_PAYMENT\_MODE\]\
 	\[calc\] insert this line:\
 	undef `$Session`-\>{payment\_result}{MStatus};

and leave \[elsif variable MV\_PAYMENT\_MODE\] as set (contrary to earlier revisions of this document), but within the same section change the following  two instances of \[var MV\_PAYMENT\_MODE\] to \[value mv\_payment\_route\]

Also add these five lines to the end of the section that starts "\[import table=transactions ": lead\_source: \[data session source\] referring\_url: \[data session referer\] locale: \[scratch mv\_locale\] currency\_locale: \[scratch mv\_currency\] cart: \[calc\]uneval($Items)\[/calc\] for use when sending the merchant report and customer receipt emails out.

Still in etc/log\_transaction, find the section that starts "Set order number in values: " and insert this just before it: \[if value mv\_order\_profile =~ /googlecheckout/\] \[value name=mv\_order\_number set="\[scratch purchaseID\]" scratch=1\] \[else\] and a closing \[/else\]\[/if\] at the end of that section, just before the  "Set order number in session:" line. The order number is generated by the module and passed to Google at an early stage, and then passed back to Interchange at a later stage. This prevents Interchange generating another order number. If your Interchange installation is 5.2.0 or older this line will not exist - set oldic to '1' in  the payment route and allow Interchange to generate the order number instead. Note: the initial order number uses the username.counter number prefixed with 'GCOtmp', and a normal order number is created and the initial order number replaced only when Google reports that the card has been charged. This is to avoid gaps in the order number sequence caused by customers abandoning the transaction while at Google.

- Failed atttempts to authorise or charge the buyer's card. If the card is declined by the bank then IC will be updated with the new status and a brief email sent to the buyer telling him of the fact, and asking him to try another payment method.

  - AVS and CV2 risk assessment: avs\_match\_accepted partial\|full\|none

  AVS options and returned values are these: Y - Full AVS match (address and postal code) P - Partial AVS match (postal code only) A - Partial AVS match (address only) N - no AVS match U - AVS not supported by issuer If the route is set to 'full' then, unless AVS is not supported (eg in cards foreign to the country doing the processing), a full match is required. Set to 'partial' (the default) for partial match, or 'none' for no match required.

  CV2 values: cv2\_match\_accepted  yes\|none M - CVN match N - No CVN match U - CVN not available E - CVN error If the route is set to 'yes' then the CV2 must match unless it is not available. If set to 'none' then a match is not required. Default is 'yes'.

  Both of these must be positive according to your rules for the transaction to be charged - if not positive then the transaction will be refused and a brief email sent to the prospective buyer to say so.

- Google Analytics

  This page: http://code.google.com/apis/checkout/developer/checkout\_analytics\_integration.html will tell you how to integrate Analytics into the system. This module will pass the data as an 'analyticsdata'  value from the checkout form, encoded as UTF-8.

- Error messages from GCO

  GCO will send error messages with a '\<' in the title, which Interchange interprets as a possible attack and so immediately stops reading the page and throws the user to the 'violation' page (defined in your catalog.cfg as 'SpecialPage ../special\_pages/violation' normally, though may be different). Insert the following at the top of that page, which will test for the string sent by Google and then bounce the user back to the checkout page with a suitable error message. This uses the 'env' UserTag.

  \[tmp uri\]\[env REQUEST\_URI\]\[/tmp\]\
    \[if  type=explicit compare=\`$Scratch-\>{uri} =~ /%20400%20Bad%20Request%3C\\?xml/\`\] \[perl\]\
    	`$msg` = errmsg("GoogleCheckout has encountered an error - if all of your address and shipping entries are correct, please consider using our 'Credit Card Checkout' instead. Our apologies for any inconvenience.");\
   	`$::Session`-\>{errors}{GoogleCheckout} = `$msg`; \[/perl\]\
    \[bounce href="\[area ord/checkout\]"\]\
    \[/if\]

## Bugs

The default CharSet.pm in Interchange 5.6 (and possibly earlier) will fail on GCO's notifications. The sympton is that GCO keeps repeating the 'new order notification' as though it has not received one, but does not return any errors. Set a variable in your catalog.cfg, thus:  Variable	MV\_HTTP\_CHARSET	UTF-8 but  be aware that this may break the display of some upper ASCII characters, eg the GBP AX sign (use &pound; instead of AX)

## Changelog

v.0.7.0, 29.01.2009\
 	\- added locale, currency\_locale, and cart fields to transaction tbl\
 	\- log basket to transaction tbl to be read and inserted back into session for final order route\
 	\- altered main 'googlecheckout' order route and added new 'gco\_final' order route. Replaced previous\
 	  method of sending emails with this final route. \
 	\- added failsafe logging prior to going to Google, in orders/gco/, file name is 'date.session\_id'

v 0.7.1, May 2009.\
 	\- changed order number creation to only come after Google reports the card as charged. Initially\
 	  uses the tid (from tid.counter) as a temporary order number.

v0.7.2, May 2009,\
 	\- updated documentation, simplifed system for co-operating with other payment systems.

v0.7.3, June 2009\
 	\- added code to update userdb, decrement inventory table and add more meaningful order subject (thanks to Andy Smith of tvcables.co.uk)\
 	\- also fixed an error whereby KDE's Kate had fooled me with incorrect bracket matching.
