@payloadcms/plugin-stripe 0.0.5 → 0.0.6

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
@@ -67,7 +67,7 @@ This option will setup a basic sync between Payload collections and Stripe resou
67
67
 
68
68
  > NOTE: If you wish to enable a _two-way_ sync, be sure to setup [`webhooks`](#webhooks) and pass the `stripeWebhooksEndpointSecret` through your config.
69
69
 
70
- > NOTE: Due to limitations in the Stripe API, this currently only works with top-level fields. This is because Stripe manages data objects separately, so a webhook originating from a customer's subscription include all customer data. Inversely, you cannot update a customer's subscription by updating the customer. In the future, we can build a pattern around this. But for now, cases like that will need to be hard-coded. See the [demo](./demo) for an example of this.
70
+ > NOTE: Due to limitations in the Stripe API, this currently only works with top-level fields. This is because every Stripe object is a separate entity, making it difficult to abstract into a simple reusable library. In the future, we may find a pattern around this. But for now, cases like that will need to be hard-coded. See the [demo](./demo) for an example of this.
71
71
 
72
72
  ```js
73
73
  import { buildConfig } from 'payload/config';
package/dist/index.js CHANGED
@@ -68,91 +68,85 @@ var syncExistingWithStripe_1 = require("./hooks/syncExistingWithStripe");
68
68
  var deleteFromStripe_1 = require("./hooks/deleteFromStripe");
69
69
  var stripePlugin = function (incomingStripeConfig) { return function (config) {
70
70
  var collections = config.collections;
71
- if (incomingStripeConfig === null || incomingStripeConfig === void 0 ? void 0 : incomingStripeConfig.stripeSecretKey) {
72
- // set config defaults here
73
- var stripeConfig_1 = __assign(__assign({}, incomingStripeConfig), { sync: (incomingStripeConfig === null || incomingStripeConfig === void 0 ? void 0 : incomingStripeConfig.sync) || [] });
74
- 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), [
75
- {
76
- path: '/stripe/webhooks',
77
- method: 'post',
78
- root: true,
79
- handler: [
80
- express_1.default.raw({ type: 'application/json' }),
81
- function (req, res, next) {
82
- (0, webhooks_1.stripeWebhooks)({
83
- req: req,
84
- res: res,
85
- next: next,
86
- config: config,
87
- stripeConfig: stripeConfig_1
88
- });
89
- }
90
- ]
91
- },
92
- {
93
- path: '/stripe/rest',
94
- method: 'post',
95
- handler: function (req, res, next) {
96
- (0, rest_1.stripeREST)({
71
+ // set config defaults here
72
+ var stripeConfig = __assign(__assign({}, incomingStripeConfig), { sync: (incomingStripeConfig === null || incomingStripeConfig === void 0 ? void 0 : incomingStripeConfig.sync) || [] });
73
+ 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), [
74
+ {
75
+ path: '/stripe/webhooks',
76
+ method: 'post',
77
+ root: true,
78
+ handler: [
79
+ express_1.default.raw({ type: 'application/json' }),
80
+ function (req, res, next) {
81
+ (0, webhooks_1.stripeWebhooks)({
97
82
  req: req,
98
83
  res: res,
99
84
  next: next,
100
- stripeConfig: stripeConfig_1
85
+ config: config,
86
+ stripeConfig: stripeConfig
101
87
  });
102
88
  }
103
- },
104
- ], false), collections: collections === null || collections === void 0 ? void 0 : collections.map(function (collection) {
105
- var _a;
106
- var existingHooks = collection.hooks;
107
- var syncConfig = (_a = stripeConfig_1.sync) === null || _a === void 0 ? void 0 : _a.find(function (sync) { return sync.collection === collection.slug; });
108
- if (syncConfig) {
109
- return __assign(__assign({}, collection), { hooks: __assign(__assign({}, collection.hooks), { beforeValidate: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.beforeValidate) || []), true), [
110
- function (args) { return __awaiter(void 0, void 0, void 0, function () {
111
- return __generator(this, function (_a) {
112
- return [2 /*return*/, (0, createNewInStripe_1.createNewInStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig_1 }))];
113
- });
114
- }); }
115
- ], false), afterChange: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.afterChange) || []), true), [
116
- function (args) { return __awaiter(void 0, void 0, void 0, function () {
117
- return __generator(this, function (_a) {
118
- return [2 /*return*/, (0, syncExistingWithStripe_1.syncExistingWithStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig_1 }))];
119
- });
120
- }); }
121
- ], false), afterDelete: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.afterDelete) || []), true), [
122
- function (args) { return __awaiter(void 0, void 0, void 0, function () {
123
- return __generator(this, function (_a) {
124
- return [2 /*return*/, (0, deleteFromStripe_1.deleteFromStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig_1 }))];
125
- });
126
- }); }
127
- ], false) }), fields: __spreadArray(__spreadArray([], collection.fields, true), [
128
- {
129
- name: 'stripeID',
130
- label: 'Stripe ID',
131
- type: 'text',
132
- saveToJWT: true,
133
- admin: {
134
- position: 'sidebar',
135
- readOnly: true,
136
- },
137
- },
138
- {
139
- name: 'skipSync',
140
- label: 'Synced To Sync',
141
- type: 'checkbox',
142
- admin: {
143
- position: 'sidebar',
144
- readOnly: true,
145
- },
146
- }
147
- ], false) });
89
+ ]
90
+ },
91
+ {
92
+ path: '/stripe/rest',
93
+ method: 'post',
94
+ handler: function (req, res, next) {
95
+ (0, rest_1.stripeREST)({
96
+ req: req,
97
+ res: res,
98
+ next: next,
99
+ stripeConfig: stripeConfig
100
+ });
148
101
  }
149
- return collection;
150
- }) }));
151
- }
152
- else {
153
- console.error("Stripe plugin: No 'stripeSecretKey' provided. Plugin not enabled.");
154
- }
155
- return config;
102
+ },
103
+ ], false), collections: collections === null || collections === void 0 ? void 0 : collections.map(function (collection) {
104
+ var _a;
105
+ var existingHooks = collection.hooks;
106
+ var syncConfig = (_a = stripeConfig.sync) === null || _a === void 0 ? void 0 : _a.find(function (sync) { return sync.collection === collection.slug; });
107
+ if (syncConfig) {
108
+ return __assign(__assign({}, collection), { hooks: __assign(__assign({}, collection.hooks), { beforeValidate: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.beforeValidate) || []), true), [
109
+ function (args) { return __awaiter(void 0, void 0, void 0, function () {
110
+ return __generator(this, function (_a) {
111
+ return [2 /*return*/, (0, createNewInStripe_1.createNewInStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
112
+ });
113
+ }); }
114
+ ], false), afterChange: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.afterChange) || []), true), [
115
+ function (args) { return __awaiter(void 0, void 0, void 0, function () {
116
+ return __generator(this, function (_a) {
117
+ return [2 /*return*/, (0, syncExistingWithStripe_1.syncExistingWithStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
118
+ });
119
+ }); }
120
+ ], false), afterDelete: __spreadArray(__spreadArray([], ((existingHooks === null || existingHooks === void 0 ? void 0 : existingHooks.afterDelete) || []), true), [
121
+ function (args) { return __awaiter(void 0, void 0, void 0, function () {
122
+ return __generator(this, function (_a) {
123
+ return [2 /*return*/, (0, deleteFromStripe_1.deleteFromStripe)(__assign(__assign({}, args), { collection: collection, stripeConfig: stripeConfig }))];
124
+ });
125
+ }); }
126
+ ], false) }), fields: __spreadArray(__spreadArray([], collection.fields, true), [
127
+ {
128
+ name: 'stripeID',
129
+ label: 'Stripe ID',
130
+ type: 'text',
131
+ saveToJWT: true,
132
+ admin: {
133
+ position: 'sidebar',
134
+ readOnly: true,
135
+ },
136
+ },
137
+ {
138
+ name: 'skipSync',
139
+ label: 'Synced To Sync',
140
+ type: 'checkbox',
141
+ admin: {
142
+ position: 'sidebar',
143
+ readOnly: true,
144
+ },
145
+ }
146
+ ], false) });
147
+ }
148
+ return collection;
149
+ }) }));
156
150
  }; };
157
151
  exports.default = stripePlugin;
158
152
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 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AAW,KAAI,EAAE,CAAC;4BACrC,UAAO,IAAI;;oCAAK,sBAAA,IAAA,+CAAsB,wBACjC,IAAI,KACP,UAAU,YAAA,EACV,YAAY,cAAA,IACZ,EAAA;;iCAAA;mCAEJ,WAAW,kCACN,CAAC,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,KAAI,EAAE,CAAC;4BACrC,UAAO,IAAI;;oCAAK,sBAAA,IAAA,mCAAgB,wBAC3B,IAAI,KACP,UAAU,YAAA,EACV,YAAY,cAAA,IACZ,EAAA;;iCAAA;sCAGN,MAAM,kCACD,UAAU,CAAC,MAAM;wBACpB;4BACE,IAAI,EAAE,UAAU;4BAChB,KAAK,EAAE,WAAW;4BAClB,IAAI,EAAE,MAAM;4BACZ,SAAS,EAAE,IAAI;4BACf,KAAK,EAAE;gCACL,QAAQ,EAAE,SAAS;gCACnB,QAAQ,EAAE,IAAI;6BACf;yBACF;wBACD;4BACE,IAAI,EAAE,UAAU;4BAChB,KAAK,EAAE,gBAAgB;4BACvB,IAAI,EAAE,UAAU;4BAChB,KAAK,EAAE;gCACL,QAAQ,EAAE,SAAS;gCACnB,QAAQ,EAAE,IAAI;6BACf;yBACF;iCAEH;aACH;YAED,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,IACF,CAAA;AACJ,CAAC,EAhH4D,CAgH5D,CAAA;AAED,kBAAe,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-stripe",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "homepage:": "https://payloadcms.com",
5
5
  "repository": "git@github.com:payloadcms/plugin-stripe.git",
6
6
  "description": "Stripe plugin for Payload CMS",