jnbt / candy_check

Check and verify in-app receipts
MIT License
125 stars 71 forks source link

Google::Apis::ClientError ??? #51

Closed nirazan1 closed 4 years ago

nirazan1 commented 4 years ago

What could be the root cause of the error as follow: Caught error invalid: Invalid Value Error - #<Google::Apis::ClientError: invalid: Invalid Value status_code: 400 header: #<HTTP::Message::Headers:0x00007fd3b4d1ca88 @http_version="1.1", @body_size=0, @chunked=false, @request_method="GET", @request_uri=#<Addressable::URI:0x3fe9dc587e64 URI:https://www.googleapis.com/androidpublisher/v3/applications/com.xxxx/purchases/subscriptions/com.xxxx.xxx/tokens/GPA.xxxx-xxxx-xxxx-xxxx?>, @request_query=nil, @request_absolute_uri=nil, @status_code=400, @reason_phrase="Bad Request", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:UTF-8>, @is_request=false, @header_item=[["Content-Type", "application/json; charset=UTF-8"], ["Vary", "Origin"], ["Vary", "X-Origin"], ["Vary", "Referer"], ["Content-Encoding", "gzip"], ["Date", "Wed, 08 Jul 2020 10:07:09 GMT"], ["Server", "ESF"], ["Cache-Control", "private"], ["X-XSS-Protection", "0"], ["X-Frame-Options", "SAMEORIGIN"], ["X-Content-Type-Options", "nosniff"], ["Alt-Svc", "h3-29=\":443\"; ma=2592000,h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-T050=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""], ["Transfer-Encoding", "chunked"]], @dumped=false> body: "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid Value\",\n \"errors\": [\n {\n \"message\": \"Invalid Value\",\n \"domain\": \"global\",\n \"reason\": \"invalid\"\n }\n ]\n }\n}\n">

here is my implementation:

module SubscriptionValidator
  class Andriod
    PACKAGE_NAME = 'com.xxxx'

    def initialize(args)
      @args = args
      google_api_key_config = 'google_api_key_config.json'
      authorization = CandyCheck::PlayStore.authorization(google_api_key_config)
      @verifier = CandyCheck::PlayStore::Verifier.new(
        authorization: authorization
      )
    end

    def verified_purchase?
      response = @verifier.verify_product_purchase(
        package_name: PACKAGE_NAME,
        product_id: @args[:product_id],
        token: @args[:purchase_token]
      )
      response
    end

    def verified_subscription?
      response = @verifier.verify_subscription_purchase(
        package_name: PACKAGE_NAME,
        subscription_id: @args[:subscription_id],
        token: @args[:purchase_token]
      )
      response
    end

  end
end

executing SubscriptionValidator::Andriod.new(subscription_id: 'com.xxxx.xxxx', purchase_token: "GPA.xxxx-xxxx-xxxx-xxxx").verified_subscription? gave the above mentioned error

my google_api_key_config.json looks just like the dummy json in fixtures , is there something i need to addresss while generating the json ?

nirazan1 commented 4 years ago

it was issue with fake purchase token after all. I wish the error message said something simple like Invalid purchase token

renatomserra commented 2 years ago

Hi, @nirazan1 how did you find out it was a fake token? i have one a user of my app who is facing this issue while others seem to be working fine

nirazan1 commented 2 years ago

Hi, @nirazan1 how did you find out it was a fake token? i have one a user of my app who is facing this issue while others seem to be working fine

I manually verified the user with subscription in google play console

renatomserra commented 2 years ago

Hi, @nirazan1 how did you find out it was a fake token? i have one a user of my app who is facing this issue while others seem to be working fine

I manually verified the user with subscription in google play console

you mean their subscription didnt show in the analytics? or is there a tool in google play console im missing?