question

jcoriston avatar image
jcoriston asked

ValidateWindowsStoreReceipt error 400 Invalid receipt

Hello,

I'm trying to test Windows Store purchases (using Unity IAP) - but some receipts return as invalid.

Here's the result of the failed validation from the dashboard:

"EventName": "player_receipt_validation",
    "PaymentProvider": "Windows Store",
    "PaymentType": "ReceiptValidation",
    "ReceiptContent": "<?xml version=\"1.0\"?><Receipt Version=\"1.0\" CertificateId=\"A656B9B1B3AA509EEA30222E6D5E7DBDA9822DCD\" xmlns=\"http://schemas.microsoft.com/windows/2012/store/receipt\"><ProductReceipt PurchasePrice=\"USD0\" PurchaseDate=\"2017-09-06T21:19:25.800Z\" Id=\"3b6f06b0-74a7-492c-8418-98b8fada16ea\" AppId=\"SPT.PlaytheShow_xhagv60wx4y2m\" ProductId=\"test\" ProductType=\"Durable\" PublisherUserId=\"FIRBmGkslmaT/gPPpxcrZNrR6J9XCNlC0520pXeEtU0=\" MicrosoftProductId=\"7a31d10d-4d6a-4f3e-9f40-0136eb10002d\" MicrosoftAppId=\"7a31d10d-4d6a-4f3e-9f40-0136eb10002d\" ExpirationDate=\"9999-12-31T23:59:59.999Z\" /><Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\" /><Reference URI=\"\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\" /></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha256\" /><DigestValue>Q73Qo5D9H+tbtLKMbM4GH1hju1u9GrVku27FGIKlfSk=</DigestValue></Reference></SignedInfo><SignatureValue>U9m3dRFXr2u+olO9q77kLo+fRkGbXimVRdDyLsFr9dXh6aLO2rWLCbRSFUJI/IsN/Xg2EUoTslPukTqJrGNcesgvsHdnfsvRxI5y+a2qdNPT2tEZRwkbetC7zWmAiAjWRI4ge4jTVWHcOLYuferm6IBYmbFhkeDOBEHaOIA1Jbnhq9TXw9SOJc4b0CHzSuudXSqwXioy6qdivWyPCWz54dbdUorJJIaFRKCsNkixKBVU6k/tgi7+1uM7rDNM4HhyW17KgP2c4gLH5QXcOASzwUSYhFgDqFmnnFfSsZ1q/mhSZO5G8QYnz+rmPpbmmxXmvCmtx70f+qtEqPhek3lVJw==</SignatureValue></Signature></Receipt>",
    "Valid": false,
    "Error": "Invalid receipt",
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "Source": "PlayFab",
    "TitleId": "1990",
    "EventId": "c45d95ef10d84aa8a25c70dd1f00ecff",
    "EntityId": "A5CA6E9F2B931740",
    "SourceType": "BackEnd",
    "Timestamp": "2018-01-24T20:53:35.843666Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null

In my request I make sure to pass the currency code and price (converted from dollars to cents) directly from the Unity purchase data. I also made sure the price matches the item in our primary catalog.

Am I missing something?

Thanks!

In-Game Economywindows
10 |1200

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

brendan avatar image
brendan answered

How exactly are you getting this receipt? It's missing some required elements - ReceiptDate and ReceiptDeviceId, specifically (https://docs.microsoft.com/en-us/windows/uwp/monetize/use-receipts-to-verify-product-purchases). Without those, the receipt is not valid and cannot be processed.

7 comments
10 |1200

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

jcoriston avatar image jcoriston commented ·

That's interesting...

I'm getting the receipt via the UnityReceipt payload as briefly mentioned in this doc.

Here's the relevant code:

    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        //Parse Unity receipt JSON for actual Windows Store receipt
        var receipt = JsonConvert.DeserializeObject<UnityReceipt>(args.purchasedProduct.receipt);
        playfab.ValidateReceipt(receipt.payload, args.purchasedProduct.metadata.localizedPrice, args.purchasedProduct.metadata.isoCurrencyCode, receipt.store, args.purchasedProduct.definition.id);
    }

The receipt.payload is the string I'm passing into ValidateWindowsReceiptRequest as the Receipt.

Thanks Brendan.

0 Likes 0 ·
brendan avatar image brendan ♦♦ jcoriston commented ·

It's not clear to us why the ReceiptDate and ReceiptDeviceId would be missing, when they are part of the Receipt element. Without knowing the internals of Unity's code, it's not really possible for us to say what, if anything, is being done on the receipt data. Can you post that question to the Unity team?

1 Like 1 ·
Artyom Kolesnikov avatar image Artyom Kolesnikov brendan ♦♦ commented ·

We have the exact same issue: ReceiptDate and ReceiptDeviceId are missing from receipts. However, I used the example from https://docs.microsoft.com/en-us/windows/uwp/monetize/use-receipts-to-verify-product-purchases#validating-a-receipt to validate these receipt locally and they are considered valid and successfully verified. So, it is strange that ReceiptDate and ReceiptDeviceId are missing but they are not required for validation, I think.

0 Likes 0 ·
Show more comments
Show more comments
marcospaulis avatar image
marcospaulis answered

Hey Brendan, any updates on this? I think we are having the same problem, although our recepit it´s a little bit different (but has ReceiptDate and ReceiptDeviceId):

{
    "EventName": "player_receipt_validation",
    "PaymentProvider": "Windows Store",
    "PaymentType": "ReceiptValidation",
    "ReceiptContent": "<?xml version=\"1.0\" encoding=\"utf-8\"?><Receipt Version=\"1.0\" ReceiptDate=\"2021-04-20T13:05:46Z\" CertificateId=\"\" ReceiptDeviceId=\"265d7b3b-6aba-4abc-ba29-b256b8ff5415\" PublisherDeviceId=\"4e1065f6-8862-4fc1-895e-e289c3dde8d2\"><ProductReceipt Id=\"e8cee4f8-5d05-40ea-a815-7ef53273326c\" AppId=\"EverguildLtd.LegionsBeta_kvxfpdspnrmqw\" ProductId=\"ticket_pack_tiny\" PurchaseDate=\"2021-04-20T13:05:46Z\" ProductType=\"Consumable\"   /></Receipt>",
    "Valid": false,
    "Error": "Invalid receipt",
    "EntityId": "E6214EA090913F5C",
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "Source": "PlayFab",
    "TitleId": "8A42",
    "EventId": "4310de8dd47d47df84599ba8b7850100",
    "SourceType": "BackEnd",
    "Timestamp": "2021-04-20T13:05:47.1227426Z",
    "PlayFabEnvironment": {
        "Vertical": "master",
        "Cloud": "main",
        "Application": "mainserverlinux",
        "Commit": "a4fede2"
    }
}

We are using the "mock billing system" of Unity IAP, and the user is not linked with WindowsHello (i saw other problem some years ago where that was the problem).

1 comment
10 |1200

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

brendan avatar image brendan ♦♦ commented ·

If you're getting "invalid receipt" on a v1 receipt, there's an issue with the receipt. In this case, I notice that your CertificateId is empty. Since that's supposed to be the thumbprint used to sign the receipt, that shouldn't be possible. I'd recommend re-checking your store setup and the logic used to get the receipt and pass it to PlayFab.

0 Likes 0 ·

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.