diff --git a/firestore-stripe-payments/_emulator/.gitignore b/firestore-stripe-payments/_emulator/.gitignore new file mode 100644 index 00000000..dbb58ffb --- /dev/null +++ b/firestore-stripe-payments/_emulator/.gitignore @@ -0,0 +1,66 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +firebase-debug.log* +firebase-debug.*.log* + +# Firebase cache +.firebase/ + +# Firebase config + +# Uncomment this if you'd like others to create their own Firebase project. +# For a team working on the same Firebase project(s), it is recommended to leave +# it commented so all members can deploy to the same project(s) in .firebaserc. +# .firebaserc + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env diff --git a/firestore-stripe-payments/_emulator/extensions/firestore-stripe-payments.secret.local b/firestore-stripe-payments/_emulator/extensions/firestore-stripe-payments.secret.local index 2ba85d00..b7026f34 100644 --- a/firestore-stripe-payments/_emulator/extensions/firestore-stripe-payments.secret.local +++ b/firestore-stripe-payments/_emulator/extensions/firestore-stripe-payments.secret.local @@ -1 +1 @@ -STRIPE_API_KEY= +STRIPE_API_KEY= \ No newline at end of file diff --git a/firestore-stripe-payments/_emulator/firebase.json b/firestore-stripe-payments/_emulator/firebase.json index 26d2d133..07dacc1a 100755 --- a/firestore-stripe-payments/_emulator/firebase.json +++ b/firestore-stripe-payments/_emulator/firebase.json @@ -9,6 +9,9 @@ "hub": { "port": 4000 }, + "firestore": { + "port": 8080 + }, "storage": { "port": 9199 }, @@ -25,5 +28,17 @@ "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" - } + }, + "functions": [ + { + "source": "functions", + "codebase": "default", + "ignore": [ + "node_modules", + ".git", + "firebase-debug.log", + "firebase-debug.*.log" + ] + } + ] } diff --git a/firestore-stripe-payments/_emulator/functions/.gitignore b/firestore-stripe-payments/_emulator/functions/.gitignore new file mode 100644 index 00000000..40b878db --- /dev/null +++ b/firestore-stripe-payments/_emulator/functions/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/firestore-stripe-payments/_emulator/functions/index.js b/firestore-stripe-payments/_emulator/functions/index.js new file mode 100644 index 00000000..e81477f6 --- /dev/null +++ b/firestore-stripe-payments/_emulator/functions/index.js @@ -0,0 +1,19 @@ +/** + * Import function triggers from their respective submodules: + * + * const {onCall} = require("firebase-functions/v2/https"); + * const {onDocumentWritten} = require("firebase-functions/v2/firestore"); + * + * See a full list of supported triggers at https://firebase.google.com/docs/functions + */ + +const {onRequest} = require("firebase-functions/v2/https"); +const logger = require("firebase-functions/logger"); + +// Create and deploy your first functions +// https://firebase.google.com/docs/functions/get-started + +// exports.helloWorld = onRequest((request, response) => { +// logger.info("Hello logs!", {structuredData: true}); +// response.send("Hello from Firebase!"); +// }); diff --git a/firestore-stripe-payments/_emulator/functions/package.json b/firestore-stripe-payments/_emulator/functions/package.json new file mode 100644 index 00000000..392196b9 --- /dev/null +++ b/firestore-stripe-payments/_emulator/functions/package.json @@ -0,0 +1,23 @@ +{ + "name": "functions", + "description": "Cloud Functions for Firebase", + "scripts": { + "serve": "firebase emulators:start --only functions", + "shell": "firebase functions:shell", + "start": "npm run shell", + "deploy": "firebase deploy --only functions", + "logs": "firebase functions:log" + }, + "engines": { + "node": "18" + }, + "main": "index.js", + "dependencies": { + "firebase-admin": "^11.8.0", + "firebase-functions": "^4.3.1" + }, + "devDependencies": { + "firebase-functions-test": "^3.1.0" + }, + "private": true +} diff --git a/firestore-stripe-payments/functions/__tests__/helpers/setupEmulator.ts b/firestore-stripe-payments/functions/__tests__/helpers/setupEmulator.ts index b55f5fff..1c647ec9 100644 --- a/firestore-stripe-payments/functions/__tests__/helpers/setupEmulator.ts +++ b/firestore-stripe-payments/functions/__tests__/helpers/setupEmulator.ts @@ -1,5 +1,5 @@ export default () => { - process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080'; - process.env.FIREBASE_FIRESTORE_EMULATOR_ADDRESS = 'localhost:8080'; - process.env.FIREBASE_AUTH_EMULATOR_HOST = 'localhost:9099'; + process.env.FIRESTORE_EMULATOR_HOST = '127.0.0.1:8080'; + process.env.FIREBASE_FIRESTORE_EMULATOR_ADDRESS = '127.0.0.1:8080'; + process.env.FIREBASE_AUTH_EMULATOR_HOST = '127.0.0.1:9099'; }; diff --git a/firestore-stripe-payments/functions/__tests__/helpers/stripeApi/subscriptions.ts b/firestore-stripe-payments/functions/__tests__/helpers/stripeApi/subscriptions.ts index 4759d1db..89ac977b 100644 --- a/firestore-stripe-payments/functions/__tests__/helpers/stripeApi/subscriptions.ts +++ b/firestore-stripe-payments/functions/__tests__/helpers/stripeApi/subscriptions.ts @@ -29,7 +29,7 @@ export const createRandomSubscription = async ( card: { number: '4242424242424242', exp_month: 5, - exp_year: 2023, + exp_year: new Date().getFullYear() + 1, cvc: '314', }, });