Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions IntegrationTests/Assets/APITests/PurchasesAPITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ private void Start()
.SetDiagnosticsEnabled(true)
.SetAutomaticDeviceIdentifierCollectionEnabled(false)
.SetPreferredUILocaleOverride("de_DE")
.SetProxyURL("https://proxy.revenuecat.com")
.Build();
string proxyURL = purchasesConfiguration.ProxyURL;
purchases.Configure(purchasesConfiguration);
purchases.RecordPurchase("product_id", (transaction, error) =>
{
Expand Down
36 changes: 36 additions & 0 deletions IntegrationTests/Assets/Tests/EditMode/PurchasesCallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ public void ConfigureForwardsEveryConfigurationValue()
Assert.That(invocation.Arguments[13], Is.EqualTo("de_DE"));
}

/// <remarks>
/// The proxy URL has to reach the native SDK before it is configured, so this pins the order
/// rather than just the fact that both calls happen.
/// </remarks>
[Test]
public void ConfigureSetsProxyUrlBeforeSettingUp()
{
var configuration = Purchases.PurchasesConfiguration.Builder
.Init("test_api_key")
.SetProxyURL("https://proxy.revenuecat.com")
.Build();

_purchases.Configure(configuration);

Assert.That(_wrapper.Invocations, Has.Count.EqualTo(2));
Assert.That(_wrapper.Invocations[0].Method, Is.EqualTo(nameof(IPurchasesWrapper.SetProxyURL)));
Assert.That(_wrapper.Invocations[0].Arguments[0], Is.EqualTo("https://proxy.revenuecat.com"));
Assert.That(_wrapper.Invocations[1].Method, Is.EqualTo(nameof(IPurchasesWrapper.Setup)));
}

/// <remarks>
/// A configuration that carries no proxy URL must not call the wrapper at all, otherwise it would
/// clear a proxy URL already set through the inspector field on Purchases.
/// </remarks>
[Test]
public void ConfigureWithoutProxyUrlDoesNotCallSetProxyUrl()
{
var configuration = Purchases.PurchasesConfiguration.Builder
.Init("test_api_key")
.Build();

_purchases.Configure(configuration);

AssertOnlyInvocation(nameof(IPurchasesWrapper.Setup), 14);
}

private PurchasesWrapperSpy.Invocation AssertOnlyInvocation(string method, int argumentCount)
{
Assert.That(_wrapper.Invocations, Has.Count.EqualTo(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void BuildUsesBuilderDefaults()
Assert.That(configuration.DiagnosticsEnabled, Is.False);
Assert.That(configuration.AutomaticDeviceIdentifierCollectionEnabled, Is.True);
Assert.That(configuration.PreferredUILocaleOverride, Is.Null);
Assert.That(configuration.ProxyURL, Is.Null);
}

[Test]
Expand All @@ -56,6 +57,7 @@ public void BuildUsesConfiguredValues()
.SetDiagnosticsEnabled(true)
.SetAutomaticDeviceIdentifierCollectionEnabled(false)
.SetPreferredUILocaleOverride("de_DE")
.SetProxyURL("https://proxy.revenuecat.com")
.Build();

Assert.That(configuration.AppUserId, Is.EqualTo("app_user_id"));
Expand All @@ -70,6 +72,7 @@ public void BuildUsesConfiguredValues()
Assert.That(configuration.DiagnosticsEnabled, Is.True);
Assert.That(configuration.AutomaticDeviceIdentifierCollectionEnabled, Is.False);
Assert.That(configuration.PreferredUILocaleOverride, Is.EqualTo("de_DE"));
Assert.That(configuration.ProxyURL, Is.EqualTo("https://proxy.revenuecat.com"));
}

[Test]
Expand Down
18 changes: 16 additions & 2 deletions RevenueCat/Scripts/Purchases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ public partial class Purchases : MonoBehaviour
[Header("Advanced")]
[Tooltip("Set this property to your proxy URL before configuring Purchases *only* if you've received " +
"a proxy key value from your RevenueCat contact.\n" +
"NOTE: This value will be ignored if \"Use Runtime Setup\" is true. For Runtime Setup, you can configure " +
"it through PurchasesConfiguration instead")]
"NOTE: Unlike the other fields here, this one is applied even when \"Use Runtime Setup\" is true. " +
"If you configure at runtime you can set it through " +
"PurchasesConfiguration.Builder.SetProxyURL instead.")]
public string proxyURL;

