Skip to content

Commit 4cebe9b

Browse files
committed
chore: format
1 parent 82143ac commit 4cebe9b

28 files changed

+185
-169
lines changed

codelab-steps/index.lab.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function startDataListeners() {
282282
.collection("prices")
283283
.orderBy("unit_amount")
284284
.get();
285-
if (!"content" in document.createElement("template")) {
285+
if ((!"content") in document.createElement("template")) {
286286
console.error("Your browser doesn't support HTML template elements.");
287287
return;
288288
}
@@ -402,14 +402,13 @@ function startDataListeners() {
402402
// In this implementation we only expect one Subscription to exist
403403
const subscription = snapshot.docs[0].data();
404404
const priceData = (await subscription.price.get()).data();
405-
document.querySelector(
406-
"#my-subscription p"
407-
).textContent = `You are paying ${new Intl.NumberFormat("en-US", {
408-
style: "currency",
409-
currency: priceData.currency,
410-
}).format((priceData.unit_amount / 100).toFixed(2))} per ${
411-
priceData.interval
412-
}`;
405+
document.querySelector("#my-subscription p").textContent =
406+
`You are paying ${new Intl.NumberFormat("en-US", {
407+
style: "currency",
408+
currency: priceData.currency,
409+
}).format((priceData.unit_amount / 100).toFixed(2))} per ${
410+
priceData.interval
411+
}`;
413412
});
414413
}
415414
```

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ const createInvoice = async function ({
6868
description: item.description,
6969
tax_rates: item.tax_rates ?? [],
7070
},
71-
{ idempotencyKey: `invoiceItems-create-${idempotencyKey}-${index}` }
71+
{ idempotencyKey: `invoiceItems-create-${idempotencyKey}-${index}` },
7272
);
73-
}
73+
},
7474
);
7575

7676
// Create the individual invoice items for this customer from the items in payload
@@ -87,7 +87,7 @@ const createInvoice = async function ({
8787
if (transfer_data) invoiceCreateParams.transfer_data = transfer_data;
8888
const invoice: Stripe.Invoice = await stripe.invoices.create(
8989
invoiceCreateParams,
90-
{ idempotencyKey: `invoices-create-${idempotencyKey}` }
90+
{ idempotencyKey: `invoices-create-${idempotencyKey}` },
9191
);
9292
logs.invoiceCreated(invoice.id, invoice.livemode);
9393
return invoice;
@@ -146,7 +146,7 @@ export const sendInvoice = functions.handler.firestore.document.onCreate(
146146
if (customers.data.length) {
147147
// Use the existing customer
148148
customer = customers.data.find(
149-
(cus) => cus.currency === payload.items[0].currency
149+
(cus) => cus.currency === payload.items[0].currency,
150150
);
151151
if (customer) logs.customerRetrieved(customer.id, customer.livemode);
152152
}
@@ -160,7 +160,7 @@ export const sendInvoice = functions.handler.firestore.document.onCreate(
160160
'Created by the Firebase Extension: Send Invoices using Stripe', // optional metadata, adds a note
161161
},
162162
},
163-
{ idempotencyKey: `customers-create-${eventId}` }
163+
{ idempotencyKey: `customers-create-${eventId}` },
164164
);
165165

166166
logs.customerCreated(customer.id, customer.livemode);
@@ -187,7 +187,7 @@ export const sendInvoice = functions.handler.firestore.document.onCreate(
187187
logs.invoiceSent(
188188
finalizedInvoice.id,
189189
email,
190-
finalizedInvoice.hosted_invoice_url
190+
finalizedInvoice.hosted_invoice_url,
191191
);
192192
} else {
193193
logs.invoiceCreatedError(finalizedInvoice);
@@ -209,7 +209,7 @@ export const sendInvoice = functions.handler.firestore.document.onCreate(
209209
logs.stripeError(e);
210210
}
211211
return;
212-
}
212+
},
213213
);
214214

215215
/* A Stripe webhook that updates each invoice's status in Cloud Firestore */
@@ -225,7 +225,7 @@ export const updateInvoice = functions.handler.https.onRequest(
225225
event = stripe.webhooks.constructEvent(
226226
req.rawBody,
227227
req.headers['stripe-signature'],
228-
config.stripeWebhookSecret
228+
config.stripeWebhookSecret,
229229
);
230230
} catch (err) {
231231
logs.badSignature(err);
@@ -285,5 +285,5 @@ export const updateInvoice = functions.handler.https.onRequest(
285285

286286
// Return a response to Stripe to acknowledge receipt of the event
287287
resp.json({ received: true });
288-
}
288+
},
289289
);

firestore-stripe-invoices/functions/src/logs.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,81 +29,81 @@ export function startInvoiceUpdate(eventType: string) {
2929
export function incorrectPayload(payload: InvoicePayload) {
3030
if (!payload.items.length) {
3131
logger.error(
32-
new Error('😞[Error] Missing at least one line item in items[]')
32+
new Error('😞[Error] Missing at least one line item in items[]'),
3333
);
3434
}
3535
if (!payload.email && !payload.uid) {
3636
logger.error(
3737
new Error(
38-
'😞[Error] Missing either a customer email address or Firebase Authentication uid'
39-
)
38+
'😞[Error] Missing either a customer email address or Firebase Authentication uid',
39+
),
4040
);
4141
}
4242
if (payload.email && payload.uid) {
4343
logger.error(
4444
new Error(
45-
'😞[Error] Only either email or uid is permitted, you specified both.'
46-
)
45+
'😞[Error] Only either email or uid is permitted, you specified both.',
46+
),
4747
);
4848
}
4949
}
5050

5151
export function noEmailForUser(uid: string) {
5252
logger.error(
53-
new Error(`😞[Error] User [${uid}] is missing an email address.`)
53+
new Error(`😞[Error] User [${uid}] is missing an email address.`),
5454
);
5555
}
5656

5757
export function stripeError(err: Stripe.StripeCardError) {
5858
logger.error(
5959
new Error('😞[Error] Error when making a request to the Stripe API:'),
60-
err
60+
err,
6161
);
6262
}
6363

6464
export function invoiceCreatedError(invoice?: Stripe.Invoice) {
6565
logger.error(
6666
new Error('😞[Error] Error when creating the invoice:'),
67-
invoice
67+
invoice,
6868
);
6969
}
7070

7171
export function customerCreated(id: string, livemode: boolean) {
7272
logger.log(
7373
`👤 Created a new customer: https://dashboard.stripe.com${
7474
livemode ? '' : '/test'
75-
}/customers/${id}`
75+
}/customers/${id}`,
7676
);
7777
}
7878

