question

tongar-guven avatar image
tongar-guven asked

Apple (iOS) receipt validation in Unity IAP

Hello, I am currently having an issue with validating receipts on iOS platforms. On Google Play, all seems to be working fine.

I was having an issue with processing transactions. The first time I purchased an item it was passing through fine. But for the second time I purchased the same item, it has prompted me "This In-App Purchase has already been bought. It will be restored for free" even though the item is a consumable. It behaves as if I have not consumed or finished the transaction. But I am completing all transactions as documented in Unity Docs "Saving purchases to the cloud". While I was looking for a possible solution, I have realized that I have forgot to install the Apple addon in PlayFab and figured it could be that causing the issue.

After that I have installed the addon with the bundle id & shared secret, now none of the transactions are passing through on iOS. I inspected the log in PlayFab and it seems that the receipt is invalid. I have not found what could be the issue here since all is working fine on Google Play. Could you please provide assistance. Thanks.

Here is the code snippet where I send the receipt data to PlayFab:

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        ...


#if UNITY_ANDROID
        var googleReceipt = GooglePurchase.FromJson(args.purchasedProduct.receipt);
        menuManager.playfabManager.AuthService.ValidateGooglePlayReceipt(
           args.purchasedProduct.metadata.isoCurrencyCode,
           (uint)(args.purchasedProduct.metadata.localizedPrice * 100),
           googleReceipt.PayloadData.json,
           googleReceipt.PayloadData.signature,
           args.purchasedProduct
           );
#elif UNITY_IPHONE || UNITY_IOS
        var appleReceipt = ApplePurchase.FromJson(args.purchasedProduct.receipt);
        menuManager.playfabManager.AuthService.ValidateIOSReceipt(
            args.purchasedProduct.metadata.isoCurrencyCode,
            (int)(args.purchasedProduct.metadata.localizedPrice * 100),
            appleReceipt.Payload,
            args.purchasedProduct
            );
#endif
        return PurchaseProcessingResult.Pending;
    }


public class JsonData
    {
        // JSON Fields, ! Case-sensitive


        public string orderId;
        public string packageName;
        public string productId;
        public long purchaseTime;
        public int purchaseState;
        public string purchaseToken;
    }


public class PayloadData
    {
        public JsonData JsonData;


        // JSON Fields, ! Case-sensitive
        public string signature;
        public string json;


        public static PayloadData FromJson(string json)
        {
            var payload = JsonUtility.FromJson<PayloadData>(json);
            payload.JsonData = JsonUtility.FromJson<JsonData>(payload.json);
            return payload;
        }
    }


public class GooglePurchase
    {
        public PayloadData PayloadData;


        // JSON Fields, ! Case-sensitive
        public string Store;
        public string TransactionID;
        public string Payload;


        public static GooglePurchase FromJson(string json)
        {
            var purchase = JsonUtility.FromJson<GooglePurchase>(json);
            purchase.PayloadData = PayloadData.FromJson(purchase.Payload);
            return purchase;
        }
    }


public class ApplePurchase
    {
        // JSON Fields, ! Case-sensitive
        public string Store;
        public string TransactionID;
        public string Payload;


        public static ApplePurchase FromJson(string json)
        {
            var purchase = JsonUtility.FromJson<ApplePurchase>(json);
            return purchase;
        }
    }

FYI. I am calling ConfirmPendingPurchase in the result callbacks of both ValidateGooglePlayPurchase & ValidateIOSReceipt.

This is the Raw Even JSON of the receipt validation:

