purchases_dart 2.0.0 copy "purchases_dart: ^2.0.0" to clipboard
purchases_dart: ^2.0.0 copied to clipboard

A pure Dart implementation of purchases_flutter (aka RevenueCat), designed to facilitate in-app purchases and subscriptions with Web Billing.

PurchasesDart #

PurchasesDart is a Dart implementation of the purchases_flutter plugin, designed to facilitate in-app purchases and subscriptions with Web Billing. The purchases_dart package closely follows the native APIs from purchases_flutter.

Usage #

Configure #

Before using PurchasesDart, you must configure it with a PurchasesDartConfiguration. This configuration requires a Web Billing API key and an appUserId.

await PurchasesDart.configure(
  PurchasesDartConfiguration(
    apiKey: WEB_BILLING_API_KEY,
    appUserId: "MY_USER_ID",
  ),
);

appUserId is an optional parameter used to identify users of your app. While optional, it is crucial to provide a persistent appUserId per user if you want to restore purchases after re-installing the app.

Why it matters: Purchase data is stored on RevenueCat's backend and associated with the appUserId. If you can provide the same appUserId after reinstall, purchases can be restored. If not provided, an anonymous ID is generated and stored locally on the device, which is lost when the app is uninstalled.

Best practice: Use an authentication system (e.g., Firebase Authentication) to generate and persist a stable appUserId that can be retrieved after app reinstall.

Get Customer Info #

await PurchasesDart.getCustomerInfo();

Get Offerings #

await PurchasesDart.getOfferings();

Purchase a Package #

In order to make purchases, you need a webCheckoutUrl. In order to have webCheckoutUrl populated, you need to create a Web Purchase Link for your offering. Here are the docs that explain how to do that.

Retrieve the web purchase link for a package and launch it in the user's browser:

Uri? webCheckoutUrl = await PurchasesDart.getWebCheckoutUrl(
  package,
  email: userEmail, // Optional: pre-fill the user's email
);

if (webCheckoutUrl != null) {
  await launchUrl(webCheckoutUrl); // Using url_launcher package
}

Make sure to import and use the url_launcher package to launch the URL.

Step 3 (Optional): Configure Deep Linking for Post-Purchase Redirect

To redirect users back to your app after a successful purchase:

  1. In the Web Purchase Link configuration, go to the Success section
  2. Choose Redirect to a custom success page
  3. Set a URL that can open your app using a deep link
  4. Configure deep link handling in your app using app_links

🧩 Apps using Purchases Dart #

Here are some of the apps leveraging the power of purchases_dart in production:

BT Cam Icon BT Cam
A Bluetooth remote app for DSLR and mirrorless cameras. Compatible with Canon, Nikon, Sony, Fujifilm, GoPro, Olympus, Panasonic, Pentax, and Blackmagic. Built using Purchases Dart to enable app purchases across iOS, Android, macOS, Windows, Linux & Web.

💡 Built something cool with Purchases Dart?
We'd love to showcase your app here!
Open a pull request and add it to this section. Please include your app icon in svg!

12
likes
160
points
38
downloads

Publisher

verified publishernavideck.com

Weekly Downloads

A pure Dart implementation of purchases_flutter (aka RevenueCat), designed to facilitate in-app purchases and subscriptions with Web Billing.

Homepage
Repository (GitHub)
View/report issues

Topics

#in-app-purchases #subscriptions #revenuecat #web-billing #payments

Documentation

Documentation
API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

crypto, dio, flutter, purchases_flutter, shared_preferences, uuid

More

Packages that depend on purchases_dart