Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
feat(paddle): support subscription plan and billing date changes
Rudy Celekli775b31e186de
diff --git a/tests/clis/paddle-subscription-updates.test.cjs b/tests/clis/paddle-subscription-updates.test.cjsnew file mode 100644index 0000000..1ad5caa--- /dev/null+++ b/tests/clis/paddle-subscription-updates.test.cjs@@ -0,0 +1,96 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawn } = require('node:child_process')+const http = require('node:http')+const path = require('node:path')+const cli = path.resolve(__dirname, '../../tools/clis/paddle.js')++async function run(args) {+ const requests = []+ const server = http.createServer((req, res) => {+ let body = ''+ req.on('data', chunk => { body += chunk })+ req.on('end', () => {+ const record = { method: req.method, path: req.url, body: JSON.parse(body) }+ requests.push(record)+ res.writeHead(200, { 'content-type': 'application/json' })+ res.end(JSON.stringify({ data: record }))+ })+ })+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))+ const local = `http://127.0.0.1:${server.address().port}`+ const source = `const originalFetch = global.fetch;+ global.fetch = (url, options) => {+ const request = new URL(url);+ if (request.origin !== 'https://api.paddle.com') throw new Error('Unexpected external request');+ return originalFetch(${JSON.stringify(local)} + request.pathname + request.search, options);+ };+ process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ try {+ const child = spawn(process.execPath, ['-e', source], {+ env: { ...process.env, PADDLE_API_KEY: 'test-only-key', PADDLE_SANDBOX: 'false' },+ stdio: ['ignore', 'pipe', 'pipe'],+ })+ let output = '', errors = ''+ child.stdout.on('data', data => { output += data })+ child.stderr.on('data', data => { errors += data })+ const timeout = setTimeout(() => child.kill('SIGKILL'), 5000)+ const exit = await new Promise((resolve, reject) => {+ child.once('error', reject)+ child.once('close', code => resolve(code))+ }).finally(() => clearTimeout(timeout))+ const result = JSON.parse(output)+ // These tests check request contracts; local validation exit conventions+ // are covered separately. Successful requests must exit zero.+ if (!result.error || result.usage) assert.equal(exit, 0, errors)+ else assert.ok(exit === 0 || exit === 1, errors)+ return { result, requests }+ } finally {+ server.closeAllConnections()+ await new Promise(resolve => server.close(resolve))+ }+}+const update = ['subscriptions', 'update', '--id', 'sub_01example']+const items = [{ price_id: 'pri_existing', quantity: 2 }, { price_id: 'pri_new', quantity: 1 }]+test('replaces the complete subscription item list with explicit proration', async () => {+ const { requests } = await run([...update, '--items', JSON.stringify(items), '--proration-billing-mode', 'prorated_next_billing_period'])+ assert.deepEqual(requests, [{ method: 'PATCH', path: '/subscriptions/sub_01example', body: { items, proration_billing_mode: 'prorated_next_billing_period' } }])+})+test('changes the next billing date with explicit proration', async () => {+ const { requests } = await run([...update, '--next-billed-at', '2026-11-01T00:00:00Z', '--proration-billing-mode', 'do_not_bill'])+ assert.deepEqual(requests[0].body, { next_billed_at: '2026-11-01T00:00:00Z', proration_billing_mode: 'do_not_bill' })+})+for (const change of [['--items', JSON.stringify(items)], ['--next-billed-at', '2026-11-01T00:00:00Z']]) {+ test(`${change[0]} requires an explicit billing policy before making a request`, async () => {+ const { result, requests } = await run([...update, ...change])+ assert.match(result.error, /proration-billing-mode required/)+ assert.equal(requests.length, 0)+ })+}+for (const value of ['{', '{}', '[]', 'null']) {+ test(`rejects invalid items ${value} before making a request`, async () => {+ const { result, requests } = await run([...update, '--items', value, '--proration-billing-mode', 'do_not_bill'])+ assert.match(result.error, /JSON|nonempty/)+ assert.equal(requests.length, 0)+ })+}+test('previews both supported changes without sending or exposing credentials', async () => {+ const { result, requests } = await run([...update, '--items', JSON.stringify(items), '--next-billed-at', '2026-11-01T00:00:00Z', '--proration-billing-mode', 'full_next_billing_period', '--dry-run'])+ assert.deepEqual(result.body, { items, next_billed_at: '2026-11-01T00:00:00Z', proration_billing_mode: 'full_next_billing_period' })+ assert.equal(result.headers.Authorization, '***')+ assert.equal(JSON.stringify(result).includes('test-only-key'), false)+ assert.equal(requests.length, 0)+})+test('preserves scheduled-change removal without requiring proration', async () => {+ const { requests } = await run([...update, '--scheduled-change', 'null'])+ assert.deepEqual(requests[0].body, { scheduled_change: null })+})+test('preserves the existing proration-only payload', async () => {+ const { requests } = await run([...update, '--proration-billing-mode', 'do_not_bill'])+ assert.deepEqual(requests[0].body, { proration_billing_mode: 'do_not_bill' })+})+test('preserves no-argument usage without requesting or requiring credentials', async () => {+ const { result, requests } = await run([])+ assert.ok(result.usage.subscriptions)+ assert.equal(requests.length, 0)+})diff --git a/tools/clis/paddle.js b/tools/clis/paddle.jsindex d414a2a..c8066c8 100755--- a/tools/clis/paddle.js+++ b/tools/clis/paddle.js@@ -203,6 +203,16 @@ async function main() {const id = args.idif (!id) { result = { error: '--id required' }; break }const body = {}+ if (args.items !== undefined) {+ try { body.items = JSON.parse(args.items) } catch { result = { error: 'Invalid JSON in --items' }; break }+ if (!Array.isArray(body.items) || body.items.length === 0) {+ result = { error: '--items must be a nonempty JSON array of {price_id, quantity}' }; break+ }+ }+ if (args['next-billed-at'] !== undefined) body.next_billed_at = args['next-billed-at']+ if ((args.items !== undefined || args['next-billed-at'] !== undefined) && !args['proration-billing-mode']) {+ result = { error: '--proration-billing-mode required when changing items or the next billing date' }; break+ }if (args['proration-billing-mode']) body.proration_billing_mode = args['proration-billing-mode']if (args['scheduled-change']) {try { body.scheduled_change = JSON.parse(args['scheduled-change']) } catch { result = { error: 'Invalid JSON in --scheduled-change' }; break }@@ -372,7 +382,7 @@ async function main() {products: 'products [list | get --id <id> | create --name <n> --tax-category <cat> | update --id <id>]',prices: 'prices [list | get --id <id> | create --product-id <id> --amount <amt> [--currency USD] [--interval month --frequency 1] | update --id <id>]',customers: 'customers [list | get --id <id> | create --email <email> [--name <name>] | update --id <id>]',- subscriptions: 'subscriptions [list | get --id <id> | update --id <id> | cancel --id <id> [--effective-from next_billing_period] | pause --id <id> | resume --id <id>]',+ subscriptions: 'subscriptions [list | get --id <id> | update --id <id> [--items <json> | --next-billed-at <ISO>] [--proration-billing-mode <mode>] | cancel --id <id> [--effective-from next_billing_period] | pause --id <id> | resume --id <id>]',transactions: 'transactions [list | get --id <id> | create --items <json>]',discounts: 'discounts [list | get --id <id> | create --amount <amt> --type <type> [--code <code>] [--max-uses <count>]]',adjustments: 'adjustments [list | create --transaction-id <id> --action <action> --reason <reason> --items <json>]',diff --git a/tools/integrations/paddle.md b/tools/integrations/paddle.mdindex aec2d11..db83b6d 100644--- a/tools/integrations/paddle.md+++ b/tools/integrations/paddle.md@@ -88,6 +88,24 @@ GET https://api.paddle.com/subscriptions?status=activeGET https://api.paddle.com/subscriptions/{subscription_id}```+### Change a subscription plan or billing date++Use the subscription update operation, with an explicit proration choice:++```bash+node tools/clis/paddle.js subscriptions update --id sub_01example \+ --items '[{"price_id":"pri_01example","quantity":1}]' \+ --proration-billing-mode prorated_next_billing_period --dry-run++node tools/clis/paddle.js subscriptions update --id sub_01example \+ --next-billed-at 2026-11-01T00:00:00Z \+ --proration-billing-mode do_not_bill --dry-run+```++`--items` replaces the **complete** subscription item list. Include retained items; omitted items are removed. Check the dry-run payload and the chosen billing mode before running without `--dry-run`. The CLI does not pick a billing policy for you. Existing `--scheduled-change null` still removes a scheduled change without an item or billing-date edit.++[Paddle's update contract](https://developer.paddle.com/api-reference/subscriptions/update-subscription/) requires `proration_billing_mode` when changing items or the next billing date; its [proration guide](https://developer.paddle.com/concepts/subscriptions/proration/) explains the available modes.+### Cancel a subscription```bash