An error while talking to google checkout: no implicit conversion from nil to integer

12 views
Skip to first unread message

Mango

unread,
Aug 5, 2009, 2:39:17 PM8/5/09
to Potion Store Discussions
I'm setting up a Potion Store, and have got Paypal working (both
options), but I'm still having some difficulties with Google. I'm
using the sandbox, and have set up everything properly (I think). I
enter the number of items, and select Google Checkout; then I go to
the second screen and enter the name of the Licensee. But then when I
click on the checkout button, I get the following: "Could not connect
to Google Checkout." Anyone have any idea how to solve this? Thanks
in advance.

Log file:
------------
Processing Store::OrderController#purchase (for 76.170.114.2 at
2009-08-05 11:15:11) [POST]
Parameters: {"items"=>{"1"=>"1"}, "commit.x"=>"0",
"action"=>"purchase", "commit.y"=>"0", "order"=>{"comment"=>"",
"licensee_name"=>"Joe Smith", "payment_type"=>"Google Checkout"},
"controller"=>"store/order"}
SQL (0.5ms) SET NAMES 'utf8'
SQL (0.4ms) SET SQL_AUTO_IS_NULL=0
Order Columns (1.3ms) SHOW FIELDS FROM `orders`
LineItem Columns (1.1ms) SHOW FIELDS FROM `line_items`
Product Columns (1.2ms) SHOW FIELDS FROM `products`
Product Load (0.8ms) SELECT * FROM `products` WHERE
(`products`.`id` = 1)
SQL (0.4ms) BEGIN
SQL (0.3ms) COMMIT
CACHE (0.0ms) SELECT * FROM `products` WHERE (`products`.`id` =
1)
SQL (0.5ms) BEGIN
Order Create (0.7ms) INSERT INTO `orders` (`coupon_id`, `company`,
`address1`, `city`, `comment`, `address2`, `country`, `zipcode`,
`failure_reason`, `failure_code`, `last_name`, `ccnum`, `status`,
`email`, `order_time`, `first_name`, `licensee_name`, `state`,
`payment_type`, `transaction_number`) VALUES(NULL, NULL, NULL, '', '',
NULL, '', '', NULL, NULL, '', NULL, 'S', '', '2009-08-05 11:15:11',
'', 'Joe Smith', '', 'Google Checkout', NULL)
LineItem Create (0.6ms) INSERT INTO `line_items` (`product_id`,
`quantity`, `order_id`, `license_key`, `unit_price`) VALUES(1, 1, 60,
NULL, 49.95)
SQL (4.1ms) COMMIT
SQL (3.7ms) BEGIN
LineItem Update (0.5ms) UPDATE `line_items` SET `license_key` =
'<key here - snip>' WHERE `id` = 60
SQL (1.8ms) COMMIT
An error while talking to google checkout: no implicit conversion from
nil to integer
Rendering template within layouts/error
Rendering store/order/failed

Mango

unread,
Aug 5, 2009, 5:26:42 PM8/5/09
to Potion Store Discussions
In trying to track down the source of this problem, I discovered that
if I replace my custom licensekey.rb with the original vanilla one
that comes with the Potion store, the problem goes away. Here is the
custom licensekey.rb (courtesy of cocoafob) below. Can anyone give me
some insight as to why the "nil to integer" error is being generated
by this? Thanks.

---
#!/usr/bin/env ruby
#
# Modify this file and put in your own license key generator
#

require "openssl"
require "rubygems"
require "base32"

# Creates a source string to generate registration code. A source
string
# contains product code name and user's registration name.
def make_license_source(product_code, name)
product_code + "|" + name
end