7979
export function customerRetrieved(id: string, livemode: boolean) {
8080
logger.log(
8181
`🙋 Found existing customer by email: https://dashboard.stripe.com${
8282
livemode ? '' : '/test'
83-
}/customers/${id}`
83+
}/customers/${id}`,
8484
);
8585
}
8686

8787
export function invoiceCreated(id: string, livemode: boolean) {
8888
logger.log(
8989
`🧾 Created invoice: https://dashboard.stripe.com${
9090
livemode ? '' : '/test'
91-
}/invoices/${id}`
91+
}/invoices/${id}`,
9292
);
9393
}
9494

9595
export function invoiceSent(
9696
id: string,
9797
email: string,
98-
hostedInvoiceUrl: string
98+
hostedInvoiceUrl: string,
9999
) {
100100
logger.log(`📧 Sent invoice ${id} to ${email}: ${hostedInvoiceUrl}`);
101101
}
102102

103103
export function badSignature(err: Error) {
104104
logger.error(
105105
'😞[Error] Webhook signature verification failed. Is your Stripe webhook secret parameter configured correctly?',
106-
err
106+
err,
107107
);
108108
}
109109

@@ -121,28 +121,28 @@ export function malformedEvent(event: Stripe.Event) {
121121

122122
export function ignoreEvent(eventType: string) {
123123
logger.log(
124-
`🙈 Ignoring event "${eventType}" because it because it isn't a relevant part of the invoice lifecycle`
124+
`🙈 Ignoring event "${eventType}" because it because it isn't a relevant part of the invoice lifecycle`,
125125
);
126126
}
127127

128128
export function unexpectedInvoiceAmount(
129129
numInvoices: number,
130-
invoiceId: string
130+
invoiceId: string,
131131
) {
132132
logger.error(
133133
'😞[Error] could not find invoice',
134134
new Error(
135-
`Expected 1 invoice with ID "${invoiceId}", but found ${numInvoices}`
136-
)
135+
`Expected 1 invoice with ID "${invoiceId}", but found ${numInvoices}`,
136+
),
137137
);
138138
}
139139

140140
export function statusUpdateComplete(
141141
invoiceId: string,
142142
newStatus: string,
143-
eventType: string
143+
eventType: string,
144144
) {
145145
logger.log(
146-
`🙂 Updated invoice "${invoiceId}" to status "${newStatus}" on event type "${eventType}"`
146+
`🙂 Updated invoice "${invoiceId}" to status "${newStatus}" on event type "${eventType}"`,
147147
);
148148
}

firestore-stripe-payments/functions/__tests__/helpers/collections.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ export async function findCustomerInCollection(user: UserRecord) {
2929
const customerDoc = await waitForDocumentToExistWithField(
3030
doc,
3131
'stripeId',
32-
60000
32+
60000,
3333
);
3434

3535
return Promise.resolve({ docId: user.uid, ...customerDoc.data() });
3636
}
3737

