question

Sszuros avatar image
Sszuros asked

PlayFab receipt validation not working properly ?

Hello, in my game I am using Unity IAP with PlayFab's receipt validation, but it is not working properly. I can always purchase a product without any errors, but when I try to validate the receipt from google it randomly fails with "Invalid receipt" error. Sending the same receipt immediately after the failed call, I almost always get a successful validation. I tried different versions of Unity, IAP package, PlayFab SDK but without success.

Here is my implementation:

public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
    {
        Debug.Log ("Processing transaction: " + e.purchasedProduct.transactionID);
        ValidateReceipt (e.purchasedProduct);
        return PurchaseProcessingResult.Complete;
    }


    public void ValidateReceipt (Product product)
    {
        Dictionary<string, object> receiptContent = (Dictionary<string, object>)MiniJson.JsonDecode(product.receipt);
        string payload = receiptContent["Payload"].ToString ();
        decimal price = product.metadata.localizedPrice;
        string currency = product.metadata.isoCurrencyCode;
        
        Dictionary<string, object> payLoadContent = (Dictionary<string, object>)MiniJson.JsonDecode(payload);
        string json = payLoadContent["json"].ToString();
        string signature = payLoadContent["signature"].ToString();


        Debug.Log ("Validating receipt: " + payload);


        PlayFabClientAPI.ValidateGooglePlayPurchase (new ValidateGooglePlayPurchaseRequest
        {
            ReceiptJson = json,
            Signature = signature,
            PurchasePrice = (uint)(price),
            CurrencyCode = currency
        }, 
        (ValidateGooglePlayPurchaseResult result) => 
        {
            Debug.Log ("Validation success");
        }, 
        (PlayFabError error) => 
        {
            Debug.Log (error.ErrorMessage);
        });
    }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sszuros avatar image
Sszuros answered

Thank you for your answer, the problem was somewhere else. After downloading and testing the IAP Package samples from Unity, I realized that my

private static IStoreController m_StoreController;

has the static keyword. After removing the static keyword from this row everything works perfectly.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image
Gosen Gao answered

I will do some research on this issue. Meanwhile, according to the API document, the PurchasePrice should be in centesimal units. Could you please replace line 28 with

PurchasePrice = (uint)(price*100),

and try again?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.