Skip to content

Commit

Permalink
Merge pull request #173 from qonversion/release/5.0.0
Browse files Browse the repository at this point in the history
Release 5.0.0
  • Loading branch information
suriksarkisyan authored Jul 12, 2023
2 parents 1c58726 + 78ebf3a commit 2df4d20
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Editor/QonversionDependencies.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="io.qonversion.sandwich:sandwich:1.5.2" />
<androidPackage spec="io.qonversion.sandwich:sandwich:2.0.0" />
<androidPackage spec="com.fasterxml.jackson.core:jackson-databind:2.11.1" />
<androidPackage spec="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" />
</androidPackages>
<iosPods>
<iosPod name="QonversionSandwich" version="1.5.2" />
<iosPod name="QonversionSandwich" version="2.0.0" />
</iosPods>
</dependencies>
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ public static synchronized void offerings(String unityCallbackName) {
qonversionSandwich.offerings(getResultListener(unityCallbackName));
}

public static synchronized void remoteConfig(String unityCallbackName) {
qonversionSandwich.remoteConfig(getResultListener(unityCallbackName));
}

public static synchronized void attachUserToExperiment(String experimentId, String groupId, String unityCallbackName) {
qonversionSandwich.attachUserToExperiment(experimentId, groupId, getResultListener(unityCallbackName));
}

public static synchronized void detachUserFromExperiment(String experimentId, String unityCallbackName) {
qonversionSandwich.detachUserFromExperiment(experimentId, getResultListener(unityCallbackName));
}


