Skip to content

Commit 13d5cc0

Browse files
authored
Add Capacitor docs for Paywalls and Customer Center (#920)
1 parent f0927f0 commit 13d5cc0

File tree

6 files changed

+118
-2
lines changed

6 files changed

+118
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { RevenueCatUI } from '@revenuecat/purchases-capacitor-ui';
2+
import { PAYWALL_RESULT } from '@revenuecat/purchases-capacitor';
3+
4+
async function presentPaywall(): Promise<boolean> {
5+
// Present paywall for current offering:
6+
const { result } = await RevenueCatUI.presentPaywall();
7+
// or if you need to present a specific offering:
8+
const { result } = await RevenueCatUI.presentPaywall({
9+
offering: offering // Optional Offering object obtained through getOfferings
10+
});
11+
12+
// Handle result if needed.
13+
switch (paywallResult) {
14+
case PAYWALL_RESULT.NOT_PRESENTED:
15+
case PAYWALL_RESULT.ERROR:
16+
case PAYWALL_RESULT.CANCELLED:
17+
return false;
18+
case PAYWALL_RESULT.PURCHASED:
19+
case PAYWALL_RESULT.RESTORED:
20+
return true;
21+
default:
22+
return false;
23+
}
24+
}
25+
26+
async function presentPaywallIfNeeded() {
27+
// Present paywall for current offering:
28+
const { result } = await RevenueCatUI.presentPaywallIfNeeded({ requiredEntitlementIdentifier: 'YOUR_ENTITLEMENT_ID'});
29+
30+
// If you need to present a specific offering:
31+
const { result } = await RevenueCatUI.presentPaywallIfNeeded({
32+
offering: offering, // Optional Offering object obtained through getOfferings
33+
requiredEntitlementIdentifier: "pro"
34+
});
35+
36+
// Handle result if needed.
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Integrating Customer Center on Capacitor
3+
sidebar_label: Capacitor Integration
4+
slug: customer-center-capacitor
5+
hidden: false
6+
---
7+
import { sdkVersions } from '@site/src/components/CustomerCenter/CustomerCenterSDKTable';
8+
9+
## Installation
10+
11+
[![Release](https://img.shields.io/github/release/RevenueCat/purchases-capacitor.svg?filter=!*beta*&style=flat)](https://github.com/RevenueCat/purchases-capacitor/releases)
12+
13+
Before integrating the Customer Center in Capacitor, update your `package.json` to include `@revenuecat/purchases-capacitor-ui` <code>{sdkVersions.capacitor}</code> or higher to your app.
14+
15+
```json
16+
{
17+
"dependencies": {
18+
"@revenuecat/purchases-capacitor": "<latest version>",
19+
"@revenuecat/purchases-capacitor-ui": "<latest version>"
20+
}
21+
}
22+
```
23+
24+
## Integration
25+
26+
Opening the customer center is as simple as:
27+
28+
```tsx
29+
await RevenueCatUI.presentCustomerCenter();
30+
```
31+
32+
## Setup promotional offers
33+
34+
Promotional Offers allow developers to apply custom pricing and trials to new customers and to existing and lapsed subscriptions. Unique promotional offers can be assigned to different paths and survey responses in the Customer Center, but first they must be setup in App Store Connect and Google Play Store.
35+
36+
The Customer Center will automatically show offers based on specific user actions. By default we have defined it for cancellations but it can be modified to any of the defined paths. For Capacitor you are going to have to configure these promotional offers in both Google Play Console and App Store Connect.
37+
Refer to [configuring Google Play Store promotional offers](/tools/customer-center/customer-center-promo-offers-google) and [configuring App Store Connect promotional offers](/tools/customer-center/customer-center-promo-offers-apple) for detailed instructions.
38+
39+
Learn more about configuring the Customer Center in the [configuration guide](/tools/customer-center/customer-center-configuration).

docs/tools/customer-center/customer-center-installation.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Follow instructions on how to install the SDK in your particular platform:
2929
- [Native iOS](/tools/customer-center/customer-center-integration#installation)
3030
- [Native Android](/tools/customer-center/customer-center-integration-android#installation)
3131
- [Flutter](/tools/customer-center/customer-center-flutter#installation)
32-
- [React Native](/tools/customer-center/customer-center-react-native#installation)
32+
- [React Native](/tools/customer-center/customer-center-react-native#installation)
33+
- [Capacitor](/tools/customer-center/customer-center-capacitor#installation)

docs/tools/paywalls/displaying-paywalls.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ Available listeners at this time are:
207207
- onRestoreCompleted
208208
- onRestoreError
209209

210+
### Capacitor
211+
212+
There are several ways to present paywalls:
213+
214+
- Using `RevenueCatUI.presentPaywall`: this will display a paywall when invoked.
215+
- Using `RevenueCatUI.presentPaywallIfNeeded`: this will present a paywall only if the customer does not have an unlocked entitlement.
216+
217+
import cap1 from '@site/code_blocks/tools/paywalls_cap_1.ts.txt?raw';
218+
219+
<RCCodeBlock
220+
tabs={[
221+
{
222+
type: "capacitor",
223+
title: "RevenueCatUI.presentPaywall",
224+
content: cap1,
225+
},
226+
]}
227+
/>
228+
210229
## Handling paywall navigation
211230

212231
When creating a paywall, consider whether it will be presented in a sheet, or as a full screen view. Sheets won't require a dedicated close button. Full screen views should have either a close button (if presented modally) or a back button (if part of a navigation stack or host) unless you intend to provide a hard paywall to your customers that cannot be bypassed.

docs/tools/paywalls/installation.mdx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RevenueCat Paywalls are included as part of the RevenueCatUI package in the Reve
1414
| react-native-purchases | 8.6.1 and up |
1515
| purchases-flutter | 8.5.0 and up |
1616
| purchases-kmp | 1.5.1+13.18.1 and up |
17+
| purchases-capacitor | 10.3.1 and up |
1718

1819
### Platforms (support for more coming)
1920

@@ -145,4 +146,16 @@ kotlin {
145146
}
146147
```
147148

148-
Lastly, you'll need to make sure you link the `PurchasesHybridCommonUI` native iOS framework. If your iOS app uses Swift Package Manager, add the `PurchasesHybridCommonUI` library to your target in the same way you added the `PurchasesHybridCommon` library. If your iOS app uses CocoaPods, either update its `Podfile`, or update your Compose Multiplatform module's `build.gradle.kts`, depending on how your Multiplatform module is integrated with your iOS project.
149+
Lastly, you'll need to make sure you link the `PurchasesHybridCommonUI` native iOS framework. If your iOS app uses Swift Package Manager, add the `PurchasesHybridCommonUI` library to your target in the same way you added the `PurchasesHybridCommon` library. If your iOS app uses CocoaPods, either update its `Podfile`, or update your Compose Multiplatform module's `build.gradle.kts`, depending on how your Multiplatform module is integrated with your iOS project.
150+
151+
## Capacitor Installation
152+
153+
- Update your `package.json` to include `@revenuecat/purchases-capacitor-ui`. Make sure it matches the version of `@revenuecat/purchases-capacitor`:
154+
```json
155+
{
156+
"dependencies": {
157+
"@revenuecat/purchases-capacitor": "<latest version>",
158+
"@revenuecat/purchases-capacitor-ui": "<latest version>"
159+
}
160+
}
161+
```

src/components/CustomerCenter/CustomerCenterSDKTable.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const sdkVersions = {
66
reactNative: "8.7.0",
77
flutter: "8.6.0",
88
kmp: "1.7.0",
9+
capacitor: "10.3.1",
910
};
1011

1112
export const CustomerCenterSDKTable: React.FC = () => {
@@ -40,6 +41,12 @@ export const CustomerCenterSDKTable: React.FC = () => {
4041
link: "https://github.com/RevenueCat/purchases-kmp",
4142
version: `${sdkVersions.kmp} and higher`,
4243
},
44+
{
45+
name: "Capacitor",
46+
sdk: "@revenuecat/purchases-capacitor-ui",
47+
link: "https://github.com/RevenueCat/purchases-capacitor",
48+
version: `${sdkVersions.capacitor} and higher`,
49+
},
4350
];
4451

4552
return (

0 commit comments

Comments
 (0)