Skip to content

Commit 0a13193

Browse files
authored
feat(firestore-stripe-payments): allow to be specify trial period days (#605)
* feat(firestore-stripe-payments): remove trial_from_plan, add trial_period_days
1 parent 973cf93 commit 0a13193

File tree

7 files changed

+189
-186
lines changed

7 files changed

+189
-186
lines changed

firestore-stripe-payments/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,47 @@
3737
[feat] - Add `setup_future_usage` parameter for one-time payment flows
3838

3939
## 0.3.5 - 2023-08-14
40+
4041
[chore] Updated naming and upgraded to node18
4142

4243
[fix] Updated icons
4344

4445
[fix] updated appinfo versioning
4546

4647
## 0.3.4 - 2023-08-14
48+
4749
This extension has been formally transferred to Invertase. See the updated README for more details.
4850

4951
## Version 0.3.3 - 2023-03-20
52+
5053
[fix] Address issue where `insertInvoiceRecord` function fails. [#511]
5154

5255
## Version 0.3.2 - 2022-11-30
56+
5357
[chore] Added support for `us-west1` as a deployable region for Firebase functions. [#464]
5458

5559
## Version 0.3.1 - 2022-08-24
60+
5661
[chore] Added `package-lock.json` to version control to prevent installation issues. [#426]
5762

5863
## Version 0.3.0 - 2022-08-23
64+
5965
[feat] Allow configurable minimum instances for `createCheckoutSession` function. [#375]
6066

6167
[feat] Throw an `unauthenticated` Firebase error from `creatPortalLink` function. [#420]
6268

6369
[feat] Add Price object IDs from invoice line items for subscription payments to payments Firestore collection. [#393]
6470

6571
## Version 0.2.7 - 2022-05-10
72+
6673
[chore] Updated package-lock.json that was causing install errors.
6774

6875
## Version 0.2.6 - 2022-05-10
76+
6977
[feat] Added Stripe extension events. This extension emits events, which allows you to listen to and run custom logic at different trigger points during the functioning of the extension. For example you can listen to events when a product has been added via the `product.created` event, or whenever a payment has succeeded through the `invoice.payment_succeeded` event. (#386)
7078

7179
## Version 0.2.5 - 2022-04-20
80+
7281
[feat] Add parameter to enable phone number collection. (#371)
7382

7483
[feat] Add parameters to enable expired Checkout Session recovery. (#350)
@@ -334,7 +343,7 @@ db.collection("products")
334343

335344
Previously, only subscriptions created via Stripe Checkout were synced to Cloud Firestore. By additionally listening to the `customer.subscription.created` event, the extension now also captures subscriptions created via the Stripe Dashboard or directly via the API. For this to work, Firebase Authentication users need to be synced with Stripe customer objects and the customers collection in Cloud Firestore (new configuration added in version `0.1.7`).
336345

337-
- Add snippet on importing Stripe.js as an ES module when using a build toolchain for your client application (e.g. Angular, React, TypeScript, etc.) to `POSTINSTALL.md`. (#74)
346+
- Add snippet on importing Stripe.js as an ES module when using a build toolchain for your client application (e.g. Angular, React, TypeScript, etc.) to `POSTINSTALL.md`. (#74)
338347

339348
## Version 0.1.6 - 2020-09-10
340349

firestore-stripe-payments/POSTINSTALL.md

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ The quickest way to sign-up new users is by using the [FirebaseUI library](https
175175
Products and pricing information are normal collections and docs in your Cloud Firestore and can be queried as such:
176176

177177
```js
178-
db.collection('${param:PRODUCTS_COLLECTION}')
179-
.where('active', '==', true)
178+
db.collection("${param:PRODUCTS_COLLECTION}")
179+
.where("active", "==", true)
180180
.get()
181181
.then(function (querySnapshot) {
182182
querySnapshot.forEach(async function (doc) {
183-
console.log(doc.id, ' => ', doc.data());
184-
const priceSnap = await doc.ref.collection('prices').get();
183+
console.log(doc.id, " => ", doc.data());
184+
const priceSnap = await doc.ref.collection("prices").get();
185185
priceSnap.docs.forEach((doc) => {
186-
console.log(doc.id, ' => ', doc.data());
186+
console.log(doc.id, " => ", doc.data());
187187
});
188188
});
189189
});
@@ -197,7 +197,7 @@ To create a Checkout Session ID for a one-time payment, pass `mode: 'payment` to
197197

198198
```js
199199
const docRef = await db
200-
.collection('${param:CUSTOMERS_COLLECTION}')
200+
.collection("${param:CUSTOMERS_COLLECTION}")
201201
.doc(currentUser.uid)
202202
.collection("checkout_sessions")
203203
.add({
@@ -238,11 +238,11 @@ To subscribe the user to a specific pricing plan, create a new doc in the `check
238238

239239
```js
240240
const docRef = await db
241-
.collection('${param:CUSTOMERS_COLLECTION}')
241+
.collection("${param:CUSTOMERS_COLLECTION}")
242242
.doc(currentUser.uid)
243-
.collection('checkout_sessions')
243+
.collection("checkout_sessions")
244244
.add({
245-
price: 'price_1GqIC8HYgolSBA35zoTTN2Zl',
245+
price: "price_1GqIC8HYgolSBA35zoTTN2Zl",
246246
success_url: window.location.origin,
247247
cancel_url: window.location.origin,
248248
});
@@ -263,7 +263,7 @@ docRef.onSnapshot((snap) => {
263263

264264
#### Handling trials
265265

266-
By default, the trial period days that you've specified on the pricing plan will be applied to the checkout session. Should you wish to not offer the trial for a certain user (e.g. they've previously had a subscription with a trial that they canceled and are now signing up again), you can specify `trial_from_plan: false` when creating the checkout session doc:
266+
You can specify subscription trial period when creating the checkout session by using the `trial_period_days` parameter. Refer to the [docs](https://stripe.com/docs/payments/checkout/free-trials) for a detailed guide on free trials and how to set them up.
267267

268268
```js
269269
const docRef = await db
@@ -272,7 +272,7 @@ const docRef = await db
272272
.collection("checkout_sessions")
273273
.add({
274274
price: "price_1GqIC8HYgolSBA35zoTTN2Zl",
275-
trial_from_plan: false,
275+
trial_period_days: 7,
276276
success_url: window.location.origin,
277277
cancel_url: window.location.origin,
278278
});
@@ -286,11 +286,11 @@ In order for the promotion code redemption box to show up on the checkout page,
286286

287287
```js
288288
const docRef = await db
289-
.collection('${param:CUSTOMERS_COLLECTION}')
289+
.collection("${param:CUSTOMERS_COLLECTION}")
290290
.doc(currentUser)
291-
.collection('checkout_sessions')
291+
.collection("checkout_sessions")
292292
.add({
293-
price: 'price_1GqIC8HYgolSBA35zoTTN2Zl',
293+
price: "price_1GqIC8HYgolSBA35zoTTN2Zl",
294294
allow_promotion_codes: true,
295295
success_url: window.location.origin,
296296
cancel_url: window.location.origin,
@@ -305,7 +305,7 @@ You can set a [promotion code](https://stripe.com/docs/billing/subscriptions/dis
305305

306306
```js
307307
const docRef = await db
308-
.collection('${param:CUSTOMERS_COLLECTION}')
308+
.collection("${param:CUSTOMERS_COLLECTION}")
309309
.doc(currentUser.uid)
310310
.collection("checkout_sessions")
311311
.add({
@@ -326,7 +326,7 @@ Stripe Tax lets you calculate and collect sales tax, VAT, and GST. Know where to
326326

327327
```js
328328
const docRef = await db
329-
.collection('${param:CUSTOMERS_COLLECTION}')
329+
.collection("${param:CUSTOMERS_COLLECTION}")
330330
.doc(currentUser.uid)
331331
.collection("checkout_sessions")
332332
.add({
@@ -340,19 +340,23 @@ const docRef = await db
340340

341341
#### Applying tax rates dynamically
342342

343-
Stripe Checkout supports applying the correct tax rate for customers in US, GB, AU, and all countries in the EU. With [dynamic tax rates](https://stripe.com/docs/billing/subscriptions/taxes#adding-tax-rates-to-checkout), you create tax rates for different regions (e.g., a 20% VAT tax rate for customers in the UK and a 7.25% sales tax rate for customers in California, US) and Stripe attempts to match your customer’s location to one of those tax rates.
343+
Stripe Checkout supports applying the correct tax rate for customers in US, GB, AU, and all countries in the EU. With [dynamic tax rates](https://stripe.com/docs/billing/subscriptions/taxes#adding-tax-rates-to-checkout), you create tax rates for different regions (e.g., a 20% VAT tax rate for customers in the UK and a 7.25% sales tax rate for customers in California, US) and Stripe attempts to match your customer’s location to one of those tax rates.
344344

345345
```js
346346
const docRef = await db
347-
.collection('${param:CUSTOMERS_COLLECTION}')
347+
.collection("${param:CUSTOMERS_COLLECTION}")
348348
.doc(currentUser)
349349
.collection("checkout_sessions")
350350
.add({
351351
line_items: [
352352
{
353353
price: "price_1HCUD4HYgolSBA35icTHEXd5",
354354
quantity: 1,
355-
dynamic_tax_rates: ["txr_1IJJtvHYgolSBA35ITTBOaew", "txr_1Hlsk0HYgolSBA35rlraUVWO", "txr_1HCshzHYgolSBA35WkPjzOOi"],
355+
dynamic_tax_rates: [
356+
"txr_1IJJtvHYgolSBA35ITTBOaew",
357+
"txr_1Hlsk0HYgolSBA35rlraUVWO",
358+
"txr_1HCshzHYgolSBA35WkPjzOOi",
359+
],
356360
},
357361
],
358362
success_url: window.location.origin,
@@ -366,12 +370,12 @@ You can collect and report taxes with [Tax Rates](https://stripe.com/docs/billin
366370

367371
```js
368372
const docRef = await db
369-
.collection('${param:CUSTOMERS_COLLECTION}')
373+
.collection("${param:CUSTOMERS_COLLECTION}")
370374
.doc(currentUser)
371-
.collection('checkout_sessions')
375+
.collection("checkout_sessions")
372376
.add({
373-
price: 'price_1GqIC8HYgolSBA35zoTTN2Zl',
374-
tax_rates: ['txr_1HCjzTHYgolSBA35m0e1tJN5'],
377+
price: "price_1GqIC8HYgolSBA35zoTTN2Zl",
378+
tax_rates: ["txr_1HCjzTHYgolSBA35m0e1tJN5"],
375379
success_url: window.location.origin,
376380
cancel_url: window.location.origin,
377381
});
@@ -385,7 +389,7 @@ Secondly, you need to add `collect_shipping_address: true` to the Checkout Sessi
385389

386390
```js
387391
const docRef = await db
388-
.collection('${param:CUSTOMERS_COLLECTION}')
392+
.collection("${param:CUSTOMERS_COLLECTION}")
389393
.doc(currentUser.uid)
390394
.collection("checkout_sessions")
391395
.add({
@@ -402,15 +406,15 @@ You can optionally set a metadata object with key-value pairs when creating the
402406

403407
```js
404408
const docRef = await db
405-
.collection('${param:CUSTOMERS_COLLECTION}')
409+
.collection("${param:CUSTOMERS_COLLECTION}")
406410
.doc(currentUser)
407-
.collection('checkout_sessions')
411+
.collection("checkout_sessions")
408412
.add({
409-
price: 'price_1GqIC8HYgolSBA35zoTTN2Zl',
413+
price: "price_1GqIC8HYgolSBA35zoTTN2Zl",
410414
success_url: window.location.origin,
411415
cancel_url: window.location.origin,
412416
metadata: {
413-
item: 'item001',
417+
item: "item001",
414418
},
415419
});
416420
```
@@ -421,25 +425,25 @@ In addition to recurring prices, you can add one-time prices. These will only be
421425

422426
```js
423427
const docRef = await db
424-
.collection('${param:CUSTOMERS_COLLECTION}')
425-
.doc(currentUser)
426-
.collection('checkout_sessions')
427-
.add({
428-
line_items: [
429-
{
430-
price: 'price_1HCUD4HYgolSBA35icTHEXd5', // RECURRING_PRICE_ID
431-
quantity: 1,
432-
tax_rates: ['txr_1HCjzTHYgolSBA35m0e1tJN5'],
433-
},
434-
{
435-
price: 'price_1HEtgDHYgolSBA35LMkO3ExX', // ONE_TIME_PRICE_ID
436-
quantity: 1,
437-
tax_rates: ['txr_1HCjzTHYgolSBA35m0e1tJN5'],
438-
},
439-
],
440-
success_url: window.location.origin,
441-
cancel_url: window.location.origin,
442-
});
428+
.collection("${param:CUSTOMERS_COLLECTION}")
429+
.doc(currentUser)
430+
.collection("checkout_sessions")
431+
.add({
432+
line_items: [
433+
{
434+
price: "price_1HCUD4HYgolSBA35icTHEXd5", // RECURRING_PRICE_ID
435+
quantity: 1,
436+
tax_rates: ["txr_1HCjzTHYgolSBA35m0e1tJN5"],
437+
},
438+
{
439+
price: "price_1HEtgDHYgolSBA35LMkO3ExX", // ONE_TIME_PRICE_ID
440+
quantity: 1,
441+
tax_rates: ["txr_1HCjzTHYgolSBA35m0e1tJN5"],
442+
},
443+
],
444+
success_url: window.location.origin,
445+
cancel_url: window.location.origin,
446+
});
443447
```
444448

445449
**_NOTE_**: If you specify more than one recurring price in the `line_items` array, the subscription object in Cloud Firestore will list all recurring prices in the `prices` array. The `price` attribute on the subscription in Cloud Firestore will be equal to the first item in the `prices` array: `price === prices[0]`.
@@ -457,14 +461,14 @@ In order for this to work, Firebase Authentication users need to be synced with
457461
Subscription details are synced to the `subscriptions` sub-collection in the user's corresponding customer doc.
458462

459463
```js
460-
db.collection('${param:CUSTOMERS_COLLECTION}')
464+
db.collection("${param:CUSTOMERS_COLLECTION}")
461465
.doc(currentUser.uid)
462-
.collection('subscriptions')
463-
.where('status', 'in', ['trialing', 'active'])
466+
.collection("subscriptions")
467+
.where("status", "in", ["trialing", "active"])
464468
.onSnapshot(async (snapshot) => {
465469
// In this implementation we only expect one active or trialing subscription to exist.
466470
const doc = snapshot.docs[0];
467-
console.log(doc.id, ' => ', doc.data());
471+
console.log(doc.id, " => ", doc.data());
468472
});
469473
```
470474

@@ -475,8 +479,8 @@ Once a customer is subscribed you should show them a button to access the custom
475479
```js
476480
const functionRef = firebase
477481
.app()
478-
.functions('${param:LOCATION}')
479-
.httpsCallable('${function:createPortalLink.name}');
482+
.functions("${param:LOCATION}")
483+
.httpsCallable("${function:createPortalLink.name}");
480484
const { data } = await functionRef({
481485
returnUrl: window.location.origin,
482486
locale: "auto", // Optional, defaults to "auto"

firestore-stripe-payments/PREINSTALL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ The design for Stripe Checkout and the customer portal can be customized in your
1919

2020
#### Recommended usage
2121

22-
If you're building on the web platform, you can use this extension for any of your payment use cases.
22+
If you're building on the web platform, you can use this extension for any of your payment use cases.
2323

24-
If you're developing native mobile applications and you're selling digital products or services within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use the app store's in-app purchase APIs. See [Apple's](https://developer.apple.com/app-store/review/guidelines/#payments) and [Google's](https://support.google.com/googleplay/android-developer/answer/9858738?hl=en&ref_topic=9857752) guidelines for more information.
24+
If you're developing native mobile applications and you're selling digital products or services within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use the app store's in-app purchase APIs. See [Apple's](https://developer.apple.com/app-store/review/guidelines/#payments) and [Google's](https://support.google.com/googleplay/android-developer/answer/9858738?hl=en&ref_topic=9857752) guidelines for more information.
2525

2626
For all other scenarios you can use the [stripe-android](https://github.com/stripe/stripe-android), [stripe-ios](https://github.com/stripe/stripe-ios), [stripe-react-native](https://github.com/stripe/stripe-react-native), or [flutter_stripe](https://github.com/flutter-stripe/flutter_stripe) SDKs.
2727

@@ -73,4 +73,4 @@ You are responsible for any costs associated with your use of these services.
7373

7474
To install this extension, your Firebase project must be on the Blaze (pay-as-you-go) plan. You will only be charged for the resources you use. Most Firebase services offer a free tier for low-volume use. [Learn more about Firebase billing.](https://firebase.google.com/pricing)
7575

76-
Starting August 17 2020, you will be billed a small amount (typically less than $0.10) when you install or reconfigure this extension. See the [Cloud Functions for Firebase billing FAQ](https://firebase.google.com/support/faq#expandable-15) for a detailed explanation.
76+
Starting August 17 2020, you will be billed a small amount (typically less than $0.10) when you install or reconfigure this extension. See the [Cloud Functions for Firebase billing FAQ](https://firebase.google.com/support/faq#expandable-15) for a detailed explanation.

0 commit comments

Comments
 (0)