Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exclude old transactions option #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.7.1
9 changes: 5 additions & 4 deletions lib/candy_check/app_store/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def initialize(endpoint_url)
# @param receipt_data [String] base64 encoded data string from the app
# @param secret [String] the password for auto-renewable subscriptions
# @return [Hash]
def verify(receipt_data, secret = nil)
request = build_request(build_request_parameters(receipt_data, secret))
def verify(receipt_data, secret = nil, exclude_old_transactions = nil)
request = build_request(build_request_parameters(receipt_data, secret, exclude_old_transactions))
response = perform_request(request)
MultiJson.load(response.body)
end
Expand All @@ -46,10 +46,11 @@ def build_request(parameters)
end
end

def build_request_parameters(receipt_data, secret)
def build_request_parameters(receipt_data, secret, exclude_old_transactions)
{
'receipt-data' => receipt_data
'receipt-data' => receipt_data,
}.tap do |h|
h['exclude-old-transactions'] = exclude_old_transactions if exclude_old_transactions
h['password'] = secret if secret
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/candy_check/app_store/subscription_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class SubscriptionVerification < CandyCheck::AppStore::Verification
# @param receipt_data [String] the raw data to be verified
# @param secret [String] optional: shared secret
# @param product_ids [Array<String>] optional: select specific products
# @param exclude_old_transactions [Boolean] optional: exclude older subscription transactions
def initialize(
endpoint_url,
receipt_data,
secret = nil,
product_ids = nil
product_ids = nil,
exclude_old_transactions = nil
)
super(endpoint_url, receipt_data, secret)
super(endpoint_url, receipt_data, secret, exclude_old_transactions)
@product_ids = product_ids
end

Expand Down
13 changes: 8 additions & 5 deletions lib/candy_check/app_store/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Verification
attr_reader :receipt_data
# @return [String] the optional shared secret
attr_reader :secret
# @return [Boolean] optional. Set this value to true for the response to include only the latest renewal transaction for any subscriptions.
attr_reader :exclude_old_transactions

# Constant for successful responses
STATUS_OK = 0
Expand All @@ -17,10 +19,11 @@ class Verification
# @param endpoint_url [String] the verification URL to use
# @param receipt_data [String] the raw data to be verified
# @param secret [String] optional: shared secret
def initialize(endpoint_url, receipt_data, secret = nil)
@endpoint_url = endpoint_url
@receipt_data = receipt_data
@secret = secret
def initialize(endpoint_url, receipt_data, secret = nil, exclude_old_transactions = nil)
@endpoint_url = endpoint_url
@receipt_data = receipt_data
@secret = secret
@exclude_old_transactions = exclude_old_transactions
end

# Performs the verification against the remote server
Expand All @@ -43,7 +46,7 @@ def valid?

def verify!
client = Client.new(endpoint_url)
@response = client.verify(receipt_data, secret)
@response = client.verify(receipt_data, secret, exclude_old_transactions)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/candy_check/app_store/verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def initialize(config)
# @param secret [String] the optional shared secret
# @return [Receipt] if successful
# @return [VerificationFailure] otherwise
def verify(receipt_data, secret = nil)
fetch_receipt_information(Verification, [receipt_data, secret])
def verify(receipt_data, secret = nil, exclude_old_transactions: false)
fetch_receipt_information(Verification, [receipt_data, secret, exclude_old_transactions])
end

# Calls a subscription verification for the given input
Expand All @@ -39,8 +39,8 @@ def verify(receipt_data, secret = nil)
# @param product_ids [Array<String>] optional: products to filter
# @return [ReceiptCollection] if successful
# @return [Verification] otherwise
def verify_subscription(receipt_data, secret = nil, product_ids = nil)
args = [receipt_data, secret, product_ids]
def verify_subscription(receipt_data, secret = nil, product_ids = nil, exclude_old_transactions: false)
args = [receipt_data, secret, product_ids, exclude_old_transactions]
fetch_receipt_information(SubscriptionVerification, args)
end

Expand Down