Skip to content

Commit

Permalink
feat: add method to get subscription info (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin authored Nov 27, 2024
1 parent d880dca commit 2335fa8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/sails-lemonsqueezy/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ const methods = require('./machines')
module.exports = {
identity: 'sails-lemonsqueezy',
config: {},
checkout: methods.checkout
checkout: methods.checkout,
subscription: {
get: methods.subscription.get
}
}
5 changes: 4 additions & 1 deletion packages/sails-lemonsqueezy/machines/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
checkout: require('./checkout')
checkout: require('./checkout'),
subscription: {
get: require('./subscription/get')
}
}
41 changes: 41 additions & 0 deletions packages/sails-lemonsqueezy/machines/subscription/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const fetch = require('../../helpers/fetch')

module.exports = require('machine').build({
friendly: 'Get Subscription',
description: 'Get a subscription by ID.',
moreInfoUrl: 'https://docs.lemonsqueezy.com/api/subscriptions',
inputs: {
apiKey: require('../../helpers/parameters').LEMON_SQUEEZY_API_KEY,
id: {
type: 'string',
description: 'The ID of the subscription to get.',
allowNull: true
}
},
exits: {
success: {
outputFriendlyName: 'Subscription',
outputDescription: 'The subscription that was retrieved.'
},
error: {
outputFriendlyName: 'Error',
outputDescription: 'An unexpected error occurred.'
}
},
fn: async function ({ apiKey, id }, exits) {
const adapterConfig = require('../../adapter').config

const subscription = await fetch(`/subscriptions/${id}`, {
method: 'GET',
headers: {
authorization: `Bearer ${apiKey || adapterConfig.apiKey}`
}
})
if (subscription.errors) {
const errors = subscription.errors
return exits.error(errors)
}

return exits.success(subscription)
}
})

0 comments on commit 2335fa8

Please sign in to comment.