{
    "EventName": "player_receipt_validation",
    "PaymentProvider": "iTunes Sandbox",
    "PaymentType": "ReceiptValidation",
    "ReceiptContent": "MIIW3AYJKoZIhvcNAQcCoIIWzTCCFskCAQExCzAJBgUrDgMCGgUAMIIGfQYJKoZIhvcNAQcBoIIGbgSCBmoxggZmMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgELAgEBBAMCAQAwCwIBDwIBAQQDAgEAMAsCARACAQEEAwIBADALAgEZAgEBBAMCAQMwDAIBAwIBAQQEDAIyOTAMAgEKAgEBBAQWAjQrMAwCAQ4CAQEEBAICAP0wDQIBDQIBAQQFAgMCSlUwDQIBEwIBAQQFDAMxLjAwDgIBCQIBAQQGAgRQMjU2MBgCAQQCAQIEEJ7aOWboP4nY6+ljlKO8whUwGwIBAAIBAQQTDBFQcm9kdWN0aW9uU2FuZGJveDAcAgEFAgEBBBQ0nTopZhV2VAl7jDcmcTTzaePibjAeAgEMAgEBBBYWFDIwMjEtMTEtMjhUMTY6MTQ6MjBaMB4CARICAQEEFhYUMjAxMy0wOC0wMVQwNzowMDowMFowHwIBAgIBAQQXDBVjb20uYm9vcHlnYW1lcy5yaWRlaW8wOwIBBw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dw3w9F4SfK8W147ee1Fxeo3H4iNcol1dkP1mvUoiQjEfehrI9zgWDGG1sJL5Ky+ERI8GA4nhX1PSZnIIozavcNgs/e66Mv+VNqW2TAYzN39zoHLFbr2g8hDtq6cxlPtdk2f8GHVdmnmbkyQvvY1XGefqFStxu9k0IkEirHDx22TZxeY8hLgBdQqorV2uT80AkHN7B1dSExggHLMIIBxwIBATCBozCBljELMAkGA1UEBhMCVVMxEzARBgNVBAoMCkFwcGxlIEluYy4xLDAqBgNVBAsMI0FwcGxlIFdvcmxkd2lkZSBEZXZlbG9wZXIgUmVsYXRpb25zMUQwQgYDVQQDDDtBcHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9ucyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eQIIDutXh+eeCY0wCQYFKw4DAhoFADANBgkqhkiG9w0BAQEFAASCAQCj/4LIldDcK/I695biDLQU2wHORCpHh8+cvDS7w344sHRWH+LzBC2go89oAQKkhO5xKVNaqiq+LaGrvm/peP2rg+r5Cfh5rcJuPDioNn17crw1mbDHXAmicQB5AmsVeXiqgSXiLuZ+82xL3nwpIZUkY6Pj4uRJkOTeRe5AG7SWi+79pjdWXnrxKZM/muVPuZHXJ5bsn9HTq46yQWZix3rrTjfuPOHycTxx+0PIAqogv98ugXV02F1COb2DT0gK8bvpBCvtcIUg6TwxBTQkujOi5yRBqaNdWZbxwFUYK5akBdqrM2m79xBbFGkDkRMkKOP2Yr7ZfY7rZOKiKa/ep/KG",
    "Valid": false,
    "Error": "Invalid receipt",
    "EntityId": "F49199EEDADC143C",
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "Source": "PlayFab",
    "TitleId": "ECA35",
    "EventId": "3e979d6bfedb42fbaf819fb8e971d938",
    "SourceType": "BackEnd",
    "Timestamp": "2021-11-28T16:43:50.9444168Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null,
    "PlayFabEnvironment": {
        "Vertical": "master",
        "Cloud": "main",
        "Application": "mainserver",
        "Commit": "f4e9e95"
    }
}
apisunity3dsdksIn-Game Economy
10 |1200

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

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

You can check the answer of this thread - Validation problems with iTunes receipts - Playfab Community to learn about how to troubleshoot the iOS receipt issues. As the above thread said, the “invalid receipt” error means some part of your receipt data is incorrect. For your case, if you can confirm the receipt you obtained from Apple is correct, you may need to print the original receipt JSON to check if the “receipt content” you sent is the same as the “Payload” of the original receipt JSON returned by Apple.

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]