-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jobs): add cancel-stripe-subscription job
- v3.66.8
- v3.66.7
- v3.66.6
- v3.66.5
- v3.66.4
- v3.66.3
- v3.66.2
- v3.66.1
- v3.66.0
- v3.65.1
- v3.65.0
- v3.64.3
- v3.64.2
- v3.64.1
- v3.64.0
- v3.63.7
- v3.63.6
- v3.63.5
- v3.63.4
- v3.63.3
- v3.63.2
- v3.63.1
- v3.63.0
- v3.62.8
- v3.62.7
- v3.62.6
- v3.62.5
- v3.62.4
- v3.62.3
- v3.62.2
- v3.62.1
- v3.62.0
- v3.61.6
- v3.61.5
- v3.61.4
- v3.61.3
- v3.61.2
- v3.61.1
- v3.61.0
- v3.60.0
- v3.59.0
- v3.58.4
- v3.58.3
- v3.58.2
- v3.58.1
- v3.58.0
- v3.57.7
- v3.57.6
- v3.57.5
- v3.57.4
- v3.57.3
- v3.57.2
- v3.57.1
- v3.57.0
- v3.56.0
- v3.55.3
- v3.55.2
- v3.55.1
- v3.55.0
- v3.54.0
- v3.53.0
- v3.52.0
- v3.51.1
- v3.51.0
- v3.50.6
- v3.50.5
- v3.50.4
- v3.50.3
- v3.50.2
- v3.50.1
- v3.50.0
- v3.49.3
- v3.49.2
- v3.49.1
- v3.49.0
- v3.48.0
- v3.47.0
- v3.46.3
- v3.46.2
- v3.46.1
- v3.46.0
- v3.45.5
- v3.45.4
- v3.45.3
- v3.45.2
- v3.45.1
- v3.45.0
- v3.44.0
- v3.43.2
- v3.43.1
- v3.43.0
- v3.42.3
- v3.42.2
- v3.42.1
- v3.42.0
- v3.41.3
- v3.41.2
- v3.41.1
- v3.41.0
- v3.40.4
- v3.40.3
- v3.40.2
- v3.40.1
- v3.40.0
- v3.39.0
- v3.38.0
- v3.37.0
- v3.36.0
- v3.35.1
- v3.35.0
- v3.34.1
- v3.34.0
- v3.33.0
- v3.32.8
- v3.32.7
- v3.32.6
- v3.32.5
- v3.32.4
- v3.32.3
- v3.32.2
- v3.32.1
- v3.32.0
- v3.31.6
- v3.31.5
- v3.31.4
- v3.31.3
- v3.31.2
- v3.31.1
- v3.31.0
- v3.30.0
- v3.29.0
- v3.28.4
- v3.28.3
- v3.28.2
- v3.28.1
- v3.28.0
- v3.27.0
- v3.26.1
- v3.26.0
- v3.25.1
- v3.25.0
- v3.24.3
- v3.24.2
- v3.24.1
- v3.24.0
- v3.23.0
- v3.22.3
- v3.22.2
- v3.22.1
- v3.22.0
- v3.21.5
- v3.21.4
- v3.21.3
- v3.21.2
- v3.21.1
- v3.21.0
- v3.20.0
- v3.19.1
- v3.19.0
- v3.18.0
- v3.17.0
- v3.16.0
- v3.15.0
- v3.14.3
- v3.14.2
- v3.14.1
- v3.14.0
- v3.13.0
- v3.12.1
- v3.12.0
- v3.11.1
- v3.11.0
- v3.10.6
- v3.10.5
- v3.10.4
- v3.10.3
- v3.10.2
- v3.10.1
- v3.10.0
- v3.9.0
- v3.8.1
- v3.8.0
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.0
- v2.49.0
- v2.48.3
- v2.48.2
- v2.48.1
- v2.48.0
- v2.47.0
- v2.46.2
- v2.46.1
- v2.46.0
- v2.45.4
- v2.45.3
- v2.45.2
- v2.45.1
- v2.45.0
- v2.44.0
- v2.43.0
- v2.42.0
- v2.41.1
- v2.41.0
- v2.40.3
- v2.40.2
- v2.40.1
- v2.40.0
- v2.39.3
- v2.39.2
- v2.39.1
- v2.39.0
- v2.38.0
- v2.37.0
- v2.36.17
- v2.36.16
- v2.36.15
- v2.36.14
- v2.36.13
- v2.36.12
- v2.36.11
- v2.36.10
- v2.36.9
- v2.36.8
- v2.36.7
- v2.36.6
- v2.36.5
- v2.36.4
- v2.36.3
- v2.36.2
- v2.36.1
- v2.36.0
- v2.35.7
- v2.35.6
- v2.35.5
- v2.35.4
- v2.35.3
- v2.35.2
- v2.35.1
- v2.35.0
- v2.34.8
- v2.34.7
- v2.34.6
- v2.34.5
- v2.34.4
- v2.34.3
- v2.34.2
- v2.34.1
- v2.34.0
- v2.33.0
- v2.32.3
- v2.32.2
- v2.32.1
- v2.32.0
- v2.31.0
- v2.30.2
- v2.30.1
- v2.30.0
- v2.29.2
- v2.29.1
- v2.29.0
- v2.28.0
- v2.27.3
- v2.27.2
- v2.27.1
- v2.27.0
- v2.26.2
- v2.26.1
- v2.26.0
- v2.25.1
- v2.25.0
- v2.24.1
- v2.24.0
- v2.23.5
- v2.23.4
- v2.23.3
- v2.23.2
- v2.23.1
- v2.23.0
- v2.22.1
- v2.22.0
- v2.21.3
- v2.21.2
- v2.21.1
- v2.21.0
- v2.20.0
- v2.19.1
- v2.19.0
- v2.18.2
- v2.18.1
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const env = require('../lib/env') | ||
const stripe = require('stripe')(env.STRIPE_SECRET_KEY) | ||
const dbs = require('../lib/dbs') | ||
const upsert = require('../lib/upsert') | ||
|
||
module.exports = async function ({ accountId, stripeSubscriptionId }) { | ||
const { payments } = await dbs() | ||
await stripe.subscriptions.del( | ||
stripeSubscriptionId, | ||
async (err, confirmation) => { | ||
if (err) { | ||
throw err | ||
} | ||
await upsert(payments, accountId, { | ||
stripeSubscriptionId: null | ||
}) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { test, tearDown } = require('tap') | ||
const nock = require('nock') | ||
const worker = require('../../jobs/cancel-stripe-subscription') | ||
|
||
const dbs = require('../../lib/dbs') | ||
|
||
nock.disableNetConnect() | ||
nock.enableNetConnect('localhost') | ||
|
||
test('Cancel Stripe Subscription', async t => { | ||
const { payments } = await dbs() | ||
t.plan(2) | ||
|
||
nock('https://api.stripe.com/v1') | ||
.delete('/subscriptions/345') | ||
.reply(200, () => { | ||
t.pass('Stripe called') | ||
return { | ||
stripeSubscriptionId: '345' | ||
} | ||
}) | ||
|
||
await payments.put({ | ||
_id: '123', | ||
plan: 'team', | ||
stripeCustomerId: 'cus_abc', | ||
stripeItemId: 'si_xyz', | ||
stripeSubscriptionId: '345' | ||
}) | ||
|
||
await worker({ | ||
accountId: '123', | ||
stripeSubscriptionId: '345' | ||
}) | ||
|
||
const payment = await payments.get('123') | ||
t.is(payment.stripeSubscriptionId, null) | ||
t.end() | ||
}) | ||
|
||
tearDown(async () => { | ||
const { payments } = await dbs() | ||
await payments.remove(await payments.get('123')) | ||
}) |