All Projects → mbaasy → itunes_receipt_validator

mbaasy / itunes_receipt_validator

Licence: MIT license
Validate iTunes Transaction and Unified style receipts with local decoding and remote validation.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to itunes receipt validator

Api Fuzzer
API Fuzzer which allows to fuzz request attributes using common pentesting techniques and lists vulnerabilities
Stars: ✭ 238 (+526.32%)
Mutual labels:  rubygem
homebridge-music
Homebridge plugin for iTunes with AirPlay speakers
Stars: ✭ 92 (+142.11%)
Mutual labels:  itunes
ruby-lokalise-api
Lokalise API v2 Ruby interface.
Stars: ✭ 17 (-55.26%)
Mutual labels:  rubygem
receipt parser
Allow parsing Russian receipts
Stars: ✭ 47 (+23.68%)
Mutual labels:  receipt-validation
glimmer-dsl-opal
Glimmer DSL for Opal (Pure-Ruby Web GUI and Auto-Webifier of Desktop Apps)
Stars: ✭ 22 (-42.11%)
Mutual labels:  rubygem
oanda api
A ruby client for the Oanda REST API.
Stars: ✭ 35 (-7.89%)
Mutual labels:  rubygem
Zold
An Experimental Non-Blockchain Cryptocurrency for Fast Micro Payments
Stars: ✭ 183 (+381.58%)
Mutual labels:  rubygem
dkdeploy-typo3-cms
dkdeploy-typo3-cms provides functionality for fully automated deployments targeting TYPO3 CMS applications
Stars: ✭ 16 (-57.89%)
Mutual labels:  rubygem
Holly-Quintet
A web app used for searching disks' covers from a series of music websites.
Stars: ✭ 22 (-42.11%)
Mutual labels:  itunes
sidekiq-backend
Karafka Sidekiq backend for background messages processing
Stars: ✭ 69 (+81.58%)
Mutual labels:  rubygem
github-now-playing
🎵 Display what you're listening to right on your Github profile
Stars: ✭ 75 (+97.37%)
Mutual labels:  itunes
itunes-artwork-grabber
Yet another iTunes artwork grabber for cover / icon lovers
Stars: ✭ 57 (+50%)
Mutual labels:  itunes
podcastcrawler
PHP library to find podcasts
Stars: ✭ 40 (+5.26%)
Mutual labels:  itunes
Dry Container
A simple, configurable object container implemented in Ruby
Stars: ✭ 240 (+531.58%)
Mutual labels:  rubygem
tty-link
Hyperlinks in your terminal
Stars: ✭ 30 (-21.05%)
Mutual labels:  rubygem
Dry Cli
General purpose Command Line Interface (CLI) framework for Ruby
Stars: ✭ 210 (+452.63%)
Mutual labels:  rubygem
kirby-podcast
A KirbyCMS-Podcast-Plugin
Stars: ✭ 22 (-42.11%)
Mutual labels:  itunes
strings-ansi
Handle ANSI escape codes in strings
Stars: ✭ 17 (-55.26%)
Mutual labels:  rubygem
ocr space
Free Online OCR for Ruby - Convert images to text
Stars: ✭ 62 (+63.16%)
Mutual labels:  rubygem
rarbg
Ruby client for the RARBG Torrent API.
Stars: ✭ 17 (-55.26%)
Mutual labels:  rubygem

iTunes Receipt Validator

Code Climate Test Coverage Build Status Gem Version

Decode locally

The difference between this gem and any of the alternatives is that it decodes the base64 encoded receipt with our ItunesReceiptDecoder library to extract the data from the receipt without making a HTTP request to Apple's servers.

No redundent HTTP requests

Because this library decodes the receipt first, it determins the origin of the receipt before making any HTTP requests. This means you don't need to make an additional request to the sandbox or production URLs.

Secondly, if the receipt can't be decoded, it can't be validated. This will prevent unnecessary requests when you receive fraudulent receipts.

Handle any style of receipt

Apple offers two kinds of receipts:

  1. The deprecated [SKPaymentTransaction transactionReceipt] and;
  2. The Grand Unified Receipt [NSBundle appStoreReceiptURL]

Validating both kinds of receipts requires separate logic because the schemas and data are entirely different.

Normalize all the things

No matter if the receipt is a [SKPaymentTransaction transactionReceipt] or [NSBundle appStoreReceiptURL], the responses are normalized with extra helpful methods for all your iOS and OSX receipt validation needs.

Need a complete solution?

