Skip to content

Commit 206e5a8

Browse files
Merge pull request #246 from stripe/firestore-stripe-payments-automatic-payment-methods
feat(payments): Manage payment methods in the Dashboard
2 parents 270e311 + bd749ec commit 206e5a8

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

firestore-stripe-payments/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.2.3 - 2021-11-29
2+
3+
[feat] Manage payment methods in the Dashboard: setting `payment_method_types` is now optional. By default, all payment methods enabled in your Stripe Dashboard will be presented on the Stripe Checkout page.
4+
15
## Version 0.2.2 - 2021-11-09
26

37
[RENAME] The extension has been renamed from `firestore-stripe-subscriptions` to `firestore-stripe-payments` to better reflect the support for both one time, and recurring payments.

firestore-stripe-payments/extension.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: firestore-stripe-payments
16-
version: 0.2.2
16+
version: 0.2.3
1717
specVersion: v1beta
1818

1919
displayName: Run Payments with Stripe

firestore-stripe-payments/functions/lib/index.js

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firestore-stripe-payments/functions/lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firestore-stripe-payments/functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"dependencies": {
1414
"firebase-admin": "^9.9.0",
1515
"firebase-functions": "^3.14.1",
16-
"stripe": "8.170.0"
16+
"stripe": "8.191.0"
1717
},
1818
"devDependencies": {
1919
"@types/express": "^4.17.11",

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const stripe = new Stripe(config.stripeSecretKey, {
3434
// https://stripe.com/docs/building-plugins#setappinfo
3535
appInfo: {
3636
name: 'Firebase firestore-stripe-payments',
37-
version: '0.2.2',
37+
version: '0.2.3',
3838
},
3939
});
4040

@@ -103,9 +103,10 @@ exports.createCheckoutSession = functions.firestore
103103
success_url,
104104
cancel_url,
105105
quantity = 1,
106-
payment_method_types = ['card'],
106+
payment_method_types,
107107
shipping_rates = [],
108108
metadata = {},
109+
automatic_payment_methods = { enabled: true },
109110
automatic_tax = false,
110111
tax_rates = [],
111112
tax_id_collection = false,
@@ -150,7 +151,6 @@ exports.createCheckoutSession = functions.firestore
150151
billing_address_collection,
151152
shipping_address_collection: { allowed_countries: shippingCountries },
152153
shipping_rates,
153-
payment_method_types,
154154
customer,
155155
customer_update,
156156
line_items: line_items
@@ -166,6 +166,9 @@ exports.createCheckoutSession = functions.firestore
166166
cancel_url,
167167
locale,
168168
};
169+
if (payment_method_types) {
170+
sessionCreateParams.payment_method_types = payment_method_types;
171+
}
169172
if (mode === 'subscription') {
170173
sessionCreateParams.subscription_data = {
171174
trial_from_plan,
@@ -225,17 +228,28 @@ exports.createCheckoutSession = functions.firestore
225228
`When using 'client:mobile' and 'mode:payment' you must specify amount and currency!`
226229
);
227230
}
228-
const paymentIntent = await stripe.paymentIntents.create({
231+
const paymentIntentCreateParams: Stripe.PaymentIntentCreateParams = {
229232
amount,
230233
currency,
231234
customer,
232235
metadata,
233-
});
236+
};
237+
if (payment_method_types) {
238+
paymentIntentCreateParams.payment_method_types =
239+
payment_method_types;
240+
} else {
241+
paymentIntentCreateParams.automatic_payment_methods =
242+
automatic_payment_methods;
243+
}
244+
const paymentIntent = await stripe.paymentIntents.create(
245+
paymentIntentCreateParams
246+
);
234247
paymentIntentClientSecret = paymentIntent.client_secret;
235248
} else if (mode === 'setup') {
236249
const setupIntent = await stripe.setupIntents.create({
237250
customer,
238251
metadata,
252+
payment_method_types: payment_method_types ?? ['card'],
239253
});
240254
setupIntentClientSecret = setupIntent.client_secret;
241255
} else {
@@ -615,6 +629,8 @@ export const handleWebhookEvents = functions.handler.https.onRequest(
615629
'price.updated',
616630
'price.deleted',
617631
'checkout.session.completed',
632+
'checkout.session.async_payment_succeeded',
633+
'checkout.session.async_payment_failed',
618634
'customer.subscription.created',
619635
'customer.subscription.updated',
620636
'customer.subscription.deleted',
@@ -682,6 +698,8 @@ export const handleWebhookEvents = functions.handler.https.onRequest(
682698
);
683699
break;
684700
case 'checkout.session.completed':
701+
case 'checkout.session.async_payment_succeeded':
702+
case 'checkout.session.async_payment_failed':
685703
const checkoutSession = event.data
686704
.object as Stripe.Checkout.Session;
687705
if (checkoutSession.mode === 'subscription') {

0 commit comments

Comments
 (0)