question

Kim Strasser avatar image
Kim Strasser asked

Receipt validation fails

On Android, receipt validation always fails and I get this exception System.NullReferenceException(Object reference not set to an instance of an object.). On iOS, I think receipt validation never fails but I sometimes get the same exception System.NullReferenceException(Object reference not set to an instance of an object.).

My device is logged in and uses LoginWithAndroidDevice/LoginWithIOSDevice.

The variables PurchaseditemCurrencyCode, PurchaseditemPurchasePrice, SignedData and Signature are not null and I think that they have the correct values because I can see in my Google Play account that the in-app product purchase is successful, but in the PlayFab Game Manager receipt validation fails.

My values on Android: PurchaseditemCurrencyCode = "EUR", PurchaseditemPurchasePrice = 229, SignedData = "{\"orderId\":..." and Signature = "eMU3xCYDD4L..."

My values on iOS: PurchaseditemCurrencyCode = "EUR", PurchaseditemPurchasePrice = 229, SignedData = "MllVSAYJK..."

I don't know why I'm getting this exception. Am I using the PlayFab API calls correctly or am I doing something wrong?

My Android and iOS code:

  if (purchaseIsSuccessful == true)
  {
    try
    {
      if (Device.RuntimePlatform == Device.iOS)
      {
        if (productId == "Consumable11")
          await DoValidateIOSReceiptAsync(PurchaseditemCurrencyCode, PurchaseditemPurchasePrice, SignedData);
      }
      else
      {
        if (Device.RuntimePlatform == Device.Android)
        {
          if (productId == "Consumable11")
            await DoValidateAndroidReceiptAsync(PurchaseditemCurrencyCode, PurchaseditemPurchasePrice, SignedData, Signature);
        }
      }
    }
    catch (Exception ex)
    {
      ExceptionMessage1 = ex.Message.ToString();
      ExceptionMessage2 = ex.ToString();
    }
  }


  public async Task DoValidateAndroidReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata, string signature)
  {
    await ValidateAndroidReceiptAsync(purchaseditemcurrencycode, purchaseditempurchaseprice, signeddata, signature);
  }

  private async Task ValidateAndroidReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata, string signature)
  {
    var result = await PlayFabClientAPI.ValidateGooglePlayPurchaseAsync(new ValidateGooglePlayPurchaseRequest()
    {
    CurrencyCode = purchaseditemcurrencycode,
    PurchasePrice = (uint)purchaseditempurchaseprice,
    ReceiptJson = signeddata,
    Signature = signature
    });

    if (result.Error != null)
      PlayFabMessage = "not successful");
    else
      PlayFabMessage = "successful");
  }


  public async Task DoValidateIOSReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata)
  {
    await ValidateIOSReceiptAsync(purchaseditemcurrencycode, purchaseditempurchaseprice, signeddata);
  }

  private async Task ValidateIOSReceiptAsync(string purchaseditemcurrencycode, int purchaseditempurchaseprice, string signeddata)
  {
    var result = await PlayFabClientAPI.ValidateIOSReceiptAsync(new ValidateIOSReceiptRequest()
    {
    CurrencyCode = purchaseditemcurrencycode,
    PurchasePrice = purchaseditempurchaseprice,
    ReceiptData = signeddata
    });

    if (result.Error != null)
      PlayFabMessage = "not successful");
    else
      PlayFabMessage = "successful");
  }

UPDATE:

I use the following code to get more informations about the exception.

catch (NullReferenceException ex)
{
  Crashes.TrackError(ex);
}

And here is what I got in App Center:

iOS Json:

{
  "length": 0,
  "offset": 0,
  "id": "71aef385-bb48-44d7-b59d-a53368c72c66",
  "exception": {
    "type": "System.NullReferenceException",
    "message": "Object reference not set to an instance of an object",
    "stackTrace": "  at InapppurchaseTest.iOS.Game1.ValidateIOSReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) <0x1047fa730 + 0x002dc> in <f7cd0204315c470baa0e7963fe272e8d#b28b8328fb987f6bc8a6ed35dda86f7b>:0 \n  at InapppurchaseTest.iOS.Game1.DoValidateIOSReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) <0x1047fa4e0 + 0x00183> in <f7cd0204315c470baa0e7963fe272e8d#b28b8328fb987f6bc8a6ed35dda86f7b>:0 \n  at InapppurchaseTest.iOS.Game1.CheckPurchase (System.String productId) <0x1047f7a00 + 0x0041f> in <f7cd0204315c470baa0e7963fe272e8d#b28b8328fb987f6bc8a6ed35dda86f7b>:0 ",
    "wrapperSdkName": "appcenter.xamarin"
  },
  "appId": "d91b27bb-6d85-406b-87be-e7d17c3e391e",
  "installId": "F8765F5D-9FD1-4113-BA5C-97116E8A9693",
  "isTestMessage": false,
  "timestamp": "2019-07-04T18:12:48.637Z",
  "sid": "b6f64559-aec0-4fef-b0be-c3290bc8dba0",
  "device": {
    "sdkName": "appcenter.ios",
    "sdkVersion": "2.1.0",
    "wrapperSdkVersion": "2.1.1",
    "wrapperSdkName": "appcenter.xamarin",
    "model": "iPhone9,3",
    "oemName": "Apple",
    "osName": "iOS",
    "osVersion": "12.3.1",
    "osBuild": "16F203",
    "locale": "de_LU",
    "timeZoneOffset": 120,
    "screenSize": "1334x750",
    "appVersion": "22.0.0",
    "carrierName": "Orange Luxembourg",
    "carrierCountry": "lu",
    "appBuild": "22.0.0",
    "appNamespace": "project.MonoGame.InapppurchaseTestNew.iOS",
    "wrapperRuntimeVersion": "11.14.0"
  }
}

