Created
April 30, 2012 15:47
-
-
Save sauloarruda/2559455 to your computer and use it in GitHub Desktop.
Apple iOS in app purchase validate receipt in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVk | |
ZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5 | |
aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcr | |
T3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFB | |
QURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RR | |
RUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pT | |
QkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlF | |
RjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIz | |
SmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVEE1TURZeE5U | |
SXlNRFUxTmxvWERURTBNRFl4TkRJeU1EVTFObG93WkRFak1DRUdBMVVFQXd3YVVI | |
VnlZMmhoYzJWU1pXTmxhWEIwUTJWeWRHbG1hV05oZEdVeEd6QVpCZ05WQkFzTUVr | |
RndjR3hsSUdsVWRXNWxjeUJUZEc5eVpURVRNQkVHQTFVRUNnd0tRWEJ3YkdVZ1NX | |
NWpMakVMTUFrR0ExVUVCaE1DVlZNd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZ | |
MEFNSUdKQW9HQkFNclJqRjJjdDRJcl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IjsK | |
CSJwb2QiID0gIjEwMCI7Cgkic2lnbmluZy1zdGF0dXMiID0gIjAiOwp9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"receipt": { | |
"original_purchase_date_pst": "2012-04-30 08:05:55 America/Los_Angeles", | |
"original_transaction_id": "1000000046178817", | |
"original_purchase_date_ms": "1335798355868", | |
"transaction_id": "1000000046178817", | |
"quantity": "1", | |
"product_id": "br.com.jera.Example", | |
"bvrs": "20120427", | |
"purchase_date_ms": "1335798355868", | |
"purchase_date": "2012-04-30 15:05:55 Etc/GMT", | |
"original_purchase_date": "2012-04-30 15:05:55 Etc/GMT", | |
"purchase_date_pst": "2012-04-30 08:05:55 America/Los_Angeles", | |
"bid": "br.com.jera.Example", | |
"item_id": "521129812" | |
}, | |
"status": 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code call the apple sandbox in app purchase server to validate a receipt using Ruby Code. | |
# Run this using "ruby verifyReceipt.rb" | |
# By @sauloarruda (http://twitter.com/sauloarruda) | |
require 'net/http' | |
# This core reads an file called receipt (see an example bellow) | |
params_json = "{ \"receipt-data\": \"#{open("./receipt").read}\" }" | |
# Use net/http to post to apple sandbox server | |
uri = URI("https://sandbox.itunes.apple.com") # Use "https://buy.itunes.apple.com" for production | |
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| | |
response = http.post('/verifyReceipt', params_json) | |
# Puts the result! (see an example below - result.json) | |
puts response.body | |
end |
For now the result.json is in the form (at least in sandbox environment):
{
'status': 0,
'environment': 'Sandbox',
'receipt': {
'download_id': 0,
'adam_id': 0,
'request_date': '2014-01-21 16:15:23 Etc/GMT',
'in_app': [{
'is_trial_period': 'false',
'purchase_date_pst': '2014-01-21 08:15:21 America/Los_Angeles',
'product_id': 'com.cinnamon.nepocujuci.lesson.6',
'original_transaction_id': '1000000098953824',
'original_purchase_date_pst': '2014-01-20 11:03:05 America/Los_Angeles',
'original_purchase_date': '2014-01-20 19:03:05 Etc/GMT',
'original_purchase_date_ms': '1390244585000',
'purchase_date': '2014-01-21 16:15:21 Etc/GMT',
'purchase_date_ms': '1390320921000',
'transaction_id': '1000000098953824',
'quantity': '1'
}],
'request_date_ms': '1390320923038',
'bundle_id': 'com.cinnamon.nepocujuci',
'request_date_pst': '2014-01-21 08:15:23 America/Los_Angeles',
'application_version': '1.0',
'receipt_type': 'ProductionSandbox'
}
}
👍 so good. Thanks for this.
thanks, this helped me a lot
This is the latest result.json:
{
"adam_id": null,
"app_item_id": null,
"application_version": null,
"bid": "com.mindmobapp.MindMob",
"bundle_id": null,
"bvrs": "20120427",
"download_id": null,
"expires_date": null,
"in_app": null,
"is_trial_period": null,
"itunes_env": "sandbox",
"latest": null,
"original": {
"adam_id": null,
"app_item_id": null,
"application_version": null,
"bid": null,
"bundle_id": null,
"bvrs": null,
"download_id": null,
"expires_date": null,
"in_app": null,
"is_trial_period": null,
"itunes_env": "production",
"latest": null,
"original": null,
"product_id": null,
"purchase_date": "2012-04-30T15:05:55.000+00:00",
"purchase_date_ms": 1335798355868,
"purchase_date_pst": "2012-04-30T08:05:55.000-08:00",
"quantity": null,
"receipt_data": null,
"request_date": null,
"request_date_ms": null,
"request_date_pst": null,
"transaction_id": "1000000046178817",
"version_external_identifier": null
},
"product_id": "com.mindmobapp.download",
"purchase_date": "2012-04-30T15:05:55.000+00:00",
"purchase_date_ms": 1335798355868,
"purchase_date_pst": "2012-04-30T08:05:55.000-08:00",
"quantity": 1,
"receipt_data": null,
"request_date": null,
"request_date_ms": null,
"request_date_pst": null,
"transaction_id": "1000000046178817",
"version_external_identifier": null
}
Thanks this post was helpful to get a better understanding. I built a gem called Monza to make receipt validation very easy. Check it out here https://github.com/gabrielgarza/monza
@gabrielgarza tnx bro!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you mind if i use your receipt in my unit tests for PHP library which validates receipts from appstore?