{"id":15321813,"url":"https://github.com/eldimious/gcf-stripe-boilerplate","last_synced_at":"2025-04-15T02:37:21.290Z","repository":{"id":42487688,"uuid":"172208628","full_name":"eldimious/gcf-stripe-boilerplate","owner":"eldimious","description":"Serverless implementation of basic Stripe requests using google cloud functions(Faas)","archived":false,"fork":false,"pushed_at":"2023-02-12T00:19:53.000Z","size":983,"stargazers_count":6,"open_issues_count":6,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T14:22:07.886Z","etag":null,"topics":["clean-architecture","faas","gcf","google-cloud","google-cloud-function","google-cloud-functions","hexagonal-architecture","javascript","layered-architecture","nodejs","serverless","serverless-architectures","stripe","stripe-payments"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eldimious.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-23T11:54:47.000Z","updated_at":"2022-12-01T07:13:49.000Z","dependencies_parsed_at":"2023-02-13T04:01:01.928Z","dependency_job_id":null,"html_url":"https://github.com/eldimious/gcf-stripe-boilerplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgcf-stripe-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgcf-stripe-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgcf-stripe-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgcf-stripe-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eldimious","download_url":"https://codeload.github.com/eldimious/gcf-stripe-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248995100,"owners_count":21195497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean-architecture","faas","gcf","google-cloud","google-cloud-function","google-cloud-functions","hexagonal-architecture","javascript","layered-architecture","nodejs","serverless","serverless-architectures","stripe","stripe-payments"],"created_at":"2024-10-01T09:13:12.456Z","updated_at":"2025-04-15T02:37:21.247Z","avatar_url":"https://github.com/eldimious.png","language":"JavaScript","funding_links":["https://ko-fi.com/Y8Y797KCA"],"categories":[],"sub_categories":[],"readme":"# Serverless Payments with Stripe and Google Cloud Functions as FaaS.\n\n\n[![Build Status](https://travis-ci.org/eldimious/gcf-stripe-boilerplate.svg?branch=master)](https://travis-ci.org/eldimious/gcf-stripe-boilerplate) [![Coverage Status](https://coveralls.io/repos/github/eldimious/gcf-stripe-boilerplate/badge.svg?branch=master)](https://coveralls.io/github/eldimious/gcf-stripe-boilerplate?branch=master)\n\nWhen we say “serverless”, it doesn’t mean servers are no longer involved. It means that you no longer need to think about them.\nServerless is an approach that aims to eliminate the need to manage infrastructure by:\n\n  - Using a managed FaaS compute service such as AWS Lambda, Webtask, Google Cloud Functions, and IBM OpenWhisk to execute code,\n  - Leveraging third-party services and APIs, and\n  - Applying serverless architectures and patterns.\n\nFaaS providers such as Gcf offers a new kind of platform that lets you deploy and invoke ephemeral (short-lived) function processes via events to handle individual requests. It provides a means to achieve the serverless dream allowing developers to execute code in response to events without building out or maintaining a complex infrastructure.\n \n `gcf-stripe-boilerplate` is a serverless implementation of basic Stripe requests using Faas(Google Cloud Functions).\n\n# Architecture Overview #\nThe app is designed to use a layered architecture. The architecture is heavily influenced by the Clean Architecture and Hexagonal Architecture. [Clean Architecture](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html) is an architecture where `the business rules can be tested without the UI, database, web server, or any external element`. \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/719/1*ZNT5apOxDzGrTKUJQAIcvg.png\" width=\"350\"/\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/900/0*R7uuhFwZbhcqZSvn\" width=\"350\" /\u003e \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/1200/0*rFs1UtU4sRns5vCJ.png\" width=\"350\" /\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/1200/0*C-snK7L4sMn7b6CW.png\" width=\"350\" /\u003e \n\u003c/p\u003e\n\nAlso, in entry point(index.js), I use Dependency Injection(DI). There are many reasons using Dependency Injection as:\n1. Decoupling\n2. Easier unit testing\n3. Faster development\n4. Dependency injection is really helpful when it comes to testing. You can easily mock your modules' dependencies using this pattern.\n\nYou can take a look at this tutorial: `https://blog.risingstack.com/dependency-injection-in-node-js/`.\nAccording to DI:\n  A. High-level modules should not depend on low-level modules. Both should depend on abstractions.\n  B. Abstractions should not depend on details.\n\nThe code style being used is based on the airbnb js style guide.\n\n\n## Data Layer ##\n\nThe data layer is implemented using repositories, that hide the underlying data sources (BaaS, database, network, cache, etc), and provides an abstraction over them so other parts of the application that make use of the repositories, don't care about the origin of the data and are decoupled from the specific implementations used. Here, we use Stripe as a BaaS provider for both creating customers and payments and exporsure methods.This is important to enable the decoupling.\n\n## Domain Layer ##\n\nThe domain layer is implemented using services. They depend on the repositories to get the exported methods and apply the *business rules* on them. They are not coupled to a specific BaaS implementation and can be reused if we change our Baas client from Stripe to another platform.\n\n## Routes/Controller Layer ##\n\nThis layer is being used in the exported GCF and depends on the domain layer (services). Here we define the middleware where we specify some validation rules for the requests.\n\n## Entry point ##\n\nThe entry point for the applications is the index.js file, where we specify all google cloud functions that we will deploy.\n\n# Quick start #\n\n### Prerequisites ###\n\nCreate an .env.yaml file in project root to register the following required environment variable(we need the Stripe secret key, and a custom api key):\n  - `STRIPE_SECRET_KEY: \"xxxxxxxxxxxx\"`\n  - `API_KEY: \"xxxxxxxxxxxx\"`\n\nIn order to secure HTTP endpoints we will send as header: `header[api-key]` our own custom **API-KEY**.\n\n### Deployment ###\n\nIn order to deploy your functions to gcloud just use gcloud cli, e.g. in order to deploy `createCharge` use this cmd:\n\n```shell\n  gcloud config set project PROJECT_ID \u0026\u0026 gcloud functions deploy createCharge --trigger-http --env-vars-file .env.yaml --runtime nodejs8\n```\n\nwhere `--env-vars-file .env.yaml` flag reads and sets the env vars from your.env.yaml as function's scope.\n\nFor more info about enviroment variables in gcf you can take a look at this [link](https://cloud.google.com/functions/docs/env-var#using_environment_variables)\n\nAlso you can take a look how we deploy a gcf at this [link](https://cloud.google.com/sdk/gcloud/reference/functions/deploy)\n\n### Usage ###\n\nAfter you deploy the function in google cloud, you can use them by a HTTP request to their URL. E.g. to trigger `createCharge` gcf we should:\n\n```shell\ncurl \"https://REGION-PROJECT_ID.cloudfunctions.net/createCharge\"\n```\n\nwhere:\n\n  - REGION is the region where your function is deployed. This is visible in your terminal when your function finishes deploying.\n  \n  - PROJECT_ID is your Cloud project ID. This is visible in your terminal when your function finishes deploying.\n\n## Support Me\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y797KCA)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fgcf-stripe-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feldimious%2Fgcf-stripe-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fgcf-stripe-boilerplate/lists"}