Vend::Payment::GoogleCheckout(3pm) User Contributed Perl Documentation 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 & and
have it returned safely, you cannot send <, > 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 < and similar UTF-8 entities, Google will return them in the < 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
£ 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.
perl v5.14.2 2011-03-09 Vend::Payment::GoogleCheckout(3pm)