lib/monza/transaction_receipt.rb in monza-1.3.8 vs lib/monza/transaction_receipt.rb in monza-1.3.9
- old
+ new
@@ -1,10 +1,12 @@
require 'time'
require 'active_support/core_ext/time'
module Monza
class TransactionReceipt
+ using BoolTypecasting
+
# Receipt Fields Documentation
# https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1
attr_reader :quantity
attr_reader :product_id
@@ -20,14 +22,19 @@
attr_reader :expires_date
attr_reader :expires_date_ms
attr_reader :expires_date_pst
attr_reader :is_trial_period
+ attr_reader :cancellation_reason
attr_reader :cancellation_date
+ attr_reader :cancellation_date_ms
+ attr_reader :cancellation_date_pst
attr_reader :is_in_intro_offer_period
+ attr_reader :original_attributes
def initialize(attributes)
+ @original_attributes = attributes
@quantity = attributes['quantity'].to_i
@product_id = attributes['product_id']
@transaction_id = attributes['transaction_id']
@original_transaction_id = attributes['original_transaction_id']
@purchase_date = DateTime.parse(attributes['purchase_date']) if attributes['purchase_date']
@@ -35,10 +42,14 @@
@purchase_date_pst = DateTime.parse(attributes['purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['purchase_date_pst']
@original_purchase_date = DateTime.parse(attributes['original_purchase_date']) if attributes['original_purchase_date']
@original_purchase_date_ms = Time.zone.at(attributes['original_purchase_date_ms'].to_i / 1000)
@original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['original_purchase_date_pst']
@web_order_line_item_id = attributes['web_order_line_item_id']
+ @cancellation_reason = attributes['cancellation_reason'] if attributes['cancellation_reason']
+ @cancellation_date = DateTime.parse(attributes['cancellation_date']) if attributes['cancellation_date']
+ @cancellation_date_ms = Time.zone.at(attributes['cancellation_date_ms'].to_i / 1000) if attributes['cancellation_date_ms']
+ @cancellation_date_pst = DateTime.parse(attributes['cancellation_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['cancellation_date_pst']
if attributes['expires_date']
begin
# Attempt to parse as RFC 3339 timestamp (new-style receipt)
@expires_date = DateTime.parse(attributes['expires_date'])
@@ -58,12 +69,9 @@
if attributes['is_trial_period']
@is_trial_period = attributes['is_trial_period'].to_bool
end
if attributes['is_in_intro_offer_period']
@is_in_intro_offer_period = attributes['is_in_intro_offer_period'].to_bool
- end
- if attributes['cancellation_date']
- @cancellation_date = DateTime.parse(attributes['cancellation_date'])
end
end # end initialize
#
# Depcrecating - don't use these