Class: Itunes::Receipt
- Inherits:
-
Object
- Object
- Itunes::Receipt
- Defined in:
- lib/itunes/receipt.rb
Defined Under Namespace
Classes: ExpiredReceiptReceived, ReceiptServerOffline, SandboxReceiptReceived, VerificationFailed
Instance Attribute Summary collapse
-
#adam_id ⇒ Object
readonly
Returns the value of attribute adam_id.
-
#app_item_id ⇒ Object
readonly
Returns the value of attribute app_item_id.
-
#application_version ⇒ Object
readonly
Returns the value of attribute application_version.
-
#bid ⇒ Object
readonly
Returns the value of attribute bid.
-
#bundle_id ⇒ Object
readonly
Returns the value of attribute bundle_id.
-
#bvrs ⇒ Object
readonly
Returns the value of attribute bvrs.
-
#download_id ⇒ Object
readonly
Returns the value of attribute download_id.
-
#expires_date ⇒ Object
readonly
Returns the value of attribute expires_date.
-
#in_app ⇒ Object
readonly
Returns the value of attribute in_app.
-
#is_trial_period ⇒ Object
readonly
Returns the value of attribute is_trial_period.
-
#itunes_env ⇒ Object
readonly
Returns the value of attribute itunes_env.
-
#latest ⇒ Object
readonly
Returns the value of attribute latest.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
-
#purchase_date ⇒ Object
readonly
Returns the value of attribute purchase_date.
-
#purchase_date_ms ⇒ Object
readonly
Returns the value of attribute purchase_date_ms.
-
#purchase_date_pst ⇒ Object
readonly
Returns the value of attribute purchase_date_pst.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#receipt_data ⇒ Object
readonly
Returns the value of attribute receipt_data.
-
#request_date ⇒ Object
readonly
Returns the value of attribute request_date.
-
#request_date_ms ⇒ Object
readonly
Returns the value of attribute request_date_ms.
-
#request_date_pst ⇒ Object
readonly
Returns the value of attribute request_date_pst.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
- #application_receipt? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Receipt
constructor
A new instance of Receipt.
- #sandbox? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Receipt
Returns a new instance of Receipt.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/itunes/receipt.rb', line 52 def initialize(attributes = {}) receipt_attributes = attributes.with_indifferent_access[:receipt] @adam_id = receipt_attributes[:adam_id] @app_item_id = receipt_attributes[:app_item_id] @application_version = receipt_attributes[:application_version] @bid = receipt_attributes[:bid] @bundle_id = receipt_attributes[:bundle_id] @bvrs = receipt_attributes[:bvrs] @download_id = receipt_attributes[:download_id] @expires_date = if receipt_attributes[:expires_date] Time.at(receipt_attributes[:expires_date].to_i / 1000) end @in_app = if receipt_attributes[:in_app] receipt_attributes[:in_app].map { |ia| self.class.new(:receipt => ia) } end @is_trial_period = if receipt_attributes[:is_trial_period] receipt_attributes[:is_trial_period] end @itunes_env = attributes[:itunes_env] || Itunes.itunes_env @latest = case attributes[:latest_receipt_info] when Hash self.class.new( :receipt => attributes[:latest_receipt_info], :latest_receipt => attributes[:latest_receipt], :receipt_type => :latest ) when Array attributes[:latest_receipt_info].collect do |latest_receipt_info| self.class.new( :receipt => latest_receipt_info, :latest_receipt => attributes[:latest_receipt], :receipt_type => :latest ) end end @original = if receipt_attributes[:original_transaction_id] || receipt_attributes[:original_purchase_date] self.class.new(:receipt => { :transaction_id => receipt_attributes[:original_transaction_id], :purchase_date => receipt_attributes[:original_purchase_date], :purchase_date_ms => receipt_attributes[:original_purchase_date_ms], :purchase_date_pst => receipt_attributes[:original_purchase_date_pst], :application_version => receipt_attributes[:original_application_version] }) end @product_id = receipt_attributes[:product_id] @purchase_date = if receipt_attributes[:purchase_date] Time.parse receipt_attributes[:purchase_date].sub('Etc/GMT', 'GMT') end @purchase_date_ms = if receipt_attributes[:purchase_date_ms] receipt_attributes[:purchase_date_ms].to_i end @purchase_date_pst = if receipt_attributes[:purchase_date_pst] Time.parse receipt_attributes[:purchase_date_pst].sub('America/Los_Angeles', 'PST') end @quantity = if receipt_attributes[:quantity] receipt_attributes[:quantity].to_i end @receipt_data = if attributes[:receipt_type] == :latest attributes[:latest_receipt] end @request_date = if receipt_attributes[:request_date] Time.parse receipt_attributes[:request_date].sub('Etc/', '') end @request_date_ms = if receipt_attributes[:request_date_ms] receipt_attributes[:request_date_ms].to_i end @request_date_pst = if receipt_attributes[:request_date_pst] Time.parse receipt_attributes[:request_date_pst].sub('America/Los_Angeles', 'PST') end @transaction_id = receipt_attributes[:transaction_id] @version_external_identifier = receipt_attributes[:version_external_identifier] end |
Instance Attribute Details
#adam_id ⇒ Object (readonly)
Returns the value of attribute adam_id.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def adam_id @adam_id end |
#app_item_id ⇒ Object (readonly)
Returns the value of attribute app_item_id.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def app_item_id @app_item_id end |
#application_version ⇒ Object (readonly)
Returns the value of attribute application_version.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def application_version @application_version end |
#bid ⇒ Object (readonly)
Returns the value of attribute bid.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def bid @bid end |
#bundle_id ⇒ Object (readonly)
Returns the value of attribute bundle_id.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def bundle_id @bundle_id end |
#bvrs ⇒ Object (readonly)
Returns the value of attribute bvrs.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def bvrs @bvrs end |
#download_id ⇒ Object (readonly)
Returns the value of attribute download_id.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def download_id @download_id end |
#expires_date ⇒ Object (readonly)
Returns the value of attribute expires_date.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def expires_date @expires_date end |
#in_app ⇒ Object (readonly)
Returns the value of attribute in_app.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def in_app @in_app end |
#is_trial_period ⇒ Object (readonly)
Returns the value of attribute is_trial_period.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def is_trial_period @is_trial_period end |
#itunes_env ⇒ Object (readonly)
Returns the value of attribute itunes_env.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def itunes_env @itunes_env end |
#latest ⇒ Object (readonly)
Returns the value of attribute latest.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def latest @latest end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def original @original end |
#product_id ⇒ Object (readonly)
Returns the value of attribute product_id.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def product_id @product_id end |
#purchase_date ⇒ Object (readonly)
Returns the value of attribute purchase_date.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def purchase_date @purchase_date end |
#purchase_date_ms ⇒ Object (readonly)
Returns the value of attribute purchase_date_ms.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def purchase_date_ms @purchase_date_ms end |
#purchase_date_pst ⇒ Object (readonly)
Returns the value of attribute purchase_date_pst.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def purchase_date_pst @purchase_date_pst end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def quantity @quantity end |
#receipt_data ⇒ Object (readonly)
Returns the value of attribute receipt_data.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def receipt_data @receipt_data end |
#request_date ⇒ Object (readonly)
Returns the value of attribute request_date.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def request_date @request_date end |
#request_date_ms ⇒ Object (readonly)
Returns the value of attribute request_date_ms.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def request_date_ms @request_date_ms end |
#request_date_pst ⇒ Object (readonly)
Returns the value of attribute request_date_pst.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def request_date_pst @request_date_pst end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
25 26 27 |
# File 'lib/itunes/receipt.rb', line 25 def transaction_id @transaction_id end |
Class Method Details
.verify!(receipt_data, allow_sandbox_receipt = false) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/itunes/receipt.rb', line 133 def self.verify!(receipt_data, allow_sandbox_receipt = false) request_data = {:'receipt-data' => receipt_data} request_data.merge!(:password => Itunes.shared_secret) if Itunes.shared_secret response = post_to_endpoint(request_data) begin successful_response(response) rescue SandboxReceiptReceived => e # Retry with sandbox, as per: # http://developer.apple.com/library/ios/#technotes/tn2259/_index.html # FAQ#16 if allow_sandbox_receipt sandbox_response = post_to_endpoint(request_data, Itunes::ENDPOINT[:sandbox]) successful_response( sandbox_response.merge(:itunes_env => :sandbox) ) else raise e end end end |
Instance Method Details
#application_receipt? ⇒ Boolean
125 126 127 |
# File 'lib/itunes/receipt.rb', line 125 def application_receipt? !@bundle_id.nil? end |
#sandbox? ⇒ Boolean
129 130 131 |
# File 'lib/itunes/receipt.rb', line 129 def sandbox? itunes_env == :sandbox end |