Class: Venice::Receipt
- Inherits:
-
Object
- Object
- Venice::Receipt
- Defined in:
- lib/venice/receipt.rb
Defined Under Namespace
Classes: VerificationError
Constant Summary collapse
- MAX_RE_VERIFY_COUNT =
3
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.
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 74 75 |
# File 'lib/venice/receipt.rb', line 43 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.
30 31 32 |
# File 'lib/venice/receipt.rb', line 30 def adam_id @adam_id end |
#application_version ⇒ Object (readonly)
The app’s version number.
14 15 16 |
# File 'lib/venice/receipt.rb', line 14 def application_version @application_version end |
#bundle_id ⇒ Object (readonly)
The app’s bundle identifier.
11 12 13 |
# File 'lib/venice/receipt.rb', line 11 def bundle_id @bundle_id end |
#download_id ⇒ Object (readonly)
Returns the value of attribute download_id.
31 32 33 |
# File 'lib/venice/receipt.rb', line 31 def download_id @download_id end |
#expires_at ⇒ Object (readonly)
The date that the app receipt expires.
26 27 28 |
# File 'lib/venice/receipt.rb', line 26 def expires_at @expires_at end |
#in_app ⇒ Object (readonly)
The receipt for an in-app purchase.
17 18 19 |
# File 'lib/venice/receipt.rb', line 17 def in_app @in_app end |
#latest_receipt_info ⇒ Object
Returns the value of attribute latest_receipt_info.
38 39 40 |
# File 'lib/venice/receipt.rb', line 38 def latest_receipt_info @latest_receipt_info end |
#original_application_version ⇒ Object (readonly)
The version of the app that was originally purchased.
20 21 22 |
# File 'lib/venice/receipt.rb', line 20 def original_application_version @original_application_version end |
#original_json_response ⇒ Object (readonly)
Original json response from AppStore
36 37 38 |
# File 'lib/venice/receipt.rb', line 36 def original_json_response @original_json_response end |
#original_purchase_date ⇒ Object (readonly)
The original purchase date
23 24 25 |
# File 'lib/venice/receipt.rb', line 23 def original_purchase_date @original_purchase_date end |
#pending_renewal_info ⇒ Object (readonly)
Information about the status of the customer’s auto-renewable subscriptions
41 42 43 |
# File 'lib/venice/receipt.rb', line 41 def pending_renewal_info @pending_renewal_info end |
#receipt_created_at ⇒ Object (readonly)
Returns the value of attribute receipt_created_at.
33 34 35 |
# File 'lib/venice/receipt.rb', line 33 def receipt_created_at @receipt_created_at end |
#receipt_type ⇒ Object (readonly)
Non-Documented receipt keys/values
29 30 31 |
# File 'lib/venice/receipt.rb', line 29 def receipt_type @receipt_type end |
#requested_at ⇒ Object (readonly)
Returns the value of attribute requested_at.
32 33 34 |
# File 'lib/venice/receipt.rb', line 32 def requested_at @requested_at end |
Class Method Details
.verify(data, options = {}) ⇒ Object Also known as: validate
101 102 103 104 105 |
# File 'lib/venice/receipt.rb', line 101 def verify(data, = {}) verify!(data, ) rescue VerificationError, Client::TimeoutError false end |
.verify!(data, options = {}) ⇒ Object Also known as: validate!
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/venice/receipt.rb', line 107 def verify!(data, = {}) client = Client.production retry_count = 0 begin client.verify!(data, ) rescue VerificationError => error case error.code when 21007 client = Client.development retry when 21008 client = Client.production retry else retry_count += 1 if error.retryable? && retry_count <= MAX_RE_VERIFY_COUNT retry end raise error end rescue Net::ReadTimeout, Timeout::Error, OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE # verifyReceipt is idempotent so we can retry it. # Net::Http has retry logic for some idempotent http methods but it verifyReceipt is POST. retry_count += 1 retry if retry_count <= MAX_RE_VERIFY_COUNT raise end end |
Instance Method Details
#to_hash ⇒ Object Also known as: to_h
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/venice/receipt.rb', line 77 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
96 97 98 |
# File 'lib/venice/receipt.rb', line 96 def to_json to_hash.to_json end |