No commit activity in last 3 years
No release in over 3 years
Decode iTunes OS X and iOS receipts without remote server-side validation by using the Apple Inc Root Certificate.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

iTunes Receipt Decoder

Decode iTunes OS X and iOS receipts without remote server-side validation by using the Apple Inc Root Certificate.

Code Climate Test Coverage Build Status Gem Version

Install

Install from the command line:

$ gem install itunes_receipt_decoder

Or include it in your Gemfile:

gem 'itunes_receipt_decoder'

Example of a Grand Unified Receipt

decoder = ItunesReceiptDecoder.new(base64_encoded_receipt)

decoder.receipt # =>
{
  :application_version=>"1",
  :original_application_version=>"1.0",
  :environment=>"ProductionSandbox",
  :bundle_id=>"com.mbaasy.ios.demo",
  :creation_date=>"2015-08-13T07:50:46Z",
  :in_app=> [{
    :expires_date=>"",
    :cancellation_date=>"",
    :quantity=>1,
    :web_order_line_item_id=>0,
    :product_id=>"consumable",
    :transaction_id=>"1000000166865231",
    :original_transaction_id=>"1000000166865231",
    :purchase_date=>"2015-08-07T20:37:55Z",
    :original_purchase_date=>"2015-08-07T20:37:55Z"
  }, {
    :cancellation_date=>"",
    :quantity=>1,
    :product_id=>"monthly",
    :web_order_line_item_id=>1000000030274153,
    :transaction_id=>"1000000166965150",
    :original_transaction_id=>"1000000166965150",
    :purchase_date=>"2015-08-10T06:49:32Z",
    :original_purchase_date=>"2015-08-10T06:49:33Z",
    :expires_date=>"2015-08-10T06:54:32Z"
  }, {
    :cancellation_date=>"",
    :quantity=>1,
    :product_id=>"monthly",
    :web_order_line_item_id=>1000000030274154,
    :transaction_id=>"1000000166965327",
    :original_transaction_id=>"1000000166965150",
    :purchase_date=>"2015-08-10T06:54:32Z",
    :original_purchase_date=>"2015-08-10T06:53:18Z",
    :expires_date=>"2015-08-10T06:59:32Z"
  }, {
    :cancellation_date=>"",
    :quantity=>1,
    :product_id=>"monthly",
    :web_order_line_item_id=>1000000030274165,
    :transaction_id=>"1000000166965895",
    :original_transaction_id=>"1000000166965150",
    :purchase_date=>"2015-08-10T06:59:32Z",
    :original_purchase_date=>"2015-08-10T06:57:34Z",
    :expires_date=>"2015-08-10T07:04:32Z"
  }, {
    :cancellation_date=>"",
    :quantity=>1,
    :product_id=>"monthly",
    :web_order_line_item_id=>1000000030274192,
    :transaction_id=>"1000000166967152",
    :original_transaction_id=>"1000000166965150",
    :purchase_date=>"2015-08-10T07:04:32Z",
    :original_purchase_date=>"2015-08-10T07:02:33Z",
    :expires_date=>"2015-08-10T07:09:32Z"
  }, {
    :cancellation_date=>"",
    :quantity=>1,
    :product_id=>"monthly",
    :web_order_line_item_id=>1000000030274219,
    :transaction_id=>"1000000166967484",
    :original_transaction_id=>"1000000166965150",
    :purchase_date=>"2015-08-10T07:09:32Z",
    :original_purchase_date=>"2015-08-10T07:08:30Z",
    :expires_date=>"2015-08-10T07:14:32Z"
  }, {
    :cancellation_date=>"",
    :quantity=>1,
    :product_id=>"monthly",
    :web_order_line_item_id=>1000000030274249,
    :transaction_id=>"1000000166967782",
    :original_transaction_id=>"1000000166965150",
    :purchase_date=>"2015-08-10T07:14:32Z",
    :original_purchase_date=>"2015-08-10T07:12:34Z",
    :expires_date=>"2015-08-10T07:19:32Z"
  }]
}

Example of a Transaction Receipt

decoder = ItunesReceiptDecoder.new(base64_encoded_receipt)

decoder.receipt # =>
{
  :original_purchase_date_pst=>"2012-04-30 08:05:55 America/Los_Angeles",
  :original_transaction_id=>"1000000046178817",
  :bvrs=>"20120427",
  :transaction_id=>"1000000046178817",
  :quantity=>"1",
  :original_purchase_date_ms=>"1335798355868",
  :product_id=>"consumable",
  :item_id=>"521129812",
  :bid=>"com.mbaasy.ios.demo",
  :purchase_date_ms=>"1335798355868",
  :purchase_date=>"2012-04-30 15:05:55 Etc/GMT",
  :purchase_date_pst=>"2012-04-30 08:05:55 America/Los_Angeles",
  :original_purchase_date=>"2012-04-30 15:05:55 Etc/GMT"
}

Constructor

ItunesReceiptDecoder.new expects the base64 encoded receipt as the first argument. There optional second argument defined as a hash, valid options are:

expand_timestamps: true : The timestamps included in the unified receipt are not in the same format as a validation from iTunes' servers. Use this option to expand the timestamps and reformat them in the same format as you would expect from a validation. e.g.

ItunesReceiptDecoder.new base64_encoded_receipt,
                         expand_timestamps: true

Methods and properties

ItunesReceiptDecoder.new will return either a ItunesReceiptDecoder::Decode::UnifiedReceipt or ItunesReceiptDecoder::Decode::TransactionReceipt instance. Both classes have the same public methods available:

#receipt : Returns the receipt properties as a Hash.

#environment : Returns the environment as a String.

#production? : True if the receipt was created in the Production environment.

#sandbox? : True if the receipt was not created in the Production environment.

#style : Either :transaction or :unified

Testing

  1. bundle install
  2. rake

Todo

  • Signature validation

Copyright 2015 mbaasy.com. This project is subject to the MIT License.