Skip to content

Commit 2b7c387

Browse files
feat(firestore-stripe-payments): Allow configuring min instances for createCheckoutSession (#375)
* feat: Allow configuring min instances for createCheckoutSession * Update firestore-stripe-payments/extension.yaml * Update firestore-stripe-payments/extension.yaml Co-authored-by: Jonathan Steele <[email protected]>
1 parent 930226f commit 2b7c387

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

firestore-stripe-payments/extension.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ params:
212212
- param: DELETE_STRIPE_CUSTOMERS
213213
label: Automatically delete Stripe customer objects
214214
description: >-
215-
Do you want to automatically delete customer objects in Stripe?
216-
When a user is deleted in Firebase Authentication or in Cloud Firestore and set to 'Auto delete'
215+
Do you want to automatically delete customer objects in Stripe?
216+
When a user is deleted in Firebase Authentication or in Cloud Firestore and set to 'Auto delete'
217217
the extension will delete their customer object in Stripe which will immediately cancel all subscriptions for the user.
218218
type: select
219219
options:
@@ -228,7 +228,7 @@ params:
228228
label: Stripe API key with restricted access
229229
type: secret
230230
description: >-
231-
What is your Stripe API key?
231+
What is your Stripe API key?
232232
We recommend creating a new [restricted key](https://stripe.com/docs/keys#limit-access)
233233
with write access only for the "Customers", "Checkout Sessions" and "Customer portal" resources.
234234
And read-only access for the "Subscriptions" and "Plans" resources.
@@ -239,13 +239,24 @@ params:
239239
label: Stripe webhook secret
240240
type: secret
241241
description: >-
242-
This is your signing secret for a Stripe-registered webhook.
242+
This is your signing secret for a Stripe-registered webhook.
243243
This webhook can only be registered after installation.
244-
Leave this value untouched during installation, then follow the
244+
Leave this value untouched during installation, then follow the
245245
postinstall instructions for registering your webhook
246246
and configuring this value.
247247
example: whsec_1234567890
248248
required: false
249+
250+
- param: CREATE_CHECKOUT_SESSION_MIN_INSTANCES
251+
label: Minimum instances for createCheckoutSession function
252+
type: secret
253+
description: >-
254+
How many instances should be always ready to process checkout requests?
255+
This number can be adjusted to reduce cold starts and increase the responsiveness
256+
of checkout creation requests. Suggested values are 0 or 1.
257+
default: 0
258+
required: true
259+
249260
events:
250261
- type: com.stripe.v1.product.created
251262
description: Occurs whenever a product is created.

firestore-stripe-payments/functions/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export default {
2222
stripeConfigCollectionPath: process.env.STRIPE_CONFIG_COLLECTION,
2323
syncUsersOnCreate: process.env.SYNC_USERS_ON_CREATE === 'Sync',
2424
autoDeleteUsers: process.env.DELETE_STRIPE_CUSTOMERS === 'Auto delete',
25+
minCheckoutInstances: process.env.CREATE_CHECKOUT_MIN_INSTANCES ?? 0,
2526
};

firestore-stripe-payments/functions/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ exports.createCustomer = functions.auth
106106
/**
107107
* Create a CheckoutSession or PaymentIntent based on which client is being used.
108108
*/
109-
exports.createCheckoutSession = functions.firestore
109+
exports.createCheckoutSession = functions.runWith({
110+
minInstances: config.minCheckoutInstances,
111+
}).firestore
110112
.document(`/${config.customersCollectionPath}/{uid}/checkout_sessions/{id}`)
111113
.onCreate(async (snap, context) => {
112114
const {

0 commit comments

Comments
 (0)