./lib/venice/in_app_receipt.rb in venice-0.5.0 vs ./lib/venice/in_app_receipt.rb in venice-0.6.0

- old
+ new

@@ -3,10 +3,13 @@ module Venice class InAppReceipt # For detailed explanations on these keys/values, see # https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW12 + # Original JSON data returned from Apple for an InAppReceipt object. + attr_reader :original_json_data + # The number of items purchased. This value corresponds to the quantity property of # the SKPayment object stored in the transaction’s payment property. attr_reader :quantity # The product identifier of the item that was purchased. This value corresponds to @@ -42,21 +45,31 @@ # For auto-renewable subscriptions, returns the date the subscription will expire attr_reader :expires_at # For a transaction that was canceled by Apple customer support, the time and date of the cancellation. + # For an auto-renewable subscription plan that was upgraded, the time and date of the upgrade transaction. attr_reader :cancellation_at + # Only present for auto-renewable subscription receipts. Value is true if the customer’s subscription is + # currently in the free trial period, false if not, nil if key is not present on receipt. + attr_reader :is_trial_period + # Only present for auto-renewable subscription receipts. Value is true if the customer’s subscription is + # currently in an introductory price period, false if not, nil if key is not present on receipt. + attr_reader :is_in_intro_offer_period + def initialize(attributes = {}) + @original_json_data = attributes @quantity = Integer(attributes['quantity']) if attributes['quantity'] @product_id = attributes['product_id'] @transaction_id = attributes['transaction_id'] @web_order_line_item_id = attributes['web_order_line_item_id'] @purchased_at = DateTime.parse(attributes['purchase_date']) if attributes['purchase_date'] @app_item_id = attributes['app_item_id'] @version_external_identifier = attributes['version_external_identifier'] - @is_trial_period = attributes['is_trial_period'].to_s == 'true' + @is_trial_period = attributes['is_trial_period'].to_s == 'true' if attributes['is_trial_period'] + @is_in_intro_offer_period = attributes['is_in_intro_offer_period'] == 'true' if attributes['is_in_intro_offer_period'] # expires_date is in ms since the Epoch, Time.at expects seconds if attributes['expires_date_ms'] @expires_at = Time.at(attributes['expires_date_ms'].to_i / 1000) elsif attributes['expires_date'] && is_number?(attributes['expires_date']) @@ -86,9 +99,10 @@ original_transaction_id: (@original.transaction_id rescue nil), original_purchase_date: (@original.purchased_at.httpdate rescue nil), app_item_id: @app_item_id, version_external_identifier: @version_external_identifier, is_trial_period: @is_trial_period, + is_in_intro_offer_period: @is_in_intro_offer_period, expires_at: (@expires_at.httpdate rescue nil), cancellation_at: (@cancellation_at.httpdate rescue nil) } end alias_method :to_h, :to_hash