views:

37

answers:

2

Hi everybody,

I'm trying to implement the in App purchase mechanism in my iPhone app. To do so I need to make a json object out of the receipt string on my rails server, and send it to a iTunes server.

  • How can I create a json object out of a string? to_json didn't work for me...
  • How can I send that json object to the specified Server and wait for the request...

Thanks Maechi

+1  A: 

You asked: How can I create a json object out of a string?

Is your string already in json format? If so, just send it along.

You'd use to_json when you have an object that you want to auto-turn into json. Example:

class InAppPurchase
  attr_accessor :whatever, :whatever_x_two
end

purchase = InAppPurchase.new
purchase.whatever = "oh hai"
purchase.whatever_x_two = "good day"

purchase.to_json

Will output: {"whatever":"oh hai","whatever_x_two":"good day"}

Jesse Wolgamott
Thanks Jesse, I got that now but how can I send this to the iTunes server? And even wait for the request until finishing the request for the iPhone?
Markus
on the iPhone side, you can use ASIHttp to do your posting to rails and handle the request, either async or sync. ..... for Rails to iTunes, use the gem HTTParty .. more info: http://github.com/jnunemaker/httparty
Jesse Wolgamott
A: 

You have to generate the "purchase request" from the iPhone and not the server. check out http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1 for more details.

Greg
I mean the transaction certificat evaluation on the server, not the purchase request...
Markus