@flink-app/s3-plugin 0.3.5
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/.flink/generated-schemas.json +311 -0
- package/.flink/generatedHandlers.ts +7 -0
- package/.flink/generatedRepos.ts +5 -0
- package/.flink/schemas/schemas.json +5 -0
- package/.flink/schemas/schemas.ts +1 -0
- package/.flink/start.ts +4 -0
- package/dist/.flink/generatedHandlers.d.ts +1 -0
- package/dist/.flink/generatedHandlers.js +7 -0
- package/dist/.flink/generatedRepos.d.ts +1 -0
- package/dist/.flink/generatedRepos.js +7 -0
- package/dist/.flink/schemas/schemas.d.ts +0 -0
- package/dist/.flink/schemas/schemas.js +2 -0
- package/dist/.flink/schemas/schemas.json +5 -0
- package/dist/.flink/start.d.ts +3 -0
- package/dist/.flink/start.js +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +172 -0
- package/dist/s3Client.d.ts +36 -0
- package/dist/s3Client.js +233 -0
- package/dist/s3PluginContext.d.ts +6 -0
- package/dist/s3PluginContext.js +2 -0
- package/dist/schemas/ListObjectsResponse.d.ts +5 -0
- package/dist/schemas/ListObjectsResponse.js +2 -0
- package/dist/schemas/s3ClientOptions.d.ts +7 -0
- package/dist/schemas/s3ClientOptions.js +2 -0
- package/dist/schemas/s3PluginOptions.d.ts +11 -0
- package/dist/schemas/s3PluginOptions.js +2 -0
- package/dist/src/Ctx.d.ts +19 -0
- package/dist/src/Ctx.js +2 -0
- package/dist/src/handlers/HandlebarsTemplateHandler.d.ts +5 -0
- package/dist/src/handlers/HandlebarsTemplateHandler.js +63 -0
- package/dist/src/handlers/Management/Get.d.ts +7 -0
- package/dist/src/handlers/Management/Get.js +53 -0
- package/dist/src/handlers/Management/GetManagement.d.ts +8 -0
- package/dist/src/handlers/Management/GetManagement.js +53 -0
- package/dist/src/handlers/User/DeleteByUserid.d.ts +9 -0
- package/dist/src/handlers/User/DeleteByUserid.js +70 -0
- package/dist/src/handlers/User/GetByUserid.d.ts +9 -0
- package/dist/src/handlers/User/GetByUserid.js +71 -0
- package/dist/src/handlers/User/GetList.d.ts +9 -0
- package/dist/src/handlers/User/GetList.js +64 -0
- package/dist/src/handlers/User/GetMe.d.ts +8 -0
- package/dist/src/handlers/User/GetMe.js +81 -0
- package/dist/src/handlers/User/Post.d.ts +10 -0
- package/dist/src/handlers/User/Post.js +87 -0
- package/dist/src/handlers/User/PostLogin.d.ts +10 -0
- package/dist/src/handlers/User/PostLogin.js +86 -0
- package/dist/src/handlers/User/PutByUserid.d.ts +9 -0
- package/dist/src/handlers/User/PutByUserid.js +97 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +380 -0
- package/dist/src/lib/customer.d.ts +6 -0
- package/dist/src/lib/customer.js +121 -0
- package/dist/src/lib/payment.d.ts +6 -0
- package/dist/src/lib/payment.js +113 -0
- package/dist/src/managementApiContext.d.ts +7 -0
- package/dist/src/managementApiContext.js +2 -0
- package/dist/src/models/ManagementApi.d.ts +28 -0
- package/dist/src/models/ManagementApi.js +8 -0
- package/dist/src/repos/ConnectSessionRepo.d.ts +5 -0
- package/dist/src/repos/ConnectSessionRepo.js +26 -0
- package/dist/src/repos/ManagementUserRepo.d.ts +5 -0
- package/dist/src/repos/ManagementUserRepo.js +26 -0
- package/dist/src/reposx/ConnectSessionRepo.d.ts +5 -0
- package/dist/src/reposx/ConnectSessionRepo.js +26 -0
- package/dist/src/schemas/ConnectSession.d.ts +4 -0
- package/dist/src/schemas/ConnectSession.js +2 -0
- package/dist/src/schemas/Management/GetReq.d.ts +2 -0
- package/dist/src/schemas/Management/GetReq.js +2 -0
- package/dist/src/schemas/Management/GetRes.d.ts +3 -0
- package/dist/src/schemas/Management/GetRes.js +2 -0
- package/dist/src/schemas/ManagementUser.d.ts +6 -0
- package/dist/src/schemas/ManagementUser.js +2 -0
- package/dist/src/schemas/ManagementUserViewModel.d.ts +4 -0
- package/dist/src/schemas/ManagementUserViewModel.js +19 -0
- package/dist/src/schemas/ModuleList.d.ts +18 -0
- package/dist/src/schemas/ModuleList.js +2 -0
- package/dist/src/schemas/User/DeleteByUseridReq.d.ts +2 -0
- package/dist/src/schemas/User/DeleteByUseridReq.js +2 -0
- package/dist/src/schemas/User/DeleteByUseridRes.d.ts +2 -0
- package/dist/src/schemas/User/DeleteByUseridRes.js +2 -0
- package/dist/src/schemas/User/GetByUseridReq.d.ts +2 -0
- package/dist/src/schemas/User/GetByUseridReq.js +2 -0
- package/dist/src/schemas/User/GetByUseridRes.d.ts +3 -0
- package/dist/src/schemas/User/GetByUseridRes.js +2 -0
- package/dist/src/schemas/User/GetListReq.d.ts +2 -0
- package/dist/src/schemas/User/GetListReq.js +2 -0
- package/dist/src/schemas/User/GetListRes.d.ts +4 -0
- package/dist/src/schemas/User/GetListRes.js +2 -0
- package/dist/src/schemas/User/GetMeReq.d.ts +2 -0
- package/dist/src/schemas/User/GetMeReq.js +2 -0
- package/dist/src/schemas/User/GetMeRes.d.ts +3 -0
- package/dist/src/schemas/User/GetMeRes.js +2 -0
- package/dist/src/schemas/User/PostLoginReq.d.ts +4 -0
- package/dist/src/schemas/User/PostLoginReq.js +2 -0
- package/dist/src/schemas/User/PostLoginRes.d.ts +5 -0
- package/dist/src/schemas/User/PostLoginRes.js +2 -0
- package/dist/src/schemas/User/PostReq.d.ts +3 -0
- package/dist/src/schemas/User/PostReq.js +2 -0
- package/dist/src/schemas/User/PostRes.d.ts +3 -0
- package/dist/src/schemas/User/PostRes.js +2 -0
- package/dist/src/schemas/User/PutByUseridReq.d.ts +3 -0
- package/dist/src/schemas/User/PutByUseridReq.js +2 -0
- package/dist/src/schemas/User/PutByUseridRes.d.ts +3 -0
- package/dist/src/schemas/User/PutByUseridRes.js +2 -0
- package/dist/src/schemas/createStripeCustomerOptions.d.ts +11 -0
- package/dist/src/schemas/createStripeCustomerOptions.js +2 -0
- package/dist/src/schemas/customer/connectToStripeConnectOptions.d.ts +3 -0
- package/dist/src/schemas/customer/connectToStripeConnectOptions.js +2 -0
- package/dist/src/schemas/customer/hasPaymentMethodOptions.d.ts +3 -0
- package/dist/src/schemas/customer/hasPaymentMethodOptions.js +2 -0
- package/dist/src/schemas/customer/setupCardOptions.d.ts +3 -0
- package/dist/src/schemas/customer/setupCardOptions.js +2 -0
- package/dist/src/schemas/customer/setupCardResponse.d.ts +4 -0
- package/dist/src/schemas/customer/setupCardResponse.js +2 -0
- package/dist/src/schemas/customer/setupCardTokenOptions.d.ts +4 -0
- package/dist/src/schemas/customer/setupCardTokenOptions.js +2 -0
- package/dist/src/schemas/payment/capturePaymentOptions.d.ts +4 -0
- package/dist/src/schemas/payment/capturePaymentOptions.js +2 -0
- package/dist/src/schemas/payment/confirmPaymentOptions.d.ts +4 -0
- package/dist/src/schemas/payment/confirmPaymentOptions.js +2 -0
- package/dist/src/schemas/payment/confirmPaymentResponse.d.ts +7 -0
- package/dist/src/schemas/payment/confirmPaymentResponse.js +2 -0
- package/dist/src/schemas/payment/confirmPaymentTokenOptions.d.ts +4 -0
- package/dist/src/schemas/payment/confirmPaymentTokenOptions.js +2 -0
- package/dist/src/schemas/payment/createPaymentResponse.d.ts +5 -0
- package/dist/src/schemas/payment/createPaymentResponse.js +2 -0
- package/dist/src/schemas/stripeAPIToken.d.ts +4 -0
- package/dist/src/schemas/stripeAPIToken.js +2 -0
- package/dist/src/schemas/stripePluginOptions.d.ts +31 -0
- package/dist/src/schemas/stripePluginOptions.js +2 -0
- package/dist/src/stripeAPI.d.ts +32 -0
- package/dist/src/stripeAPI.js +163 -0
- package/dist/src/stripePlguinContext.d.ts +5 -0
- package/dist/src/stripePlguinContext.js +2 -0
- package/dist/src/stripePluginContext.d.ts +6 -0
- package/dist/src/stripePluginContext.js +2 -0
- package/dist/src/templates/connect-done.d.ts +1 -0
- package/dist/src/templates/connect-done.js +4 -0
- package/dist/src/templates/error.d.ts +1 -0
- package/dist/src/templates/error.js +4 -0
- package/dist/src/templates/master.d.ts +1 -0
- package/dist/src/templates/master.js +4 -0
- package/dist/src/templates/pay-enter-card.d.ts +1 -0
- package/dist/src/templates/pay-enter-card.js +4 -0
- package/dist/src/templates/pay-select-card.d.ts +1 -0
- package/dist/src/templates/pay-select-card.js +4 -0
- package/dist/src/templates/setup-card.d.ts +1 -0
- package/dist/src/templates/setup-card.js +4 -0
- package/dist/src/templates/setup-done.d.ts +1 -0
- package/dist/src/templates/setup-done.js +4 -0
- package/dist/src/templates/style.d.ts +1 -0
- package/dist/src/templates/style.js +4 -0
- package/dist/src/utils/bcrypt.d.ts +2 -0
- package/dist/src/utils/bcrypt.js +28 -0
- package/nodemon.json +7 -0
- package/package.json +34 -0
- package/readme.md +57 -0
- package/src/index.ts +100 -0
- package/src/s3Client.ts +150 -0
- package/src/s3PluginContext.ts +8 -0
- package/src/schemas/ListObjectsResponse.ts +3 -0
- package/src/schemas/s3ClientOptions.ts +7 -0
- package/src/schemas/s3PluginOptions.ts +11 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,380 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
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>;
|
|
@@ -0,0 +1,121 @@
|
|
|
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;
|
|
@@ -0,0 +1,6 @@
|
|
|
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>;
|
|
@@ -0,0 +1,113 @@
|
|
|
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;
|