In-app-purchases are not work in mobile

in-app-purchases are not work in mobile. but work in editor.
Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing;

public class Store : MonoBehaviour
{
    [SerializeField] private GameObject restoreButton;

    public const string NewCarUnlockedKey = "NewCarUnlocked";

    private void Awake()
    {
        if(Application.platform != RuntimePlatform.IPhonePlayer)
        {
            restoreButton.SetActive(false);
        }
    }

    public void OnPurchaseComplete(Product product)
    {
      PlayerPrefs.SetInt(NewCarUnlockedKey, 1);
    }

     public void OnPurchaseFailed(Product product, PurchaseFailureReason reason)
    {
         Debug.LogWarning($"Failed to purchase product {product.definition.id} because {reason}");
    }
}

Is your game published to the App Store or Play Store? I’m not sure with Apple, but I know Google will reject purchases if the game isn’t at least created and an APK uploaded to the store.

What happens when you click on the purchase button? Do you get a purchase dialogue?

No my game is not uploaded on google play store or app store.
In Mobile when i click the purchase button nothing happen.
But in editor when i click the purchase button purchase dialogue is appeared and everything works.

Thanks.

That is most likely what’s happening.
In the Editor, the purchase API is simulated, no information is sent to Google or Apple, but instead is sent to “FakeStore” which is really just a script in the IAP package.
In a built game, on the device, info is sent to Google or Apple, and as I said, they’re likely to reject purchases on a game that they know nothing about (I know from experience that Google will).

1 Like

Yes you are right i also think that.
Thanks i think that when i upload the game on Google play store in-app-purchases worked in mobile.
Thanks again.
You clear my doubt.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms