@revenuecat/purchases-js 0.0.17 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,178 +10,29 @@ Sign up to [get started for free](https://app.revenuecat.com/signup).
10
10
 
11
11
  Login @ [app.revenuecat.com](https://app.revenuecat.com)
12
12
 
13
+ - Connect your Stripe account if you haven't already (More payment gateways are coming soon)
13
14
  - Create a Project (if you haven't already)
14
-
15
- ### ======> Only while testing <======
16
-
17
- - Add the private project id (a.k.a. app_id) to the following feature flags
18
- - RCBILLING
19
- - GENERATE_V2_SUBSCRIPTION_MODELS_FOR_RCBILLING
20
- - GENERATE_V2_SUBSCRIPTION_MODELS
21
-
22
- ### ======> Only while testing <======
23
-
24
15
  - Add a new RCBilling app
25
- - Get the `RC_PUBLISHABLE_API_KEY` (you will need it soon)
26
- - Connect your Stripe account (More payment gateways are coming soon)
16
+ - Get the sandbox API key or production API key (depending on the environment)
27
17
  - Create some products for the RCBilling App
28
18
  - Create an offering and add packages with RCBilling products
29
19
  - Create the entitlements you need in your app and link them to the RCBilling products
30
20
 
31
21
  # Installation
32
22
 
33
- ### ======> Only during testing <======
34
-
35
- - Get a token to download the sdk from our private npm registry
36
- - Set the environment variable `NODE_AUTH_TOKEN`
37
-
38
- ```bash
39
- export NODE_AUTH_TOKEN="the token you got from the npm registry"
40
- ```
41
-
42
- ### ======> Only during testing <======
43
-
44
23
  - Add the library to your project's dependencies
45
-
46
- ```
47
- npm add --save @revenuecat/purchases-js
48
- ```
24
+ - npm
25
+ ```
26
+ npm install --save @revenuecat/purchases-js
27
+ ```
28
+ - yarn
29
+ ```
30
+ yarn add --save @revenuecat/purchases-js
31
+ ```
49
32
 
50
33
  # Usage
51
34
 
52
- ## Download the current Offerings
53
-
54
- By downloading the current Offerings you can easily build a Paywall page using the embedded Packages and their
55
- associated `rcBillingProduct` and price.
56
-
57
- ```typescript
58
- const purchases = Purchases.configure(
59
- "your RC_PUBLISHABLE_API_KEY",
60
- "the unique id of the user in your systems",
61
- );
62
-
63
- purchases.getOfferings().then((offerings) => {
64
- // Get current offering
65
- console.log(offerings.current);
66
- // Or a dictionary of all offerings
67
- console.log(offerings.all);
68
- });
69
- ```
70
-
71
- This should print the current offerings you have set up in your RC Account.
72
-
73
- Please check out [this file](https://github.com/RevenueCat/purchases-js/blob/main/src/entities/offerings.ts) for the
74
- Offering's data structure
75
-
76
- ## Check User Entitlements
77
-
78
- You can check the entitlements granted to your users throughout all the platforms, now
79
- also on your website!
80
-
81
- ```typescript
82
- const entitlementId = "the entitlementId you set up in RC";
83
-
84
- const purchases = Purchases.configure(
85
- "your RC_PUBLISHABLE_API_KEY",
86
- "the unique id of the user in your systems",
87
- );
88
- const appUserID = purchases.getAppUserId();
89
-
90
- purchases.isEntitledTo(entitlementId).then((isEntitled) => {
91
- if (isEntitled == true) {
92
- console.log(`User ${appUserID} is entitled to ${entitlementId}`);
93
- } else {
94
- console.log(`User ${appUserID} is not entitled to ${entitlementId}`);
95
- }
96
- });
97
- ```
98
-
99
- As example, you can build a cool React component with it:
100
-
101
- ```tsx
102
- Purchases.configure(
103
- "your RC_PUBLISHABLE_API_KEY",
104
- "the unique id of the user in your systems",
105
- );
106
-
107
- const WithEntitlement = ({ entitlementId, children }) => {
108
- const [isEntitled, setIsEntitled] = useState<boolean | null>(null);
109
-
110
- useEffect(() => {
111
- Purchases.getSharedInstance()
112
- .isEntitledTo(entitlementId)
113
- .then((isEntitled) => {
114
- setIsEntitled(isEntitled);
115
- });
116
- }, [entitlementId]);
117
-
118
- if (isEntitled === null) {
119
- return <>"loading..."</>;
120
- }
121
-
122
- if (isEntitled === true) {
123
- return <>{children}</>;
124
- }
125
-
126
- return <>You are not entitled!</>;
127
- };
128
- ```
129
-
130
- And then use it in your app:
131
-
132
- ```tsx
133
- const App = () => (
134
- <>
135
- <WithEntitlement entitlementId={"functionality5"}>
136
- <Functionality5 />
137
- </WithEntitlement>
138
- </>
139
- );
140
- ```
141
-
142
- If you need further information about the user's entitlements, you can use the `getCustomerInfo` method:
143
-
144
- ```ts
145
- const customerInfo = await purchases.getCustomerInfo();
146
- ```
147
-
148
- ### Important note
149
-
150
- Please be aware that the information about the entitlements can be manipulated by malicious actors, so make sure
151
- you protect your apps against attacks that modify the entitlements by validating access through your servers.
152
-
153
- ## Subscribe a User to an entitlement and allow payment with Stripe
154
-
155
- RCBilling allows you to use your payment gateway for payments.
156
- In this example we will show Stripe, more will be supported soon!
157
-
158
- ### Context
159
-
160
- You built your paywall, and your user just clicked on the offer they want to subscribe to.
161
-
162
- ```tsx
163
- const purchases = Purchases.configure(
164
- "your RC_PUBLISHABLE_API_KEY",
165
- "the unique id of the user in your systems",
166
- );
167
- // You can retrieve the package from the offerings through `getOfferings`:
168
- const rcBillingPackage = offerings.current.availablePackages[0];
169
- const appUserId = purchases.getAppUserId();
170
- const entitlementIdToCheck =
171
- "the entitlementId you set up in RC for your product"; // TODO: remove once this is not needed
172
-
173
- purchase.purchasePackage(rcBillingPackage).then((response) => {
174
- const isEntitled =
175
- entitlementIdToCheck in response.customerInfo.entitlements.active;
176
- if (isEntitled == true) {
177
- console.log(`User ${appUserID} is entitled to ${entitlementId}`);
178
- } else {
179
- console.log(
180
- `User ${appUserID} is not entitled to ${entitlementId}, even after ${numberOfAttempts} attempts`,
181
- );
182
- }
183
- });
184
- ```
35
+ See the [RevenueCat docs](https://www.revenuecat.com/docs/web/revenuecat-billing) and the [SDK Reference](https://revenuecat.github.io/purchases-js-docs).
185
36
 
186
37
  # Development
187
38
 
@@ -218,6 +69,17 @@ npm run prettier
218
69
  npm run lint
219
70
  ```
220
71
 
72
+ ## Running E2E tests
73
+
74
+ ```bash
75
+ npm run build
76
+ cd examples/rcbilling-demo
77
+ npm run build
78
+ # In a different terminal or background the process
79
+ npm run dev
80
+ npm run test
81
+ ```
82
+
221
83
  ## Update API specs
222
84
 
223
85
  ```bash