Class: Venice::Receipt
- Inherits:
-
Object
- Object
- Venice::Receipt
- Defined in:
- lib/venice/receipt.rb
Defined Under Namespace
Classes: VerificationError
Instance Attribute Summary collapse
-
#adam_id ⇒ Object
readonly
Returns the value of attribute adam_id.
-
#application_version ⇒ Object
readonly
The app’s version number.
-
#bundle_id ⇒ Object
readonly
The app’s bundle identifier.
-
#download_id ⇒ Object
readonly
Returns the value of attribute download_id.
-
#expires_at ⇒ Object
readonly
The date that the app receipt expires.
-
#in_app ⇒ Object
readonly
The receipt for an in-app purchase.
-
#latest_receipt ⇒ Object
For auto-renewable subscriptions: the ‘receipt-data’ base64 representation of the last receipt if happened after the current receipt.
-
#latest_receipt_info ⇒ Object
the in_app-transactions part of the last receipt.
-
#original_application_version ⇒ Object
readonly
The version of the app that was originally purchased.
-
#original_purchase_date ⇒ Object
readonly
The original purchase date.
-
#receipt_type ⇒ Object
readonly
Non-Documented receipt keys/values.
-
#requested_at ⇒ Object
readonly
Returns the value of attribute requested_at.
Class Method Summary collapse
- .verify(data, options = {}) ⇒ Object (also: validate)
- .verify!(data, options = {}) ⇒ Object (also: validate!)
Instance Method Summary collapse
- #init_iap_receipts(attributes) ⇒ Object
-
#initialize(attributes = {}) ⇒ Receipt
constructor
A new instance of Receipt.
- #map_iap_receipts(receipt_hashes) ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
- #to_json ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Receipt
Returns a new instance of Receipt.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 |
Instance Attribute Details
#adam_id ⇒ Object (readonly)
Returns the value of attribute adam_id.
28 29 30 |
# File 'lib/venice/receipt.rb', line 28 def adam_id @adam_id end |
#application_version ⇒ Object (readonly)
The app’s version number.
12 13 14 |
# File 'lib/venice/receipt.rb', line 12 def application_version @application_version end |
#bundle_id ⇒ Object (readonly)
The app’s bundle identifier.
9 10 11 |
# File 'lib/venice/receipt.rb', line 9 def bundle_id @bundle_id end |
#download_id ⇒ Object (readonly)
Returns the value of attribute download_id.
29 30 31 |
# File 'lib/venice/receipt.rb', line 29 def download_id @download_id end |
#expires_at ⇒ Object (readonly)
The date that the app receipt expires.
24 25 26 |
# File 'lib/venice/receipt.rb', line 24 def expires_at @expires_at end |
#in_app ⇒ Object (readonly)
The receipt for an in-app purchase.
15 16 17 |
# File 'lib/venice/receipt.rb', line 15 def in_app @in_app end |
#latest_receipt ⇒ Object
For auto-renewable subscriptions: the ‘receipt-data’ base64 representation of the last receipt if happened after the current receipt
35 36 37 |
# File 'lib/venice/receipt.rb', line 35 def latest_receipt @latest_receipt end |
#latest_receipt_info ⇒ Object
the in_app-transactions part of the last receipt
37 38 39 |
# File 'lib/venice/receipt.rb', line 37 def latest_receipt_info @latest_receipt_info end |
#original_application_version ⇒ Object (readonly)
The version of the app that was originally purchased.
18 19 20 |
# File 'lib/venice/receipt.rb', line 18 def original_application_version @original_application_version end |
#original_purchase_date ⇒ Object (readonly)
The original purchase date
21 22 23 |
# File 'lib/venice/receipt.rb', line 21 def original_purchase_date @original_purchase_date end |
#receipt_type ⇒ Object (readonly)
Non-Documented receipt keys/values
27 28 29 |
# File 'lib/venice/receipt.rb', line 27 def receipt_type @receipt_type end |
#requested_at ⇒ Object (readonly)
Returns the value of attribute requested_at.
30 31 32 |
# File 'lib/venice/receipt.rb', line 30 def requested_at @requested_at end |
Class Method Details
.verify(data, options = {}) ⇒ Object Also known as: validate
98 99 100 |
# File 'lib/venice/receipt.rb', line 98 def verify(data, = {}) verify!(data, ) rescue false end |
.verify!(data, options = {}) ⇒ Object Also known as: validate!
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/venice/receipt.rb', line 102 def verify!(data, = {}) client = Client.production begin client.verify!(data, ) rescue VerificationError => error case error.code when 21007 client = Client.development retry when 21008 client = Client.production retry else raise error end end end |
Instance Method Details
#init_iap_receipts(attributes) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# 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) ⇒ Object
91 92 93 94 95 |
# File 'lib/venice/receipt.rb', line 91 def map_iap_receipts(receipt_hashes) receipt_hashes.map do |tx| InAppReceipt.new(tx) end end |
#to_hash ⇒ Object Also known as: to_h
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 |
#to_json ⇒ Object
87 88 89 |
# File 'lib/venice/receipt.rb', line 87 def to_json self.to_hash.to_json end |