Skip to content

Commit c4a3777

Browse files
authored
Update purchases-js code snippets to 1.7.0 (#936)
1 parent c6386ca commit c4a3777

File tree

3 files changed

+67
-30
lines changed

3 files changed

+67
-30
lines changed

code_blocks/_projects/web-billing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "module",
1010
"author": "RevenueCat",
1111
"dependencies": {
12-
"@revenuecat/purchases-js": "^1.4.1"
12+
"@revenuecat/purchases-js": "^1.7.0"
1313
},
1414
"devDependencies": {
1515
"eslint": "^8.56.0",

code_blocks/_projects/web-billing/web-billing-doc-snippets.test.ts.txt

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ test('Snippet "Configuring SDK Anonymous" works', () => {
3131

3232
test('Snippet "Get customer info" works', async () => {
3333
Purchases.configure(
34-
WEB_BILLING_PUBLIC_API_KEY,
35-
"customer_with_gold_entitlement"
34+
{
35+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
36+
appUserId: "customer_with_gold_entitlement",
37+
}
3638
);
3739
expect(await getCustomerInfo()).toBeDefined();
3840
Purchases.getSharedInstance().close();
3941
});
4042

4143
test('Snippet "Check for specific entitlement" works for customer with entitlement', async () => {
4244
Purchases.configure(
43-
WEB_BILLING_PUBLIC_API_KEY,
44-
"customer_with_gold_entitlement"
45+
{
46+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
47+
appUserId: "customer_with_gold_entitlement",
48+
}
4549
);
4650
const callback = vi.fn();
4751
await checkForSpecificEntitlement(callback);
@@ -51,8 +55,10 @@ test('Snippet "Check for specific entitlement" works for customer with entitleme
5155

5256
test('Snippet "Check for specific entitlement" works for customer without any entitlement', async () => {
5357
Purchases.configure(
54-
WEB_BILLING_PUBLIC_API_KEY,
55-
"customer_without_entitlement"
58+
{
59+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
60+
appUserId: "customer_without_entitlement",
61+
}
5662
);
5763
const callback = vi.fn();
5864
await checkForSpecificEntitlement(callback);
@@ -62,8 +68,10 @@ test('Snippet "Check for specific entitlement" works for customer without any en
6268

6369
test('Snippet "Check for specific entitlement" works for customer with different entitlement', async () => {
6470
Purchases.configure(
65-
WEB_BILLING_PUBLIC_API_KEY,
66-
"customer_with_silver_entitlement"
71+
{
72+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
73+
appUserId: "customer_with_silver_entitlement",
74+
}
6775
);
6876
const callback = vi.fn();
6977
await checkForSpecificEntitlement(callback);
@@ -74,14 +82,18 @@ test('Snippet "Check for specific entitlement" works for customer with different
7482
test('Snippet "Check for any entitlement" works for both customers with entitlement', async () => {
7583
const callback = vi.fn();
7684
Purchases.configure(
77-
WEB_BILLING_PUBLIC_API_KEY,
78-
"customer_with_gold_entitlement"
85+
{
86+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
87+
appUserId: "customer_with_gold_entitlement",
88+
}
7989
);
8090
await checkForAnyEntitlement(callback);
8191
Purchases.getSharedInstance().close();
8292
Purchases.configure(
83-
WEB_BILLING_PUBLIC_API_KEY,
84-
"customer_with_silver_entitlement"
93+
{
94+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
95+
appUserId: "customer_with_silver_entitlement",
96+
}
8597
);
8698
await checkForAnyEntitlement(callback);
8799
Purchases.getSharedInstance().close();
@@ -90,8 +102,10 @@ test('Snippet "Check for any entitlement" works for both customers with entitlem
90102

91103
test('Snippet "Check for any entitlement" works for customer without any entitlement', async () => {
92104
Purchases.configure(
93-
WEB_BILLING_PUBLIC_API_KEY,
94-
"customer_without_entitlement"
105+
{
106+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
107+
appUserId: "customer_without_entitlement",
108+
}
95109
);
96110
const callback = vi.fn();
97111
await checkForAnyEntitlement(callback);
@@ -101,8 +115,10 @@ test('Snippet "Check for any entitlement" works for customer without any entitle
101115

102116
test('Snippet "Get current offering" works', async () => {
103117
Purchases.configure(
104-
WEB_BILLING_PUBLIC_API_KEY,
105-
"customer_without_entitlement"
118+
{
119+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
120+
appUserId: "customer_without_entitlement",
121+
}
106122
);
107123
let pkgs: Package[] | undefined;
108124
const callback = vi
@@ -120,8 +136,10 @@ test('Snippet "Get current offering" works', async () => {
120136

121137
test('Snippet "Get current offering for EUR" works', async () => {
122138
Purchases.configure(
123-
WEB_BILLING_PUBLIC_API_KEY,
124-
"customer_without_entitlement"
139+
{
140+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
141+
appUserId: "customer_without_entitlement",
142+
}
125143
);
126144
let pkgs: Package[] | undefined;
127145
const callback = vi
@@ -142,8 +160,10 @@ test('Snippet "Get current offering for EUR" works', async () => {
142160

143161
test('Snippet "Get custom offering" works', async () => {
144162
Purchases.configure(
145-
WEB_BILLING_PUBLIC_API_KEY,
146-
"customer_without_entitlement"
163+
{
164+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
165+
appUserId: "customer_without_entitlement",
166+
}
147167
);
148168
let pkgs: Package[] | null = null;
149169
const callback = vi
@@ -165,8 +185,10 @@ test('Snippet "Get custom offering" works', async () => {
165185

166186
test('Snippet "Displaying packages" works', async () => {
167187
Purchases.configure(
168-
WEB_BILLING_PUBLIC_API_KEY,
169-
"customer_without_entitlement"
188+
{
189+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
190+
appUserId: "customer_without_entitlement",
191+
}
170192
);
171193
let allPackages: Package[] = [];
172194
let monthlyPackage: Package | undefined;
@@ -198,8 +220,10 @@ test('Snippet "Displaying packages" works', async () => {
198220

199221
test('Snippet "Getting product" works', async () => {
200222
Purchases.configure(
201-
WEB_BILLING_PUBLIC_API_KEY,
202-
"customer_without_entitlement"
223+
{
224+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
225+
appUserId: "customer_without_entitlement",
226+
}
203227
);
204228
let product: Product | undefined;
205229
const callback = vi.fn().mockImplementation((theProduct: Product) => {
@@ -215,8 +239,10 @@ test('Snippet "Getting product" works', async () => {
215239

216240
test('Snippet "Purchasing package" works', async () => {
217241
Purchases.configure(
218-
WEB_BILLING_PUBLIC_API_KEY,
219-
"customer_without_entitlement"
242+
{
243+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
244+
appUserId: "customer_without_entitlement",
245+
}
220246
);
221247

222248
await purchasingPackage();

code_blocks/_projects/web-billing/web-billing-doc-snippets.ts.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const authentication = {getAppUserId: () => "test"};
66
function configuringSDK(WEB_BILLING_PUBLIC_API_KEY: string) {
77
// MARK: Configuring SDK
88
const appUserId = authentication.getAppUserId(); // Replace with your own authentication system
9-
const purchases = Purchases.configure(WEB_BILLING_PUBLIC_API_KEY, appUserId);
9+
const purchases = Purchases.configure({
10+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
11+
appUserId: appUserId,
12+
});
1013
// END
1114
return purchases;
1215
}
@@ -16,7 +19,12 @@ function configuringSDKOutOutOfAutomaticUTMCollection(WEB_BILLING_PUBLIC_API_KEY
1619
const appUserId = authentication.getAppUserId(); // Replace with your own authentication system
1720
const httpConfig = {}; // Any setting you want to customize in purchases-js HTTP client.
1821
const flagsConfig = {autoCollectUTMAsMetadata: false};
19-
const purchases = Purchases.configure(WEB_BILLING_PUBLIC_API_KEY, appUserId, httpConfig, flagsConfig);
22+
const purchases = Purchases.configure({
23+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
24+
appUserId: appUserId,
25+
httpConfig: httpConfig,
26+
flags: flagsConfig,
27+
});
2028
// END
2129
return purchases;
2230
}
@@ -27,7 +35,10 @@ function configuringSDKWithAnonUser(WEB_BILLING_PUBLIC_API_KEY: string) {
2735
// Make sure to enable the Redemption Links feature in the RevenueCat dashboard and use the
2836
// redemption link to redeem the purchase in your mobile app.
2937
const appUserId = Purchases.generateRevenueCatAnonymousAppUserId();
30-
const purchases = Purchases.configure(WEB_BILLING_PUBLIC_API_KEY, appUserId);
38+
const purchases = Purchases.configure({
39+
apiKey: WEB_BILLING_PUBLIC_API_KEY,
40+
appUserId: appUserId,
41+
});
3142
// END
3243
return purchases;
3344
}

0 commit comments

Comments
 (0)