Skip to content

Commit

Permalink
feat(api): allow pagination and fetching all subs
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Oct 12, 2022
1 parent 1fd233c commit df3ecae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 19 additions & 3 deletions lib/paddle/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,29 @@ module.exports = class {
}

/**
* Note: Returns all active, past_due, trialing and paused subscription
* plans if not specified.
*
* @param {String} state list only subscriptions with given state
* @param {String} state list only subscriptions with given state. Lists only active subs by default.
* @param {Number} perPage limit the response to a certain number of results
* @returns
*/
async listSubscriptions(state = 'active') {
async listSubscriptions(state = 'active', perPage) {
const form = {
vendor_id: this._vendorId,
vendor_auth_code: this._authCode
}
if (state) {
form.state = state
}
if (perPage) {
form.results_per_page = perPage
}
return this._returnResponseIf200(this._got(PATH_LIST_USERS, {
form
}))
}

/**
*
* @param {String} plan return only specific plan info
Expand Down Expand Up @@ -146,7 +163,6 @@ module.exports = class {
const response = await promise
const { statusCode, body } = response
const data = JSON.parse(body)

if (statusCode === 200 && data.success === true) {
return data.response || true
} else {
Expand Down
8 changes: 6 additions & 2 deletions test-e2e/spec/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ test('list all products', async () => {
expect(products.products).toHaveLength(0)
})


test('list all subscriptions', async () => {
test('list all active subscriptions', async () => {
const subs = await api.listSubscriptions()
expect(subs).toHaveLength(0)
})

test('list all deleted subscriptions', async () => {
const subs = await api.listSubscriptions('deleted', 51)
expect(subs.length).toBeGreaterThan(50)
})

test('list all plans', async () => {
const subs = await api.listPlans()
expect(subs).toHaveLength(2)
Expand Down

0 comments on commit df3ecae

Please sign in to comment.