Search Unity

Verify Google Play In-App purchase with server

Discussion in 'Android' started by SplashFoxGames, Jul 6, 2019.

  1. SplashFoxGames

    SplashFoxGames

    Joined:
    Oct 10, 2012
    Posts:
    53
    hello !

    I'm trying to make a test in-app purchase (alpha track) using Unity 2019.2.a14.
    All is good on technical side - I can see native OS purchase confirmation window and can see purchase details in log.
    Now I want to send it to my server using RestAPI to verify.
    I found that verification method is:

    GET https://www.googleapis.com/androidp...ame/purchases/products/productId/tokens/token

    packageName - is my app bundle - ok
    productId - is in-app purchase id - ok
    token - ?

    I tried to grab it here:
    Code (CSharp):
    1.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2.     {
    3.  
    4.         string receipt_hash = args.purchasedProduct.receipt;
    5. ....
    in the received data I found "purchaseToken", there are many chars like \\\ but I hope I copied it correctly.
    But when I try to build the GET url and test it using any browser or postman - I see only "not found" as the result.

    am I doing something wrong on integration side or should I search on google account settings or elsewhere?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Where are you seeing the documentation for the Google REST call that you are making? I suspect the token is a login/auth token, separate from IAP.
     
  3. SplashFoxGames

    SplashFoxGames

    Joined:
    Oct 10, 2012
    Posts:
    53
    thanks for the answer,
    I'm working with a developer's tutorial found on web, it says next:

    - we need authorization in order to access "verification" service on google for in-app purchases,
    so we can send purchase token and receive response - receipt with details.

    - simply calling "https://www.googleapis.com/androidp...ame/purchases/products/productId/tokens/token" will not work as I understand, as there should be authorization included (in request header)

    Tutorial says that OAuth can work but there is IAM (Identy Access Management) available and its better.
    I went to Google Cloud Console, Created a service key in credentials, have a json-file generated, created an account on google developer console (with custom role, be able to read financial/orders data, I was using credentials (email) from this json),
    API Access -> Google Play Android Developer -> Linked (there was also an option to link the game, but I choose "Google Play Android Developer" as I see it from tutorial)

    I'll check again, can't say I really stuck on something, need to double check and test again and again,
    from another side I still curious about the json format that Google say to Unity after purchase done,
    there are lot of "\" or "\\\" chars, I guess I can't parse like that classes, so should I make something like
    s = string.Replace(s, "\\\", string.empty)
    s = string.Replace(s, "\\", string.empty)
    s = string.Replace(s, "\", string.empty)
    ? : ))

    e.g.:
    Code (CSharp):
    1. purchaseState\\\":0,\\\"developerPayload\\\":\\\"{\\\\\\\"developerPayload\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"is_free_trial\\\\\\\":false,\\\\\\\"has_introductory_price_trial\\\\\\\":false,\\\\\\\"is_updated\\\\\\\":false,\\\\\\\"accountId\\\\\\\"
    p.s.: https://developers.google.com/android-publisher/authorization this looks way too complicated and the token is "temporary" so backend needs to request new access tokens from time to time.