nov / itunes-receipt

Handle iTunes In App Purchase Receipt Verification
MIT License
94 stars 65 forks source link

recipt validations #12

Closed sulphur closed 9 years ago

sulphur commented 9 years ago

i have some exceptions since we put it in production. Basically it works i checked with my live app account etc. But for some receipts i have these errors :

 no implicit conversion of Symbol into Integer
 itunes-receipt (1.0.0) lib/itunes/receipt.rb:54:in `[]'

do you have any ideas you want me to send you a sample receipt?

philipgiuliani commented 9 years ago

I have the same error here.

nov commented 9 years ago

I have no idea. It seems receipt_attributes is an Array in your case. Can you inspect receipt_attributes instance?

philipgiuliani commented 9 years ago

I already checked it out and the problem is that apple returns in some cases (i think auto-renewable-subscription receipts) "latest_receipt_info" as an array, but its expected to be an object.

nov commented 9 years ago

does it relate to line 54? @adam_id = receipt_attributes[:adam_id]

philipgiuliani commented 9 years ago

Not it does not really relate to 54. Its because of the line 73.

attributes[:latest_receipt_info] is an array in this case instead of the object, and so you are initializing the same class (Receipt) again, but you pass a array as receipt instead of the expected object. And then it goes into the initialize method again, but this time with an array.

I uploaded the receipt that i get from Apple: https://gist.github.com/philipgiuliani/b63b22309d04048f0827

In this case @latest should return an Array of Receipt's instead of a single Receipt

You think you could do a quick fix?

nov commented 9 years ago

Ah, I got it. I haven't play with "auto-renewable-subscription receipts", but if the latest receipt info is always an array for such receipts, I'll just make @latest an array.

Do you guys think that my solution will solve your errors?

philipgiuliani commented 9 years ago

Yes that will defently solve our problems. Just for backward compability, i would only make it an array if : latest_receipt_info is a Array.

nov commented 9 years ago

I've just released v1.1.0 with this change. https://github.com/nov/itunes-receipt/commit/77c0b4dd5c9ad72179ef78ec3036429979d226ee

Thanks for your help!

philipgiuliani commented 9 years ago

Thanks to you for the quick update.

philipgiuliani commented 9 years ago

Are the changes tested? For me receipt.latest.inspect returns nil when i pass the following json :(

json = JSON.parse(content of https://gist.github.com/philipgiuliani/b63b22309d04048f0827)
receipt = Itunes::Receipt.new(json)
puts receipt.latest.inspect

Any idea why thats nil?

nov commented 9 years ago

I guess it's because the Hash keys are String, not Symbol.

philipgiuliani commented 9 years ago

Havent thought about that yet. I will try out symbolize_keys later :)

Nov Matake notifications@github.com schrieb am Do., 13. Nov. 2014 15:09:

I guess it's because the Hash keys are String, not Symbol.

— Reply to this email directly or view it on GitHub https://github.com/nov/itunes-receipt/issues/12#issuecomment-62894803.

philipgiuliani commented 9 years ago

Fixed it, symbolize_keys wasn't the issue, i just had to set .with_indifferent_access

json = JSON.parse(content of https://gist.github.com/philipgiuliani/b63b22309d04048f0827)
receipt = Itunes::Receipt.new(json.with_indifferent_access)
puts receipt.latest.inspect
sulphur commented 9 years ago

new version totally solves the problem. Thanks !