cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with IAP.

NFlex
Honored Guest

I have a script that handles IAP purchases
The button works when I press it, the SKU is set the "menu" and so is an item in meta named "menu".
there is also an item named "menu" in playfab and in unity and in the "special items" section.

After the purchase is complete, the user does not receive the item, after hours of waiting aswell.
```

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Oculus.Platform;
using Oculus.Platform.Models;
using PlayFab;
using PlayFab.ClientModels;
 
public class IAPChimp : MonoBehaviour
{
    [SerializeField]
    private Playfablogin playfablogin;
    public string SKU;
    
    public int Amount;
 
    public Material normal;
    public Material pressed;
 
    public AudioSource sfx;
 
    private Renderer render;
 
    private void Awake()
    {
        render = GetComponent<Renderer>();
        render.material = normal;
 
        Oculus.Platform.Core.AsyncInitialize("OCULUS_DEV_KEY").OnComplete(OnPlatformInitialized);
    }
 
    private void OnPlatformInitialized(Message<Oculus.Platform.Models.PlatformInitialize> msg)
    {
        if (msg.IsError)
        {
            Debug.LogError("Oculus Platform initialization failed: " + msg.GetError().Message);
        }
        else
        {
            Debug.Log("Oculus Platform initialized successfully!");
        }
    }
 
    private void GetPurchases()
    {
        IAP.GetViewerPurchases().OnComplete(GetPurchasesCallback);
    }
 
    private void GetPurchasesCallback(Message<PurchaseList> msg)
    {
        if (msg.IsError)
            return;
 
        foreach (var purchase in msg.GetPurchaseList())
        {
            if (purchase.Sku == SKU)
            {
                CurrencyAdd();
                IAP.ConsumePurchase(SKU);
            }
        }
    }
 
 
    public void BuyIAP()
    {
        IAP.LaunchCheckoutFlow(SKU).OnComplete(BuyProductCallback);
    }
 
    private void BuyProductCallback(Message<Purchase> msg)
    {
        if (msg.IsError)
            return;
 
        GetPurchases();
    }
 
 
    public void CurrencyAdd()
    {
        var request = new AddUserVirtualCurrencyRequest
        {
            VirtualCurrency = "OR",
            Amount = Amount
        };
        PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddCoinsSuccess, OnError);
        playfablogin.GetVirtualCurrencies();
    }
 
    void OnAddCoinsSuccess(ModifyUserVirtualCurrencyResult result)
    {
        playfablogin.GetVirtualCurrencies();
    }
 
    void OnError(PlayFabError error)
    {
        Debug.Log("Error: " + error.ErrorMessage);
    }
 
    private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "HandTag")
        {
            Debug.Log("Clicked Button...");
            sfx.Play();
            StartCoroutine(resetColor());
            if (playfablogin.loggedIn)
            {
                Debug.Log("Buying ITEM...");
                BuyIAP();
            }
        }
 
    }
 
    IEnumerator resetColor()
    {
        render.material = pressed;
        yield return new WaitForSeconds(0.1f);
        render.material = normal;
    }
 
}
```
0 REPLIES 0