Skip to content

Commit 5833fa6

Browse files
facumenzellavegaro
andauthored
RefactorUI: Clean API Architecture (#682)
Co-authored-by: Cesar de la Vega <664544+vegaro@users.noreply.github.com>
1 parent 3ca63e7 commit 5833fa6

12 files changed

Lines changed: 82 additions & 36 deletions

RevenueCatUI/Scripts/IPaywallPresenter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Threading.Tasks;
22

3-
namespace RevenueCat.UI
3+
namespace RevenueCatUI.Internal
44
{
55
/// <summary>
66
/// Internal interface for presenting paywalls.
@@ -13,15 +13,15 @@ internal interface IPaywallPresenter
1313
/// </summary>
1414
/// <param name="options">Paywall presentation options</param>
1515
/// <returns>Result of the paywall presentation</returns>
16-
Task<PaywallResult> PresentPaywallAsync(PaywallOptions options);
16+
Task<RevenueCatUI.PaywallResult> PresentPaywallAsync(RevenueCatUI.PaywallOptions options);
1717

1818
/// <summary>
1919
/// Presents a paywall only if the user does not have the specified entitlement.
2020
/// </summary>
2121
/// <param name="requiredEntitlementIdentifier">Required entitlement identifier</param>
2222
/// <param name="options">Paywall presentation options</param>
2323
/// <returns>Result of the paywall presentation</returns>
24-
Task<PaywallResult> PresentPaywallIfNeededAsync(string requiredEntitlementIdentifier, PaywallOptions options);
24+
Task<RevenueCatUI.PaywallResult> PresentPaywallIfNeededAsync(string requiredEntitlementIdentifier, RevenueCatUI.PaywallOptions options);
2525

2626
/// <summary>
2727
/// Whether paywall presentation is supported on this platform.

RevenueCatUI/Scripts/PaywallOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace RevenueCat.UI
3+
namespace RevenueCatUI
44
{
55
/// <summary>
66
/// Options for configuring paywall presentation.

RevenueCatUI/Scripts/PaywallPresenter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Threading.Tasks;
22
using UnityEngine;
33

4-
namespace RevenueCat.UI
4+
namespace RevenueCatUI.Internal
55
{
66
/// <summary>
77
/// Platform-agnostic factory for paywall presenters.
@@ -43,16 +43,16 @@ private static IPaywallPresenter CreatePlatformPresenter()
4343
/// </summary>
4444
internal class UnsupportedPaywallPresenter : IPaywallPresenter
4545
{
46-
public Task<PaywallResult> PresentPaywallAsync(PaywallOptions options)
46+
public Task<RevenueCatUI.PaywallResult> PresentPaywallAsync(RevenueCatUI.PaywallOptions options)
4747
{
4848
Debug.LogWarning("[RevenueCatUI] Paywall presentation is not supported on this platform.");
49-
return Task.FromResult(PaywallResult.Error);
49+
return Task.FromResult(RevenueCatUI.PaywallResult.Error);
5050
}
5151

52-
public Task<PaywallResult> PresentPaywallIfNeededAsync(string requiredEntitlementIdentifier, PaywallOptions options)
52+
public Task<RevenueCatUI.PaywallResult> PresentPaywallIfNeededAsync(string requiredEntitlementIdentifier, RevenueCatUI.PaywallOptions options)
5353
{
5454
Debug.LogWarning("[RevenueCatUI] Paywall presentation is not supported on this platform.");
55-
return Task.FromResult(PaywallResult.Error);
55+
return Task.FromResult(RevenueCatUI.PaywallResult.Error);
5656
}
5757

5858
public bool IsSupported()

RevenueCatUI/Scripts/PaywallResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace RevenueCat.UI
3+
namespace RevenueCatUI
44
{
55
/// <summary>
66
/// Represents the result of a paywall presentation.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Threading.Tasks;
2+
using UnityEngine;
3+
4+
namespace RevenueCatUI
5+
{
6+
/// <summary>
7+
/// MonoBehaviour helper that forwards to the static PaywallsPresenter API so paywalls can be driven from scenes.
8+
/// </summary>
9+
public class PaywallsBehaviour : MonoBehaviour
10+
{
11+
/// <summary>
12+
/// Presents a paywall configured in the RevenueCat dashboard.
13+
/// </summary>
14+
/// <param name="options">Options for presenting the paywall.</param>
15+
/// <returns>A <see cref="PaywallResult"/> describing the outcome.</returns>
16+
public async Task<PaywallResult> PresentPaywall(PaywallOptions options = null)
17+
{
18+
return await PaywallsPresenter.Present(options);
19+
}
20+
21+
/// <summary>
22+
/// Presents a paywall only if the user does not have the specified entitlement.
23+
/// </summary>
24+
/// <param name="requiredEntitlementIdentifier">Entitlement identifier to check before presenting.</param>
25+
/// <param name="options">Options for presenting the paywall.</param>
26+
/// <returns>A <see cref="PaywallResult"/> describing the outcome.</returns>
27+
public async Task<PaywallResult> PresentPaywallIfNeeded(string requiredEntitlementIdentifier, PaywallOptions options = null)
28+
{
29+
return await PaywallsPresenter.PresentIfNeeded(requiredEntitlementIdentifier, options);
30+
}
31+
32+
/// <summary>
33+
/// Checks if the Paywall UI is available on the current platform.
34+
/// Returns true on iOS/Android device builds when paywall is supported; otherwise false.
35+
/// </summary>
36+
/// <returns>True if UI is supported on this platform, otherwise false.</returns>
37+
public bool IsSupported()
38+
{
39+
return PaywallsPresenter.IsSupported();
40+
}
41+
}
42+
}

RevenueCatUI/Scripts/PaywallsBehaviour.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RevenueCatUI/Scripts/Platforms/Android/AndroidPaywallPresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using System.Threading.Tasks;
44
using UnityEngine;
55
using UnityEngine.Android;
6+
using RevenueCatUI.Internal;
67

7-
namespace RevenueCat.UI.Platforms
8+
namespace RevenueCatUI.Platforms
89
{
910
internal class AndroidPaywallPresenter : IPaywallPresenter
1011
{

RevenueCatUI/Scripts/Platforms/iOS/IOSPaywallPresenter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
using System;
33
using System.Runtime.InteropServices;
44
using System.Threading.Tasks;
5+
using RevenueCatUI.Internal;
56

6-
namespace RevenueCat.UI.Platforms
7+
namespace RevenueCatUI.Platforms
78
{
89
internal class IOSPaywallPresenter : IPaywallPresenter
910
{
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
using System;
22
using System.Threading.Tasks;
33
using UnityEngine;
4+
using RevenueCatUI.Internal;
45

5-
namespace RevenueCat.UI
6+
namespace RevenueCatUI
67
{
78
/// <summary>
8-
/// Main interface for RevenueCat UI components.
9+
/// Main interface for RevenueCatUI paywall presentation.
910
/// Provides static methods to present paywalls.
1011
/// </summary>
11-
public static class RevenueCatUI
12+
public static class PaywallsPresenter
1213
{
1314

1415
/// <summary>
1516
/// Presents a paywall configured in the RevenueCat dashboard.
1617
/// </summary>
1718
/// <param name="options">Options for presenting the paywall</param>
1819
/// <returns>A PaywallResult indicating what happened during the paywall presentation</returns>
19-
public static async Task<PaywallResult> PresentPaywall(PaywallOptions options = null)
20+
public static async Task<PaywallResult> Present(PaywallOptions options = null)
2021
{
2122
try
2223
{
@@ -38,7 +39,7 @@ public static async Task<PaywallResult> PresentPaywall(PaywallOptions options =
3839
/// <param name="requiredEntitlementIdentifier">Entitlement identifier to check before presenting</param>
3940
/// <param name="options">Options for presenting the paywall</param>
4041
/// <returns>A PaywallResult indicating what happened during the paywall presentation</returns>
41-
public static async Task<PaywallResult> PresentPaywallIfNeeded(
42+
public static async Task<PaywallResult> PresentIfNeeded(
4243
string requiredEntitlementIdentifier,
4344
PaywallOptions options = null)
4445
{
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)