Module: ItunesReceiptDecoder

Defined in:
lib/itunes_receipt_decoder.rb,
lib/itunes_receipt_decoder/version.rb,
lib/itunes_receipt_decoder/decode/base.rb,
lib/itunes_receipt_decoder/decode/unified_receipt.rb,
lib/itunes_receipt_decoder/decode/transaction_receipt.rb

Overview

ItunesReceiptDecoder

Defined Under Namespace

Modules: Decode Classes: DecodingError

Constant Summary collapse

PLIST_REGEX =
/(\{(?=.+?\bsignature\b.+?)(?=.+?\bpurchase-info\b.+?).+?\})/m
VERSION =

Gem version

'0.2.3'

Class Method Summary collapse

Class Method Details

.new(receipt_data, options = {}) ⇒ Object

Initializes either ItunesReceiptDecoder::Decode::Transaction or ItunesReceiptDecoder::Decode::Unified with the base64 encoded receipt

Arguments

  • receipt_data - the base64 encoded receipt

  • options - optional arguments



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/itunes_receipt_decoder.rb', line 23

def self.new(receipt_data, options = {})
  raw_receipt = receipt_data.unpack('m').first
rescue ArgumentError => e
  raise DecodingError, e.message
else
  if (match = raw_receipt.match(PLIST_REGEX).to_a.first) && match.ascii_only?
    Decode::TransactionReceipt.new(match, options)
  else
    Decode::UnifiedReceipt.new(raw_receipt, options)
  end
end