Skip to content

Commit

Permalink
feat(api): add list products method
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Oct 12, 2022
1 parent 96f6011 commit be6f391
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/paddle/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const BASE_URL = 'https://vendors.paddle.com/api/2.0/'
const PATH_CANCEL_SUBSCRIPTION = 'subscription/users_cancel'
const PATH_LIST_USERS = 'subscription/users'
const PATH_UPDATE_USERS = 'subscription/users/update'
const PATH_LIST_PRODUCTS = 'product/get_products'

module.exports = class {

Expand Down Expand Up @@ -66,6 +67,19 @@ module.exports = class {
}))
}

/**
*
* @returns
*/
async listProducts() {
return this._returnResponseIf200(this._got(PATH_LIST_PRODUCTS, {
form: {
vendor_id: this._vendorId,
vendor_auth_code: this._authCode
}
}))
}

/**
*
* @param {Object} subscription the target subscription object
Expand Down
16 changes: 16 additions & 0 deletions test-e2e/spec/api.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const { test, expect } = require('@playwright/test')

let api

test.beforeAll(async () => {
const API = await (await import('../../lib/paddle/api.js')).default
api = new API({ useSandbox: true, authCode: process.env.AUTH_CODE, vendorId: process.env.VENDOR_ID })
await api.init()
})

test.only('list all products', async () => {
const products = await api.listProducts()
expect(products.products).toHaveLength(0)
})

0 comments on commit be6f391

Please sign in to comment.