-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add acknowledgement response * Add product acknowledgement API call * Allow tests contexts * Add acknowledge_product_purchase public method * Fix typo * Add acknowledgement info to README Co-authored-by: gerard-morera <[email protected]>
- Loading branch information
1 parent
aa190df
commit 1d7a7b7
Showing
12 changed files
with
645 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
end | ||
end | ||
end | ||
end |
45 changes: 45 additions & 0 deletions
45
lib/candy_check/play_store/product_acknowledgements/acknowledgement.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
acknowledge! | ||
|
||
CandyCheck::PlayStore::ProductAcknowledgements::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_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
24
lib/candy_check/play_store/product_acknowledgements/response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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 |
105 changes: 105 additions & 0 deletions
105
spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/acknowledged.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/already_acknowledged.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.