Android Json:

{
  "length": 0,
  "offset": 0,
  "id": "63783019-f17b-47e1-8865-4e6290f43fbd",
  "exception": {
    "type": "System.NullReferenceException",
    "message": "Object reference not set to an instance of an object",
    "stackTrace": "  at ggdgdgd.Android.Game1.ValidateAndroidReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) [0x000c3] in <11446e8c56cb4e78a270889c3b890601>:0 \n  at ggdgdgd.Android.Game1.DoValidateAndroidReceiptAsync (System.String purchaseditemcurrencycode, System.Int32 purchaseditempurchaseprice, System.String signeddata, System.String signature) [0x0007a] in <11446e8c56cb4e78a270889c3b890601>:0 \n  at ggdgdgd.Android.Game1.CheckPurchase (System.String productId) [0x0030a] in <11446e8c56cb4e78a270889c3b890601>:0 ",
    "wrapperSdkName": "appcenter.xamarin"
  },
  "appId": "9a9708c4-af57-452a-8751-53e06bb4544c",
  "installId": "6700532c-571e-4afe-bc4f-0273bfd8674c",
  "isTestMessage": false,
  "timestamp": "2019-07-04T17:42:35.861Z",
  "sid": "50ec5b4f-11b5-48d3-b653-6528eb796b8d",
  "device": {
    "sdkName": "appcenter.android",
    "sdkVersion": "2.1.0",
    "wrapperSdkVersion": "2.1.1",
    "wrapperSdkName": "appcenter.xamarin",
    "model": "SM-P600",
    "oemName": "samsung",
    "osName": "Android",
    "osVersion": "5.1.1",
    "osBuild": "LMY47X",
    "osApiLevel": 22,
    "locale": "de_DE",
    "timeZoneOffset": 120,
    "screenSize": "2560x1600",
    "appVersion": "22.0",
    "appBuild": "22",
    "appNamespace": "com.test.GetinapppurchaseAndroidneu",
    "wrapperRuntimeVersion": "9.3.0.23"
  }
}

Will this help to find the problem?

Player Inventory
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

·
Citrus Yan avatar image
Citrus Yan answered

The code you posted seems alright, could you provide us more details about it such as you call stacks to let us investigate more.

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.

Kim Strasser avatar image Kim Strasser commented ·

I added my App Center Json files.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Kim Strasser commented ·

Hey, first of all, apologies for keeping you waiting so long. After a discussion with our team, the problem probably is in your code. Hence we think that maybe you should add a breakpoint to your validation results (line 34 and 56) to see whether it's where your problem came from because it's the only place where the null-reference exception may take place.

If you still can't get your issue fixed or you suspect that the problem may be on PlayFab's side, provide us your title id and we will look into that.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser commented ·

@Citrus Yan

I think I found the problem that caused the System.NullReferenceException and I don't get this exception anymore.

But I always get the following error when I use var result = await PlayFabClientAPI.ValidateGooglePlayPurchaseAsync(new ValidateGooglePlayPurchaseRequest(): MissingTitleGoogleProperties.

I don't know what I should do to solve the issue. Could you explain me what to do?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Kim Strasser commented ·

Hey, have you activated Google for your title? If not, you may need to enter your applications configuration info in the Add-ons->Google tab for your title. In this way we can query Google on your behalf, to verify the receipt. If you’ve already activated it and the error still occurs, please provide us your title id for us to take a look at.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser commented ·

Thank you. It works now. I have a question about the order total. In my Json file, the order total is different than the transaction total. Why are these values not equal? "EventName": "player_realmoney_purchase", "PaymentProvider": "Google Play", "PaymentType": "ReceiptValidation", "OrderTotal": 256, "TransactionTotal": 229, "TransactionCurrency": "EUR"

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Kim Strasser commented ·

Hey, I checked this doc: https://docs.microsoft.com/en-us/gaming/playfab/api-references/events/player-realmoney-purchase. It says: OrderTotal : Total value of the purchase in the system currency (defaults to USD)”. Your transaction currency is EUR, 229 EUR = 256.78 USD according to the latest exchange rate. I think this might be the case.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser commented ·

Ok. Thank you.

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.