B4i Library RevenueCat

RevenueCat is a platform that simplifies in-app subscriptions and purchases for mobile apps. It provides tools for managing subscription billing, analytics, and user retention across iOS, Android, and web, without needing to build a backend. Usage is free for apps with less than $2,500 in monthly tracked revenue (MTR).


I use the library in CleanTasks, I have only tested the whole thing in B4I.

RevenueCat
Author: Alexander Stolte
Version: 1.00

  • RevenueCat
    • Functions:
      • Class_Globals As String
      • CreatePurchase (ProductId As String, Product As Object) As ResumableSub
        Records a purchase for a Customer from iOS, Android, or Stripe and will create a Customer if they don't already exist.
        https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/receipts
        Product - In B4I the ProductInformation Object in B4A the Receipt Token
      • GetCustomer As ResumableSub
        Gets the latest Customer Info for the customer with the given App User ID, or creates a new customer if it doesn't exist.
        https://www.revenuecat.com/docs/api-v1#tag/customers/operation/subscribers
      • GUID As String
        Generates a new GUID
      • Initialize (API_KEY As String, AppUserId As String, lst_ProductIdentifier As List) As String
        Initializes the object. You can add parameters to this method if needed.
        <code>RevCat.Initialize("RevenueCatAPIKey",RevCatUserId,Array As String("all_access_1_year","all_access_1_month"))</code>
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
  • RevenueCat_Error
    • Fields:
      • ErrorMessage As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Success As Boolean
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • RevenueCat_Subscription
    • Fields:
      • AutoResumeDate As Long
      • BillingIssuesDetectedAt As Long
      • Error As RevenueCat_Error
      • ExpiresDate As Long
      • GracePeriodExpiresDate As Long
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • isSandbox As Boolean
      • OriginalPurchaseDate As Long
      • OwnershipType As String
      • PeriodType As String
      • ProductIdentifier As String
      • PurchaseDate As Long
      • RefundedAt As Long
      • Store As String
      • StoreTransactionId As String
      • UnsubscribeDetectedAt As Long
    • Functions:
      • Initialize
        Initializes the fields to their default value.

Changelog
  • 1.00
    • Release
Have Fun :)

If you have errors or questions, then please create a new thread
 

Attachments

  • RevenueCat Example.zip
    4.7 KB · Views: 1
  • RevenueCat.b4xlib
    2.8 KB · Views: 2

Cristian Achim

Member
Licensed User
Longtime User
Hi!

I replaced

B4X:
RevCat.Initialize("RevenueCatAPIKey",RevCatUserId,Array As String("all_access_1_year","all_access_1_month"))

with

B4X:
RevCat.Initialize("appl_BwXDhxxxxxxxxxxxxxxx", RevCatUserId, Array As String("rto_silver", "rto_gold", "rto_platinum"))

and I received this error:

B4X:
ResponseError: request completed with error, status code: 404
{"code":7117,"message":"Page not found."}
01/01/1970 02:00:00
Has Premium? false

Also I see that
B4X:
Dim RevCatUserId As String = KeyValue.GetDefault("RevCatUserId",RevCat.GUID)
Log(RevCatUserId)

(empty string)

Is there anything else to change?
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
and I received this error:
Make sure you have followed all the steps in the documentation:

only when you see all products from the apple dev console in revenuecat can you start testing.
 

Cristian Achim

Member
Licensed User
Longtime User
I already made all steps.
The products in RevenueCat, I imported them from App Store, I didn't create them manually.
That means that App Store communicate with RevenueCat.
Thank you!
 

Alexander Stolte

Expert
Licensed User
Longtime User
I have updated the example project, the user id is now saved.

It is best to execute the following again after initializing:
B4X:
KeyValue.Remove("RevCatUserId")
 

Cristian Achim

Member
Licensed User
Longtime User
1722497296589.png

1722497358128.png

Still not working :(

I think RevCat.GUID doesn't generate anything.

Is mandatory to create an integration like Webhook or else in RevenueCat?
 

Alexander Stolte

Expert
Licensed User
Longtime User

Alexander Stolte

Expert
Licensed User
Longtime User
I'm using this exact code:
 

Cristian Achim

Member
Licensed User
Longtime User
I'm using this exact code:
That's how it works. Thank you very much for your patience. :)
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Be nice to see example for B4a

Maybe help some of us take Google out of the loop

PS: Looks nice and promising
 
Last edited:
Top