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 server ACK for consumable #1

Merged
merged 4 commits into from
Jun 23, 2020
Merged
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
3 changes: 3 additions & 0 deletions lib/candy_check/play_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
require "candy_check/play_store/product_purchases/product_purchase"
require "candy_check/play_store/subscription_purchases/subscription_purchase"
require "candy_check/play_store/product_purchases/product_verification"
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/verification_failure"
require "candy_check/play_store/verifier"
require "candy_check/play_store/acknowledger"

module CandyCheck
# Module to request and verify a AppStore receipt
Expand Down
19 changes: 19 additions & 0 deletions lib/candy_check/play_store/acknowledger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module CandyCheck
module PlayStore
class Acknowledger
def initialize(authorization:)
@authorization = authorization
end

def acknowledge_product_purchase(package_name:, product_id:, token:)
acknowledger = CandyCheck::PlayStore::ProductAcknowledgements::Acknowledgement.new(
package_name: package_name,
product_id: product_id,
token: token,
authorization: @authorization,
)
acknowledger.call!
gerard-morera marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module CandyCheck
module PlayStore
module ProductAcknowledgements
# Verifies a purchase token against the PlayStore 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 :product_id
# @return [String] the token for authentication
attr_reader :token

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

def call!
acknowlege!

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

private

def acknowlege!
service = CandyCheck::PlayStore::AndroidPublisherService.new
oricodes89 marked this conversation as resolved.
Show resolved Hide resolved

service.authorization = @authorization
service.acknowledge_purchase_product(package_name, product_id, token) do |result, error_data|
@response = { result: result, error_data: error_data }
end
end
end
end
end
end
24 changes: 24 additions & 0 deletions lib/candy_check/play_store/product_acknowledgements/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module CandyCheck
module PlayStore
module ProductAcknowledgements
class Response
def initialize(result:, error_data:)
@result = result
@error_data = error_data
end

def acknowleged?
!!result
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI result when comes is an empty string.

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