This module adds a piece module and utility operation to automatically synchronize Stripe Products with the database. Saved products can be easily accessed and viewed via the admin UI.
Use your preferred package manager to install the module. You'll also need to install the read-only-field
package alongside it:
npm install stripe-products@npm:@stepanjakl/apostrophe-stripe-products
npm install read-only-field@npm:@stepanjakl/apostrophe-read-only-field
It is highly recommended to explore the apostrophe-stripe-examples
repository, which offers a comprehensive set of examples and full configurations demonstrating how to set up a complete e-commerce store experience.
First, add installed modules to your configuration in the app.js
root file:
require('apostrophe')({
shortName: 'project-name',
modules: {
// Custom fields
'read-only-field': {},
// Stripe Products
'stripe-products': {},
'stripe-products/product': {}
}
});
Then, set global variables inside the .env
file. It's important to set the STRIPE_TEST_MODE
variable to anything other than false
to enable test mode.
PORT='4000'
APOS_BASE_URL='http://localhost:4000'
APOS_RELEASE_ID='a4-boilerplate'
APOS_MONGODB_URI='mongodb://localhost:27017/a4-boilerplate'
STRIPE_KEY='sk_test_xyz'
STRIPE_TEST_MODE='false'
STRIPE_DASHBOARD_BASE_URL='https://dashboard.stripe.com'
The stripe-products
module contains a custom API route ('/api/v1/stripe-products/synchronize'
) triggered by the Synchronize Products
utility operation. It is executed through the '@apostrophecms/job'
module. Once the job is completed, it saves the difference between the existing and received data to the results object in the aposJobs
collection document.
To run tests locally, you'll need to set up the stripe/stripe-mock
package:
brew install stripe/stripe-mock/stripe-mock
brew services start stripe-mock
Once set up, run tests using npm run tests
to validate any changes before deploying them.
- fix disappering
stripeProductObject
andstripePriceObject
data when moved betweendraft
andpublished
modes and vice versa