Closed zabolotnov87 closed 3 years ago
@zabolotnov87 Thanks for your work. It looks quite great. Maybe we should think about dropping support for the iOS6 style receipts at all.
As also mentioned in #15: I'm currently in a situation where I cannot work on this project for a couple of weeks. I'm very sorry for this, but my family goes first. I'll check this PR as soon as possible.
Any updates on this issue?
Nice to have you back @jnbt.
So, apparently these extra fields are presented outside of the receipt under the pending_renewal_info
-key.
"pending_renewal_info":
[{"expiration_intent"=>"1",
"auto_renew_product_id"=>"com.fishbrain.dev.monthly_notrial_799",
"original_transaction_id"=>"1000000348868401",
"is_in_billing_retry_period"=>"0",
"product_id"=>"com.fishbrain.dev.monthly_notrial_799",
"auto_renew_status"=>"0"},
{"expiration_intent"=>"1",
"auto_renew_product_id"=>
"com.fishbrain.dev.subscription_1_month_30_days_trial",
"original_transaction_id"=>"1000000348903541",
"is_in_billing_retry_period"=>"0",
"product_id"=>"com.fishbrain.dev.subscription_1_month_30_days_trial",
"auto_renew_status"=>"0"}],
We've solved this in our fork by attaching the renewal info to the last transaction/receipts.
module CandyCheck
module AppStore
# Store multiple {Receipt}s in order to perform collective operation on them
class ReceiptCollection
PENDING_RENEWAL_INFO_KEYS = %w(expiration_intent
is_in_billing_retry_period
auto_renew_status
auto_renew_product_id).freeze
# Initializes a new instance which bases on a JSON result
# from Apple's verification server
# @param attributes [Array<Hash>]
def initialize(attributes, pending_renewal_info = nil)
@attributes = attributes
@pending_renewal_info = pending_renewal_info
end
# Check if the latest expiration date is passed
# @return [bool]
def expired?
expires_at.to_time <= Time.now.utc
end
# Check if in trial
# @return [bool]
def trial?
latest_expiring_receipt.is_trial_period
end
# Get latest expiration date
# @return [DateTime]
def expires_at
latest_expiring_receipt.expires_date
end
# Get number of overdue days. If this is negative, it is not overdue.
# @return [Integer]
def overdue_days
(Date.today - expires_at.to_date).to_i
end
# Multiple receipts as in verfication response
# @return [Array<Unified::InAppReceipt>]
def receipts
@receipts ||= receipt_data.map { |r| Unified::InAppReceipt.new(r) }
end
private
def latest_expiring_receipt
receipts.sort_by(&:expires_date).last
end
def receipt_data
return @attributes unless @pending_renewal_info.present?
@attributes.group_by{ |r| r['original_transaction_id']}.map do |original_transaction_id, transactions|
extra_info = @pending_renewal_info.find do |info|
info["original_transaction_id"] == original_transaction_id
end.try(:slice, *PENDING_RENEWAL_INFO_KEYS)
transactions.last.merge! extra_info
transactions
end.flatten
end
end
end
end
Updated.
Hi, will you check it?
The PR adds classes to work with ios 7 style grand unified receips:
Unified::AppReceipt
andUnified::InAppReceipt
.