We have a cloud service available at mbaasy.com, it takes care of in-app purchase management, receipt validation and reporting so you don't have to. It even offers integration with your own API through webhooks to notify you of new, expired, renewed and cancelled purchases for iOS, OSX and Google Play receipts. It will save you time and money but most of all it allows you to focus on your core project instead of wasting time on receipt validation.

We offer this libary because we believe in the Open Source movement, mbaasy.com is built upon a foundation of Open Source projects, so this libary is our way of giving back to the community.

Install

Install from the command line:

$ gem install itunes_receipt_validator

Or include it in your Gemfile:

gem 'itunes_receipt_validator'

Usage

Initialization

validator = ItunesReceiptValidator.new(
  base64_encoded_receipt,
  shared_secret: 'your_shared_secret'
) # => ItunesReceiptValidator::Receipt

Or intialize with a block:

shared_secrets = {
  'com.example.app1' => 'shared_secret_for_app1'
  'com.example.app2' => 'shared_secret_for_app2'
}
validator = ItunesReceiptValidator.new(base64_encoded_receipt) do |receipt|
  receipt.shared_secret = shared_secrets.fetch(receipt.bundle_id)
end

BYO HTTP requests

If you require more flexibility with upstream HTTP requests to Apple's Validation API you can initialize with your own request method.

validator = ItunesReceiptValidator.new(base64_encoded_receipt) do |receipt|
  receipt.shared_secret = 'your_shared_secret'
  receipt.request_method = lambda do |url, headers, body|
    MyFancyRequest.new(url, headers: headers, body: body)
  end
end

Your custom method exposes a HTTP status code and a response body as status and body respectively.

ItunesReceiptValidator::Receipt methods

validator.sandbox?

Returns true or false (opposite of production?).

validator.production?

Returns true or false (opposite of sandbox?).

validator.bundle_id

Returns the bundle_id of the app (e.g. com.mbaasy.ios).

validator.transactions

Returns a sub-class of Array, with transactions sourced locally from the receipt. See ItunesReceiptValidator::TransactionsProxy methods.

validator.latest_transactions

Returns a sub-class of Array, with transactions sourced from Apple's validation API. See ItunesReceiptValidator::TransactionsProxy methods.

validator.latest_receipt

Returns a base64 encoded string for the latest receipt sourced from Apple's validation API.

validator.local

Returns the ItunesReceiptDecoder::Decode::Transaction or ItunesReceiptDecoder::Decode::Unified instances. See the ItunesReceiptDecoder gem.

validator.remote

Returns the ItunesReceiptValidator::Remote instance.

ItunesReceiptValidator::TransactionsProxy methods

Inerhits from Array and includes Enumerable.

transactions.where(id: 1234)

Like ActiveRecord's where it accepts a hash of arguments and returns a new instance of ItunesReceiptValidator::TransactionsProxy.

ItunesReceiptValidator::Transaction methods

transaction.expired?

Returns true or false. This method will make a request to Apple's validation API to check if the receipt itself has expired, or if the latest transaction retrieved is expired.

transaction.cancelled?

Returns true or false.

transaction.auto_renewing?

Returns true if web_order_line_item_id is present.

transaction.trial_period?

Returns true or false.

transaction.latest

Returns a ItunesReceiptValidator::Transaction by making a request to Apple's validation API and matches it with the original_id.

ItunesReceiptValidator::Transaction properties

transaction.id

The transaction identifier of the item that was purchased.

See Transaction Identifier.

transaction.original_id

For a transaction that restores a previous transaction, the transaction identifier of the original transaction. Otherwise, identical to the transaction identifier.

See Original Transaction Identifier.

transaction.product_id

The product identifier of the item that was purchased.

See Product Identifier.

transaction.quantity

The number of items purchased.

See Quantity.

transaction.first_purchased_at

For a transaction that restores a previous transaction, the date of the original transaction. Cast as a Time instance.

See Original Purchase Date.

transaction.purchased_at

The date and time that the item was purchased. Cast as a Time instance.

See Purchase Date.

transaction.expires_at

The expiration date for the subscription. Cast as a Time instance.

See Subscription Expiration Date.

transaction.cancelled_at

For a transaction that was canceled by Apple customer support, the time and date of the cancellation. Cast as a Time instance.

See Cancellation Date.

transaction.web_order_line_item_id

The primary key for identifying subscription purchases.

See Web Order Line Item ID.

transaction.trial_period

Undocumented with Apple.

Testing

  1. bundle install
  2. rake

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].