@payloadcms/plugin-stripe 0.0.3 → 0.0.4

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 CHANGED
@@ -24,11 +24,11 @@ In the `plugins` array of your [Payload config](https://payloadcms.com/docs/conf
24
24
 
25
25
  ```js
26
26
  import { buildConfig } from 'payload/config';
27
- import stripe from '@payloadcms/plugin-stripe';
27
+ import stripePlugin from '@payloadcms/plugin-stripe';
28
28
 
29
29
  const config = buildConfig({
30
30
  plugins: [
31
- stripe({
31
+ stripePlugin({
32
32
  stripeSecretKey: process.env.STRIPE_SECRET_KEY,
33
33
  })
34
34
  ]
@@ -43,7 +43,7 @@ export default config;
43
43
 
44
44
  Required. Your Stripe secret key.
45
45
 
46
- - `stripeWebhookEndpointSecret`
46
+ - `stripeWebhooksEndpointSecret`
47
47
 
48
48
  Optional. Your Stripe webhook endpoint secret. This is needed only if you wish to sync data from Stripe to Payload.
49
49
 
@@ -84,20 +84,25 @@ One core functionality of this plugin is to enable a two-way communication chann
84
84
 
85
85
  ### Webhooks
86
86
 
87
- [Stripe webhooks](https://stripe.com/docs/webhooks) are used to sync from Stripe to Payload. Webhooks listen for events on your Stripe account so you can trigger reactions to them. To enable webhooks:
87
+ [Stripe webhooks](https://stripe.com/docs/webhooks) are used to sync from Stripe to Payload. Webhooks listen for events on your Stripe account so you can trigger reactions to them. Follow the steps below to enable webhooks.
88
88
 
89
+ Development:
90
+ 1. Login using Stripe cli `stripe login`
91
+ 1. Forward events to localhost `stripe listen --forward-to localhost:3000/api/stripe/webhooks`
92
+
93
+ Production:
89
94
  1. Login and [create a new webhook](https://dashboard.stripe.com/test/webhooks/create) from the Stripe dashboard
90
- 1. Paste `/api/stripe/webhooks` as the "Webhook Endpoint URL"
95
+ 1. Paste `YOUR_DOMAIN_NAME/api/stripe/webhooks` as the "Webhook Endpoint URL"
91
96
  1. Select which events to broadcast
92
97
  1. Then, handle these events using the `webhooks` portion of this plugin's config:
93
98
 
94
99
  ```js
95
100
  import { buildConfig } from 'payload/config';
96
- import stripe from '@payloadcms/plugin-stripe';
101
+ import stripePlugin from '@payloadcms/plugin-stripe';
97
102
 
98
103
  const config = buildConfig({
99
104
  plugins: [
100
- stripe({
105
+ stripePlugin({
101
106
  stripeSecretKey: process.env.STRIPE_SECRET_KEY,
102
107
  stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOKS_ENDPOINT_SECRET,
103
108
  webhooks: {
@@ -114,7 +119,28 @@ For a full list of available webhooks, see [here](https://stripe.com/docs/cli/tr
114
119
 
115
120
  ### Node
116
121
 
117
- You can also proxy the Stripe API server-side using the `stripeProxy` function exported by the plugin. This is exactly what the `/api/stripe/rest` endpoint does behind-the-scenes. Here's an example:
122
+ On the server you should interface with Stripe directly using the [stripe](https://www.npmjs.com/package/stripe) npm module. That might look something like this:
123
+
124
+ ```js
125
+ import Stripe from 'stripe';
126
+
127
+ const stripeSecretKey = process.env.STRIPE_SECRET_KEY;
128
+ const stripe = new Stripe(stripeSecretKey, { apiVersion: '2022-08-01' });
129
+
130
+ export const MyFunction = async () => {
131
+ try {
132
+ const customer = await stripe.customers.create({
133
+ email: data.email,
134
+ });
135
+
136
+ // DO SOMETHING
137
+ } catch (error) {
138
+ console.error(error.message);
139
+ }
140
+ }
141
+ ```
142
+
143
+ Alternatively, you can interface with the Stripe using the `stripeProxy`, which is exactly what the `/api/stripe/rest` endpoint does behind-the-scenes. Here's the same example as above, but piped through the proxy:
118
144
 
119
145
  ```js
120
146
  import { stripeProxy } from '@payloadcms/plugin-stripe';
@@ -0,0 +1,3 @@
1
+ import type { Config } from 'payload/config';
2
+ import type { Configuration as WebpackConfig } from 'webpack';
3
+ export declare const extendWebpackConfig: (config: Config) => (webpackConfig: WebpackConfig) => WebpackConfig;
@@ -0,0 +1,31 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.extendWebpackConfig = void 0;
18
+ var path_1 = __importDefault(require("path"));
19
+ var mockModulePath = path_1.default.resolve(__dirname, 'mocks/serverModule.js');
20
+ var extendWebpackConfig = function (config) {
21
+ return function (webpackConfig) {
22
+ var _a;
23
+ var _b, _c;
24
+ var existingWebpackConfig = typeof ((_b = config.admin) === null || _b === void 0 ? void 0 : _b.webpack) === 'function'
25
+ ? config.admin.webpack(webpackConfig)
26
+ : webpackConfig;
27
+ return __assign(__assign({}, existingWebpackConfig), { resolve: __assign(__assign({}, (existingWebpackConfig.resolve || {})), { alias: __assign(__assign({}, (((_c = existingWebpackConfig.resolve) === null || _c === void 0 ? void 0 : _c.alias) ? existingWebpackConfig.resolve.alias : {})), (_a = { "stripe": mockModulePath }, _a[path_1.default.resolve(__dirname, 'routes/rest')] = mockModulePath, _a[path_1.default.resolve(__dirname, 'routes/webhooks')] = mockModulePath, _a)) }) });
28
+ };
29
+ };
30
+ exports.extendWebpackConfig = extendWebpackConfig;
31
+ //# sourceMappingURL=extendWebpackConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extendWebpackConfig.js","sourceRoot":"","sources":["../src/extendWebpackConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,8CAAuB;AAGvB,IAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,CAAC;AAEjE,IAAM,mBAAmB,GAAG,UAAC,MAAc;IAChD,OAAA,UAAA,aAAa;;;QACX,IAAM,qBAAqB,GACzB,OAAO,CAAA,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,CAAA,KAAK,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC;YACrC,CAAC,CAAC,aAAa,CAAA;QAEnB,6BACK,qBAAqB,KACxB,OAAO,wBACF,CAAC,qBAAqB,CAAC,OAAO,IAAI,EAAE,CAAC,KACxC,KAAK,wBACA,CAAC,CAAA,MAAA,qBAAqB,CAAC,OAAO,0CAAE,KAAK,EAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,WACpF,QAAQ,EAAE,cAAc,OACvB,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,IAAG,cAAc,KACvD,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,IAAG,cAAc,aAGjE;IACH,CAAC;AAlBD,CAkBC,CAAA;AAnBU,QAAA,mBAAmB,uBAmB7B"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Config } from 'payload/config';
2
2
  import { StripeConfig } from './types';
3
- export { stripeProxy } from './utilities/stripeProxy';
4
- declare const stripe: (stripeConfig: StripeConfig) => (config: Config) => Config;
5
- export default stripe;
3
+ declare const stripePlugin: (stripeConfig: StripeConfig) => (config: Config) => Config;
4
+ export default stripePlugin;
package/dist/index.js CHANGED
@@ -20,13 +20,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
20
20
  return to.concat(ar || Array.prototype.slice.call(from));
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.stripeProxy = void 0;
24
23
  var rest_1 = require("./routes/rest");
25
24
  var webhooks_1 = require("./routes/webhooks");
26
- var stripeProxy_1 = require("./utilities/stripeProxy");
27
- Object.defineProperty(exports, "stripeProxy", { enumerable: true, get: function () { return stripeProxy_1.stripeProxy; } });
28
- var stripe = function (stripeConfig) { return function (config) {
29
- return (__assign(__assign({}, config), { endpoints: __spreadArray(__spreadArray([], (config === null || config === void 0 ? void 0 : config.endpoints) || [], true), [
25
+ var extendWebpackConfig_1 = require("./extendWebpackConfig");
26
+ var stripePlugin = function (stripeConfig) { return function (config) {
27
+ return (__assign(__assign({}, config), { admin: __assign(__assign({}, config.admin), { webpack: (0, extendWebpackConfig_1.extendWebpackConfig)(config) }), endpoints: __spreadArray(__spreadArray([], (config === null || config === void 0 ? void 0 : config.endpoints) || [], true), [
30
28
  {
31
29
  path: '/stripe/webhooks',
32
30
  method: 'post',
@@ -43,5 +41,5 @@ var stripe = function (stripeConfig) { return function (config) {
43
41
  },
44
42
  ], false) }));
45
43
  }; };
46
- exports.default = stripe;
44
+ exports.default = stripePlugin;
47
45
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,sCAA2C;AAC3C,8CAAmD;AAGnD,uDAAsD;AAA7C,0GAAA,WAAW,OAAA;AAEpB,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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,sCAA2C;AAC3C,8CAAmD;AAEnD,6DAA4D;AAE5D,IAAM,YAAY,GAAG,UAAC,YAA0B,IAAK,OAAA,UAAC,MAAc;IAClE,OAAO,uBACF,MAAM,KACT,KAAK,wBACA,MAAM,CAAC,KAAK,KACf,OAAO,EAAE,IAAA,yCAAmB,EAAC,MAAM,CAAC,KAEtC,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,EAzBoD,CAyBpD,CAAC;AAEF,kBAAe,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ module.exports = {};
3
+ //# sourceMappingURL=serverModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverModule.js","sourceRoot":"","sources":["../../src/mocks/serverModule.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG,EAAE,CAAA"}
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.stripeWebhooks = void 0;
7
7
  var stripe_1 = __importDefault(require("stripe"));
8
8
  var stripeWebhooks = function (req, res, next, stripeConfig) {
9
- var stripeSecretKey = stripeConfig.stripeSecretKey, stripeWebhookEndpointSecret = stripeConfig.stripeWebhookEndpointSecret, webhooks = stripeConfig.webhooks;
10
- if (webhooks && stripeWebhookEndpointSecret) {
9
+ var stripeSecretKey = stripeConfig.stripeSecretKey, stripeWebhooksEndpointSecret = stripeConfig.stripeWebhooksEndpointSecret, webhooks = stripeConfig.webhooks;
10
+ if (webhooks && stripeWebhooksEndpointSecret) {
11
11
  var stripe = new stripe_1.default(stripeSecretKey, { apiVersion: '2022-08-01' });
12
12
  var stripeSignature = req.headers['stripe-signature'];
13
13
  if (stripeSignature) {
14
14
  var event_1;
15
15
  try {
16
- event_1 = stripe.webhooks.constructEvent(req.body, stripeSignature, stripeWebhookEndpointSecret);
16
+ event_1 = stripe.webhooks.constructEvent(req.body, stripeSignature, stripeWebhooksEndpointSecret);
17
17
  }
18
18
  catch (err) {
19
19
  res.status(400).send("Webhook Error: ".concat(err.message));
@@ -1 +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,IAA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C,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,4BAA4B,CAAC,CAAC;aACjG;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"}
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@ import Stripe from "stripe";
2
2
  export declare type StripeWebhookHandler = (event: any, stripe: Stripe, stripeConfig: StripeConfig) => void;
3
3
  export declare type StripeConfig = {
4
4
  stripeSecretKey: string;
5
- stripeWebhookEndpointSecret?: string;
5
+ stripeWebhooksEndpointSecret?: string;
6
6
  webhooks?: {
7
7
  [webhookName: string]: StripeWebhookHandler;
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-stripe",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "homepage:": "https://payloadcms.com",
5
5
  "repository": "git@github.com:payloadcms/plugin-stripe.git",
6
6
  "description": "Stripe plugin for Payload CMS",