./lib/venice/in_app_receipt.rb in venice-0.4.2 vs ./lib/venice/in_app_receipt.rb in venice-0.4.3
- old
+ new
@@ -16,10 +16,14 @@
# The transaction identifier of the item that was purchased. This value corresponds
# to the transaction’s transactionIdentifier property.
attr_reader :transaction_id
+ # The primary key for identifying subscription purchases. This value is a unique ID that identifies purchase events across devices, including subscription renewal purchase events.
+ # When restoring purchase, transaction_id could change
+ attr_reader :web_order_line_item_id
+
# The date and time this transaction occurred. This value corresponds to the
# transaction’s transactionDate property.
attr_reader :purchased_at
# A string that the App Store uses to uniquely identify the application that created
@@ -44,16 +48,21 @@
def initialize(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']
# expires_date is in ms since the Epoch, Time.at expects seconds
- @expires_at = Time.at(attributes['expires_date_ms'].to_i / 1000) if attributes['expires_date_ms']
+ 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'])
+ @expires_at = Time.at(attributes['expires_date'].to_i / 1000)
+ end
# cancellation_date is in ms since the Epoch, Time.at expects seconds
@cancellation_at = Time.at(attributes['cancellation_date_ms'].to_i / 1000) if attributes['cancellation_date_ms']
if attributes['original_transaction_id'] || attributes['original_purchase_date']
@@ -69,10 +78,11 @@
def to_hash
{
quantity: @quantity,
product_id: @product_id,
transaction_id: @transaction_id,
+ web_order_line_item_id: @web_order_line_item_id,
purchase_date: (@purchased_at.httpdate rescue nil),
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,
@@ -82,8 +92,14 @@
end
alias_method :to_h, :to_hash
def to_json
to_hash.to_json
+ end
+
+ private
+
+ def is_number?(string)
+ !!(string && string.to_s =~ /^[0-9]+$/)
end
end
end