@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 +1 -1
- package/dist/index.js +73 -79
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
85
|
+
config: config,
|
|
86
|
+
stripeConfig: stripeConfig
|
|
101
87
|
});
|
|
102
88
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sCAA2C;AAC3C,8CAAmD;AACnD,oDAA8B;AAE9B,6DAA4D;AAC5D,+DAA8D;AAC9D,yEAAwE;AACxE,6DAA4D;AAE5D,IAAM,YAAY,GAAG,UAAC,oBAAkC,IAAK,OAAA,UAAC,MAAc;IAClE,IAAA,WAAW,GAAK,MAAM,YAAX,CAAY;IAE/B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sCAA2C;AAC3C,8CAAmD;AACnD,oDAA8B;AAE9B,6DAA4D;AAC5D,+DAA8D;AAC9D,yEAAwE;AACxE,6DAA4D;AAE5D,IAAM,YAAY,GAAG,UAAC,oBAAkC,IAAK,OAAA,UAAC,MAAc;IAClE,IAAA,WAAW,GAAK,MAAM,YAAX,CAAY;IAE/B,2BAA2B;IAC3B,IAAM,YAAY,yBACb,oBAAoB,KACvB,IAAI,EAAE,CAAA,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,IAAI,KAAI,EAAE,GACvC,CAAA;IAED,OAAO,uBACF,MAAM,KACT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