lib/itunes/receipt.rb in itunes-receipt-1.0.0 vs lib/itunes/receipt.rb in itunes-receipt-1.1.0
- old
+ new
@@ -66,17 +66,25 @@
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 = if attributes[:latest_receipt_info]
- full_receipt_data = attributes[:latest_receipt]
+ @latest = case attributes[:latest_receipt_info]
+ when Hash
self.class.new(
:receipt => attributes[:latest_receipt_info],
- :latest_receipt => full_receipt_data,
+ :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],
@@ -110,24 +118,9 @@
@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
-
- def as_json
- {
- :quantity => @quantity,
- :product_id => @product_id,
- :transaction_id => @transaction_id,
- :purchase_date => @purchase_date,
- :original_transaction_id => @original.try(:transaction_id),
- :original_purchase_date => @original.try(:purchase_date),
- :is_trial_period => @is_trial_period
- }.tap do |hash|
- hash[:application_version] = @application_version if @application_version.present?
- hash[:bundle_id] = @bundle_id if @bundle_id.present?
- end
end
def application_receipt?
!@bundle_id.nil?
end