{"id":31227438,"url":"https://github.com/moscatellimarco/stripe-mongoose-api","last_synced_at":"2025-09-22T04:09:14.847Z","repository":{"id":57372816,"uuid":"467257565","full_name":"MoscatelliMarco/stripe-mongoose-api","owner":"MoscatelliMarco","description":"🎉 Accepting payments is a snap with this easy-to-use payment integration tool! 💳🛍️ Sell products or manage subscriptions with straightforward setup steps. Designed for hassle-free payment processing in apps. 🙌🎈","archived":false,"fork":false,"pushed_at":"2024-06-10T08:52:06.000Z","size":41,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T14:43:49.332Z","etag":null,"topics":["api","api-rest","earn-money","javascript","monetization","mongodb","mongoose","passive-income","rest-api","stripe","stripe-api","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MoscatelliMarco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-07T20:59:21.000Z","updated_at":"2024-12-09T10:16:27.000Z","dependencies_parsed_at":"2024-06-10T10:40:46.882Z","dependency_job_id":null,"html_url":"https://github.com/MoscatelliMarco/stripe-mongoose-api","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.4285714285714286,"last_synced_commit":"f273fb660ef5fe13d5d29d6f6f89e3845abf3747"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MoscatelliMarco/stripe-mongoose-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoscatelliMarco%2Fstripe-mongoose-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoscatelliMarco%2Fstripe-mongoose-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoscatelliMarco%2Fstripe-mongoose-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoscatelliMarco%2Fstripe-mongoose-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MoscatelliMarco","download_url":"https://codeload.github.com/MoscatelliMarco/stripe-mongoose-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoscatelliMarco%2Fstripe-mongoose-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276342595,"owners_count":25625590,"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","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","api-rest","earn-money","javascript","monetization","mongodb","mongoose","passive-income","rest-api","stripe","stripe-api","stripe-payments"],"created_at":"2025-09-22T04:09:13.562Z","updated_at":"2025-09-22T04:09:14.799Z","avatar_url":"https://github.com/MoscatelliMarco.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stripe Mongoose Api\n\nStripe Mongoose Api is a [Mongoose plugin](https://github.com/Automattic/mongoose) that simplifies building checkout and payment system for apis with stripe.\nIt will provide you:\n- Simple way to manage all the users for your api\n- Highly customizable code for all your projects\n- Ready in a few lines of code\n\u003cbr/\u003e\n\n![wallpaper money](https://user-images.githubusercontent.com/94981444/157924374-ad4e08de-af6c-4adf-8f1e-a12b197706b9.png)\n\n## Installation\n```\nnpm install stripe-mongoose-api\n```\n\n## Usage\n### Plugin Stripe Mongoose Api\nFirst you need to plugin Stripe Mongoose Api into your User schema\n```javascript\nconst mongoose = require('mongoose');\nconst Schema = mongoose.Schema;\nconst stripeMongooseApi = require('stripe-mongoose-api');\nconst User = new Schema({});\nUser.plugin(stripeMongooseApi);\nmodule.exports = mongoose.model('User', User);\n```\nYou're free to define your User how you like. Stripe Mongoose Api will add a apiKey, customerId, subscriptionId and ItemId field.\n\nAdditionally Stripe Mongoose Api adds some methods to your Schema. see the Documentation section for more details.\n\n\n### Options\nWhen plugging in Stripe Mongoose Api plugin additional options can be provided to configure the hashing algorithm.\n```javascript\nUser.plugin(stripeMongooseApi, options);\n```\n\n#### Main Options\n* `stripeSecret`: the secret key needed for the stripe api. Default: *null*\n* `webhookSecret`: the key to connect the stripe webhook to your localhost. Default: *null*\n* `priceId`: the price id of the product that your clients will buy. Default: *null*\n* `showUsage`: specifies if send the user record after every api call. Default: *false*\n* `successUrl`: specifies the url where the user will be redirected after a successful checkout. Default: * localhost:3000*\n* `cancelUrl`: specifies the url where the user will be redirected after a non-successful checkout. Default: *localhost:3000*\n* `apiKeyField`: specifies the field name that holds the username. Default *apiKey*\n* `saltField`: specifies the field name that holds the salt. Default *salt*\n* `customerIdField`: specifies the field name that holds the customer id. Default *customerId*\n* `subscriptionIdField`: specifies the field name that holds the subscription id. Default *subscriptionid*\n* `itemIdField`: specifies the field name that holds the item id. Default *itemId*\n* `bytesApiKey`: specifies api key length in bytes. Default *16*\n* `iterations`: specifies the number of iterations used in pbkdf2 hashing algorithm. Default: *25000*\n* `salten`: specifies the secret word provided to the hashing algorithm\n* `keylen`: specifies the length in byte of the hashed key. Default: *512*\n* `digest`: specifies the pbkdf2 digest algorithm. Default: *sha256*. (get a list of supported algorithms with crypto.getHashes())\n\n***Attention!*** Changing any of the hashing options(salten, iterations, keylen or digest) in production environment will prevent that existing users to authenticate!\n\n#### Error Messages\n* `MissingStripeSecretKey`: No stripe secret key was given\n* `MissingStripeSignKey`: No stripe sign key was given\n* `InvalidUserError`: User cannot be created because of invalid input\n* `InvalidStripeOptions`:  Bad stripe options was provided\n* `InvalidHashingOptions`: Bad hashing options was provided\n\n### Hash Algorithm\n\nStripe Mongoose Api use the pbkdf2 algorithm of the node crypto library.  [Pbkdf2](http://en.wikipedia.org/wiki/PBKDF2)  was chosen because platform independent (in contrary to bcrypt). \n\n#### Examples\nFor a complete example implementing all the features of this projects see the test folder.\n\n## Documentation\n\n*You can find a  [tutorial here](https://dev.to/moscatellimarco/monetize-your-api-using-stripe-mongoose-api-4k1o)*\n\n### Instance methods\nMethods directly connected to the user.\nFor example to use customerRecords function use\n```javascript\nconst User = require('./models/user');\nconst user = User.findOne({});\nconst user.customerRecords(res);\n```\n#### customerRecords(res)\nReturn the customer records in base of the user activity\n\n### Static methods\nStatic methods are exposed on the model constructor. For example to use subscribeUser function use\n```javascript\nconst User = require('./models/user');\nUser.subscribeUser(user, res)\n```\n#### subscribeUser(user, res)\nsubscribeUser will create a checkout session for the user\n\n#### webhook(user, res, res)\nan handler to request sended by stripe api, that will add to the user an apiKey, a customerId, a subscriptionId and an itemId\n\n#### api(req, res, dataToSend)\nThe hearth of the application, it will check if the user exist and the validity of the api key, and then i will send `dataToSend` to the client\n\n#### changeApiKey(user)\nThis method will simply provide a new apiKey to then user and the it will return an object with { apiKey, hashedApiKey } , if the user does not have an api it will return 'user.api.failed'\n\n## License\n\nStripe Mongoose Api is licenses under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoscatellimarco%2Fstripe-mongoose-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoscatellimarco%2Fstripe-mongoose-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoscatellimarco%2Fstripe-mongoose-api/lists"}