# This method is called by Potion Store to generate a registration
code. It
# receives a product code string, a registration name and quantity.
I'm not
# using quantity here, but you're free to do it.
def make_license(product_code, name, copies)
sign_dss1 = OpenSSL::Digest::DSS1.new
priv = OpenSSL::PKey::DSA.new(File.read("lib/"+product_code+"/
dsapriv512.pem"))
b32 = Base32.encode(priv.sign(sign_dss1, make_license_source
(product_code, name)))
# Replace Os with 8s and Is with 9s
# See http://members.shaw.ca/akochoi-old/blog/2004/11-07/index.html
b32.gsub!(/O/, '8')
b32.gsub!(/I/, '9')
# chop off trailing padding
b32.delete("=").scan(/.{1,5}/).join("-")
end

def verify_license(product_code, name, copies, lic)
verify_dss1 = OpenSSL::Digest::DSS1.new
pub = OpenSSL::PKey::DSA.new(File.read("lib/"+product_code+"/
dsapub512.pem"))
lic.delete!("-")
lic.gsub!(/9/, 'I')
lic.gsub!(/8/, 'O')
# padded length has to divide by 8
padded_length = lic.length%8 ? (lic.length/8 + 1)*8 : lic.length
padded = lic + "=" * (padded_length-lic.length)
pub.verify(verify_dss1, Base32.decode(padded), make_license_source
(product_code, name))
end

dreamcat four

unread,
Aug 5, 2009, 5:42:41 PM8/5/09
to potion...@googlegroups.com
On Wed, Aug 5, 2009 at 10:26 PM, Mango<wanderi...@gmail.com> wrote:
LineItem Update (0.5ms) UPDATE `line_items` SET `license_key` =
'<key here - snip>' WHERE `id` = 60
SQL (1.8ms) COMMIT
An error while talking to google checkout: no implicit conversion from
nil to integer

If your license key is '<key here - snip>', perhaps google is parsing
the value as a nested xml element (because of the angle brackets).
That's not valid xml. you can imagine the complete line of xml to look
something this:

<GoogleMerchantDataField><key here - snip></GoogleMerchantDataField>

You probably want your license.rb file to return a valid string?
Then the google parser would behave normally, for a valid xml, for example

<GoogleMerchantData>d3b07384d113edec49eaa6238ad5ff00</GoogleMerchantData>

Does that work?

dreamcat4
drea...@gmail.com

Mango

unread,
Aug 6, 2009, 12:46:50 PM8/6/09
to Potion Store Discussions
Thank you for your suggestion; it doesn't work, but you did pinpoint
the issue: Google is reacting to the license key for some reason;
specifically, it seems not to like the dashes in certain cases.

A sample license key looks something like this:

GAWQE-FB2LU-AM9G6-EF79M-UXB59-W9JWR-JYLKE-2KDYC-CUA97-VS5TA-V93EK-
ZVKQE-TWHDJ-QM4XJ-FB9DF-A

It is generated by the following line of code in license.rb (quoted in
context above):

b32.delete("=").scan(/.{1,5}/).join("-")

Here's the weird thing: If I add a space on either side of the dash,
or change the dash to an em-dash, the error goes away. So, either of
the following work:

b32.delete("=").scan(/.{1,5}/).join(" - ")
b32.delete("=").scan(/.{1,5}/).join("–")

But if the user actually types in the license key, this will cause
problems given the possible entry errors introduced with these
symbols.

Interestingly, if I replace a single dash with an exclamation point,
Google also fails:

b32.delete("=").scan(/.{1,5}/).join("!")

Paypal is happy regardless of the symbol used to separate the chunks.

Any ideas? Thanks again.

On Aug 5, 2:42 pm, dreamcat four <dreamc...@gmail.com> wrote:
> dreamc...@gmail.com

dreamcat four

unread,
Aug 6, 2009, 1:17:40 PM8/6/09
to potion...@googlegroups.com
On Thu, Aug 6, 2009 at 5:46 PM, Mango<wanderi...@gmail.com> wrote:
> Any ideas?  Thanks again.


No idea, out of lock, sorry.

I have generated license keys with a dash (minus sign '-') and had
worked for me with Google Checkout. Its not really possible to double
check this (due to a database error, PotionStore hasn't been working
for me lately). You may need to consult the google api docs if there's
nothing wrong in PS.

Here's my licensekey.rb:

#!/usr/bin/env ruby
#
# Modify this file and put in your own license key generator
#

def random_chars_of_length(len)
chars = ("A".."Z").to_a + ("0".."9").to_a
result = ""
1.upto(len) { |i| result << chars[rand(chars.size-1)] }
return result
end

def make_license(product_code, name, copies)
# license = product_code.upcase() + '-' + random_chars_of_length(16)
license = product_code.upcase() + '-' + "LICENSE_KEY"
return license
end

# Simple command line test
if __FILE__ == $0
puts make_license('tgr', 'Andy Kim', 1)
end


dreamcat4
drea...@gmail.com

Mango

unread,
Aug 6, 2009, 7:11:36 PM8/6/09
to Potion Store Discussions
Okay, I was unable to rectify this situation with Google Checkout. I
do note, though, that I can't get the store to connect on the keyboard
dash (hyphen), and many other symbols (including em-dash, en-dash,
minus-sign, and /). All of these symbols work if surrounded by
spaces. But in any case, I have decided to make my license keys work
with space-separators. This now works with both Paypal and Google
Checktout.

Here is the change to the Cocoafob code to make it work. First, in
licensekey.rb, at make_license, change:

b32.delete("=").scan(/.{1,5}/).join("-")

to:

b32.delete("=").scan(/.{1,5}/).join(" ")

That's easy enough, Now to change the Cocoafob code. In
CFobLicVerifier.m, at -verify, change:

NSString *keyNoDashes = [regKeyBase32
stringByReplacingOccurrencesOfString:@"-" withString:@""];

to:

NSString *keyNoDashes = [regKeyBase32
stringByReplacingOccurrencesOfString:@" " withString:@""];
keyNoDashes = [keyNoDashes stringByReplacingOccurrencesOfString:@"%20"
withString:@""];

When using spaces, it is necessary to remove spaces (in case the user
typed or pasted), and also to remove %20 (in case the user clicked
"Activate Now").

Thanks to Alex Clarke, Gleb and Dreamcat4, all of whom helped me work
out this solution.

On Aug 6, 10:17 am, dreamcat four <dreamc...@gmail.com> wrote:
> dreamc...@gmail.com
Reply all
Reply to author
Forward
0 new messages