3838
export async function findCustomerPaymentInCollection(
3939
userId: string,
40-
stripeId: string
40+
stripeId: string,
4141
) {
4242
const paymentDoc: DocumentData = await waitForDocumentToExistInCollection(
4343
paymentsCollection(userId),
4444
'customer',
45-
stripeId
45+
stripeId,
4646
);
4747

4848
const paymentRef = paymentsCollection(userId).doc(paymentDoc.doc.id);
4949

5050
const updatedPaymentDoc = await waitForDocumentToExistWithField(
5151
paymentRef,
52-
'prices'
52+
'prices',
5353
);
5454

5555
return updatedPaymentDoc.data();
@@ -69,7 +69,7 @@ export async function createCheckoutSession(userId, subscription) {
6969

7070
const checkoutSessionDoc = await waitForDocumentToExistWithField(
7171
checkoutSessionDocument,
72-
'created'
72+
'created',
7373
);
7474

7575
return checkoutSessionDoc.data();

firestore-stripe-payments/functions/__tests__/helpers/setupEnvironment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ const path = require('path');
22

33
export const pathToenvFile = path.resolve(
44
__dirname,
5-
'../../../_emulator/extensions/firestore-stripe-payments.env.local'
5+
'../../../_emulator/extensions/firestore-stripe-payments.env.local',
66
);
77

88
export const pathTosecretsFile = path.resolve(
99
__dirname,
10-
'../../../_emulator/extensions/firestore-stripe-payments.secret.local'
10+
'../../../_emulator/extensions/firestore-stripe-payments.secret.local',
1111
);
1212

1313
export const setupEnvironment = () => {

firestore-stripe-payments/functions/__tests__/helpers/stripeApi/subscriptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Product, Subscription } from '../../../src/interfaces';
55
const stripe = require('stripe')(config.stripeSecretKey);
66

77
export const createRandomSubscription = async (
8-
customer
8+
customer,
99
): Promise<Subscription> => {
1010
const name = faker.commerce.product();
1111

@@ -26,7 +26,7 @@ export const createRandomSubscription = async (
2626
/** Attach the test PaymentMethod to the customer */
2727
const attachedPaymentMethod = await stripe.paymentMethods.attach(
2828
'pm_card_visa',
29-
{ customer: customer }
29+
{ customer: customer },
3030
);
3131

3232
/** Update the customer's default PaymentMethod */

firestore-stripe-payments/functions/__tests__/helpers/utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function repeat(
66
fn: { (): Promise<any>; (): any },
77
until: { ($: any): any; (arg0: any): any },
88
retriesLeft = 5,
9-
interval = 1000
9+
interval = 1000,
1010
) {
1111
const result = await fn();
1212

@@ -24,16 +24,16 @@ export async function repeat(
2424
export const waitForDocumentToExistWithField = (
2525
document: DocumentData,
2626
field: string | number,
27-
timeout: number = 20_000
27+
timeout: number = 20_000,
2828
): Promise<DocumentData> => {
2929
return new Promise((resolve, reject) => {
3030
let timedOut = false;
3131
const timer = setTimeout(() => {
3232
timedOut = true;
3333
reject(
3434
new Error(
35-
`Timeout waiting for firestore document to exist with field ${field}`
36-
)
35+
`Timeout waiting for firestore document to exist with field ${field}`,
36+
),
3737
);
3838
}, timeout);
3939
const unsubscribe = document.onSnapshot(async (snapshot: DocumentData) => {
@@ -52,16 +52,16 @@ export const waitForDocumentUpdate = (
5252
document: DocumentData,
5353
field: string | number,
5454
value: any,
55-
timeout: number = 10_000
55+
timeout: number = 10_000,
5656
): Promise<FirebaseFirestore.DocumentData> => {
5757
return new Promise((resolve, reject) => {
5858
let timedOut = false;
5959
const timer = setTimeout(() => {
6060
timedOut = true;
6161
reject(
6262
new Error(
63-
`Timeout waiting for firestore document to update with ${field}`
64-
)
63+
`Timeout waiting for firestore document to update with ${field}`,
64+
),
6565
);
6666
}, timeout);
6767
const unsubscribe = document.onSnapshot(async (snapshot: DocumentData) => {
@@ -80,24 +80,24 @@ export const waitForDocumentToExistInCollection = (
8080
query: Query,
8181
field: string | number,
8282
value: any,
83-
timeout: number = 20_000
83+
timeout: number = 20_000,
8484
): Promise<DocumentData> => {
8585
return new Promise((resolve, reject) => {
8686
let timedOut = false;
8787
const timer = setTimeout(() => {
8888
timedOut = true;
8989
reject(
9090
new Error(
91-
`Timeout waiting for firestore document to exist with field ${field} in collection`
92-
)
91+
`Timeout waiting for firestore document to exist with field ${field} in collection`,
92+
),
9393
);
9494
}, timeout);
9595

9696
const unsubscribe = query.onSnapshot(async (snapshot) => {
9797
const docs = snapshot.docChanges();
9898

9999
const record: DocumentData = docs.filter(
100-
($) => $.doc.data()[field] === value
100+
($) => $.doc.data()[field] === value,
101101
)[0];
102102

103103
if (record) {

0 commit comments

Comments
 (0)