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_info ⇒ Object
Returns the value of attribute latest_receipt_info.
-
#original_application_version ⇒ Object
readonly
The version of the app that was originally purchased.
-
#original_json_response ⇒ Object
readonly
Original json response from AppStore.
-
#original_purchase_date ⇒ Object
readonly
The original purchase date.
-
#pending_renewal_info ⇒ Object
readonly
Information about the status of the customer’s auto-renewable subscriptions.
-
#receipt_created_at ⇒ Object
readonly
Returns the value of attribute receipt_created_at.
-
#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
-
#initialize(attributes = {}) ⇒ Receipt
constructor
A new instance of Receipt.
- #to_hash ⇒ Object (also: #to_h)
- #to_json ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Receipt
Returns a new instance of Receipt.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/venice/receipt.rb', line 41 def initialize(attributes = {}) @original_json_response = attributes['original_json_response'] @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'] @receipt_created_at = DateTime.parse(attributes['receipt_creation_date']) if attributes['receipt_creation_date'] @in_app = [] if attributes['in_app'] attributes['in_app'].each do |in_app_purchase_attributes| @in_app << InAppReceipt.new(in_app_purchase_attributes) end end @pending_renewal_info = [] if original_json_response && original_json_response['pending_renewal_info'] original_json_response['pending_renewal_info'].each do |pending_renewal_attributes| @pending_renewal_info << PendingRenewalInfo.new(pending_renewal_attributes) end end 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_info ⇒ Object
Returns the value of attribute latest_receipt_info.
36 37 38 |
# File 'lib/venice/receipt.rb', line 36 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_json_response ⇒ Object (readonly)
Original json response from AppStore
34 35 36 |
# File 'lib/venice/receipt.rb', line 34 def original_json_response @original_json_response 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 |
#pending_renewal_info ⇒ Object (readonly)
Information about the status of the customer’s auto-renewable subscriptions
39 40 41 |
# File 'lib/venice/receipt.rb', line 39 def pending_renewal_info @pending_renewal_info end |
#receipt_created_at ⇒ Object (readonly)
Returns the value of attribute receipt_created_at.
31 32 33 |
# File 'lib/venice/receipt.rb', line 31 def receipt_created_at @receipt_created_at 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
99 100 101 102 103 |
# File 'lib/venice/receipt.rb', line 99 def verify(data, = {}) verify!(data, ) rescue VerificationError, Client::TimeoutError false end |
.verify!(data, options = {}) ⇒ Object Also known as: validate!
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/venice/receipt.rb', line 105 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
#to_hash ⇒ Object Also known as: to_h
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/venice/receipt.rb', line 75 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), receipt_created_at: (@receipt_created_at.httpdate rescue nil), in_app: @in_app.map(&:to_h), pending_renewal_info: @pending_renewal_info.map(&:to_h), latest_receipt_info: @latest_receipt_info } end |
#to_json ⇒ Object
94 95 96 |
# File 'lib/venice/receipt.rb', line 94 def to_json to_hash.to_json end |