public static synchronized void checkTrialIntroEligibility(String productIds, String unityCallbackName) {
try {
ObjectMapper mapper = new ObjectMapper();
Expand Down
15 changes: 15 additions & 0 deletions Runtime/Android/QonversionWrapperAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ public void Offerings(string callbackName)
CallQonversion("offerings", callbackName);
}

public void RemoteConfig(string callbackName)
{
CallQonversion("remoteConfig", callbackName);
}

public void AttachUserToExperiment(string experimentId, string groupId, string callbackName)
{
CallQonversion("attachUserToExperiment", experimentId, groupId, callbackName);
}

public void DetachUserFromExperiment(string experimentId, string callbackName)
{
CallQonversion("detachUserFromExperiment", experimentId, callbackName);
}

public void CheckTrialIntroEligibility(string productIdsJson, string callbackName)
{
CallQonversion("checkTrialIntroEligibility", productIdsJson, callbackName);
Expand Down
29 changes: 29 additions & 0 deletions Runtime/Scripts/Dto/Experiment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;

namespace QonversionUnity
{
public class Experiment
{
public readonly string Id;
public readonly string Name;
public readonly ExperimentGroup Group;


public Experiment(Dictionary<string, object> dict)
{
if (dict.TryGetValue("id", out object value)) Id = value as string;
if (dict.TryGetValue("name", out value)) Name = value as string;
if (dict.TryGetValue("group", out value) && value is Dictionary<string, object> group)
{
Group = new ExperimentGroup(group);
}
}

public override string ToString()
{
return $"{nameof(Id)}: {Id}, " +
$"{nameof(Name)}: {Name}, " +
$"{nameof(Group)}: {Group}";
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Dto/Experiment.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Runtime/Scripts/Dto/ExperimentGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;

namespace QonversionUnity
{
public class ExperimentGroup
{
public readonly string Id;
public readonly string Name;
public readonly ExperimentGroupType Type;

public ExperimentGroup(Dictionary<string, object> dict)
{
if (dict.TryGetValue("id", out object value)) Id = value as string;
if (dict.TryGetValue("name", out value)) Name = value as string;
if (dict.TryGetValue("type", out value)) Type = FormatGroupType(value);
}

public ExperimentGroupType FormatGroupType(object typeValue) {
string type = typeValue as string;
if (type == "control") {
return ExperimentGroupType.Control;
} else if (type == "treatment") {
return ExperimentGroupType.Treatment;
}

return ExperimentGroupType.Unknown;
}

public override string ToString()
{
return $"{nameof(Id)}: {Id}, " +
$"{nameof(Name)}: {Name}, " +
$"{nameof(Type)}: {Type}";
}
}

public enum ExperimentGroupType
{
Unknown = -1,
Control = 0,
Treatment = 1
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Dto/ExperimentGroup.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Runtime/Scripts/Dto/RemoteConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;

namespace QonversionUnity
{
public class RemoteConfig
{
public readonly Dictionary<string, object> Payload;
[CanBeNull] public readonly Experiment Experiment;

public RemoteConfig(Dictionary<string, object> dict)
{
if (dict.TryGetValue("payload", out object value) && value is Dictionary<string, object>) Payload = value as Dictionary<string, object>;
if (dict.TryGetValue("experiment", out value) && value is Dictionary<string, object> experimentInfo)
{
Experiment = new Experiment(experimentInfo);
}
}

public override string ToString()
{
return $"{nameof(Payload)}: {Payload}, " +
$"{nameof(Experiment)}: {Experiment}";
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/Dto/RemoteConfig.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Runtime/Scripts/IQonversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ public void UpdatePurchaseWithProduct(
/// <see href="https://qonversion.io/docs/product-center">Product Center</see>
public void Offerings(Qonversion.OnOfferingsReceived callback);

/// <summary>
/// Returns Qonversion remote config object
/// Use this function to get the remote config with specific payload and experiment info.
/// </summary>
/// <see href="https://documentation.qonversion.io/docs/experiments-overview">Experiments</see>
public void RemoteConfig(Qonversion.OnRemoteConfigReceived callback);

/// <summary>
/// This function should be used for the test purposes only. Do not forget to delete the usage of this function before the release.
/// Use this function to attach the user to the experiment.
/// </summary>
/// <param name="experimentId">Experiment identifier</param>
/// <param name="groupId">Group identifier</param>
public void AttachUserToExperiment(string experimentId, string groupId, Qonversion.OnAttachUserResponseReceived callback);

/// <summary>
/// This function should be used for the test purposes only. Do not forget to delete the usage of this function before the release.
/// Use this function to detach the user from the experiment.
/// </summary>
/// <param name="experimentId">Experiment identifier</param>
public void DetachUserFromExperiment(string experimentId, Qonversion.OnAttachUserResponseReceived callback);

/// <summary>
/// You can check if a user is eligible for an introductory offer, including a free trial.
/// You can show only a regular price for users who are not eligible for an introductory offer.
Expand Down
11 changes: 11 additions & 0 deletions Runtime/Scripts/Internal/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ internal static Offerings OfferingsFromJson(string jsonStr)
return new Offerings(offerings);
}

internal static RemoteConfig RemoteConfigFromJson(string jsonStr)
{
if (!(Json.Deserialize(jsonStr) is Dictionary<string, object> remoteConfig))
{
Debug.LogError("Could not parse RemoteConfig");
return null;
}

return new RemoteConfig(remoteConfig);
}

internal static ActionResult ActionResultFromJson(string jsonStr)
{
if (!(Json.Deserialize(jsonStr) is Dictionary<string, object> actionResult))
Expand Down
76 changes: 75 additions & 1 deletion Runtime/Scripts/Internal/QonversionInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ internal class QonversionInternal : MonoBehaviour, IQonversion
private const string OnRestoreMethodName = "OnRestore";
private const string OnProductsMethodName = "OnProducts";
private const string OnOfferingsMethodName = "OnOfferings";
private const string OnRemoteConfigMethodName = "OnRemoteConfig";
private const string OnEligibilitiesMethodName = "OnEligibilities";
private const string OnUserInfoMethodName = "OnUserInfo";
private const string OnAttachUserMethodName = "OnAttachUser";
private const string OnDetachUserMethodName = "OnDetachUser";

private const string SdkVersion = "4.4.2";
private const string SdkVersion = "5.0.0";
private const string SdkSource = "unity";

private IQonversionWrapper _nativeWrapperInstance;
Expand All @@ -38,9 +41,12 @@ internal class QonversionInternal : MonoBehaviour, IQonversion
private Qonversion.OnPurchaseResultReceived UpdatePurchaseWithProductCallback { get; set; }
private List<Qonversion.OnProductsReceived> ProductsCallbacks { get; } = new List<Qonversion.OnProductsReceived>();
private List<Qonversion.OnOfferingsReceived> OfferingsCallbacks { get; } = new List<Qonversion.OnOfferingsReceived>();
private List<Qonversion.OnRemoteConfigReceived> RemoteConfigCallbacks { get; } = new List<Qonversion.OnRemoteConfigReceived>();
private Qonversion.OnEligibilitiesReceived EligibilitiesCallback { get; set; }
private Qonversion.OnEntitlementsReceived PromoPurchaseCallback { get; set; }
private Qonversion.OnUserInfoReceived UserInfoCallback { get; set; }
private Qonversion.OnAttachUserResponseReceived AttachUserCallback { get; set; }
private Qonversion.OnAttachUserResponseReceived DetachUserCallback { get; set; }

public event Qonversion.OnPromoPurchasesReceived PromoPurchasesReceived
{
Expand Down Expand Up @@ -153,6 +159,27 @@ public void Offerings(Qonversion.OnOfferingsReceived callback)
instance.Offerings(OnOfferingsMethodName);
}

public void RemoteConfig(Qonversion.OnRemoteConfigReceived callback)
{
RemoteConfigCallbacks.Add(callback);
IQonversionWrapper instance = GetNativeWrapper();
instance.RemoteConfig(OnRemoteConfigMethodName);
}

public void AttachUserToExperiment(string experimentId, string groupId, Qonversion.OnAttachUserResponseReceived callback)
{
AttachUserCallback = callback;
IQonversionWrapper instance = GetNativeWrapper();
instance.AttachUserToExperiment(experimentId, groupId, OnAttachUserMethodName);
}

public void DetachUserFromExperiment(string experimentId, Qonversion.OnAttachUserResponseReceived callback)
{
DetachUserCallback = callback;
IQonversionWrapper instance = GetNativeWrapper();
instance.DetachUserFromExperiment(experimentId, OnDetachUserMethodName);
}

public void CheckTrialIntroEligibility(IList<string> productIds, Qonversion.OnEligibilitiesReceived callback)
{
var productIdsJson = Json.Serialize(productIds);
Expand Down Expand Up @@ -337,6 +364,53 @@ private void OnOfferings(string jsonString)
OfferingsCallbacks.Clear();
}

// Called from the native SDK - Called when remoteConfig received from the remoteConfig() method
private void OnRemoteConfig(string jsonString)
{
if (RemoteConfigCallbacks.Count == 0) return;

var error = Mapper.ErrorFromJson(jsonString);
if (error != null)
{
RemoteConfigCallbacks.ForEach(callback => callback(null, error));
}
else
{
var remoteConfig = Mapper.RemoteConfigFromJson(jsonString);
RemoteConfigCallbacks.ForEach(callback => callback(remoteConfig, null));
}

RemoteConfigCallbacks.Clear();
}

private void OnAttachUser(string jsonString)
{
if (AttachUserCallback == null) return;
var error = Mapper.ErrorFromJson(jsonString);
if (error != null)
{
AttachUserCallback(false, error);
}
else
{
AttachUserCallback(true, null);
}
}

private void OnDetachUser(string jsonString)
{
if (DetachUserCallback == null) return;
var error = Mapper.ErrorFromJson(jsonString);
if (error != null)
{
DetachUserCallback(false, error);
}
else
{
DetachUserCallback(true, null);
}
}

// Called from the native SDK - Called when eligibilities received from the checkTrialIntroEligibilityForProductIds() method
private void OnEligibilities(string jsonString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal interface IQonversionWrapper
void UpdatePurchaseWithProduct(string productId, string offeringId, string oldProductId, ProrationMode prorationMode, string callbackName);
void Products(string callbackName);
void Offerings(string callbackName);
void RemoteConfig(string callbackName);
void AttachUserToExperiment(string experimentId, string groupId, string callbackName);
void DetachUserFromExperiment(string experimentId, string callbackName);
void CheckTrialIntroEligibility(string productIdsJson, string callbackName);
void SetAppleSearchAdsAttributionEnabled(bool enable);
void Identify(string userID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public void Offerings(string callbackName)
{
}

public void RemoteConfig(string callbackName)
{
}

public void AttachUserToExperiment(string experimentId, string groupId, string callbackName)
{
}

public void DetachUserFromExperiment(string experimentId, string callbackName)
{
}

public void StoreSdkInfo(string version, string source)
{
}
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Scripts/Qonversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public static IQonversion Initialize(QonversionConfig config)
public delegate void OnEntitlementsReceived(Dictionary<string, Entitlement> entitlements, QonversionError error);
public delegate void OnProductsReceived(Dictionary<string, Product> products, QonversionError error);
public delegate void OnOfferingsReceived(Offerings offerings, QonversionError error);
public delegate void OnRemoteConfigReceived(RemoteConfig remoteConfig, QonversionError error);
public delegate void OnAttachUserResponseReceived(bool success, QonversionError error);
public delegate void OnEligibilitiesReceived(Dictionary<string, Eligibility> eligibilities, QonversionError error);
public delegate void OnUserInfoReceived(User userInfo, QonversionError error);

Expand Down
Loading

0 comments on commit 2df4d20

Please sign in to comment.