-
Notifications
You must be signed in to change notification settings - Fork 20
Proper PaywallsBehaviour #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
764038d to
9226899
Compare
# Conflicts: # RevenueCatUI/Scripts/PaywallsBehaviour.cs
|
|
||
| [Header("Events")] | ||
| [Tooltip("Invoked when the user completes a purchase.")] | ||
| public UnityEvent OnPurchased = new UnityEvent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These UnityEvents can accept generics, but won't work with a custom class like PaywallResult, so I decided to split it into multiple events, that way they can be set in the editor. The alternative is to use a primitive type (string), but I think that limits us more if we ever want to send something in the events:
[Serializable]
public class StringEvent : UnityEvent<string> { }
[Header("Events")]
public StringEvent OnPaywallResult = new StringEvent();
private void HandleResult(PaywallResult result)
{
OnPaywallResult?.Invoke(result.Result.ToString());
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever need to send something like UnityEvent<CustomerInfo>, it's still possible but devs need to hook to it via code (it doesn't show up in the Editor's dropdown):
[Serializable]
public class CustomerInfoEvent : UnityEvent<CustomerInfo> { }
[Header("Events")]
public CustomerInfoEvent OnCustomerInfoUpdated = new CustomerInfoEvent();using UnityEngine;
public class CustomerInfoHandler : MonoBehaviour
{
[SerializeField] private Purchases purchases;
void Start()
{
// Subscribe to the event
purchases.OnCustomerInfoUpdated.AddListener(HandleCustomerInfo);
}
void OnDestroy()
{
// Unsubscribe
purchases.OnCustomerInfoUpdated.RemoveListener(HandleCustomerInfo);
}
private void HandleCustomerInfo(Purchases.CustomerInfo customerInfo)
{
Debug.Log($"Customer info updated: {customerInfo.ActiveSubscriptions.Count} active subscriptions");
foreach (var entitlement in customerInfo.Entitlements.Active)
{
Debug.Log($"Active entitlement: {entitlement.Key}");
}
}
}Or we could remove the parameter and inform developers to fetch the CustomerInfo themselves which I believe is the Unity standard since it works in the Editor:
[Header("Events")]
[Tooltip("Invoked when customer info is updated. Use GetCustomerInfo() to fetch the latest data.")]
public UnityEvent OnCustomerInfoUpdated = new UnityEvent();
private void NotifyCustomerInfoUpdate()
{
OnCustomerInfoUpdated?.Invoke();
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple comments, but looking great!! Excited to get this out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as far as I can tell 🙌
|
@tonidero @facumenzella In the last commit I added a The alternative is to add an internal constructor to PaywallOptions and do this: The problem that has is that What do you think? |
|
nothing 🙃 |
|
Actually, I was looking at Android's implementation and there's a sealed class OfferingSelection to solve the |
|
ok finally! I think the last commit is what I like the most |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
We realized the current version wasn't correct since the functions are not available from the Editor. Meaning that if you try to link a Button's
onClickevent toPresentPaywall, it's not possible because of the parameters, and becuase it doesn't returnvoid.This PR adds proper configuration options and refactors the functions so they can be worked directly from the Editor.
Here's an example of the component with a handler for the result events attached to it:
And then a Button can be configured to present the paywall: