@flink-app/s3-plugin 0.3.5 → 0.3.7

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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +3 -3
  3. package/.flink/generated-schemas.json +0 -311
  4. package/.flink/generatedHandlers.ts +0 -7
  5. package/.flink/generatedRepos.ts +0 -5
  6. package/.flink/schemas/schemas.json +0 -5
  7. package/.flink/schemas/schemas.ts +0 -1
  8. package/.flink/start.ts +0 -4
  9. package/dist/.flink/generatedHandlers.d.ts +0 -1
  10. package/dist/.flink/generatedHandlers.js +0 -7
  11. package/dist/.flink/generatedRepos.d.ts +0 -1
  12. package/dist/.flink/generatedRepos.js +0 -7
  13. package/dist/.flink/schemas/schemas.d.ts +0 -0
  14. package/dist/.flink/schemas/schemas.js +0 -2
  15. package/dist/.flink/schemas/schemas.json +0 -5
  16. package/dist/.flink/start.d.ts +0 -3
  17. package/dist/.flink/start.js +0 -6
  18. package/dist/src/Ctx.d.ts +0 -19
  19. package/dist/src/Ctx.js +0 -2
  20. package/dist/src/handlers/HandlebarsTemplateHandler.d.ts +0 -5
  21. package/dist/src/handlers/HandlebarsTemplateHandler.js +0 -63
  22. package/dist/src/handlers/Management/Get.d.ts +0 -7
  23. package/dist/src/handlers/Management/Get.js +0 -53
  24. package/dist/src/handlers/Management/GetManagement.d.ts +0 -8
  25. package/dist/src/handlers/Management/GetManagement.js +0 -53
  26. package/dist/src/handlers/User/DeleteByUserid.d.ts +0 -9
  27. package/dist/src/handlers/User/DeleteByUserid.js +0 -70
  28. package/dist/src/handlers/User/GetByUserid.d.ts +0 -9
  29. package/dist/src/handlers/User/GetByUserid.js +0 -71
  30. package/dist/src/handlers/User/GetList.d.ts +0 -9
  31. package/dist/src/handlers/User/GetList.js +0 -64
  32. package/dist/src/handlers/User/GetMe.d.ts +0 -8
  33. package/dist/src/handlers/User/GetMe.js +0 -81
  34. package/dist/src/handlers/User/Post.d.ts +0 -10
  35. package/dist/src/handlers/User/Post.js +0 -87
  36. package/dist/src/handlers/User/PostLogin.d.ts +0 -10
  37. package/dist/src/handlers/User/PostLogin.js +0 -86
  38. package/dist/src/handlers/User/PutByUserid.d.ts +0 -9
  39. package/dist/src/handlers/User/PutByUserid.js +0 -97
  40. package/dist/src/index.d.ts +0 -4
  41. package/dist/src/index.js +0 -380
  42. package/dist/src/lib/customer.d.ts +0 -6
  43. package/dist/src/lib/customer.js +0 -121
  44. package/dist/src/lib/payment.d.ts +0 -6
  45. package/dist/src/lib/payment.js +0 -113
  46. package/dist/src/managementApiContext.d.ts +0 -7
  47. package/dist/src/managementApiContext.js +0 -2
  48. package/dist/src/models/ManagementApi.d.ts +0 -28
  49. package/dist/src/models/ManagementApi.js +0 -8
  50. package/dist/src/repos/ConnectSessionRepo.d.ts +0 -5
  51. package/dist/src/repos/ConnectSessionRepo.js +0 -26
  52. package/dist/src/repos/ManagementUserRepo.d.ts +0 -5
  53. package/dist/src/repos/ManagementUserRepo.js +0 -26
  54. package/dist/src/reposx/ConnectSessionRepo.d.ts +0 -5
  55. package/dist/src/reposx/ConnectSessionRepo.js +0 -26
  56. package/dist/src/schemas/ConnectSession.d.ts +0 -4
  57. package/dist/src/schemas/ConnectSession.js +0 -2
  58. package/dist/src/schemas/Management/GetReq.d.ts +0 -2
  59. package/dist/src/schemas/Management/GetReq.js +0 -2
  60. package/dist/src/schemas/Management/GetRes.d.ts +0 -3
  61. package/dist/src/schemas/Management/GetRes.js +0 -2
  62. package/dist/src/schemas/ManagementUser.d.ts +0 -6
  63. package/dist/src/schemas/ManagementUser.js +0 -2
  64. package/dist/src/schemas/ManagementUserViewModel.d.ts +0 -4
  65. package/dist/src/schemas/ManagementUserViewModel.js +0 -19
  66. package/dist/src/schemas/ModuleList.d.ts +0 -18
  67. package/dist/src/schemas/ModuleList.js +0 -2
  68. package/dist/src/schemas/User/DeleteByUseridReq.d.ts +0 -2
  69. package/dist/src/schemas/User/DeleteByUseridReq.js +0 -2
  70. package/dist/src/schemas/User/DeleteByUseridRes.d.ts +0 -2
  71. package/dist/src/schemas/User/DeleteByUseridRes.js +0 -2
  72. package/dist/src/schemas/User/GetByUseridReq.d.ts +0 -2
  73. package/dist/src/schemas/User/GetByUseridReq.js +0 -2
  74. package/dist/src/schemas/User/GetByUseridRes.d.ts +0 -3
  75. package/dist/src/schemas/User/GetByUseridRes.js +0 -2
  76. package/dist/src/schemas/User/GetListReq.d.ts +0 -2
  77. package/dist/src/schemas/User/GetListReq.js +0 -2
  78. package/dist/src/schemas/User/GetListRes.d.ts +0 -4
  79. package/dist/src/schemas/User/GetListRes.js +0 -2
  80. package/dist/src/schemas/User/GetMeReq.d.ts +0 -2
  81. package/dist/src/schemas/User/GetMeReq.js +0 -2
  82. package/dist/src/schemas/User/GetMeRes.d.ts +0 -3
  83. package/dist/src/schemas/User/GetMeRes.js +0 -2
  84. package/dist/src/schemas/User/PostLoginReq.d.ts +0 -4
  85. package/dist/src/schemas/User/PostLoginReq.js +0 -2
  86. package/dist/src/schemas/User/PostLoginRes.d.ts +0 -5
  87. package/dist/src/schemas/User/PostLoginRes.js +0 -2
  88. package/dist/src/schemas/User/PostReq.d.ts +0 -3
  89. package/dist/src/schemas/User/PostReq.js +0 -2
  90. package/dist/src/schemas/User/PostRes.d.ts +0 -3
  91. package/dist/src/schemas/User/PostRes.js +0 -2
  92. package/dist/src/schemas/User/PutByUseridReq.d.ts +0 -3
  93. package/dist/src/schemas/User/PutByUseridReq.js +0 -2
  94. package/dist/src/schemas/User/PutByUseridRes.d.ts +0 -3
  95. package/dist/src/schemas/User/PutByUseridRes.js +0 -2
  96. package/dist/src/schemas/createStripeCustomerOptions.d.ts +0 -11
  97. package/dist/src/schemas/createStripeCustomerOptions.js +0 -2
  98. package/dist/src/schemas/customer/connectToStripeConnectOptions.d.ts +0 -3
  99. package/dist/src/schemas/customer/connectToStripeConnectOptions.js +0 -2
  100. package/dist/src/schemas/customer/hasPaymentMethodOptions.d.ts +0 -3
  101. package/dist/src/schemas/customer/hasPaymentMethodOptions.js +0 -2
  102. package/dist/src/schemas/customer/setupCardOptions.d.ts +0 -3
  103. package/dist/src/schemas/customer/setupCardOptions.js +0 -2
  104. package/dist/src/schemas/customer/setupCardResponse.d.ts +0 -4
  105. package/dist/src/schemas/customer/setupCardResponse.js +0 -2
  106. package/dist/src/schemas/customer/setupCardTokenOptions.d.ts +0 -4
  107. package/dist/src/schemas/customer/setupCardTokenOptions.js +0 -2
  108. package/dist/src/schemas/payment/capturePaymentOptions.d.ts +0 -4
  109. package/dist/src/schemas/payment/capturePaymentOptions.js +0 -2
  110. package/dist/src/schemas/payment/confirmPaymentOptions.d.ts +0 -4
  111. package/dist/src/schemas/payment/confirmPaymentOptions.js +0 -2
  112. package/dist/src/schemas/payment/confirmPaymentResponse.d.ts +0 -7
  113. package/dist/src/schemas/payment/confirmPaymentResponse.js +0 -2
  114. package/dist/src/schemas/payment/confirmPaymentTokenOptions.d.ts +0 -4
  115. package/dist/src/schemas/payment/confirmPaymentTokenOptions.js +0 -2
  116. package/dist/src/schemas/payment/createPaymentResponse.d.ts +0 -5
  117. package/dist/src/schemas/payment/createPaymentResponse.js +0 -2
  118. package/dist/src/schemas/stripeAPIToken.d.ts +0 -4
  119. package/dist/src/schemas/stripeAPIToken.js +0 -2
  120. package/dist/src/schemas/stripePluginOptions.d.ts +0 -31
  121. package/dist/src/schemas/stripePluginOptions.js +0 -2
  122. package/dist/src/stripeAPI.d.ts +0 -32
  123. package/dist/src/stripeAPI.js +0 -163
  124. package/dist/src/stripePlguinContext.d.ts +0 -5
  125. package/dist/src/stripePlguinContext.js +0 -2
  126. package/dist/src/stripePluginContext.d.ts +0 -6
  127. package/dist/src/stripePluginContext.js +0 -2
  128. package/dist/src/templates/connect-done.d.ts +0 -1
  129. package/dist/src/templates/connect-done.js +0 -4
  130. package/dist/src/templates/error.d.ts +0 -1
  131. package/dist/src/templates/error.js +0 -4
  132. package/dist/src/templates/master.d.ts +0 -1
  133. package/dist/src/templates/master.js +0 -4
  134. package/dist/src/templates/pay-enter-card.d.ts +0 -1
  135. package/dist/src/templates/pay-enter-card.js +0 -4
  136. package/dist/src/templates/pay-select-card.d.ts +0 -1
  137. package/dist/src/templates/pay-select-card.js +0 -4
  138. package/dist/src/templates/setup-card.d.ts +0 -1
  139. package/dist/src/templates/setup-card.js +0 -4
  140. package/dist/src/templates/setup-done.d.ts +0 -1
  141. package/dist/src/templates/setup-done.js +0 -4
  142. package/dist/src/templates/style.d.ts +0 -1
  143. package/dist/src/templates/style.js +0 -4
  144. package/dist/src/utils/bcrypt.d.ts +0 -2
  145. package/dist/src/utils/bcrypt.js +0 -28
@@ -1,4 +0,0 @@
1
- import { FlinkPlugin } from "@flink-app/flink";
2
- import { stripePluginOptions } from "./schemas/stripePluginOptions";
3
- export * from "./stripePluginContext";
4
- export declare const stripePlugin: (options: stripePluginOptions) => FlinkPlugin;
package/dist/src/index.js DELETED
@@ -1,380 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- 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;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __importDefault = (this && this.__importDefault) || function (mod) {
49
- return (mod && mod.__esModule) ? mod : { "default": mod };
50
- };
51
- Object.defineProperty(exports, "__esModule", { value: true });
52
- exports.stripePlugin = void 0;
53
- var flink_1 = require("@flink-app/flink");
54
- var stripeAPI_1 = require("./stripeAPI");
55
- var HandlebarsTemplateHandler_1 = require("./handlers/HandlebarsTemplateHandler");
56
- __exportStar(require("./stripePluginContext"), exports);
57
- var master_1 = require("./templates/master");
58
- var setup_card_1 = require("./templates/setup-card");
59
- var style_1 = require("./templates/style");
60
- var setup_done_1 = require("./templates/setup-done");
61
- var error_1 = require("./templates/error");
62
- var pay_select_card_1 = require("./templates/pay-select-card");
63
- var pay_enter_card_1 = require("./templates/pay-enter-card");
64
- var connect_done_1 = require("./templates/connect-done");
65
- var jsonwebtoken_1 = require("jsonwebtoken");
66
- var ConnectSessionRepo_1 = __importDefault(require("./reposx/ConnectSessionRepo"));
67
- var stripePlugin = function (options) {
68
- var _a, _b, _c, _d, _e, _f, _g, _h;
69
- if (options.paymentCallback == null)
70
- options.paymentCallback = function () { };
71
- if (options.stripeConnectCallback == null)
72
- options.stripeConnectCallback = function () { };
73
- var stripeAPI = new stripeAPI_1.StripeAPI(options);
74
- var templates = {
75
- master: ((_a = options.templates) === null || _a === void 0 ? void 0 : _a.master) || master_1.masterTemplate,
76
- style: ((_b = options.templates) === null || _b === void 0 ? void 0 : _b.style) || style_1.styleTemplate,
77
- setupCard: ((_c = options.templates) === null || _c === void 0 ? void 0 : _c.setupCard) || setup_card_1.setupCardTemplate,
78
- setupDone: ((_d = options.templates) === null || _d === void 0 ? void 0 : _d.setupDone) || setup_done_1.setupDoneTemplate,
79
- error: ((_e = options.templates) === null || _e === void 0 ? void 0 : _e.error) || error_1.errorTemplate,
80
- paySelectCard: ((_f = options.templates) === null || _f === void 0 ? void 0 : _f.paySelectCard) || pay_select_card_1.paySelectCardTemplate,
81
- payEnterCard: ((_g = options.templates) === null || _g === void 0 ? void 0 : _g.payEnterCard) || pay_enter_card_1.payEnterCardTemplate,
82
- connectDone: ((_h = options.templates) === null || _h === void 0 ? void 0 : _h.connectDone) || connect_done_1.connectDoneTemplate,
83
- };
84
- return {
85
- id: "stripePlugin",
86
- init: function (app) { return init(app, options); },
87
- ctx: {
88
- stripeAPI: stripeAPI,
89
- templates: templates,
90
- },
91
- };
92
- };
93
- exports.stripePlugin = stripePlugin;
94
- function init(app, options) {
95
- var _this = this;
96
- var _a, _b, _c, _d, _e, _f, _g, _h;
97
- if (options.baseUrl == null)
98
- options.baseUrl = "/stripe";
99
- flink_1.log.info("Registered route GET " + options.baseUrl + "/customer/setup-card/:token");
100
- (_a = app.expressApp) === null || _a === void 0 ? void 0 : _a.get(options.baseUrl + "/customer/setup-card/:token", function (req, res) {
101
- var _a, _b;
102
- try {
103
- var tokenData = jsonwebtoken_1.verify(req.params.token, options.JTW_TOKEN);
104
- if (tokenData.type != "setup_card") {
105
- throw "Invalid token type";
106
- }
107
- HandlebarsTemplateHandler_1.HandlebarsTemplateHandler(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.setupCard, {
108
- setupDescription: (_a = options.phrases) === null || _a === void 0 ? void 0 : _a.setupDescription,
109
- logo: options.logo,
110
- stripePublishableKey: options.stripePublishableKey,
111
- client_secret: tokenData.options.client_secret,
112
- baseUrl: options.baseUrl,
113
- setupButtonText: ((_b = options.phrases) === null || _b === void 0 ? void 0 : _b.setupButtonText) || "Spara",
114
- }, res);
115
- }
116
- catch (ex) {
117
- flink_1.log.error(ex);
118
- res.redirect(options.baseUrl + "/error");
119
- return;
120
- }
121
- });
122
- flink_1.log.info("Registered route GET " + options.baseUrl + "/customer/setup-card-done");
123
- (_b = app.expressApp) === null || _b === void 0 ? void 0 : _b.get(options.baseUrl + "/customer/setup-card-done/", function (req, res) {
124
- var _a;
125
- try {
126
- HandlebarsTemplateHandler_1.HandlebarsTemplateHandler(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.setupDone, {
127
- redirectUrl: options.redirectUrl,
128
- message: ((_a = options.phrases) === null || _a === void 0 ? void 0 : _a.setupDoneMessage) || "Kortet har sparats.",
129
- }, res);
130
- }
131
- catch (ex) {
132
- flink_1.log.error(ex);
133
- res.redirect(options.baseUrl + "/error");
134
- return;
135
- }
136
- });
137
- (_c = app.expressApp) === null || _c === void 0 ? void 0 : _c.get(options.baseUrl + "/error", function (req, res) {
138
- try {
139
- HandlebarsTemplateHandler_1.HandlebarsTemplateHandler(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.error, {}, res);
140
- }
141
- catch (ex) {
142
- flink_1.log.error(ex);
143
- res.redirect(options.baseUrl + "/");
144
- return;
145
- }
146
- });
147
- flink_1.log.info("Registered route GET " + options.baseUrl + "/payment/confirm/:token");
148
- (_d = app.expressApp) === null || _d === void 0 ? void 0 : _d.get(options.baseUrl + "/payment/confirm/:token", function (req, res) { return __awaiter(_this, void 0, void 0, function () {
149
- var tokenData, stripe, paymentIntent, paymentMethods, ex_1;
150
- var _a;
151
- return __generator(this, function (_b) {
152
- switch (_b.label) {
153
- case 0:
154
- _b.trys.push([0, 3, , 4]);
155
- tokenData = jsonwebtoken_1.verify(req.params.token, options.JTW_TOKEN);
156
- if (tokenData.type != "payment") {
157
- throw "Invalid token type";
158
- }
159
- stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
160
- return [4 /*yield*/, stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId)];
161
- case 1:
162
- paymentIntent = _b.sent();
163
- return [4 /*yield*/, stripe.paymentMethods.list({
164
- customer: (_a = paymentIntent.customer) === null || _a === void 0 ? void 0 : _a.toString(),
165
- type: "card",
166
- })];
167
- case 2:
168
- paymentMethods = _b.sent();
169
- if (paymentMethods.data.length == 0) {
170
- res.redirect(options.baseUrl + "/payment/enter-card/" + req.params.token);
171
- }
172
- else {
173
- res.redirect(options.baseUrl + "/payment/select-card/" + req.params.token);
174
- }
175
- return [3 /*break*/, 4];
176
- case 3:
177
- ex_1 = _b.sent();
178
- flink_1.log.error(ex_1);
179
- res.redirect(options.baseUrl + "/error");
180
- return [2 /*return*/];
181
- case 4: return [2 /*return*/];
182
- }
183
- });
184
- }); });
185
- flink_1.log.info("Registered route GET " + options.baseUrl + "/payment/select-card/:token");
186
- (_e = app.expressApp) === null || _e === void 0 ? void 0 : _e.get(options.baseUrl + "/payment/select-card/:token", function (req, res) { return __awaiter(_this, void 0, void 0, function () {
187
- var tokenData, stripe, paymentIntent, paymentMethods, ctx, ex_2;
188
- var _a, _b, _c;
189
- return __generator(this, function (_d) {
190
- switch (_d.label) {
191
- case 0:
192
- _d.trys.push([0, 3, , 4]);
193
- tokenData = jsonwebtoken_1.verify(req.params.token, options.JTW_TOKEN);
194
- if (tokenData.type != "payment") {
195
- throw "Invalid token type";
196
- }
197
- stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
198
- return [4 /*yield*/, stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId)];
199
- case 1:
200
- paymentIntent = _d.sent();
201
- return [4 /*yield*/, stripe.paymentMethods.list({
202
- customer: (_a = paymentIntent.customer) === null || _a === void 0 ? void 0 : _a.toString(),
203
- type: "card",
204
- })];
205
- case 2:
206
- paymentMethods = _d.sent();
207
- if (paymentMethods.data.length == 0) {
208
- res.redirect(options.baseUrl + "/payment/enter-card/" + req.params.token);
209
- }
210
- ctx = {
211
- card: paymentMethods.data[0].card,
212
- paymentSelectCardPayButtonText: ((_b = options.phrases) === null || _b === void 0 ? void 0 : _b.paymentSelectCardPayButtonText) || "Betala",
213
- paymentSelectCardChangeCardButtonText: ((_c = options.phrases) === null || _c === void 0 ? void 0 : _c.paymentSelectCardChangeCardButtonText) || "Byt kort",
214
- publishableKey: options.stripePublishableKey,
215
- token: req.params.token,
216
- baseUrl: options.baseUrl,
217
- logo: options.logo,
218
- client_secrect: paymentIntent.client_secret,
219
- price: (paymentIntent.amount / 100).toFixed(2) + " " + paymentIntent.currency.toUpperCase(),
220
- description: paymentIntent.description,
221
- };
222
- HandlebarsTemplateHandler_1.HandlebarsTemplateHandler(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.paySelectCard, ctx, res);
223
- return [3 /*break*/, 4];
224
- case 3:
225
- ex_2 = _d.sent();
226
- flink_1.log.error(ex_2);
227
- res.redirect(options.baseUrl + "/error");
228
- return [2 /*return*/];
229
- case 4: return [2 /*return*/];
230
- }
231
- });
232
- }); });
233
- flink_1.log.info("Registered route GET " + options.baseUrl + "/payment/enter-card/:token");
234
- (_f = app.expressApp) === null || _f === void 0 ? void 0 : _f.get(options.baseUrl + "/payment/enter-card/:token", function (req, res) { return __awaiter(_this, void 0, void 0, function () {
235
- var tokenData, stripe, paymentIntent, paymentMethods, _a, _b, _i, x, pi, ctx, ex_3;
236
- var _c, _d;
237
- return __generator(this, function (_e) {
238
- switch (_e.label) {
239
- case 0:
240
- _e.trys.push([0, 7, , 8]);
241
- tokenData = jsonwebtoken_1.verify(req.params.token, options.JTW_TOKEN);
242
- if (tokenData.type != "payment") {
243
- throw "Invalid token type";
244
- }
245
- stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
246
- return [4 /*yield*/, stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId)];
247
- case 1:
248
- paymentIntent = _e.sent();
249
- return [4 /*yield*/, stripe.paymentMethods.list({
250
- customer: (_c = paymentIntent.customer) === null || _c === void 0 ? void 0 : _c.toString(),
251
- type: "card",
252
- })];
253
- case 2:
254
- paymentMethods = _e.sent();
255
- _a = [];
256
- for (_b in paymentMethods.data)
257
- _a.push(_b);
258
- _i = 0;
259
- _e.label = 3;
260
- case 3:
261
- if (!(_i < _a.length)) return [3 /*break*/, 6];
262
- x = _a[_i];
263
- pi = paymentMethods.data[x];
264
- return [4 /*yield*/, stripe.paymentMethods.detach(pi.id)];
265
- case 4:
266
- _e.sent();
267
- _e.label = 5;
268
- case 5:
269
- _i++;
270
- return [3 /*break*/, 3];
271
- case 6:
272
- ctx = {
273
- paymentEnterCardPayButtonText: ((_d = options.phrases) === null || _d === void 0 ? void 0 : _d.paymentEnterCardPayButtonText) || "Betala",
274
- publishableKey: options.stripePublishableKey,
275
- token: req.params.token,
276
- baseUrl: options.baseUrl,
277
- logo: options.logo,
278
- client_secrect: paymentIntent.client_secret,
279
- price: (paymentIntent.amount / 100).toFixed(2) + " " + paymentIntent.currency.toUpperCase(),
280
- description: paymentIntent.description,
281
- };
282
- HandlebarsTemplateHandler_1.HandlebarsTemplateHandler(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.payEnterCard, ctx, res);
283
- return [3 /*break*/, 8];
284
- case 7:
285
- ex_3 = _e.sent();
286
- flink_1.log.error(ex_3);
287
- res.redirect(options.baseUrl + "/error");
288
- return [2 /*return*/];
289
- case 8: return [2 /*return*/];
290
- }
291
- });
292
- }); });
293
- flink_1.log.info("Registered route GET " + options.baseUrl + "/callback/:event");
294
- (_g = app.expressApp) === null || _g === void 0 ? void 0 : _g.post(options.baseUrl + "/callback/:event", function (req, res) { return __awaiter(_this, void 0, void 0, function () {
295
- var paymentIntentId, stripe, paymentIntent, ex_4;
296
- var _a, _b, _c;
297
- return __generator(this, function (_d) {
298
- switch (_d.label) {
299
- case 0:
300
- if (!(req.params.event == "charge.succeeded")) return [3 /*break*/, 4];
301
- paymentIntentId = (_c = (_b = (_a = req.body) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.object) === null || _c === void 0 ? void 0 : _c.payment_intent;
302
- if (paymentIntentId == null) {
303
- res.status(400).send("Bad request");
304
- return [2 /*return*/];
305
- }
306
- stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
307
- _d.label = 1;
308
- case 1:
309
- _d.trys.push([1, 3, , 4]);
310
- return [4 /*yield*/, stripe.paymentIntents.retrieve(paymentIntentId)];
311
- case 2:
312
- paymentIntent = _d.sent();
313
- if (paymentIntent == null) {
314
- res.status(400).send("Bad request");
315
- return [2 /*return*/];
316
- }
317
- if (paymentIntent.status == "succeeded" || paymentIntent.status == "requires_capture") {
318
- try {
319
- options.paymentCallback(paymentIntent.id, paymentIntent.status);
320
- }
321
- catch (ex) {
322
- flink_1.log.error("paymentCallback:" + ex);
323
- }
324
- }
325
- return [3 /*break*/, 4];
326
- case 3:
327
- ex_4 = _d.sent();
328
- flink_1.log.error(ex_4);
329
- res.status(500).send("Internal error");
330
- return [3 /*break*/, 4];
331
- case 4:
332
- res.status(200).send("Completed");
333
- return [2 /*return*/];
334
- }
335
- });
336
- }); });
337
- flink_1.log.info("Registered route GET " + options.baseUrl + "/connect");
338
- (_h = app.expressApp) === null || _h === void 0 ? void 0 : _h.get(options.baseUrl + "/connect", function (req, res) { return __awaiter(_this, void 0, void 0, function () {
339
- var _a, code, state, stripe, token, repo, session;
340
- var _b;
341
- return __generator(this, function (_c) {
342
- switch (_c.label) {
343
- case 0:
344
- _a = req.query, code = _a.code, state = _a.state;
345
- if (!(code && state)) return [3 /*break*/, 3];
346
- stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
347
- return [4 /*yield*/, stripe.oauth.token({
348
- grant_type: "authorization_code",
349
- code: code.toString(),
350
- })];
351
- case 1:
352
- token = _c.sent();
353
- repo = app.ctx.repos.connectsessionRepo;
354
- return [4 /*yield*/, repo.getById(state.toString())];
355
- case 2:
356
- session = _c.sent();
357
- try {
358
- options.stripeConnectCallback(session.userId, token.stripe_user_id);
359
- HandlebarsTemplateHandler_1.HandlebarsTemplateHandler(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.connectDone, {
360
- redirectUrl: options.redirectUrl,
361
- message: ((_b = options.phrases) === null || _b === void 0 ? void 0 : _b.connectDoneMessage) || "Kontot har kopplats till Stripe.",
362
- }, res);
363
- }
364
- catch (ex) {
365
- flink_1.log.error("paymentCallback:" + ex);
366
- res.redirect(options.baseUrl + "/error");
367
- }
368
- return [3 /*break*/, 4];
369
- case 3:
370
- res.redirect(options.baseUrl + "/error");
371
- _c.label = 4;
372
- case 4: return [2 /*return*/];
373
- }
374
- });
375
- }); });
376
- if (app.db != null) {
377
- app.addRepo("connectsessionRepo", new ConnectSessionRepo_1.default("ConnectSessionRepo", app.db));
378
- }
379
- app.ctx.plugins.stripePlugin.stripeAPI.config.setRepo(app.ctx.repos.connectsessionRepo);
380
- }
@@ -1,6 +0,0 @@
1
- import { setupCardOptions } from "../schemas/customer/setupCardOptions";
2
- import { hasPaymentMethodOptions } from "../schemas/customer/hasPaymentMethodOptions";
3
- import { Stripe } from "stripe";
4
- export declare const createStripeCustomer: (stripe: Stripe, options: Stripe.CustomerCreateParams) => Promise<string>;
5
- export declare const hasPaymentMethod: (stripe: Stripe, options: hasPaymentMethodOptions) => Promise<boolean>;
6
- export declare const setupCardRegistration: (stripe: Stripe, JWT_TOKEN: string, options: setupCardOptions) => Promise<string>;
@@ -1,121 +0,0 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.setupCardRegistration = exports.hasPaymentMethod = exports.createStripeCustomer = void 0;
51
- var jsonwebtoken_1 = require("jsonwebtoken");
52
- var createStripeCustomer = function (stripe, options) { return __awaiter(void 0, void 0, void 0, function () {
53
- var resp;
54
- return __generator(this, function (_a) {
55
- switch (_a.label) {
56
- case 0: return [4 /*yield*/, stripe.customers.create(options)];
57
- case 1:
58
- resp = _a.sent();
59
- return [2 /*return*/, resp.id];
60
- }
61
- });
62
- }); };
63
- exports.createStripeCustomer = createStripeCustomer;
64
- var hasPaymentMethod = function (stripe, options) { return __awaiter(void 0, void 0, void 0, function () {
65
- var paymentMethods;
66
- return __generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0: return [4 /*yield*/, stripe.paymentMethods.list({
69
- customer: options.stripeCustomerId,
70
- type: "card",
71
- })];
72
- case 1:
73
- paymentMethods = _a.sent();
74
- return [2 /*return*/, paymentMethods.data.length > 0];
75
- }
76
- });
77
- }); };
78
- exports.hasPaymentMethod = hasPaymentMethod;
79
- var setupCardRegistration = function (stripe, JWT_TOKEN, options) { return __awaiter(void 0, void 0, void 0, function () {
80
- var paymentMethods, _a, _b, _i, x, pi, intent, tokenOptions, tokenData, token;
81
- return __generator(this, function (_c) {
82
- switch (_c.label) {
83
- case 0: return [4 /*yield*/, stripe.paymentMethods.list({
84
- customer: options.stripeCustomerId,
85
- type: "card",
86
- })];
87
- case 1:
88
- paymentMethods = _c.sent();
89
- _a = [];
90
- for (_b in paymentMethods.data)
91
- _a.push(_b);
92
- _i = 0;
93
- _c.label = 2;
94
- case 2:
95
- if (!(_i < _a.length)) return [3 /*break*/, 5];
96
- x = _a[_i];
97
- pi = paymentMethods.data[x];
98
- return [4 /*yield*/, stripe.paymentMethods.detach(pi.id)];
99
- case 3:
100
- _c.sent();
101
- _c.label = 4;
102
- case 4:
103
- _i++;
104
- return [3 /*break*/, 2];
105
- case 5: return [4 /*yield*/, stripe.setupIntents.create({
106
- customer: options.stripeCustomerId,
107
- })];
108
- case 6:
109
- intent = _c.sent();
110
- tokenOptions = __assign(__assign({}, options), { client_secret: intent.client_secret });
111
- intent.client_secret;
112
- tokenData = {
113
- type: "setup_card",
114
- options: tokenOptions,
115
- };
116
- token = jsonwebtoken_1.sign(tokenData, JWT_TOKEN);
117
- return [2 /*return*/, token];
118
- }
119
- });
120
- }); };
121
- exports.setupCardRegistration = setupCardRegistration;
@@ -1,6 +0,0 @@
1
- import { Stripe } from "stripe";
2
- import { confirmPaymentOptions } from "../schemas/payment/confirmPaymentOptions";
3
- import { confirmPaymentResponse } from "../schemas/payment/confirmPaymentResponse";
4
- import { createPaymentResponse } from "../schemas/payment/createPaymentResponse";
5
- export declare const createPaymentIntent: (stripe: Stripe, JWT_TOKEN: string, options: Stripe.PaymentIntentCreateParams) => Promise<createPaymentResponse>;
6
- export declare const confirmPayment: (stripe: Stripe, JWT_TOKEN: string, options: confirmPaymentOptions) => Promise<confirmPaymentResponse>;
@@ -1,113 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.confirmPayment = exports.createPaymentIntent = void 0;
40
- var jsonwebtoken_1 = require("jsonwebtoken");
41
- var createPaymentIntent = function (stripe, JWT_TOKEN, options) { return __awaiter(void 0, void 0, void 0, function () {
42
- var paymentIntent, tokenData, token;
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0: return [4 /*yield*/, stripe.paymentIntents.create(options)];
46
- case 1:
47
- paymentIntent = _a.sent();
48
- tokenData = {
49
- type: "payment",
50
- options: {
51
- paymentIntentId: paymentIntent.id,
52
- client_secret: paymentIntent.client_secret,
53
- },
54
- };
55
- token = jsonwebtoken_1.sign(tokenData, JWT_TOKEN);
56
- return [2 /*return*/, {
57
- paymentIntentId: paymentIntent.id,
58
- token: token,
59
- }];
60
- }
61
- });
62
- }); };
63
- exports.createPaymentIntent = createPaymentIntent;
64
- var confirmPayment = function (stripe, JWT_TOKEN, options) { return __awaiter(void 0, void 0, void 0, function () {
65
- var paymentIntent, paymentMethods, resp, captured, confirmed, token, tokenData;
66
- var _a;
67
- return __generator(this, function (_b) {
68
- switch (_b.label) {
69
- case 0: return [4 /*yield*/, stripe.paymentIntents.retrieve(options.paymentIntentId)];
70
- case 1:
71
- paymentIntent = _b.sent();
72
- return [4 /*yield*/, stripe.paymentMethods.list({
73
- customer: (_a = paymentIntent.customer) === null || _a === void 0 ? void 0 : _a.toString(),
74
- type: "card",
75
- })];
76
- case 2:
77
- paymentMethods = _b.sent();
78
- if (paymentMethods.data.length == 0) {
79
- throw "Payment method is missing";
80
- }
81
- return [4 /*yield*/, stripe.paymentIntents.confirm(options.paymentIntentId, {
82
- payment_method: paymentMethods.data[0].id,
83
- })];
84
- case 3:
85
- resp = _b.sent();
86
- captured = false;
87
- confirmed = false;
88
- token = undefined;
89
- if (resp.status == "requires_capture" || resp.status == "succeeded") {
90
- confirmed = true;
91
- if (resp.status == "succeeded")
92
- captured = true;
93
- }
94
- else {
95
- tokenData = {
96
- type: "payment",
97
- options: {
98
- paymentIntentId: options.paymentIntentId,
99
- client_secret: paymentIntent.client_secret,
100
- },
101
- };
102
- token = jsonwebtoken_1.sign(tokenData, JWT_TOKEN);
103
- }
104
- return [2 /*return*/, {
105
- paymentIntentId: options.paymentIntentId,
106
- captured: captured,
107
- confirmed: confirmed,
108
- token: token,
109
- }];
110
- }
111
- });
112
- }); };
113
- exports.confirmPayment = confirmPayment;
@@ -1,7 +0,0 @@
1
- import { ModuleList } from "./schemas/ModuleList";
2
- export interface managementApiContext {
3
- managementApi: {
4
- jwtSecret: string;
5
- moduleList: ModuleList;
6
- };
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });