@payloadcms/plugin-stripe 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # Payload Stripe Plugin
2
+
3
+ [![NPM](https://img.shields.io/npm/v/@payloadcms/plugin-stripe)](https://www.npmjs.com/package/@payloadcms/plugin-stripe)
4
+
5
+ A plugin for [Payload CMS](https://github.com/payloadcms/payload) to manage a [Stripe](https://stripe.com/) account through Payload.
6
+
7
+ Core features:
8
+ - Layers your Stripe account with Payload access control
9
+ - Opens custom routes to interface with the Stripe REST API
10
+ - Handles Stripe webhooks to allow for a two-way data sync
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ yarn add @payloadcms/plugin-stripe
16
+ # OR
17
+ npm i @payloadcms/plugin-stripe
18
+ ```
19
+
20
+ ## Basic Usage
21
+
22
+ In the `plugins` array of your [Payload config](https://payloadcms.com/docs/configuration/overview), call the plugin with [options](#options):
23
+
24
+ ```js
25
+ import { buildConfig } from 'payload/config';
26
+ import stripe from '@payloadcms/plugin-stripe';
27
+
28
+ const config = buildConfig({
29
+ plugins: [
30
+ stripe({
31
+ stripeSecretKey: process.env.STRIPE_SECRET_KEY,
32
+ })
33
+ ]
34
+ });
35
+
36
+ export default config;
37
+ ```
38
+
39
+ ### Options
40
+
41
+ - `stripeSecretKey`
42
+
43
+ Required. Your Stripe secret key.
44
+
45
+ - `stripeWebhookEndpointSecret`
46
+
47
+ Optional. Your Stripe webhook endpoint secret. This is needed only if you wish to sync data from Stripe to Payload.
48
+
49
+ - `webhooks`
50
+
51
+ Optional. An object of Stripe webhook handlers, keyed to the name of the event. See [webhooks](#webhooks) for more details or for a list of all available webhooks, see [here](https://stripe.com/docs/cli/trigger#trigger-event).
52
+
53
+ ### Routes
54
+
55
+ The following routes are automatically opened to allow you to interact with the Stripe API behind Payload access control. This allows you to read and make updates to your account.
56
+
57
+ >NOTE: the `/api` part of these routes may be different based on the settings defined in your Payload config.
58
+
59
+ - `POST /api/stripe/rest`
60
+
61
+ Calls the given [Stripe REST API](https://stripe.com/docs/api) method and returns the result.
62
+
63
+ ```
64
+ const res = await fetch(`/api/stripe/rest`, {
65
+ body: JSON.stringify({
66
+ stripeMethod: "stripe.subscriptions.list",
67
+ stripeMethodArgs: {
68
+ customer: "abc"
69
+ }
70
+ })
71
+ })
72
+ ```
73
+
74
+ - `POST /api/stripe/webhooks`
75
+
76
+ Returns an http status code. This is where all Stripe webhook events are sent to be handled. See [webhooks](#webhooks).
77
+
78
+ ### Webhooks
79
+
80
+ This plugin also allows for a two-way data sync from Stripe to Payload using [Stripe webhooks](https://stripe.com/docs/webhooks). Webhooks listen for events on your Stripe account so you can trigger reactions to them. To enable webhooks:
81
+
82
+ 1. Login and [create a new webhook](https://dashboard.stripe.com/test/webhooks/create) from the Stripe dashboard
83
+ 1. Paste `/api/stripe/webhooks` as the "Webhook Endpoint URL"
84
+ 1. Select which events to broadcast
85
+ 1. Then, handle these events using the `webhooks` portion of this plugin's config:
86
+
87
+ ```js
88
+ import { buildConfig } from 'payload/config';
89
+ import stripe from '@payloadcms/plugin-stripe';
90
+
91
+ const config = buildConfig({
92
+ plugins: [
93
+ stripe({
94
+ stripeSecretKey: process.env.STRIPE_SECRET_KEY,
95
+ stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOKS_ENDPOINT_SECRET,
96
+ webhooks: {
97
+ 'customer.subscription.updated': () => {}
98
+ }
99
+ })
100
+ ]
101
+ });
102
+
103
+ export default config;
104
+ ```
105
+
106
+ For a full list of available webhooks, see [here](https://stripe.com/docs/cli/trigger#trigger-event).
107
+
108
+ ## TypeScript
109
+
110
+ All types can be directly imported:
111
+
112
+ ```js
113
+ import {
114
+ StripeConfig,
115
+ WebhookHandler
116
+ } from '@payloadcms/plugin-stripe/dist/types';
117
+ ```
118
+
119
+ ### Development
120
+
121
+ This plugin can be developed locally using any Stripe account that you have access to. Then:
122
+
123
+ ```bash
124
+ git clone git@github.com:payloadcms/plugin-stripe.git \
125
+ cd plugin-stripe && yarn \
126
+ cd demo && yarn \
127
+ cp .env.example .env \
128
+ vim .env \ # add your Stripe creds to this file
129
+ yarn dev
130
+ ```
131
+
132
+ Now you have a running Payload server with this plugin installed, so you can authenticate and begin hitting the routes. To do this, open [Postman](https://www.postman.com/) and import [our config](https://github.com/payloadcms/plugin-stripe/blob/main/src/payload-stripe-plugin.postman_collection.json). First, login to retrieve your Payload access token. This token is automatically attached to the header of all other requests.
133
+
134
+ ## Screenshots
135
+
136
+ <!-- ![screenshot 1](https://github.com/@payloadcms/plugin-stripe/blob/main/images/screenshot-1.jpg?raw=true) -->
@@ -0,0 +1,4 @@
1
+ import { Config } from 'payload/config';
2
+ import { StripeConfig } from './types';
3
+ declare const stripe: (stripeConfig: StripeConfig) => (config: Config) => Config;
4
+ export default stripe;
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ var rest_1 = require("./routes/rest");
24
+ var webhooks_1 = require("./routes/webhooks");
25
+ var stripe = function (stripeConfig) { return function (config) {
26
+ return (__assign(__assign({}, config), { endpoints: __spreadArray(__spreadArray([], (config === null || config === void 0 ? void 0 : config.endpoints) || [], true), [
27
+ {
28
+ path: '/stripe/webhooks',
29
+ method: 'post',
30
+ handler: function (req, res, next) {
31
+ (0, webhooks_1.stripeWebhooks)(req, res, next, stripeConfig);
32
+ }
33
+ },
34
+ {
35
+ path: '/stripe/rest',
36
+ method: 'post',
37
+ handler: function (req, res, next) {
38
+ (0, rest_1.stripeREST)(req, res, next, stripeConfig);
39
+ }
40
+ },
41
+ ], false) }));
42
+ }; };
43
+ exports.default = stripe;
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,sCAA2C;AAC3C,8CAAmD;AAGnD,IAAM,MAAM,GAAG,UAAC,YAA0B,IAAK,OAAA,UAAC,MAAc;IAC5D,OAAO,uBACF,MAAM,KACT,SAAS,kCACJ,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,KAAI,EAAE;YAC1B;gBACE,IAAI,EAAE,kBAAkB;gBACxB,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,UAAC,GAAG,EAAE,GAAG,EAAE,IAAI;oBACtB,IAAA,yBAAc,EAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;gBAC9C,CAAC;aACF;YACD;gBACE,IAAI,EAAE,cAAc;gBACpB,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,UAAC,GAAG,EAAE,GAAG,EAAE,IAAI;oBACtB,IAAA,iBAAU,EAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;gBAC1C,CAAC;aACF;qBAEH,CAAA;AACJ,CAAC,EArB8C,CAqB9C,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { PayloadRequest } from 'payload/dist/types';
2
+ import { StripeConfig } from '../types';
3
+ export declare const getAllProducts: (req: PayloadRequest, res: any, next: any, stripeConfig: StripeConfig) => Promise<any>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.getAllProducts = void 0;
43
+ var errors_1 = require("payload/errors");
44
+ var stripe_1 = __importDefault(require("stripe"));
45
+ var getAllProducts = function (req, res, next, stripeConfig) { return __awaiter(void 0, void 0, void 0, function () {
46
+ var stripeSecretKey, stripe, id, user, products, err_1;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ stripeSecretKey = stripeConfig.stripeSecretKey;
51
+ stripe = new stripe_1.default(stripeSecretKey, { apiVersion: '2022-08-01' });
52
+ _a.label = 1;
53
+ case 1:
54
+ _a.trys.push([1, 3, , 4]);
55
+ id = req.params.id, user = req.user;
56
+ if (!user) {
57
+ throw new errors_1.Forbidden();
58
+ }
59
+ return [4 /*yield*/, stripe.products.list(({
60
+ limit: 20,
61
+ }))];
62
+ case 2:
63
+ products = _a.sent();
64
+ if (!(products === null || products === void 0 ? void 0 : products.data)) {
65
+ return [2 /*return*/, res.status(404)];
66
+ }
67
+ return [2 /*return*/, res.json({
68
+ products: products
69
+ })];
70
+ case 3:
71
+ err_1 = _a.sent();
72
+ return [2 /*return*/, next(err_1)];
73
+ case 4: return [2 /*return*/];
74
+ }
75
+ });
76
+ }); };
77
+ exports.getAllProducts = getAllProducts;
78
+ //# sourceMappingURL=getAllProducts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAllProducts.js","sourceRoot":"","sources":["../../src/routes/getAllProducts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAA2C;AAC3C,kDAA4B;AAGrB,IAAM,cAAc,GAAG,UAC5B,GAAmB,EACnB,GAAQ,EACR,IAAS,EACT,YAA0B;;;;;gBAElB,eAAe,GAAK,YAAY,gBAAjB,CAAkB;gBAEnC,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;;;;gBAGrD,EAAE,GAAa,GAAG,UAAhB,EAAI,IAAI,GAAK,GAAG,KAAR,CAAS;gBAErC,IAAI,CAAC,IAAI,EAAE;oBACT,MAAM,IAAI,kBAAS,EAAE,CAAC;iBACvB;gBAEgB,qBAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;wBAC3C,KAAK,EAAE,EAAE;qBACV,CAAC,CAAC,EAAA;;gBAFG,QAAQ,GAAG,SAEd;gBAEH,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAA,EAAE;oBACnB,sBAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAC;iBACxB;gBAED,sBAAO,GAAG,CAAC,IAAI,CAAC;wBACd,QAAQ,UAAA;qBACT,CAAC,EAAC;;;gBAEH,sBAAO,IAAI,CAAC,KAAG,CAAC,EAAC;;;;KAEpB,CAAC;AA/BW,QAAA,cAAc,kBA+BzB"}
@@ -0,0 +1,3 @@
1
+ import { PayloadRequest } from 'payload/dist/types';
2
+ import { StripeConfig } from '../types';
3
+ export declare const getStripeSubscriptions: (req: PayloadRequest, res: any, next: any, stripeConfig: StripeConfig) => Promise<any>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.getStripeSubscriptions = void 0;
43
+ var payload_1 = __importDefault(require("payload"));
44
+ var errors_1 = require("payload/errors");
45
+ var stripe_1 = __importDefault(require("stripe"));
46
+ var getStripeSubscriptions = function (req, res, next, stripeConfig) { return __awaiter(void 0, void 0, void 0, function () {
47
+ var stripeSecretKey, stripe, id, user, matchingCustomers, customer, subscription, paymentMethod, invoices, err_1;
48
+ var _a, _b, _c, _d, _e, _f;
49
+ return __generator(this, function (_g) {
50
+ switch (_g.label) {
51
+ case 0:
52
+ stripeSecretKey = stripeConfig.stripeSecretKey;
53
+ stripe = new stripe_1.default(stripeSecretKey, { apiVersion: '2022-08-01' });
54
+ _g.label = 1;
55
+ case 1:
56
+ _g.trys.push([1, 6, , 7]);
57
+ id = req.params.id, user = req.user;
58
+ if (!user) {
59
+ throw new errors_1.Forbidden();
60
+ }
61
+ return [4 /*yield*/, payload_1.default.find({
62
+ collection: 'customers',
63
+ where: {
64
+ and: [
65
+ {
66
+ stripeSubscriptionID: {
67
+ equals: id,
68
+ },
69
+ },
70
+ ],
71
+ },
72
+ })];
73
+ case 2:
74
+ matchingCustomers = _g.sent();
75
+ if (matchingCustomers.docs.length !== 1) {
76
+ throw new errors_1.Forbidden();
77
+ }
78
+ customer = matchingCustomers.docs[0];
79
+ return [4 /*yield*/, stripe.subscriptions.retrieve(id)];
80
+ case 3:
81
+ subscription = _g.sent();
82
+ if (!((_d = (_c = (_b = (_a = subscription === null || subscription === void 0 ? void 0 : subscription.items) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.plan) === null || _d === void 0 ? void 0 : _d.id)) {
83
+ return [2 /*return*/, res.status(404)];
84
+ }
85
+ return [4 /*yield*/, stripe.paymentMethods.retrieve(subscription.default_payment_method)];
86
+ case 4:
87
+ paymentMethod = _g.sent();
88
+ return [4 /*yield*/, stripe.invoices.list({
89
+ subscription: id,
90
+ limit: 20,
91
+ })];
92
+ case 5:
93
+ invoices = _g.sent();
94
+ return [2 /*return*/, res.json({
95
+ paymentMethod: {
96
+ brand: (_e = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.card) === null || _e === void 0 ? void 0 : _e.brand,
97
+ last4: (_f = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.card) === null || _f === void 0 ? void 0 : _f.last4,
98
+ },
99
+ invoices: invoices.data.map(function (_a) {
100
+ var amount = _a.amount_due, created = _a.created;
101
+ return ({
102
+ amount: amount,
103
+ created: created,
104
+ });
105
+ }),
106
+ })];
107
+ case 6:
108
+ err_1 = _g.sent();
109
+ return [2 /*return*/, next(err_1)];
110
+ case 7: return [2 /*return*/];
111
+ }
112
+ });
113
+ }); };
114
+ exports.getStripeSubscriptions = getStripeSubscriptions;
115
+ //# sourceMappingURL=getSubscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSubscriptions.js","sourceRoot":"","sources":["../../src/routes/getSubscriptions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAE9B,yCAA2C;AAC3C,kDAA4B;AAGrB,IAAM,sBAAsB,GAAG,UACpC,GAAmB,EACnB,GAAQ,EACR,IAAS,EACT,YAA0B;;;;;;gBAElB,eAAe,GAAK,YAAY,gBAAjB,CAAkB;gBAEnC,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;;;;gBAGrD,EAAE,GAAa,GAAG,UAAhB,EAAI,IAAI,GAAK,GAAG,KAAR,CAAS;gBAErC,IAAI,CAAC,IAAI,EAAE;oBACT,MAAM,IAAI,kBAAS,EAAE,CAAC;iBACvB;gBAEyB,qBAAM,iBAAO,CAAC,IAAI,CAAC;wBAC3C,UAAU,EAAE,WAAW;wBACvB,KAAK,EAAE;4BACL,GAAG,EAAE;gCACH;oCACE,oBAAoB,EAAE;wCACpB,MAAM,EAAE,EAAE;qCACX;iCACF;6BACF;yBACF;qBACF,CAAC,EAAA;;gBAXI,iBAAiB,GAAG,SAWxB;gBAEF,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;oBACvC,MAAM,IAAI,kBAAS,EAAE,CAAC;iBACvB;gBAEK,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAQ,CAAC;gBAE7B,qBAAM,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAA;;gBAAtD,YAAY,GAAG,SAAuC;gBAE5D,IAAI,CAAC,CAAA,MAAA,MAAA,MAAA,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,0CAAE,IAAI,0CAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,EAAE,CAAA,EAAE;oBAC7C,sBAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAC;iBACxB;gBAEqB,qBAAM,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,sBAAgC,CAAC,EAAA;;gBAAnG,aAAa,GAAG,SAAmF;gBAExF,qBAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;wBAC1C,YAAY,EAAE,EAAE;wBAChB,KAAK,EAAE,EAAE;qBACV,CAAC,EAAA;;gBAHI,QAAQ,GAAG,SAGf;gBAEF,sBAAO,GAAG,CAAC,IAAI,CAAC;wBACd,aAAa,EAAE;4BACb,KAAK,EAAE,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,0CAAE,KAAK;4BACjC,KAAK,EAAE,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,0CAAE,KAAK;yBAClC;wBACD,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,EAA+B;gCAAjB,MAAM,gBAAA,EAAE,OAAO,aAAA;4BAAO,OAAA,CAAC;gCAChE,MAAM,QAAA;gCACN,OAAO,SAAA;6BACR,CAAC;wBAH+D,CAG/D,CAAC;qBACJ,CAAC,EAAC;;;gBAEH,sBAAO,IAAI,CAAC,KAAG,CAAC,EAAC;;;;KAEpB,CAAC;AA9DW,QAAA,sBAAsB,0BA8DjC"}
@@ -0,0 +1,4 @@
1
+ import { PayloadRequest } from 'payload/types';
2
+ import { StripeConfig } from '../types';
3
+ import { Response } from 'express';
4
+ export declare const stripeREST: (req: PayloadRequest, res: Response, next: any, stripeConfig: StripeConfig) => Promise<any>;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.stripeREST = void 0;
43
+ var errors_1 = require("payload/errors");
44
+ var stripe_1 = __importDefault(require("stripe"));
45
+ var lodash_get_1 = __importDefault(require("lodash.get"));
46
+ var stripeREST = function (req, res, next, stripeConfig) { return __awaiter(void 0, void 0, void 0, function () {
47
+ var stripeSecretKey, stripe, _a, stripeMethod, stripeArgs // 'cus_MGgt3Tuj3D66f2'
48
+ , user, topLevelMethod, contextToBind, foundMethod, stripeResponse, err_1;
49
+ return __generator(this, function (_b) {
50
+ switch (_b.label) {
51
+ case 0:
52
+ stripeSecretKey = stripeConfig.stripeSecretKey;
53
+ stripe = new stripe_1.default(stripeSecretKey, { apiVersion: '2022-08-01' });
54
+ _b.label = 1;
55
+ case 1:
56
+ _b.trys.push([1, 7, , 8]);
57
+ _a = req.body, stripeMethod = _a.stripeMethod, stripeArgs = _a.stripeArgs, user = req.user;
58
+ if (!user) { // TODO: make this customizable from the config
59
+ throw new errors_1.Forbidden();
60
+ }
61
+ if (!(typeof stripeMethod === 'string')) return [3 /*break*/, 5];
62
+ topLevelMethod = stripeMethod.split('.')[0];
63
+ contextToBind = stripe[topLevelMethod];
64
+ foundMethod = (0, lodash_get_1.default)(stripe, stripeMethod).bind(contextToBind);
65
+ if (!(typeof foundMethod === 'function')) return [3 /*break*/, 3];
66
+ return [4 /*yield*/, foundMethod(stripeArgs)];
67
+ case 2:
68
+ stripeResponse = _b.sent();
69
+ if (!(stripeResponse === null || stripeResponse === void 0 ? void 0 : stripeResponse.data)) {
70
+ return [2 /*return*/, res.status(404)];
71
+ }
72
+ return [2 /*return*/, res.json(stripeResponse)];
73
+ case 3:
74
+ console.warn("The provide Stripe method of '".concat(stripeMethod, "' is not a part of the Stripe API."));
75
+ return [2 /*return*/, next()];
76
+ case 4: return [3 /*break*/, 6];
77
+ case 5:
78
+ console.warn('You must provide a Stripe method to call.');
79
+ return [2 /*return*/, next()];
80
+ case 6: return [3 /*break*/, 8];
81
+ case 7:
82
+ err_1 = _b.sent();
83
+ return [2 /*return*/, next(err_1)];
84
+ case 8: return [2 /*return*/];
85
+ }
86
+ });
87
+ }); };
88
+ exports.stripeREST = stripeREST;
89
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/routes/rest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA2C;AAC3C,kDAA4B;AAE5B,0DAAmC;AAG5B,IAAM,UAAU,GAAG,UACxB,GAAmB,EACnB,GAAa,EACb,IAAS,EACT,YAA0B;;;;;;gBAElB,eAAe,GAAK,YAAY,gBAAjB,CAAkB;gBAEnC,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;;;;gBAIrE,KAKE,GAAG,KAFJ,EAFC,YAAY,kBAAA,EACZ,UAAU,gBAAA,EAEZ,IAAI,GACF,GAAG,KADD,CACE;gBAER,IAAI,CAAC,IAAI,EAAE,EAAE,+CAA+C;oBAC1D,MAAM,IAAI,kBAAS,EAAE,CAAC;iBACvB;qBAEG,CAAA,OAAO,YAAY,KAAK,QAAQ,CAAA,EAAhC,wBAAgC;gBAC5B,cAAc,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAiB,CAAC;gBAC5D,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;gBACvC,WAAW,GAAG,IAAA,oBAAS,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;qBAEpE,CAAA,OAAO,WAAW,KAAK,UAAU,CAAA,EAAjC,wBAAiC;gBACZ,qBAAM,WAAW,CAAC,UAAU,CAAC,EAAA;;gBAA9C,cAAc,GAAG,SAA6B;gBAEpD,IAAI,CAAC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAA,EAAE;oBACzB,sBAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAC;iBACxB;gBAED,sBAAO,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,EAAC;;gBAEhC,OAAO,CAAC,IAAI,CAAC,wCAAiC,YAAY,uCAAoC,CAAC,CAAC;gBAChG,sBAAO,IAAI,EAAE,EAAC;;;gBAGhB,OAAO,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;gBAC1D,sBAAO,IAAI,EAAE,EAAC;;;;gBAIhB,sBAAO,IAAI,CAAC,KAAG,CAAC,EAAC;;;;KAEpB,CAAC;AAhDW,QAAA,UAAU,cAgDrB"}
@@ -0,0 +1,3 @@
1
+ import { PayloadRequest } from 'payload/dist/types';
2
+ import { StripeConfig } from '../types';
3
+ export declare const updateStripePayment: (req: PayloadRequest, res: any, next: any, stripeConfig: StripeConfig) => Promise<any>;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.updateStripePayment = void 0;
43
+ var payload_1 = __importDefault(require("payload"));
44
+ var errors_1 = require("payload/errors");
45
+ var stripe_1 = __importDefault(require("stripe"));
46
+ var updateStripePayment = function (req, res, next, stripeConfig) { return __awaiter(void 0, void 0, void 0, function () {
47
+ var stripeSecretKey, stripe, _a, subscriptionID, paymentMethodID, user, matchingCustomers, err_1;
48
+ return __generator(this, function (_b) {
49
+ switch (_b.label) {
50
+ case 0:
51
+ stripeSecretKey = stripeConfig.stripeSecretKey;
52
+ stripe = new stripe_1.default(stripeSecretKey, { apiVersion: '2022-08-01' });
53
+ _b.label = 1;
54
+ case 1:
55
+ _b.trys.push([1, 5, , 6]);
56
+ _a = req.body, subscriptionID = _a.subscriptionID, paymentMethodID = _a.paymentMethodID, user = req.user;
57
+ if (!user) {
58
+ throw new errors_1.Forbidden();
59
+ }
60
+ return [4 /*yield*/, payload_1.default.find({
61
+ collection: 'customers',
62
+ where: {
63
+ and: [
64
+ {
65
+ stripeSubscriptionID: {
66
+ equals: subscriptionID,
67
+ },
68
+ },
69
+ ],
70
+ },
71
+ })];
72
+ case 2:
73
+ matchingCustomers = _b.sent();
74
+ if (matchingCustomers.docs.length !== 1) {
75
+ throw new errors_1.Forbidden();
76
+ }
77
+ return [4 /*yield*/, stripe.paymentMethods.attach(paymentMethodID, {
78
+ customer: user.stripeCustomerID,
79
+ })];
80
+ case 3:
81
+ _b.sent();
82
+ return [4 /*yield*/, stripe.subscriptions.update(subscriptionID, {
83
+ default_payment_method: paymentMethodID,
84
+ })];
85
+ case 4:
86
+ _b.sent();
87
+ return [2 /*return*/, res.sendStatus(200)];
88
+ case 5:
89
+ err_1 = _b.sent();
90
+ return [2 /*return*/, next(err_1)];
91
+ case 6: return [2 /*return*/];
92
+ }
93
+ });
94
+ }); };
95
+ exports.updateStripePayment = updateStripePayment;
96
+ //# sourceMappingURL=updatePayment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updatePayment.js","sourceRoot":"","sources":["../../src/routes/updatePayment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAE9B,yCAA2C;AAC3C,kDAA4B;AAGrB,IAAM,mBAAmB,GAAG,UACjC,GAAmB,EACnB,GAAQ,EACR,IAAS,EACT,YAA0B;;;;;gBAElB,eAAe,GAAK,YAAY,gBAAjB,CAAkB;gBAEnC,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;;;;gBAG/D,KAAoD,GAAG,KAAd,EAAjC,cAAc,oBAAA,EAAE,eAAe,qBAAA,EAAI,IAAI,GAAK,GAAG,KAAR,CAAS;gBAEhE,IAAI,CAAC,IAAI,EAAE;oBACT,MAAM,IAAI,kBAAS,EAAE,CAAC;iBACvB;gBAEyB,qBAAM,iBAAO,CAAC,IAAI,CAAC;wBAC3C,UAAU,EAAE,WAAW;wBACvB,KAAK,EAAE;4BACL,GAAG,EAAE;gCACH;oCACE,oBAAoB,EAAE;wCACpB,MAAM,EAAE,cAAc;qCACvB;iCACF;6BACF;yBACF;qBACF,CAAC,EAAA;;gBAXI,iBAAiB,GAAG,SAWxB;gBAEF,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;oBACvC,MAAM,IAAI,kBAAS,EAAE,CAAC;iBACvB;gBAED,qBAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,eAAe,EAAE;wBAClD,QAAQ,EAAE,IAAI,CAAC,gBAAgB;qBAChC,CAAC,EAAA;;gBAFF,SAEE,CAAC;gBAEH,qBAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE;wBAChD,sBAAsB,EAAE,eAAe;qBACxC,CAAC,EAAA;;gBAFF,SAEE,CAAC;gBAEH,sBAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAC;;;gBAE3B,sBAAO,IAAI,CAAC,KAAG,CAAC,EAAC;;;;KAEpB,CAAC;AA9CW,QAAA,mBAAmB,uBA8C9B"}
@@ -0,0 +1,4 @@
1
+ import { PayloadRequest } from 'payload/dist/types';
2
+ import { StripeConfig } from '../types';
3
+ import { Response } from 'express';
4
+ export declare const stripeWebhooks: (req: PayloadRequest, res: Response, next: any, stripeConfig: StripeConfig) => void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.stripeWebhooks = void 0;
7
+ var stripe_1 = __importDefault(require("stripe"));
8
+ var stripeWebhooks = function (req, res, next, stripeConfig) {
9
+ var stripeSecretKey = stripeConfig.stripeSecretKey, stripeWebhookEndpointSecret = stripeConfig.stripeWebhookEndpointSecret, webhooks = stripeConfig.webhooks;
10
+ if (webhooks && stripeWebhookEndpointSecret) {
11
+ var stripe = new stripe_1.default(stripeSecretKey, { apiVersion: '2022-08-01' });
12
+ var stripeSignature = req.headers['stripe-signature'];
13
+ if (stripeSignature) {
14
+ var event_1;
15
+ try {
16
+ event_1 = stripe.webhooks.constructEvent(req.body, stripeSignature, stripeWebhookEndpointSecret);
17
+ }
18
+ catch (err) {
19
+ res.status(400).send("Webhook Error: ".concat(err.message));
20
+ }
21
+ if (event_1) {
22
+ var webhookEventHandler = webhooks[event_1.type];
23
+ if (typeof webhookEventHandler === 'function') {
24
+ webhookEventHandler(event_1, stripe, stripeConfig);
25
+ }
26
+ ;
27
+ }
28
+ }
29
+ }
30
+ res.json({ received: true });
31
+ };
32
+ exports.stripeWebhooks = stripeWebhooks;
33
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/routes/webhooks.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA4B;AAKrB,IAAM,cAAc,GAAG,UAC5B,GAAmB,EACnB,GAAa,EACb,IAAS,EACT,YAA0B;IAGxB,IAAA,eAAe,GAGb,YAAY,gBAHC,EACf,2BAA2B,GAEzB,YAAY,4BAFa,EAC3B,QAAQ,GACN,YAAY,SADN,CACO;IAEjB,IAAI,QAAQ,IAAI,2BAA2B,EAAE;QAC3C,IAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;QAEzE,IAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAExD,IAAI,eAAe,EAAE;YACnB,IAAI,OAA+B,CAAC;YAEpC,IAAI;gBACF,OAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,2BAA2B,CAAC,CAAC;aAChG;YAAC,OAAO,GAAQ,EAAE;gBACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,yBAAkB,GAAG,CAAC,OAAO,CAAE,CAAC,CAAC;aACvD;YAED,IAAI,OAAK,EAAE;gBACT,IAAM,mBAAmB,GAAG,QAAQ,CAAC,OAAK,CAAC,IAAI,CAAC,CAAC;gBACjD,IAAI,OAAO,mBAAmB,KAAK,UAAU,EAAE;oBAC7C,mBAAmB,CAAC,OAAK,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;iBACjD;gBAAA,CAAC;aACH;SACF;KACF;IAED,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/B,CAAC,CAAC;AApCW,QAAA,cAAc,kBAoCzB"}
@@ -0,0 +1,9 @@
1
+ import Stripe from "stripe";
2
+ export declare type WebhookHandler = (event: any, stripe: Stripe, stripeConfig: StripeConfig) => void;
3
+ export declare type StripeConfig = {
4
+ stripeSecretKey: string;
5
+ stripeWebhookEndpointSecret?: string;
6
+ webhooks?: {
7
+ [webhookName: string]: WebhookHandler;
8
+ };
9
+ };
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@payloadcms/plugin-stripe",
3
+ "version": "0.0.1",
4
+ "homepage:": "https://payloadcms.com",
5
+ "repository": "git@github.com:payloadcms/plugin-stripe.git",
6
+ "description": "Stripe plugin for Payload CMS",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "keywords": [
14
+ "payload",
15
+ "stripe",
16
+ "cms",
17
+ "plugin",
18
+ "typescript",
19
+ "payments"
20
+ ],
21
+ "author": "dev@payloadcms.com",
22
+ "license": "MIT",
23
+ "peerDependencies": {
24
+ "payload": "^0.18.5 || ^1.0.27"
25
+ },
26
+ "dependencies": {
27
+ "lodash.get": "^4.4.2",
28
+ "stripe": "^10.2.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/express": "^4.17.13",
32
+ "@types/lodash.get": "^4.4.7",
33
+ "payload": "^1.0.9",
34
+ "typescript": "^4.5.5"
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ]
39
+ }