Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Add missing fields in pending renewal info (#82)
Browse files Browse the repository at this point in the history
* Add grace_period_expires_at into pending renewal info

* Add original_transaction_id into pending renewal info
  • Loading branch information
ohbarye authored and dankimio committed Dec 5, 2019
1 parent 9fc0b8f commit 59c162c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/venice/pending_renewal_info.rb
Expand Up @@ -31,6 +31,13 @@ class PendingRenewalInfo
# Use this value along with the cancellation date to identify possible issues in your app that may lead customers to contact Apple customer support.
attr_reader :cancellation_reason

# The time at which the grace period for subscription renewals expires, in a date-time format similar to the ISO 8601.
# This key is only present for apps that have Billing Grace Period enabled and when the user experiences a billing error at the time of renewal.
attr_reader :grace_period_expires_at

# The transaction identifier of the original purchase.
attr_reader :original_transaction_id

def initialize(attributes)
@original_json_data = attributes
@expiration_intent = Integer(attributes['expiration_intent']) if attributes['expiration_intent']
Expand All @@ -45,6 +52,8 @@ def initialize(attributes)

@price_consent_status = Integer(attributes['price_consent_status']) if attributes['price_consent_status']
@cancellation_reason = Integer(attributes['cancellation_reason']) if attributes['cancellation_reason']
@grace_period_expires_at = DateTime.parse(attributes['grace_period_expires_date']) if attributes['grace_period_expires_date']
@original_transaction_id = attributes['original_transaction_id'] if attributes['original_transaction_id']
end

def to_hash
Expand All @@ -55,7 +64,9 @@ def to_hash
is_in_billing_retry_period: @is_in_billing_retry_period,
product_id: @product_id,
price_consent_status: @price_consent_status,
cancellation_reason: @cancellation_reason
cancellation_reason: @cancellation_reason,
grace_period_expires_at: (@grace_period_expires_at.httpdate rescue nil),
original_transaction_id: @original_transaction_id,
}
end

Expand Down
5 changes: 4 additions & 1 deletion spec/pending_renewal_info_spec.rb
Expand Up @@ -33,7 +33,10 @@
is_in_billing_retry_period: false,
product_id: 'com.foo.product1',
price_consent_status: nil,
cancellation_reason: nil)
cancellation_reason: nil,
grace_period_expires_at: nil,
original_transaction_id: "37xxxxxxxxx89",
)
end
end
end
5 changes: 4 additions & 1 deletion spec/receipt_spec.rb
Expand Up @@ -172,7 +172,10 @@ def stub_json_response_from_verifying_data(returns)
is_in_billing_retry_period: false,
product_id: 'com.foo.product1',
price_consent_status: nil,
cancellation_reason: nil }])
cancellation_reason: nil,
grace_period_expires_at: nil,
original_transaction_id: "37xxxxxxxxx89",
}])
end
end
end

0 comments on commit 59c162c

Please sign in to comment.