I recently integrated a simple website with Google Checkout. They have perl modules available, and these simplify the process quite a bit. But there's still some questions to be asked by the newcomer to the monolith. This is the story of how one man (me), made it to the cheese. (this was also done quite quickly, I would welcome comments and improvements from the brethren)

Install The Modules

To begin, you'll need the swarm of Google Checkout modules, Google::Checkout, over at CPAN, which looks to be maintained by a cheerful google staffer. Since the underlying technology to these modules is the GCO XML API (not to be confused with the HTML API), you may want to familiarize yourself with the documentation over at http://code.google.com/apis/checkout/developer/index.html - but most of it's functionality is encapsulated in the modules (joy!), concern yourself primarily with the XML data schema, so you know what options are available to you as you muck about with your cart.

Config Your Rig

In our case, I'm only allowing one item to be ordered and then it checks you right out. It works for us, but might not for you, comments from the clergy regarding alternatives are welcomed, and requested.

When I began working, the module available was only able to get it's configuration from a conf file. You can now pass all the needed conf options to the new() call, so take your pick, when I refer to the conf options, I'll do so generally.

You probably want to start working on the GCO sandbox to begin with. If you haven't initiated your sandbox account yet, you'll need to visit http://sandbox.google.com/checkout/sell to do so (and use all fake information! use a fake EIN instead of SSN, there's less form to fill out). Then set up your config for the GCO with:

# -- Sandbox Server: BASE_GCO_SERVER = https://sandbox.google.com/checkout/cws/v2/Merchant/
and everything else as you'd expect it to be.

You can find your MERCHANT_ID and MERCHANT_KEY by logging into your (sandbox) account, and hitting "Settings" and then "Integration". They're there in bold on the right. Make sure you use the *sandbox* ID and KEY with the *sandbox* BASE_GCO_SERVER and the *production* ID and KEY with the *production* server (I haven't given you all the relevant urls to the production servers, I will)

Now you're pretty close. You can also pretty much work right out of the sample code that came with the modules at this point (see ex 1, ex 2, and ex 3). My own method is usually to wrap up these "foreign functions" so I wrote a generic order_item sub, that will call the google functions, but maybe tomorrow.. who knows? That's here (which is mostly just ex 1 from above):

sub order_item { my ( $item, $opts ) = @_; my $config = $GCOSystemGlobalconf; my $checkout_flow; if( my $csurl = $opts->{continue_shopping_url} ) { $checkout_flow = Google::Checkout::General::MerchantCheckoutFlow +->new( continue_shopping_url => $csurl, ); } my $gco = Google::Checkout::General::GCO->new(config_path => $confi +g); my $cart = Google::Checkout::General::ShoppingCart->new( ( $checkout_flow ? ( checkout_flow => $checkout_flow ) : () ), expiration => "+1 month", private => "Simple shopping cart" ); my $gcoitem = Google::Checkout::General::MerchantItem->new( %$item +); $cart->add_item($gcoitem); my $response = $gco->checkout($cart); if( is_gco_error($response) ) { warn $response->string; return { error => $response->string }; } return { redir => $response }; }

Test Your Rig

There are a few credit card numbers you can use (that are fake) to test with, I mostly just use 4433221111223344 which is fun to type to boot. Use any CCV code and (future) expiry date, they will make you use a valid city/st/zip combo though.

After you placed your test order(s), login to the sandbox server to see what you can do with it. (Note that you won't be able to purchase anything from your seller account using the same google account, it will give you an error saying that you can't purchase from yourself. So use a different account when you're acting as a purchaser.)

Test this thoroughly, and tweak to your liking, and when you're ready to go live..

Switch To The Live Cart

Head to the production server, and get your MERCHANT_ID and _KEY from the same place (Setttings -> Integration), and add those live ID and KEY values to your config, finally change your BASE_GCO_SERVER to
# -- Production Server: BASE_GCO_SERVER = https://checkout.google.com/ws/v2/Merchant/

And away you go.

Remember, transactions are free now, but 2008 will see them costing 2% + $0.20 per transaction. Info at https://checkout.google.com/seller/fees.html. There's some kind of deal for those who advertise too, you folks will have to sort that out on your own.

Links


It's not what you look like, when you're doin' what you’re doin'.
It's what you’re doin' when you’re doin' what you look like you’re doin'!
     - Charles Wright & the Watts 103rd Street Rhythm Band, Express yourself

In reply to Getting Started with Google Checkout's perl suite by qbxk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.