Skip to content

Commit

Permalink
add various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanjakl committed May 17, 2024
1 parent abbfa5b commit 8c9ebcd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ STRIPE_DASHBOARD_BASE_URL='https://dashboard.stripe.com'

<br>

## Recommended use

This module is utilized to primarily mirror datasets fetched from the connected Stripe account. To enhance the front-end with additional custom data, it is recommended to create a separate piece type and link it to the Stripe product piece using a `relationship` schema field type. This enables the addition of extra schema fields for images, supporting documents, and other necessary data while keeping it decoupled from Stripe's data, which may change during synchronization.

```js
module.exports = {
extend: 'apostrophe-pieces',
name: 'product',
fields: {
add: {
_stripeProduct: {
label: 'Stripe Product',
type: 'relationship',
withType: 'stripe-products/product',
max: 1
},
_images: {
label: 'Images',
type: 'relationship',
withType: '@apostrophecms/image'
},
_documents: {
label: 'Documents',
type: 'relationship',
withType: '@apostrophecms/file'
}
}
}
}
```

## API Routes

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.
Expand All @@ -125,3 +156,4 @@ Once set up, run tests using `npm run tests` to validate any changes before depl
## TODOs (Limitations)

- fix disappering `stripeProductObject` and `stripePriceObject` data when moved between `draft` and `published` modes and vice versa
- two-way synchronization between ApostropheCMS and Stripe
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ _.mixin({ deepDiff });
const Stripe = require('stripe');
let stripe = null;

if (process.env.STRIPE_TEST_MODE === 'false') {
// Using Stripe production mode settings with the API key
stripe = Stripe(process.env.STRIPE_KEY);
} else {
// Using Stripe test mode settings
if (process.env.STRIPE_MOCK_TEST_MODE === 'true') {
// Using Stripe mock test mode settings
stripe = new Stripe('sk_test_xyz', {
host: '127.0.0.1',
protocol: 'http',
port: 12111
});
} else {
// Using Stripe production mode settings with the API key
stripe = Stripe(process.env.STRIPE_KEY);
}

module.exports = {
Expand Down Expand Up @@ -209,6 +209,8 @@ module.exports = {
stripeProductInstance.stripeProductObject = product;
stripeProductInstance.stripePriceObject = product.default_price ? price : null;

stripeProductInstance.archived = !product.active;

await self.apos.stripeProduct.insert(req, stripeProductInstance);
}
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions modules/stripe-products/product/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
publicApiProjection: {
'stripeProductObject.id': 1,
'stripeProductObject.name': 1,
'stripeProductObject.description': 1,
'stripeProductObject.type': 1,
'stripeProductObject.images': 1,

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stepanjakl/apostrophe-stripe-products",
"version": "0.0.4",
"version": "0.0.5",
"description": "Stripe Products For ApostropheCMS",
"keywords": [
"apostrophe",
Expand Down Expand Up @@ -38,8 +38,8 @@
"mocha": "^10.x.x",
"read-only-field": "npm:@stepanjakl/apostrophe-read-only-field@latest",
"stripe": "^15.x.x",
"stylelint": "^15.x.x",
"stylelint-config-apostrophe": "^3.0.2"
"stylelint": "^16.x.x",
"stylelint-config-apostrophe": "^4.x.x"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 8c9ebcd

Please sign in to comment.