diff --git a/apps/stripe/bundle/bots/runaction/subscription_list/bot.ts b/apps/stripe/bundle/bots/runaction/subscription_list/bot.ts new file mode 100644 index 0000000..f14fb3c --- /dev/null +++ b/apps/stripe/bundle/bots/runaction/subscription_list/bot.ts @@ -0,0 +1,33 @@ +import { RunActionBotApi } from "@uesio/bots" +import { Params } from "@uesio/app/bots/runaction/uesio/stripe/subscription_list" +import { Stripe } from "stripe" + +export default function subscription_retrieve(bot: RunActionBotApi) { + const params = bot.params.getAll() as Params + const { customer } = params + const actionName = bot.getActionName() + + if (actionName !== "subscription_list") { + bot.addError("unsupported action name: " + actionName) + return + } + + const baseURL = bot.getIntegration().getBaseURL() + const result = bot.http.request< + Stripe.SubscriptionListParams, + Stripe.Subscription + >({ + method: "GET", + url: baseURL + `/v1/subscriptions`, + body: { + customer: customer as string, + }, + }) + + if (result.code !== 200) { + bot.addError("could not complete subscription list: " + result.code) + return + } + + bot.addResult("subscriptions", result.body) +} diff --git a/apps/stripe/bundle/bots/runaction/subscription_list/bot.yaml b/apps/stripe/bundle/bots/runaction/subscription_list/bot.yaml new file mode 100644 index 0000000..7fa04e7 --- /dev/null +++ b/apps/stripe/bundle/bots/runaction/subscription_list/bot.yaml @@ -0,0 +1,9 @@ +name: subscription_list +public: true +type: RUNACTION +dialect: TYPESCRIPT +params: + - name: customer + label: Customer Id + type: TEXT + required: true diff --git a/package-lock.json b/package-lock.json index 625f063..3bf84b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "prettier": "2.7.1", "react": "^17.0.2", "react-dom": "^17.0.2", + "stripe": "^14.18.0", "ts-jest": "^29.1.1", "ts-node": "10.9.1", "typescript": "4.8.4" @@ -8502,6 +8503,21 @@ } ] }, + "node_modules/qs": { + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", @@ -9202,6 +9218,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/stripe": { + "version": "14.18.0", + "resolved": "https://registry.npmjs.org/stripe/-/stripe-14.18.0.tgz", + "integrity": "sha512-yLqKPqYgGJbMxrQiE4+i2i00ZVA2NRIZbZ1rejzj5XR3F3Uc+1iy9QE133knZudhVGMw367b8vTpB8D9pYMETw==", + "dev": true, + "dependencies": { + "@types/node": ">=8.1.0", + "qs": "^6.11.0" + }, + "engines": { + "node": ">=12.*" + } + }, "node_modules/strong-log-transformer": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz", diff --git a/package.json b/package.json index 5bc6e66..e01a246 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "prettier": "2.7.1", "react": "^17.0.2", "react-dom": "^17.0.2", + "stripe": "^14.18.0", "ts-jest": "^29.1.1", "ts-node": "10.9.1", "typescript": "4.8.4"