Giter Club home page Giter Club logo

itunes_receipt_decoder's Introduction

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.

itunes_receipt_decoder's People

Contributors

marcgreenstock avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.