Skip to content

Commit c3b6a2b

Browse files
committed
chore: update readme
1 parent bad298f commit c3b6a2b

6 files changed

+40
-29
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ npm install @discue/paddle-integration-mongodb
4646
### Preparing a New Subscription
4747
For the webhooks integration to work and to be able to correlate incoming hooks with the correct subscription, a placeholder needs to be created **before the checkout** and - afterward - a specific value must be passed to the [Checkout API](https://developer.paddle.com/guides/ZG9jOjI1MzU0MDQz-pass-parameters-to-the-checkout) via the `passthrough` parameter. This value will be returned by the `addSubscriptionPlaceholder` method.
4848

49-
You can see in the example below, the Subscriptions constructor is called with the name of the target `collection` and the id of the target document. The id could be your `user` or `api_client` id. Remember: the target document must exist before creating the placeholder.
50-
5149
```js
5250
'use strict'
5351

5452
const readApiClient = require('./lib/your-application/read-api-client')
5553
const paddleIntegration = require('@discue/paddle-integration-mongodb')
56-
// pass the path to the collection here
57-
const subscriptions = new paddleIntegration.SubscriptionHooks('api_clients')
54+
55+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
56+
const subscriptions = new paddleIntegration.SubscriptionHooks({ storage })
5857

5958
module.exports = async (req, res, next) => {
6059
// requires application to read api_client information

README_HOOK_BODY_PARSER.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const express = require('express')
1111
const app = express()
1212
const port = process.env.PORT || 3456
1313

14-
const paddleIntegrationFirestore = require('@discue/paddle-firebase-integration')
15-
// pass the path to the collection here
16-
const subscriptions = new paddleIntegrationFirestore.SubscriptionHooks('api_clients')
14+
const paddleIntegration = require('@discue/paddle-integration-mongodb')
15+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
16+
const subscriptions = new paddleIntegration.SubscriptionHooks({ storage })
1717

1818
// register body parser first and middleware second
19-
app.use('/_/payments', paddleIntegrationFirestore.bodyparser())
20-
app.post('/_/payments', paddleIntegrationFirestore.middleware(subscriptions))
19+
app.use('/_/payments', paddleIntegration.bodyparser())
20+
app.post('/_/payments', paddleIntegration.middleware(subscriptions))
2121

2222
module.exports = app.listen(port)
2323
```

README_HOOK_MIDDLEWARE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const app = express()
1818
const port = process.env.PORT || 3456
1919

2020
const paddleIntegration = require('@discue/paddle-firebase-integration')
21-
// pass the path to the collection here
22-
const subscriptions = new paddleIntegration.SubscriptionHooks('api_clients')
21+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
22+
const subscriptions = new paddleIntegration.SubscriptionHooks({ storage })
2323

2424
// register body parser first and middleware second
2525
app.use('/_/payments', paddleIntegration.bodyparser())

README_SUBSCRIPTION_API.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Low level wrapper for Paddle API.
1919
- [List products](#list-products)
2020
- [Refund a payment](#refund-a-payment)
2121

22-
:information_source: The API component will be loaded asynchronously to preserve backwards compatibility with commonjs. This is achieved by returning a proxy for the entire `paddle-integration-firestore` module. The reactivity a proxy provides allows us to add the API module then at a later point to the module instance. The drawback is, we do not return named exports and, therefore, cannot not enable destructuring in ES modules.
22+
:information_source: The API component will be loaded asynchronously to preserve backwards compatibility with commonjs. This is achieved by returning a proxy for the entire `paddle-integration-mongodb` module. The reactivity a proxy provides allows us to add the API module then at a later point to the module instance. The drawback is, we do not return named exports and, therefore, cannot not enable destructuring in ES modules.
2323

2424
## Creating a new instance
2525
To create a new instance, four parameters need to be passed to the constructor:

README_SUBSCRIPTION_HYDRATION.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Due to limitations of the Paddle API some assumptions will be made, like derivin
77
- [Hydrate subscription created](#hydrate-subscription-created)
88
- [Hydrate subscription cancelled](#hydrate-subscription-cancelled)
99

10-
:information_source: The API component of this module will be loaded asynchronously to preserve backwards compatibility with commonjs. This is achieved by returning a proxy for the entire `paddle-integration-firestore` module. The reactivity a proxy provides allows us to add the API module then at a later point to the module instance. The drawback is, we do not return named exports and, therefore, cannot not enable destructuring in ES modules.
10+
:information_source: The API component of this module will be loaded asynchronously to preserve backwards compatibility with commonjs. This is achieved by returning a proxy for the entire `paddle-integration-mongodb` module. The reactivity a proxy provides allows us to add the API module then at a later point to the module instance. The drawback is, we do not return named exports and, therefore, cannot not enable destructuring in ES modules.
1111

1212
## Hydrate subscription created
1313
Fetches subscription-related information from Paddle API to initialize the local storage. Has various safety measures to ensure users **cannot** hydrate their own subscriptions from already existing ones.
@@ -18,18 +18,21 @@ Uses the `subscription_id` to contact Paddle API and checks whether the given lo
1818
'use strict'
1919

2020
const paddleIntegration = require('@discue/paddle-firebase-integration')
21-
// initialize api and subscription hooks first
21+
2222
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
23-
const hookStorage = new paddleIntegration.SubscriptionHooks('api_clients')
24-
const subscriptions = new paddleIntegration.SubscriptionHydration('api_clients', { api, hookStorage })
23+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
24+
const hookStorage = new paddleIntegration.SubscriptionHooks({ storage })
25+
const subscriptionInfo = new paddleIntegration.SubscriptionInfo({ api, storage })
26+
27+
const subscriptions = new paddleIntegration.SubscriptionHydration('api_clients', { api, hookStorage, subscriptionInfo })
2528

2629
router.post('/subscriptions/initialize', async (req, res) => {
2730
const { _dsq: { clientId } = {}, body } = req
2831
const { subscription_id, checkout_id } = body
2932

3033
await errorHandler(res, async () => {
3134
try {
32-
await subscriptionInfo.hydrateSubscriptionCreated([clientId], { subscription_id }, checkout_id)
35+
await subscriptions.hydrateSubscriptionCreated([clientId], { subscription_id }, checkout_id)
3336
sendOkNoContent({ res })
3437
} catch (e) {
3538
console.error(`Hydration failed with ${e} at ${e.stack}}`)
@@ -42,7 +45,7 @@ router.post('/subscriptions/initialize', async (req, res) => {
4245

4346
In your front end application, use the `customData` function of this module to create the validation object, that is required during hydration. The `usePaddleCheckout` below will populate the `checkoutOptions` object with necessary values and open the Paddle checkout.
4447
```js
45-
import { customData as createCustomData } from '@discue/paddle-integration-firestore/client'
48+
import { customData as createCustomData } from '@discue/paddle-integration-mongodb/client'
4649

4750
export const checkoutDefaults = {
4851
allowQuantity: false,
@@ -95,10 +98,13 @@ Uses the `subscription_id` to contact Paddle API and checks whether the given lo
9598
'use strict'
9699

97100
const paddleIntegration = require('@discue/paddle-firebase-integration')
98-
// initialize api and subscription hooks first
101+
99102
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
100-
const hookStorage = new paddleIntegration.SubscriptionHooks('api_clients')
101-
const subscriptions = new paddleIntegration.SubscriptionHydration('api_clients', { api, hookStorage })
103+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
104+
const hookStorage = new paddleIntegration.SubscriptionHooks({ storage })
105+
const subscriptionInfo = new paddleIntegration.SubscriptionInfo({ api, storage })
106+
107+
const subscriptions = new paddleIntegration.SubscriptionHydration('api_clients', { api, hookStorage, subscriptionInfo })
102108

103109
router.post('/subscriptions/cancel', async (req, res) => {
104110
const { _dsq: { clientId } = {}, body } = req
@@ -109,7 +115,7 @@ router.post('/subscriptions/cancel', async (req, res) => {
109115
// cancel subscription
110116
// ..
111117
// then hydrate cancellation
112-
await subscriptionInfo.hydrateSubscriptionCancelled([clientId], { subscription_id })
118+
await subscriptions.hydrateSubscriptionCancelled([clientId], { subscription_id })
113119
sendOkNoContent({ res })
114120
} catch (e) {
115121
console.error(`Hydration failed with ${e} at ${e.stack}}`)

README_SUBSCRIPTION_INFO.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ High level wrapper for Paddle API. Manages locally stored data and interacts wit
99
- [Cancel a subscription](#cancel-a-subscription)
1010
- [Update a subscription plan](#update-a-subscription-plan)
1111

12-
:information_source: The API component of this module will be loaded asynchronously to preserve backwards compatibility with commonjs. This is achieved by returning a proxy for the entire `paddle-integration-firestore` module. The reactivity a proxy provides allows us to add the API module then at a later point to the module instance. The drawback is, we do not return named exports and, therefore, cannot not enable destructuring in ES modules.
12+
:information_source: The API component of this module will be loaded asynchronously to preserve backwards compatibility with commonjs. This is achieved by returning a proxy for the entire `paddle-integration-mongodb` module. The reactivity a proxy provides allows us to add the API module then at a later point to the module instance. The drawback is, we do not return named exports and, therefore, cannot not enable destructuring in ES modules.
1313

1414
## Get subscription infos
1515
Returns all available information about a subscription. Will include the `start` and (optionally) `end` date, the `status_trail`, and the `payments_trail` and a property indicating whether the subscription is currently `active`.
@@ -20,7 +20,8 @@ Returns all available information about a subscription. Will include the `start`
2020
const paddleIntegration = require('@discue/paddle-firebase-integration')
2121
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
2222
// pass the path to the collection here
23-
const subscriptions = new paddleIntegration.SubscriptionInfo('api_clients', { api })
23+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
24+
const subscriptions = new paddleIntegration.SubscriptionInfo({ api, storage })
2425

2526
const PREMIUM_SUBSCRIPTION_PLAN_ID = '123'
2627

@@ -51,7 +52,8 @@ Returns list of payments for for all subscriptions associated with the given use
5152
const paddleIntegration = require('@discue/paddle-firebase-integration')
5253
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
5354
// pass the path to the collection here
54-
const subscriptions = new paddleIntegration.SubscriptionInfo('api_clients', { api })
55+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
56+
const subscriptions = new paddleIntegration.SubscriptionInfo({ api, storage })
5557

5658
const PREMIUM_SUBSCRIPTION_PLAN_ID = '123'
5759

@@ -80,7 +82,8 @@ Returns list of payments for for all subscriptions associated with the given use
8082
const paddleIntegration = require('@discue/paddle-firebase-integration')
8183
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
8284
// pass the path to the collection here
83-
const subscriptions = new paddleIntegration.SubscriptionInfo('api_clients', { api })
85+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
86+
const subscriptions = new paddleIntegration.SubscriptionInfo({ api, storage })
8487

8588
const PREMIUM_SUBSCRIPTION_PLAN_ID = '123'
8689

@@ -109,7 +112,8 @@ Will return the status for all subscriptions associated with the given user/api_
109112
const paddleIntegration = require('@discue/paddle-firebase-integration')
110113
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
111114
// pass the path to the collection here
112-
const subscriptions = new paddleIntegration.SubscriptionInfo('api_clients', { api })
115+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
116+
const subscriptions = new paddleIntegration.SubscriptionInfo({ api, storage })
113117

114118
const PREMIUM_SUBSCRIPTION_PLAN_ID = '123'
115119

@@ -139,7 +143,8 @@ Cancels a specific subscription plan. The subscription plan id must be passed.
139143
const paddleIntegration = require('@discue/paddle-firebase-integration')
140144
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
141145
// pass the path to the collection here
142-
const subscriptions = new paddleIntegration.SubscriptionInfo('api_clients', { api })
146+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
147+
const subscriptions = new paddleIntegration.SubscriptionInfo({ api, storage })
143148

144149
const PREMIUM_SUBSCRIPTION_PLAN_ID = '123'
145150

@@ -163,7 +168,8 @@ Updates a subscription plan. The previous one will be cancelled and the new one
163168
const paddleIntegration = require('@discue/paddle-firebase-integration')
164169
const api = new paddleIntegration.Api({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
165170
// pass the path to the collection here
166-
const subscriptions = new paddleIntegration.SubscriptionInfo('api_clients', { api })
171+
const storage = paddleIntegration.subscriptionStorage({ url: 'mongodb://localhost:27017' })
172+
const subscriptions = new paddleIntegration.SubscriptionInfo({ api, storage })
167173

168174
const PREMIUM_SUBSCRIPTION_PLAN_ID = '123'
169175

0 commit comments

Comments
 (0)