@flink-app/stripe-plugin 2.0.0-alpha.55 → 2.0.0-alpha.57
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/generatedAgents.ts +1 -1
- package/.flink/generatedHandlers.ts +1 -1
- package/.flink/generatedJobs.ts +1 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/generatedTools.ts +1 -1
- package/.flink/start.ts +1 -1
- package/CHANGELOG.md +25 -0
- package/dist/.flink/generatedAgents.js +13 -6
- package/dist/.flink/generatedAgents.js.map +1 -0
- package/dist/.flink/generatedHandlers.js +13 -6
- package/dist/.flink/generatedHandlers.js.map +1 -0
- package/dist/.flink/generatedJobs.js +13 -6
- package/dist/.flink/generatedJobs.js.map +1 -0
- package/dist/.flink/generatedRepos.js +13 -6
- package/dist/.flink/generatedRepos.js.map +1 -0
- package/dist/.flink/generatedTools.js +13 -6
- package/dist/.flink/generatedTools.js.map +1 -0
- package/dist/.flink/schema-manifest.json +234 -0
- package/dist/.flink/schemas/schemas.js +1 -1
- package/dist/.flink/start.js +12 -3
- package/dist/.flink/start.js.map +1 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/src/Ctx.js +3 -1
- package/dist/src/Ctx.js.map +1 -0
- package/dist/src/handlers/HandlebarsTemplateHandler.d.ts +1 -1
- package/dist/src/handlers/HandlebarsTemplateHandler.js +24 -60
- package/dist/src/handlers/HandlebarsTemplateHandler.js.map +1 -0
- package/dist/src/index.js +225 -341
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/customer.js +101 -116
- package/dist/src/lib/customer.js.map +1 -0
- package/dist/src/lib/payment.js +64 -107
- package/dist/src/lib/payment.js.map +1 -0
- package/dist/src/reposx/ConnectSessionRepo.js +12 -24
- package/dist/src/reposx/ConnectSessionRepo.js.map +1 -0
- package/dist/src/schemas/ConnectSession.js +3 -1
- package/dist/src/schemas/ConnectSession.js.map +1 -0
- package/dist/src/schemas/createStripeCustomerOptions.js +3 -1
- package/dist/src/schemas/createStripeCustomerOptions.js.map +1 -0
- package/dist/src/schemas/customer/connectToStripeConnectOptions.js +3 -1
- package/dist/src/schemas/customer/connectToStripeConnectOptions.js.map +1 -0
- package/dist/src/schemas/customer/hasPaymentMethodOptions.js +3 -1
- package/dist/src/schemas/customer/hasPaymentMethodOptions.js.map +1 -0
- package/dist/src/schemas/customer/setupCardOptions.js +3 -1
- package/dist/src/schemas/customer/setupCardOptions.js.map +1 -0
- package/dist/src/schemas/customer/setupCardResponse.js +3 -1
- package/dist/src/schemas/customer/setupCardResponse.js.map +1 -0
- package/dist/src/schemas/customer/setupCardTokenOptions.js +3 -1
- package/dist/src/schemas/customer/setupCardTokenOptions.js.map +1 -0
- package/dist/src/schemas/payment/capturePaymentOptions.js +3 -1
- package/dist/src/schemas/payment/capturePaymentOptions.js.map +1 -0
- package/dist/src/schemas/payment/confirmPaymentOptions.js +3 -1
- package/dist/src/schemas/payment/confirmPaymentOptions.js.map +1 -0
- package/dist/src/schemas/payment/confirmPaymentResponse.js +3 -1
- package/dist/src/schemas/payment/confirmPaymentResponse.js.map +1 -0
- package/dist/src/schemas/payment/confirmPaymentTokenOptions.js +3 -1
- package/dist/src/schemas/payment/confirmPaymentTokenOptions.js.map +1 -0
- package/dist/src/schemas/payment/createPaymentResponse.js +3 -1
- package/dist/src/schemas/payment/createPaymentResponse.js.map +1 -0
- package/dist/src/schemas/stripeAPIToken.js +3 -1
- package/dist/src/schemas/stripeAPIToken.js.map +1 -0
- package/dist/src/schemas/stripePluginOptions.js +3 -1
- package/dist/src/schemas/stripePluginOptions.js.map +1 -0
- package/dist/src/stripeAPI.js +87 -154
- package/dist/src/stripeAPI.js.map +1 -0
- package/dist/src/stripePluginContext.js +3 -1
- package/dist/src/stripePluginContext.js.map +1 -0
- package/dist/src/templates/connect-done.js +23 -3
- package/dist/src/templates/connect-done.js.map +1 -0
- package/dist/src/templates/error.js +10 -3
- package/dist/src/templates/error.js.map +1 -0
- package/dist/src/templates/master.js +29 -3
- package/dist/src/templates/master.js.map +1 -0
- package/dist/src/templates/pay-done.d.ts +1 -0
- package/dist/src/templates/pay-done.js +24 -0
- package/dist/src/templates/pay-done.js.map +1 -0
- package/dist/src/templates/pay-enter-card.js +95 -3
- package/dist/src/templates/pay-enter-card.js.map +1 -0
- package/dist/src/templates/pay-select-card.js +79 -3
- package/dist/src/templates/pay-select-card.js.map +1 -0
- package/dist/src/templates/setup-card.js +102 -3
- package/dist/src/templates/setup-card.js.map +1 -0
- package/dist/src/templates/setup-done.js +23 -3
- package/dist/src/templates/setup-done.js.map +1 -0
- package/dist/src/templates/style.js +144 -3
- package/dist/src/templates/style.js.map +1 -0
- package/package.json +3 -3
- package/.flink/schemas/schemas.ts +0 -1
package/dist/src/index.js
CHANGED
|
@@ -1,387 +1,271 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "stripePlugin", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return stripePlugin;
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
});
|
|
11
|
+
const _flink = require("@flink-app/flink");
|
|
12
|
+
const _HandlebarsTemplateHandler = require("./handlers/HandlebarsTemplateHandler");
|
|
13
|
+
const _stripeAPI = require("./stripeAPI");
|
|
14
|
+
_export_star(require("./stripePluginContext"), exports);
|
|
15
|
+
const _connectdone = require("./templates/connect-done");
|
|
16
|
+
const _error = require("./templates/error");
|
|
17
|
+
const _master = require("./templates/master");
|
|
18
|
+
const _payentercard = require("./templates/pay-enter-card");
|
|
19
|
+
const _payselectcard = require("./templates/pay-select-card");
|
|
20
|
+
const _setupcard = require("./templates/setup-card");
|
|
21
|
+
const _setupdone = require("./templates/setup-done");
|
|
22
|
+
const _style = require("./templates/style");
|
|
23
|
+
const _jsonwebtoken = require("jsonwebtoken");
|
|
24
|
+
const _ConnectSessionRepo = /*#__PURE__*/ _interop_require_default(require("./reposx/ConnectSessionRepo"));
|
|
25
|
+
function _export_star(from, to) {
|
|
26
|
+
Object.keys(from).forEach(function(k) {
|
|
27
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
28
|
+
Object.defineProperty(to, k, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function() {
|
|
31
|
+
return from[k];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
23
35
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
53
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
|
-
};
|
|
55
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
-
exports.stripePlugin = void 0;
|
|
57
|
-
var flink_1 = require("@flink-app/flink");
|
|
58
|
-
var HandlebarsTemplateHandler_1 = require("./handlers/HandlebarsTemplateHandler");
|
|
59
|
-
var stripeAPI_1 = require("./stripeAPI");
|
|
60
|
-
__exportStar(require("./stripePluginContext"), exports);
|
|
61
|
-
var connect_done_1 = require("./templates/connect-done");
|
|
62
|
-
var error_1 = require("./templates/error");
|
|
63
|
-
var master_1 = require("./templates/master");
|
|
64
|
-
var pay_enter_card_1 = require("./templates/pay-enter-card");
|
|
65
|
-
var pay_select_card_1 = require("./templates/pay-select-card");
|
|
66
|
-
var setup_card_1 = require("./templates/setup-card");
|
|
67
|
-
var setup_done_1 = require("./templates/setup-done");
|
|
68
|
-
var style_1 = require("./templates/style");
|
|
69
|
-
var jsonwebtoken_1 = require("jsonwebtoken");
|
|
70
|
-
var ConnectSessionRepo_1 = __importDefault(require("./reposx/ConnectSessionRepo"));
|
|
71
|
-
var stripePlugin = function (options) {
|
|
72
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
73
|
-
if (options.paymentCallback == null)
|
|
74
|
-
options.paymentCallback = function () { };
|
|
75
|
-
if (options.stripeConnectCallback == null)
|
|
76
|
-
options.stripeConnectCallback = function () { };
|
|
77
|
-
var stripeAPI = new stripeAPI_1.StripeAPI(options);
|
|
78
|
-
var templates = {
|
|
79
|
-
master: ((_a = options.templates) === null || _a === void 0 ? void 0 : _a.master) || master_1.masterTemplate,
|
|
80
|
-
style: ((_b = options.templates) === null || _b === void 0 ? void 0 : _b.style) || style_1.styleTemplate,
|
|
81
|
-
setupCard: ((_c = options.templates) === null || _c === void 0 ? void 0 : _c.setupCard) || setup_card_1.setupCardTemplate,
|
|
82
|
-
setupDone: ((_d = options.templates) === null || _d === void 0 ? void 0 : _d.setupDone) || setup_done_1.setupDoneTemplate,
|
|
83
|
-
error: ((_e = options.templates) === null || _e === void 0 ? void 0 : _e.error) || error_1.errorTemplate,
|
|
84
|
-
paySelectCard: ((_f = options.templates) === null || _f === void 0 ? void 0 : _f.paySelectCard) || pay_select_card_1.paySelectCardTemplate,
|
|
85
|
-
payEnterCard: ((_g = options.templates) === null || _g === void 0 ? void 0 : _g.payEnterCard) || pay_enter_card_1.payEnterCardTemplate,
|
|
86
|
-
connectDone: ((_h = options.templates) === null || _h === void 0 ? void 0 : _h.connectDone) || connect_done_1.connectDoneTemplate,
|
|
36
|
+
return from;
|
|
37
|
+
}
|
|
38
|
+
function _interop_require_default(obj) {
|
|
39
|
+
return obj && obj.__esModule ? obj : {
|
|
40
|
+
default: obj
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const stripePlugin = (options)=>{
|
|
44
|
+
var _options_templates, _options_templates1, _options_templates2, _options_templates3, _options_templates4, _options_templates5, _options_templates6, _options_templates7;
|
|
45
|
+
if (options.paymentCallback == null) options.paymentCallback = ()=>{};
|
|
46
|
+
if (options.stripeConnectCallback == null) options.stripeConnectCallback = ()=>{};
|
|
47
|
+
const stripeAPI = new _stripeAPI.StripeAPI(options);
|
|
48
|
+
const templates = {
|
|
49
|
+
master: ((_options_templates = options.templates) === null || _options_templates === void 0 ? void 0 : _options_templates.master) || _master.masterTemplate,
|
|
50
|
+
style: ((_options_templates1 = options.templates) === null || _options_templates1 === void 0 ? void 0 : _options_templates1.style) || _style.styleTemplate,
|
|
51
|
+
setupCard: ((_options_templates2 = options.templates) === null || _options_templates2 === void 0 ? void 0 : _options_templates2.setupCard) || _setupcard.setupCardTemplate,
|
|
52
|
+
setupDone: ((_options_templates3 = options.templates) === null || _options_templates3 === void 0 ? void 0 : _options_templates3.setupDone) || _setupdone.setupDoneTemplate,
|
|
53
|
+
error: ((_options_templates4 = options.templates) === null || _options_templates4 === void 0 ? void 0 : _options_templates4.error) || _error.errorTemplate,
|
|
54
|
+
paySelectCard: ((_options_templates5 = options.templates) === null || _options_templates5 === void 0 ? void 0 : _options_templates5.paySelectCard) || _payselectcard.paySelectCardTemplate,
|
|
55
|
+
payEnterCard: ((_options_templates6 = options.templates) === null || _options_templates6 === void 0 ? void 0 : _options_templates6.payEnterCard) || _payentercard.payEnterCardTemplate,
|
|
56
|
+
connectDone: ((_options_templates7 = options.templates) === null || _options_templates7 === void 0 ? void 0 : _options_templates7.connectDone) || _connectdone.connectDoneTemplate
|
|
87
57
|
};
|
|
88
58
|
return {
|
|
89
59
|
id: "stripePlugin",
|
|
90
|
-
init:
|
|
60
|
+
init: (app)=>init(app, options),
|
|
91
61
|
ctx: {
|
|
92
|
-
stripeAPI
|
|
93
|
-
templates
|
|
94
|
-
}
|
|
62
|
+
stripeAPI,
|
|
63
|
+
templates
|
|
64
|
+
}
|
|
95
65
|
};
|
|
96
66
|
};
|
|
97
|
-
exports.stripePlugin = stripePlugin;
|
|
98
67
|
function init(app, options) {
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
flink_1.log.info("Registered route GET " + options.baseUrl + "/customer/setup-card/:token");
|
|
104
|
-
(_a = app.expressApp) === null || _a === void 0 ? void 0 : _a.get(options.baseUrl + "/customer/setup-card/:token", function (req, res) {
|
|
105
|
-
var _a, _b;
|
|
68
|
+
var _app_expressApp, _app_expressApp1, _app_expressApp2, _app_expressApp3, _app_expressApp4, _app_expressApp5, _app_expressApp6, _app_expressApp7;
|
|
69
|
+
if (options.baseUrl == null) options.baseUrl = "/stripe";
|
|
70
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/customer/setup-card/:token");
|
|
71
|
+
(_app_expressApp = app.expressApp) === null || _app_expressApp === void 0 ? void 0 : _app_expressApp.get(options.baseUrl + "/customer/setup-card/:token", (req, res)=>{
|
|
106
72
|
try {
|
|
107
|
-
var
|
|
73
|
+
var _options_phrases, _options_phrases1;
|
|
74
|
+
const tokenData = (0, _jsonwebtoken.verify)(req.params.token, options.JTW_TOKEN);
|
|
108
75
|
if (tokenData.type != "setup_card") {
|
|
109
76
|
throw "Invalid token type";
|
|
110
77
|
}
|
|
111
|
-
(0,
|
|
112
|
-
setupDescription: (
|
|
78
|
+
(0, _HandlebarsTemplateHandler.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.setupCard, {
|
|
79
|
+
setupDescription: (_options_phrases = options.phrases) === null || _options_phrases === void 0 ? void 0 : _options_phrases.setupDescription,
|
|
113
80
|
logo: options.logo,
|
|
114
81
|
stripePublishableKey: options.stripePublishableKey,
|
|
115
82
|
client_secret: tokenData.options.client_secret,
|
|
116
83
|
baseUrl: options.baseUrl,
|
|
117
|
-
setupButtonText: ((
|
|
84
|
+
setupButtonText: ((_options_phrases1 = options.phrases) === null || _options_phrases1 === void 0 ? void 0 : _options_phrases1.setupButtonText) || "Spara"
|
|
118
85
|
}, res);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
flink_1.log.error(ex);
|
|
86
|
+
} catch (ex) {
|
|
87
|
+
_flink.log.error(ex);
|
|
122
88
|
res.redirect(options.baseUrl + "/error");
|
|
123
89
|
return;
|
|
124
90
|
}
|
|
125
91
|
});
|
|
126
|
-
|
|
127
|
-
(
|
|
128
|
-
var _a;
|
|
92
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/customer/setup-card-done");
|
|
93
|
+
(_app_expressApp1 = app.expressApp) === null || _app_expressApp1 === void 0 ? void 0 : _app_expressApp1.get(options.baseUrl + "/customer/setup-card-done/", (req, res)=>{
|
|
129
94
|
try {
|
|
130
|
-
|
|
95
|
+
var _options_phrases;
|
|
96
|
+
(0, _HandlebarsTemplateHandler.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.setupDone, {
|
|
131
97
|
redirectUrl: options.redirectUrl,
|
|
132
|
-
message: ((
|
|
98
|
+
message: ((_options_phrases = options.phrases) === null || _options_phrases === void 0 ? void 0 : _options_phrases.setupDoneMessage) || "Kortet har sparats."
|
|
133
99
|
}, res);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
flink_1.log.error(ex);
|
|
100
|
+
} catch (ex) {
|
|
101
|
+
_flink.log.error(ex);
|
|
137
102
|
res.redirect(options.baseUrl + "/error");
|
|
138
103
|
return;
|
|
139
104
|
}
|
|
140
105
|
});
|
|
141
|
-
(
|
|
106
|
+
(_app_expressApp2 = app.expressApp) === null || _app_expressApp2 === void 0 ? void 0 : _app_expressApp2.get(options.baseUrl + "/error", (req, res)=>{
|
|
142
107
|
try {
|
|
143
|
-
(0,
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
flink_1.log.error(ex);
|
|
108
|
+
(0, _HandlebarsTemplateHandler.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.error, {}, res);
|
|
109
|
+
} catch (ex) {
|
|
110
|
+
_flink.log.error(ex);
|
|
147
111
|
res.redirect(options.baseUrl + "/");
|
|
148
112
|
return;
|
|
149
113
|
}
|
|
150
114
|
});
|
|
151
|
-
|
|
152
|
-
(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
_b.trys.push([0, 3, , 4]);
|
|
159
|
-
tokenData = (0, jsonwebtoken_1.verify)(req.params.token, options.JTW_TOKEN);
|
|
160
|
-
if (tokenData.type != "payment") {
|
|
161
|
-
throw "Invalid token type";
|
|
162
|
-
}
|
|
163
|
-
stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
164
|
-
return [4 /*yield*/, stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId)];
|
|
165
|
-
case 1:
|
|
166
|
-
paymentIntent = _b.sent();
|
|
167
|
-
return [4 /*yield*/, stripe.paymentMethods.list({
|
|
168
|
-
customer: (_a = paymentIntent.customer) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
169
|
-
type: "card",
|
|
170
|
-
})];
|
|
171
|
-
case 2:
|
|
172
|
-
paymentMethods = _b.sent();
|
|
173
|
-
if (paymentMethods.data.length == 0) {
|
|
174
|
-
res.redirect(options.baseUrl + "/payment/enter-card/" + req.params.token);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
res.redirect(options.baseUrl + "/payment/select-card/" + req.params.token);
|
|
178
|
-
}
|
|
179
|
-
return [3 /*break*/, 4];
|
|
180
|
-
case 3:
|
|
181
|
-
ex_1 = _b.sent();
|
|
182
|
-
flink_1.log.error(ex_1);
|
|
183
|
-
res.redirect(options.baseUrl + "/error");
|
|
184
|
-
return [2 /*return*/];
|
|
185
|
-
case 4: return [2 /*return*/];
|
|
115
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/payment/confirm/:token");
|
|
116
|
+
(_app_expressApp3 = app.expressApp) === null || _app_expressApp3 === void 0 ? void 0 : _app_expressApp3.get(options.baseUrl + "/payment/confirm/:token", async (req, res)=>{
|
|
117
|
+
try {
|
|
118
|
+
var _paymentIntent_customer;
|
|
119
|
+
const tokenData = (0, _jsonwebtoken.verify)(req.params.token, options.JTW_TOKEN);
|
|
120
|
+
if (tokenData.type != "payment") {
|
|
121
|
+
throw "Invalid token type";
|
|
186
122
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
tokenData = (0, jsonwebtoken_1.verify)(req.params.token, options.JTW_TOKEN);
|
|
198
|
-
if (tokenData.type != "payment") {
|
|
199
|
-
throw "Invalid token type";
|
|
200
|
-
}
|
|
201
|
-
stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
202
|
-
return [4 /*yield*/, stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId)];
|
|
203
|
-
case 1:
|
|
204
|
-
paymentIntent = _d.sent();
|
|
205
|
-
return [4 /*yield*/, stripe.paymentMethods.list({
|
|
206
|
-
customer: (_a = paymentIntent.customer) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
207
|
-
type: "card",
|
|
208
|
-
})];
|
|
209
|
-
case 2:
|
|
210
|
-
paymentMethods = _d.sent();
|
|
211
|
-
if (paymentMethods.data.length == 0) {
|
|
212
|
-
res.redirect(options.baseUrl + "/payment/enter-card/" + req.params.token);
|
|
213
|
-
}
|
|
214
|
-
ctx = {
|
|
215
|
-
card: paymentMethods.data[0].card,
|
|
216
|
-
paymentSelectCardPayButtonText: ((_b = options.phrases) === null || _b === void 0 ? void 0 : _b.paymentSelectCardPayButtonText) || "Betala",
|
|
217
|
-
paymentSelectCardChangeCardButtonText: ((_c = options.phrases) === null || _c === void 0 ? void 0 : _c.paymentSelectCardChangeCardButtonText) || "Byt kort",
|
|
218
|
-
publishableKey: options.stripePublishableKey,
|
|
219
|
-
token: req.params.token,
|
|
220
|
-
baseUrl: options.baseUrl,
|
|
221
|
-
logo: options.logo,
|
|
222
|
-
client_secrect: paymentIntent.client_secret,
|
|
223
|
-
price: (paymentIntent.amount / 100).toFixed(2) + " " + paymentIntent.currency.toUpperCase(),
|
|
224
|
-
description: paymentIntent.description,
|
|
225
|
-
};
|
|
226
|
-
(0, HandlebarsTemplateHandler_1.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.paySelectCard, ctx, res);
|
|
227
|
-
return [3 /*break*/, 4];
|
|
228
|
-
case 3:
|
|
229
|
-
ex_2 = _d.sent();
|
|
230
|
-
flink_1.log.error(ex_2);
|
|
231
|
-
res.redirect(options.baseUrl + "/error");
|
|
232
|
-
return [2 /*return*/];
|
|
233
|
-
case 4: return [2 /*return*/];
|
|
123
|
+
const stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
124
|
+
const paymentIntent = await stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId);
|
|
125
|
+
const paymentMethods = await stripe.paymentMethods.list({
|
|
126
|
+
customer: (_paymentIntent_customer = paymentIntent.customer) === null || _paymentIntent_customer === void 0 ? void 0 : _paymentIntent_customer.toString(),
|
|
127
|
+
type: "card"
|
|
128
|
+
});
|
|
129
|
+
if (paymentMethods.data.length == 0) {
|
|
130
|
+
res.redirect(options.baseUrl + "/payment/enter-card/" + req.params.token);
|
|
131
|
+
} else {
|
|
132
|
+
res.redirect(options.baseUrl + "/payment/select-card/" + req.params.token);
|
|
234
133
|
}
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
250
|
-
return [4 /*yield*/, stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId)];
|
|
251
|
-
case 1:
|
|
252
|
-
paymentIntent = _f.sent();
|
|
253
|
-
return [4 /*yield*/, stripe.paymentMethods.list({
|
|
254
|
-
customer: (_d = paymentIntent.customer) === null || _d === void 0 ? void 0 : _d.toString(),
|
|
255
|
-
type: "card",
|
|
256
|
-
})];
|
|
257
|
-
case 2:
|
|
258
|
-
paymentMethods = _f.sent();
|
|
259
|
-
_a = paymentMethods.data;
|
|
260
|
-
_b = [];
|
|
261
|
-
for (_c in _a)
|
|
262
|
-
_b.push(_c);
|
|
263
|
-
_i = 0;
|
|
264
|
-
_f.label = 3;
|
|
265
|
-
case 3:
|
|
266
|
-
if (!(_i < _b.length)) return [3 /*break*/, 6];
|
|
267
|
-
_c = _b[_i];
|
|
268
|
-
if (!(_c in _a)) return [3 /*break*/, 5];
|
|
269
|
-
x = _c;
|
|
270
|
-
pi = paymentMethods.data[x];
|
|
271
|
-
return [4 /*yield*/, stripe.paymentMethods.detach(pi.id)];
|
|
272
|
-
case 4:
|
|
273
|
-
_f.sent();
|
|
274
|
-
_f.label = 5;
|
|
275
|
-
case 5:
|
|
276
|
-
_i++;
|
|
277
|
-
return [3 /*break*/, 3];
|
|
278
|
-
case 6:
|
|
279
|
-
ctx = {
|
|
280
|
-
paymentEnterCardPayButtonText: ((_e = options.phrases) === null || _e === void 0 ? void 0 : _e.paymentEnterCardPayButtonText) || "Betala",
|
|
281
|
-
publishableKey: options.stripePublishableKey,
|
|
282
|
-
token: req.params.token,
|
|
283
|
-
baseUrl: options.baseUrl,
|
|
284
|
-
logo: options.logo,
|
|
285
|
-
client_secrect: paymentIntent.client_secret,
|
|
286
|
-
price: (paymentIntent.amount / 100).toFixed(2) + " " + paymentIntent.currency.toUpperCase(),
|
|
287
|
-
description: paymentIntent.description,
|
|
288
|
-
};
|
|
289
|
-
(0, HandlebarsTemplateHandler_1.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.payEnterCard, ctx, res);
|
|
290
|
-
return [3 /*break*/, 8];
|
|
291
|
-
case 7:
|
|
292
|
-
ex_3 = _f.sent();
|
|
293
|
-
flink_1.log.error(ex_3);
|
|
294
|
-
res.redirect(options.baseUrl + "/error");
|
|
295
|
-
return [2 /*return*/];
|
|
296
|
-
case 8: return [2 /*return*/];
|
|
134
|
+
} catch (ex) {
|
|
135
|
+
_flink.log.error(ex);
|
|
136
|
+
res.redirect(options.baseUrl + "/error");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/payment/select-card/:token");
|
|
141
|
+
(_app_expressApp4 = app.expressApp) === null || _app_expressApp4 === void 0 ? void 0 : _app_expressApp4.get(options.baseUrl + "/payment/select-card/:token", async (req, res)=>{
|
|
142
|
+
try {
|
|
143
|
+
var _paymentIntent_customer, _options_phrases, _options_phrases1;
|
|
144
|
+
const tokenData = (0, _jsonwebtoken.verify)(req.params.token, options.JTW_TOKEN);
|
|
145
|
+
if (tokenData.type != "payment") {
|
|
146
|
+
throw "Invalid token type";
|
|
297
147
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
148
|
+
const stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
149
|
+
const paymentIntent = await stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId);
|
|
150
|
+
const paymentMethods = await stripe.paymentMethods.list({
|
|
151
|
+
customer: (_paymentIntent_customer = paymentIntent.customer) === null || _paymentIntent_customer === void 0 ? void 0 : _paymentIntent_customer.toString(),
|
|
152
|
+
type: "card"
|
|
153
|
+
});
|
|
154
|
+
if (paymentMethods.data.length == 0) {
|
|
155
|
+
res.redirect(options.baseUrl + "/payment/enter-card/" + req.params.token);
|
|
156
|
+
}
|
|
157
|
+
const ctx = {
|
|
158
|
+
card: paymentMethods.data[0].card,
|
|
159
|
+
paymentSelectCardPayButtonText: ((_options_phrases = options.phrases) === null || _options_phrases === void 0 ? void 0 : _options_phrases.paymentSelectCardPayButtonText) || "Betala",
|
|
160
|
+
paymentSelectCardChangeCardButtonText: ((_options_phrases1 = options.phrases) === null || _options_phrases1 === void 0 ? void 0 : _options_phrases1.paymentSelectCardChangeCardButtonText) || "Byt kort",
|
|
161
|
+
publishableKey: options.stripePublishableKey,
|
|
162
|
+
token: req.params.token,
|
|
163
|
+
baseUrl: options.baseUrl,
|
|
164
|
+
logo: options.logo,
|
|
165
|
+
client_secrect: paymentIntent.client_secret,
|
|
166
|
+
price: (paymentIntent.amount / 100).toFixed(2) + " " + paymentIntent.currency.toUpperCase(),
|
|
167
|
+
description: paymentIntent.description
|
|
168
|
+
};
|
|
169
|
+
(0, _HandlebarsTemplateHandler.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.paySelectCard, ctx, res);
|
|
170
|
+
} catch (ex) {
|
|
171
|
+
_flink.log.error(ex);
|
|
172
|
+
res.redirect(options.baseUrl + "/error");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/payment/enter-card/:token");
|
|
177
|
+
(_app_expressApp5 = app.expressApp) === null || _app_expressApp5 === void 0 ? void 0 : _app_expressApp5.get(options.baseUrl + "/payment/enter-card/:token", async (req, res)=>{
|
|
178
|
+
try {
|
|
179
|
+
var _paymentIntent_customer, _options_phrases;
|
|
180
|
+
const tokenData = (0, _jsonwebtoken.verify)(req.params.token, options.JTW_TOKEN);
|
|
181
|
+
if (tokenData.type != "payment") {
|
|
182
|
+
throw "Invalid token type";
|
|
183
|
+
}
|
|
184
|
+
const stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
185
|
+
const paymentIntent = await stripe.paymentIntents.retrieve(tokenData.options.paymentIntentId);
|
|
186
|
+
const paymentMethods = await stripe.paymentMethods.list({
|
|
187
|
+
customer: (_paymentIntent_customer = paymentIntent.customer) === null || _paymentIntent_customer === void 0 ? void 0 : _paymentIntent_customer.toString(),
|
|
188
|
+
type: "card"
|
|
189
|
+
});
|
|
190
|
+
for(var x in paymentMethods.data){
|
|
191
|
+
const pi = paymentMethods.data[x];
|
|
192
|
+
await stripe.paymentMethods.detach(pi.id);
|
|
341
193
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
194
|
+
const ctx = {
|
|
195
|
+
paymentEnterCardPayButtonText: ((_options_phrases = options.phrases) === null || _options_phrases === void 0 ? void 0 : _options_phrases.paymentEnterCardPayButtonText) || "Betala",
|
|
196
|
+
publishableKey: options.stripePublishableKey,
|
|
197
|
+
token: req.params.token,
|
|
198
|
+
baseUrl: options.baseUrl,
|
|
199
|
+
logo: options.logo,
|
|
200
|
+
client_secrect: paymentIntent.client_secret,
|
|
201
|
+
price: (paymentIntent.amount / 100).toFixed(2) + " " + paymentIntent.currency.toUpperCase(),
|
|
202
|
+
description: paymentIntent.description
|
|
203
|
+
};
|
|
204
|
+
(0, _HandlebarsTemplateHandler.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.payEnterCard, ctx, res);
|
|
205
|
+
} catch (ex) {
|
|
206
|
+
_flink.log.error(ex);
|
|
207
|
+
res.redirect(options.baseUrl + "/error");
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/callback/:event");
|
|
212
|
+
(_app_expressApp6 = app.expressApp) === null || _app_expressApp6 === void 0 ? void 0 : _app_expressApp6.post(options.baseUrl + "/callback/:event", async (req, res)=>{
|
|
213
|
+
if (req.params.event == "charge.succeeded") {
|
|
214
|
+
var _req_body_data_object, _req_body_data, _req_body;
|
|
215
|
+
const paymentIntentId = (_req_body = req.body) === null || _req_body === void 0 ? void 0 : (_req_body_data = _req_body.data) === null || _req_body_data === void 0 ? void 0 : (_req_body_data_object = _req_body_data.object) === null || _req_body_data_object === void 0 ? void 0 : _req_body_data_object.payment_intent;
|
|
216
|
+
if (paymentIntentId == null) {
|
|
217
|
+
res.status(400).send("Bad request");
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
221
|
+
try {
|
|
222
|
+
const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId);
|
|
223
|
+
if (paymentIntent == null) {
|
|
224
|
+
res.status(400).send("Bad request");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (paymentIntent.status == "succeeded" || paymentIntent.status == "requires_capture") {
|
|
364
228
|
try {
|
|
365
|
-
options.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
message: ((_b = options.phrases) === null || _b === void 0 ? void 0 : _b.connectDoneMessage) || "Kontot har kopplats till Stripe.",
|
|
369
|
-
}, res);
|
|
370
|
-
}
|
|
371
|
-
catch (ex) {
|
|
372
|
-
flink_1.log.error("paymentCallback:" + ex);
|
|
373
|
-
res.redirect(options.baseUrl + "/error");
|
|
229
|
+
options.paymentCallback(paymentIntent.id, paymentIntent.status);
|
|
230
|
+
} catch (ex) {
|
|
231
|
+
_flink.log.error("paymentCallback:" + ex);
|
|
374
232
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
case 4: return [2 /*return*/];
|
|
233
|
+
}
|
|
234
|
+
} catch (ex) {
|
|
235
|
+
_flink.log.error(ex);
|
|
236
|
+
res.status(500).send("Internal error");
|
|
380
237
|
}
|
|
381
|
-
}
|
|
382
|
-
|
|
238
|
+
}
|
|
239
|
+
res.status(200).send("Completed");
|
|
240
|
+
});
|
|
241
|
+
_flink.log.info("Registered route GET " + options.baseUrl + "/connect");
|
|
242
|
+
(_app_expressApp7 = app.expressApp) === null || _app_expressApp7 === void 0 ? void 0 : _app_expressApp7.get(options.baseUrl + "/connect", async (req, res)=>{
|
|
243
|
+
const { code, state } = req.query;
|
|
244
|
+
if (code && state) {
|
|
245
|
+
const stripe = app.ctx.plugins.stripePlugin.stripeAPI.stripe;
|
|
246
|
+
const token = await stripe.oauth.token({
|
|
247
|
+
grant_type: "authorization_code",
|
|
248
|
+
code: code.toString()
|
|
249
|
+
});
|
|
250
|
+
const repo = app.ctx.repos.connectsessionRepo;
|
|
251
|
+
const session = await repo.getById(state.toString());
|
|
252
|
+
try {
|
|
253
|
+
var _options_phrases;
|
|
254
|
+
options.stripeConnectCallback(session.userId, token.stripe_user_id);
|
|
255
|
+
(0, _HandlebarsTemplateHandler.HandlebarsTemplateHandler)(app.ctx.plugins.stripePlugin.templates.master, app.ctx.plugins.stripePlugin.templates.style, app.ctx.plugins.stripePlugin.templates.connectDone, {
|
|
256
|
+
redirectUrl: options.redirectUrl,
|
|
257
|
+
message: ((_options_phrases = options.phrases) === null || _options_phrases === void 0 ? void 0 : _options_phrases.connectDoneMessage) || "Kontot har kopplats till Stripe."
|
|
258
|
+
}, res);
|
|
259
|
+
} catch (ex) {
|
|
260
|
+
_flink.log.error("paymentCallback:" + ex);
|
|
261
|
+
res.redirect(options.baseUrl + "/error");
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
res.redirect(options.baseUrl + "/error");
|
|
265
|
+
}
|
|
266
|
+
});
|
|
383
267
|
if (app.db != null) {
|
|
384
|
-
app.addRepo("connectsessionRepo", new
|
|
268
|
+
app.addRepo("connectsessionRepo", new _ConnectSessionRepo.default("ConnectSessionRepo", app.db));
|
|
385
269
|
}
|
|
386
270
|
app.ctx.plugins.stripePlugin.stripeAPI.config.setRepo(app.ctx.repos.connectsessionRepo);
|
|
387
271
|
}
|