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

Add service for acknowledging subscriptions (#48) #58

Open
wants to merge 3 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: 2 additions & 0 deletions lib/candy_check/play_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require "candy_check/play_store/product_acknowledgements/acknowledgement"
require "candy_check/play_store/product_acknowledgements/response"
require "candy_check/play_store/subscription_purchases/subscription_verification"
require "candy_check/play_store/subscription_acknowledgements/acknowledgement"
require "candy_check/play_store/subscription_acknowledgements/response"
require "candy_check/play_store/verification_failure"
require "candy_check/play_store/verifier"
require "candy_check/play_store/acknowledger"
Expand Down
9 changes: 9 additions & 0 deletions lib/candy_check/play_store/acknowledger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def acknowledge_product_purchase(package_name:, product_id:, token:)
)
acknowledger.call!
end

def acknowledge_subscription_purchase(package_name:, subscription_id:, token:)
CandyCheck::PlayStore::SubscriptionAcknowledgements::Acknowledgement.new(
package_name: package_name,
subscription_id: subscription_id,
token: token,
authorization: @authorization,
).call!
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module CandyCheck
module PlayStore
module SubscriptionAcknowledgements
# Acknowledges a subscription through the API

class Acknowledgement
# @return [String] the package_name which will be queried
attr_reader :package_name
# @return [String] the item id which will be queried
attr_reader :subscription_id
# @return [String] the token for authentication
attr_reader :token

# Initializes a new call to the API
# @param package_name [String]
# @param subscription_id [String]
# @param token [String]
def initialize(package_name:, subscription_id:, token:, authorization:)
@package_name = package_name
@subscription_id = subscription_id
@token = token
@authorization = authorization
end

def call!
acknowledge!

CandyCheck::PlayStore::SubscriptionAcknowledgements::Response.new(
result: @response[:result], error_data: @response[:error_data])
end

private

def acknowledge!
service = CandyCheck::PlayStore::AndroidPublisherService.new

service.authorization = @authorization
service.acknowledge_purchase_subscription(package_name, subscription_id, token) do |result, error_data|
@response = { result: result, error_data: error_data }
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module CandyCheck
module PlayStore
module SubscriptionAcknowledgements
class Response
def initialize(result:, error_data:)
@result = result
@error_data = error_data
end

def acknowledged?
!!result
end

def error
return unless error_data

{ status_code: error_data.status_code, body: error_data.body }
end

attr_reader :result, :error_data
end
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading