class Venice::Receipt

Attributes

adam_id[R]
application_version[R]

The app’s version number.

bundle_id[R]

The app’s bundle identifier.

download_id[R]
expires_at[R]

The date that the app receipt expires.

in_app[R]

The receipt for an in-app purchase.

latest_receipt[RW]

For auto-renewable subscriptions: the ‘receipt-data’ base64 representation of the last receipt if happened after the current receipt

latest_receipt_info[RW]

the in_app-transactions part of the last receipt

original_application_version[R]

The version of the app that was originally purchased.

original_purchase_date[R]

The original purchase date

receipt_type[R]

Non-Documented receipt keys/values

requested_at[R]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/venice/receipt.rb, line 39
def initialize(attributes = {})
  @bundle_id = attributes['bundle_id']
  @application_version = attributes['application_version']
  @original_application_version = attributes['original_application_version']
  if attributes['original_purchase_date']
    @original_purchase_date = DateTime.parse(attributes['original_purchase_date'])
  end
  if attributes['expiration_date']
    @expires_at = Time.at(attributes['expiration_date'].to_i / 1000).to_datetime
  end

  @receipt_type = attributes['receipt_type']
  @adam_id = attributes['adam_id']
  @download_id = attributes['download_id']
  @requested_at = DateTime.parse(attributes['request_date']) if attributes['request_date']

  init_iap_receipts(attributes)
end
validate(data, options = {})
Alias for: verify
validate!(data, options = {})
Alias for: verify!
verify(data, options = {}) click to toggle source
# File lib/venice/receipt.rb, line 98
def verify(data, options = {})
  verify!(data, options) rescue false
end
Also aliased as: validate
verify!(data, options = {}) click to toggle source
# File lib/venice/receipt.rb, line 102
def verify!(data, options = {})
  client = Client.production

  begin
    client.verify!(data, options)
  rescue VerificationError => error
    case error.code
    when 21007
      client = Client.development
      retry
    when 21008
      client = Client.production
      retry
    else
      raise error
    end
  end
end
Also aliased as: validate!

Public Instance Methods

init_iap_receipts(attributes) click to toggle source
# File lib/venice/receipt.rb, line 58
def init_iap_receipts(attributes)
  @in_app = map_iap_receipts(attributes['in_app'] || [])
  # From Apple docs:
  # > Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
  # > The JSON representation of the receipt for the most recent renewal

  # @latest_receipt_info = map_iap_receipts(attributes['latest_receipt_info'] || [])
  @latest_receipt_info = InAppReceipt.new (attributes['latest_receipt_info']) rescue []
  @latest_receipt = attributes['latest_receipt']
end
map_iap_receipts(receipt_hashes) click to toggle source
# File lib/venice/receipt.rb, line 91
def map_iap_receipts(receipt_hashes)
  receipt_hashes.map do |tx|
    InAppReceipt.new(tx)
  end
end
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/venice/receipt.rb, line 69
def to_hash
  {
    :bundle_id => @bundle_id,
    :application_version => @application_version,
    :original_application_version => @original_application_version,
    :original_purchase_date => (@original_purchase_date.httpdate rescue nil),
    :expires_at => (@expires_at.httpdate rescue nil),
    :receipt_type => @receipt_type,
    :adam_id => @adam_id,
    :download_id => @download_id,
    :requested_at => (@requested_at.httpdate rescue nil),
    :in_app => @in_app.map{|iap| iap.to_h },
    :latest_receipt_info => @latest_receipt_info.map{|iap| iap.to_h },
    :latest_receipt => @latest_receipt,
  }
end
Also aliased as: to_h
to_json() click to toggle source
# File lib/venice/receipt.rb, line 87
def to_json
  self.to_hash.to_json
end