1

I implement in my project RevenueCat and it doesn't see my purchases only installs. I make all like in guide

https://docs.revenuecat.com/v1.0/docs/setting-up-unity-sdk

This is my code:

using UnityEngine;
using System.Collections;
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Runtime.InteropServices;

#pragma warning disable CS0649

public class Purchases : MonoBehaviour
{
public abstract class Listener : MonoBehaviour
{
    public abstract void ProductsReceived(List<Product> products);
    public abstract void PurchaseCompleted(string productIdentifier,       Error error, PurchaserInfo purchaserInfo, bool userCanceled);
    public abstract void PurchaserInfoReceived(PurchaserInfo purchaserInfo);
}

/*
 * PurchaserInfo encapsulate the current status of subscriber. 
 * Use it to determine which entitlements to unlock, typically by checking 
 * ActiveSubscriptions or via LatestExpirationDate. 
 * 
 * Note: All DateTimes are in UTC, be sure to compare them with 
 * DateTime.UtcNow
 */
public class PurchaserInfo
{
    private PurchaserInfoResponse response;
    public PurchaserInfo(PurchaserInfoResponse response)
    {
        this.response = response;
    }


    public List<string> ActiveSubscriptions
    {
        get
        {
            return response.activeSubscriptions;
        }
    }

    public List<string> AllPurchasedProductIdentifiers
    {
        get
        {
            return response.allPurchasedProductIdentifiers;
        }
    }

    public DateTime LatestExpirationDate 
    {
        get
        {
            return DateTime.Parse(response.latestExpirationDate, null, DateTimeStyles.RoundtripKind );
        }
    }

    public Dictionary<string, DateTime> AllExpirationDates
    {
        get
        {
            Dictionary<string, DateTime> allExpirations = new Dictionary<string, DateTime>();
            for (int i = 0; i < response.allExpirationDateKeys.Count; i++)
            {
                var date = DateTime.Parse(response.allExpirationDateValues[i], null, DateTimeStyles.RoundtripKind | DateTimeStyles.AdjustToUniversal);
                if (date != null)
                {
                    allExpirations[response.allExpirationDateKeys[i]] = date;
                }
            }
            return allExpirations;
        }
    }

}

[Serializable]
public class Error
{
    public string message;
    public int code;
    public string domain;
}

[Serializable]
public class Product
{
    public string title;
    public string identifier;
    public string description;
    public float price;
    public string priceString;
}

[Tooltip("Your RevenueCat API Key. Get from   https://app.revenuecat.com/")]
public string revenueCatAPIKey;

[Tooltip("App user id. Pass in your own ID if your app has accounts.   If blank, RevenueCat will generate a user ID for you.")]
public string appUserID;

[Tooltip("List of product identifiers.")]
public string[] productIdentifiers;

[Tooltip("A subclass of Purchases.Listener component. Use your custom  subclass to define how to handle events.")]
public Listener listener;

void Start()
{
   // string appUserID = (this.appUserID.Length == 0) ? null : this.appUserID;
    PurchasesWrapper.Setup(revenueCatAPIKey);
    PurchasesWrapper.GetProducts(productIdentifiers);
}

// Call this to initialte a purchase
public void MakePurchase(string productIdentifier, string type = "subs")
{
    PurchasesWrapper.MakePurchase(productIdentifier, type);
}

[Serializable]
private class ProductResponse {
    public List<Product> products;
}

private void _receiveProducts(string productsJSON)
{
    ProductResponse response = JsonUtility.FromJson<ProductResponse>(productsJSON);
    listener.ProductsReceived(response.products);
}

[Serializable]
private class ReceivePurchaserInfoResponse 
{
    public string productIdentifier;
    public PurchaserInfoResponse purchaserInfo;
    public Error error;
}

[Serializable]
public class PurchaserInfoResponse
{
    public List<string> activeSubscriptions;
    public List<string> allPurchasedProductIdentifiers;
    public string latestExpirationDate;
    public List<string> allExpirationDateKeys;
    public List<string> allExpirationDateValues;
}

private void _receivePurchaserInfo(string arguments)
{
    var response = JsonUtility.FromJson<ReceivePurchaserInfoResponse>(arguments);

    var error = (response.error.message != null) ? response.error : null;
    var info = (response.purchaserInfo.activeSubscriptions != null) ? new PurchaserInfo(response.purchaserInfo) : null;


    if (response.productIdentifier != null) 
    {
        bool userCanceled = (error != null && error.domain ==  "SKErrorDomain" && error.code == 2);
        listener.PurchaseCompleted(response.productIdentifier, error, info, userCanceled);
    } else if (info != null) 
    {
        listener.PurchaserInfoReceived(info);
    }
}
}

And this is the second:

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;


public class PurchasesWrapper: Purchases
{
[DllImport("__Internal")]
private static extern void _RCSetupPurchases(string apiKey);
public static void Setup(string apiKey)
{
    _RCSetupPurchases(apiKey);
}

public class ProductsRequest
{
    public string[] productIdentifiers;
}

[DllImport("__Internal")]
private static extern void _RCGetProducts(string  productIdentifiersJSON, string type);
public static void GetProducts(string[] productIdentifiers, string type = "subs")
{
    ProductsRequest request = new ProductsRequest
    {
        productIdentifiers = productIdentifiers
    };

    _RCGetProducts(JsonUtility.ToJson(request), type);
}

[DllImport("__Internal")]
private static extern void _RCMakePurchase(string productIdentifier, string type);
public static void MakePurchase(string productIdentifier, string type = "subs")
{
    _RCMakePurchase(productIdentifier, type);
}
}

I get this error

EntryPointNotFoundException: _RCSetupPurchases PurchasesWrapper.Setup (System.String apiKey) (at Assets/Plugins/PurchasesWrapper.cs:14) Purchases.Start () (at Assets/Plugins/Purchases.cs:113)

What can it be? I set my key, and I tried to set it at start scene and at purchase scene, the same thing.What can it be?

derHugo
  • 83,094
  • 9
  • 75
  • 115
Pikachu
  • 11
  • 4
  • @Programmer 1. I add PurchasesUnityHelper.m to iOS folder 2. Install Purchases Unity package. 3. Add them to an empty GameObject in my first Scene and add ApiKey and App Store product ID. 4. Add a Purchases.Listener (all code is from Revenue Cat guide) and add it to main Purchase script. 5. Build it to Xcode and install Purchase pod. 6. Run it, and wait. It see only when I install app no more. I tried to set it in scene where I am doing purchase but the same. Do I miss something? --- Or you need images how I did it step by step? – Pikachu Jul 24 '18 at 12:22
  • Can you show the screenshot of where you put "PurchasesUnityHelper.m" in your project? Yes, the images would help as one single mistake can break it – Programmer Jul 24 '18 at 12:25
  • @Programmer https://imgur.com/a/a8prNyq - Project works because I got analytic that I am installing app on device but no more – Pikachu Jul 24 '18 at 12:28
  • Just wanted to make sure that path was correct. Ok when do you have error? See which function you call is causing that error. – Programmer Jul 24 '18 at 12:33
  • @Programmer https://imgur.com/a/bThfBLe - I did like this, code in scripts you see in the post. After all this I use "pod install" and Launch app enabling In-App Purchase. I am getting this error when it is called (When game start, or when it was in purchase scene - it appears when I launch this scene. Do I need to add something else?). Maybe I doing something wrong. My main answer is why when I purchase something, it didn't show in RevenueCat analytic. Or it's because of this error? – Pikachu Jul 24 '18 at 12:36

0 Answers0