private IPurchasesWrapper _wrapper;
Expand All @@ -115,6 +116,11 @@ private void Start()
#else
SetWrapper(new PurchasesWrapperNoop());
#endif
// Deliberately applied above the early return, so it takes effect on both the inspector and the
// runtime-setup paths. That makes it the one inspector field runtime setup does not ignore: the
// others are read by Configure below, which runtime setup skips. Aligning it with them would stop
// runtime-setup apps from picking up an inspector-set proxy URL, silently sending their traffic
// straight to RevenueCat, so that change is deferred to the next major.
if (!string.IsNullOrEmpty(proxyURL))
{
_wrapper.SetProxyURL(proxyURL);
Expand Down Expand Up @@ -194,6 +200,14 @@ public void Setup(PurchasesConfiguration purchasesConfiguration)
///
public void Configure(PurchasesConfiguration purchasesConfiguration)
{
// Only forwarded when set, for two reasons: it mirrors how the inspector field is applied in
// Start, and it keeps a configuration that carries no proxy URL from clearing one that was
// already set through the inspector.
if (!string.IsNullOrEmpty(purchasesConfiguration.ProxyURL))
{
_wrapper.SetProxyURL(purchasesConfiguration.ProxyURL);
}

var dangerousSettings = purchasesConfiguration.DangerousSettings.Serialize().ToString();
_wrapper.Setup(gameObject.name, purchasesConfiguration.ApiKey, purchasesConfiguration.AppUserId,
purchasesConfiguration.PurchasesAreCompletedBy, purchasesConfiguration.StoreKitVersion, purchasesConfiguration.UserDefaultsSuiteName,
Expand Down
21 changes: 18 additions & 3 deletions RevenueCat/Scripts/PurchasesConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class PurchasesConfiguration
public readonly bool DiagnosticsEnabled;
public readonly bool AutomaticDeviceIdentifierCollectionEnabled;
public readonly string PreferredUILocaleOverride;
public readonly string ProxyURL;

private PurchasesConfiguration(string apiKey, string appUserId, PurchasesAreCompletedBy purchasesAreCompletedBy, string userDefaultsSuiteName,
bool useAmazon, DangerousSettings dangerousSettings, StoreKitVersion storeKitVersion, bool shouldShowInAppMessagesAutomatically,
EntitlementVerificationMode entitlementVerificationMode, bool pendingTransactionsForPrepaidPlansEnabled, bool diagnosticsEnabled,
bool automaticDeviceIdentifierCollectionEnabled, string preferredUILocaleOverride)
bool automaticDeviceIdentifierCollectionEnabled, string preferredUILocaleOverride, string proxyURL)
{
ApiKey = apiKey;
AppUserId = appUserId;
Expand All @@ -55,6 +56,7 @@ private PurchasesConfiguration(string apiKey, string appUserId, PurchasesAreComp
DiagnosticsEnabled = diagnosticsEnabled;
AutomaticDeviceIdentifierCollectionEnabled = automaticDeviceIdentifierCollectionEnabled;
PreferredUILocaleOverride = preferredUILocaleOverride;
ProxyURL = proxyURL;
}

/// <summary>
Expand Down Expand Up @@ -91,6 +93,7 @@ public class Builder
private bool _diagnosticsEnabled;
private bool _automaticDeviceIdentifierCollectionEnabled = true;
private string _preferredUILocaleOverride;
private string _proxyURL;

private Builder(string apiKey)
{
Expand All @@ -108,7 +111,7 @@ public PurchasesConfiguration Build()
return new PurchasesConfiguration(_apiKey, _appUserId, _purchasesAreCompletedBy, _userDefaultsSuiteName,
_useAmazon, _dangerousSettings, _storeKitVersion, _shouldShowInAppMessagesAutomatically,
_entitlementVerificationMode, _pendingTransactionsForPrepaidPlansEnabled, _diagnosticsEnabled,
_automaticDeviceIdentifierCollectionEnabled, _preferredUILocaleOverride);
_automaticDeviceIdentifierCollectionEnabled, _preferredUILocaleOverride, _proxyURL);
}

public Builder SetAppUserId(string appUserId)
Expand Down Expand Up @@ -197,6 +200,17 @@ public Builder SetPreferredUILocaleOverride(string preferredUILocaleOverride)
return this;
}

/// <summary>
/// Sets the proxy URL used for all RevenueCat network requests. Only set this if you have
/// received a proxy key value from your RevenueCat contact.
/// The proxy URL is applied before the SDK is configured.
/// </summary>
public Builder SetProxyURL(string proxyURL)
{
_proxyURL = proxyURL;
return this;
}

}

public override string ToString()
Expand All @@ -214,7 +228,8 @@ public override string ToString()
$"{nameof(PendingTransactionsForPrepaidPlansEnabled)}: {PendingTransactionsForPrepaidPlansEnabled}\n" +
$"{nameof(DiagnosticsEnabled)}: {DiagnosticsEnabled}\n" +
$"{nameof(AutomaticDeviceIdentifierCollectionEnabled)}: {AutomaticDeviceIdentifierCollectionEnabled}\n" +
$"{nameof(PreferredUILocaleOverride)}: {PreferredUILocaleOverride}\n";
$"{nameof(PreferredUILocaleOverride)}: {PreferredUILocaleOverride}\n" +
$"{nameof(ProxyURL)}: {ProxyURL}\n";
}
}
}