payment-skill 1.0.0

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 (110) hide show
  1. package/LICENSE +62 -0
  2. package/README.md +545 -0
  3. package/SKILL.md +99 -0
  4. package/SUPPORT.md +153 -0
  5. package/bin/payment-skill.js +2 -0
  6. package/dashboard.html +669 -0
  7. package/dist/api/bunq.d.ts +35 -0
  8. package/dist/api/bunq.d.ts.map +1 -0
  9. package/dist/api/bunq.js +164 -0
  10. package/dist/api/bunq.js.map +1 -0
  11. package/dist/api/wise.d.ts +32 -0
  12. package/dist/api/wise.d.ts.map +1 -0
  13. package/dist/api/wise.js +155 -0
  14. package/dist/api/wise.js.map +1 -0
  15. package/dist/cli.d.ts +8 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +69 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/commands/bunq.d.ts +8 -0
  20. package/dist/commands/bunq.d.ts.map +1 -0
  21. package/dist/commands/bunq.js +193 -0
  22. package/dist/commands/bunq.js.map +1 -0
  23. package/dist/commands/config.d.ts +8 -0
  24. package/dist/commands/config.d.ts.map +1 -0
  25. package/dist/commands/config.js +70 -0
  26. package/dist/commands/config.js.map +1 -0
  27. package/dist/commands/emergency.d.ts +8 -0
  28. package/dist/commands/emergency.d.ts.map +1 -0
  29. package/dist/commands/emergency.js +85 -0
  30. package/dist/commands/emergency.js.map +1 -0
  31. package/dist/commands/limits.d.ts +6 -0
  32. package/dist/commands/limits.d.ts.map +1 -0
  33. package/dist/commands/limits.js +125 -0
  34. package/dist/commands/limits.js.map +1 -0
  35. package/dist/commands/merchant.d.ts +6 -0
  36. package/dist/commands/merchant.d.ts.map +1 -0
  37. package/dist/commands/merchant.js +41 -0
  38. package/dist/commands/merchant.js.map +1 -0
  39. package/dist/commands/pay.d.ts +10 -0
  40. package/dist/commands/pay.d.ts.map +1 -0
  41. package/dist/commands/pay.js +112 -0
  42. package/dist/commands/pay.js.map +1 -0
  43. package/dist/commands/provider.d.ts +6 -0
  44. package/dist/commands/provider.d.ts.map +1 -0
  45. package/dist/commands/provider.js +74 -0
  46. package/dist/commands/provider.js.map +1 -0
  47. package/dist/commands/server.d.ts +8 -0
  48. package/dist/commands/server.d.ts.map +1 -0
  49. package/dist/commands/server.js +92 -0
  50. package/dist/commands/server.js.map +1 -0
  51. package/dist/commands/template.d.ts +8 -0
  52. package/dist/commands/template.d.ts.map +1 -0
  53. package/dist/commands/template.js +161 -0
  54. package/dist/commands/template.js.map +1 -0
  55. package/dist/commands/transaction.d.ts +6 -0
  56. package/dist/commands/transaction.d.ts.map +1 -0
  57. package/dist/commands/transaction.js +72 -0
  58. package/dist/commands/transaction.js.map +1 -0
  59. package/dist/commands/wise.d.ts +8 -0
  60. package/dist/commands/wise.d.ts.map +1 -0
  61. package/dist/commands/wise.js +240 -0
  62. package/dist/commands/wise.js.map +1 -0
  63. package/dist/core/config.d.ts +40 -0
  64. package/dist/core/config.d.ts.map +1 -0
  65. package/dist/core/config.js +201 -0
  66. package/dist/core/config.js.map +1 -0
  67. package/dist/core/template-engine.d.ts +27 -0
  68. package/dist/core/template-engine.d.ts.map +1 -0
  69. package/dist/core/template-engine.js +410 -0
  70. package/dist/core/template-engine.js.map +1 -0
  71. package/dist/core/transaction.d.ts +31 -0
  72. package/dist/core/transaction.d.ts.map +1 -0
  73. package/dist/core/transaction.js +214 -0
  74. package/dist/core/transaction.js.map +1 -0
  75. package/dist/index.d.ts +12 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +36 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/server/server.d.ts +14 -0
  80. package/dist/server/server.d.ts.map +1 -0
  81. package/dist/server/server.js +120 -0
  82. package/dist/server/server.js.map +1 -0
  83. package/dist/types/index.d.ts +141 -0
  84. package/dist/types/index.d.ts.map +1 -0
  85. package/dist/types/index.js +8 -0
  86. package/dist/types/index.js.map +1 -0
  87. package/logo.png +0 -0
  88. package/package.json +78 -0
  89. package/src/api/bunq.ts +257 -0
  90. package/src/api/wise.ts +204 -0
  91. package/src/cli.ts +67 -0
  92. package/src/commands/bunq.ts +223 -0
  93. package/src/commands/config.ts +72 -0
  94. package/src/commands/emergency.ts +94 -0
  95. package/src/commands/limits.ts +126 -0
  96. package/src/commands/merchant.ts +39 -0
  97. package/src/commands/pay.ts +109 -0
  98. package/src/commands/provider.ts +75 -0
  99. package/src/commands/server.ts +59 -0
  100. package/src/commands/template.ts +172 -0
  101. package/src/commands/transaction.ts +66 -0
  102. package/src/commands/wise.ts +279 -0
  103. package/src/core/config.ts +202 -0
  104. package/src/core/template-engine.ts +454 -0
  105. package/src/core/transaction.ts +228 -0
  106. package/src/index.ts +14 -0
  107. package/src/server/server.ts +131 -0
  108. package/src/types/index.ts +178 -0
  109. package/tsconfig.json +23 -0
  110. package/verified-merchants.json +63 -0
@@ -0,0 +1,410 @@
1
+ "use strict";
2
+ /**
3
+ * Payment Skill - Template Engine
4
+ *
5
+ * Implements the configurable template-based payment flow system
6
+ * OpenClaw selects templates and provides parameters
7
+ * Payment-skill executes the predefined flow
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.templateEngine = exports.TemplateEngine = void 0;
44
+ const fs = __importStar(require("fs-extra"));
45
+ const path = __importStar(require("path"));
46
+ const wise_1 = require("../api/wise");
47
+ const bunq_1 = require("../api/bunq");
48
+ const config_1 = require("./config");
49
+ const transaction_1 = require("./transaction");
50
+ const TEMPLATES_DIR = path.join(__dirname, '../../templates');
51
+ class TemplateEngine {
52
+ constructor() {
53
+ this.templates = new Map();
54
+ this.loadTemplates();
55
+ }
56
+ loadTemplates() {
57
+ // Ensure templates directory exists
58
+ if (!fs.existsSync(TEMPLATES_DIR)) {
59
+ fs.mkdirSync(TEMPLATES_DIR, { recursive: true });
60
+ this.createDefaultTemplates();
61
+ }
62
+ // Load all template files
63
+ const files = fs.readdirSync(TEMPLATES_DIR).filter(f => f.endsWith('.json'));
64
+ for (const file of files) {
65
+ const template = fs.readJsonSync(path.join(TEMPLATES_DIR, file));
66
+ this.templates.set(template.templateId, template);
67
+ }
68
+ }
69
+ createDefaultTemplates() {
70
+ const defaultTemplates = [
71
+ {
72
+ templateId: 'wise_standard_transfer',
73
+ merchant: 'wise.com',
74
+ version: '1.0.0',
75
+ description: 'Standard Wise transfer flow with PSD2 confirmation',
76
+ prerequisites: {
77
+ apiKey: 'required',
78
+ webhookEndpoint: 'recommended'
79
+ },
80
+ steps: [
81
+ {
82
+ order: 1,
83
+ name: 'create_quote',
84
+ command: 'wise.createQuote',
85
+ params: {
86
+ profileId: '{{profileId}}',
87
+ sourceCurrency: '{{sourceCurrency}}',
88
+ targetCurrency: '{{targetCurrency}}',
89
+ sourceAmount: '{{amount}}'
90
+ },
91
+ output: {
92
+ quoteId: 'id',
93
+ rate: 'rate',
94
+ fee: 'fee'
95
+ }
96
+ },
97
+ {
98
+ order: 2,
99
+ name: 'create_transfer',
100
+ command: 'wise.createTransfer',
101
+ params: {
102
+ profileId: '{{profileId}}',
103
+ quoteId: '{{quoteId}}',
104
+ targetAccountId: '{{recipientId}}',
105
+ reference: '{{reference}}'
106
+ },
107
+ output: {
108
+ transferId: 'id',
109
+ status: 'status'
110
+ },
111
+ async: true
112
+ },
113
+ {
114
+ order: 3,
115
+ name: 'fund_transfer',
116
+ command: 'wise.fundTransfer',
117
+ params: {
118
+ profileId: '{{profileId}}',
119
+ transferId: '{{transferId}}'
120
+ },
121
+ async: true,
122
+ confirmation: {
123
+ type: 'webhook',
124
+ events: ['transfer.completed', 'transfer.failed'],
125
+ timeout: 300
126
+ }
127
+ }
128
+ ],
129
+ errorHandling: {
130
+ retryOn: ['network_error', 'rate_limit'],
131
+ maxRetries: 3,
132
+ fallback: 'cancel_transfer'
133
+ }
134
+ },
135
+ {
136
+ templateId: 'bunq_instant_payment',
137
+ merchant: 'bunq.com',
138
+ version: '1.0.0',
139
+ description: 'Instant Bunq payment to IBAN',
140
+ prerequisites: {
141
+ apiKey: 'required',
142
+ webhookEndpoint: 'optional'
143
+ },
144
+ steps: [
145
+ {
146
+ order: 1,
147
+ name: 'create_payment',
148
+ command: 'bunq.createPayment',
149
+ params: {
150
+ userId: '{{userId}}',
151
+ accountId: '{{accountId}}',
152
+ amount: '{{amount}}',
153
+ currency: '{{currency}}',
154
+ counterpartyIban: '{{recipientIban}}',
155
+ counterpartyName: '{{recipientName}}',
156
+ description: '{{description}}'
157
+ },
158
+ output: {
159
+ paymentId: 'id',
160
+ status: 'status'
161
+ }
162
+ }
163
+ ],
164
+ errorHandling: {
165
+ retryOn: ['network_error'],
166
+ maxRetries: 2
167
+ }
168
+ },
169
+ {
170
+ templateId: 'bunq_payment_request',
171
+ merchant: 'bunq.com',
172
+ version: '1.0.0',
173
+ description: 'Request payment from someone via Bunq',
174
+ prerequisites: {
175
+ apiKey: 'required'
176
+ },
177
+ steps: [
178
+ {
179
+ order: 1,
180
+ name: 'create_request',
181
+ command: 'bunq.createRequestInquiry',
182
+ params: {
183
+ userId: '{{userId}}',
184
+ accountId: '{{accountId}}',
185
+ amount: '{{amount}}',
186
+ currency: '{{currency}}',
187
+ counterpartyAlias: {
188
+ type: '{{recipientType}}',
189
+ value: '{{recipientValue}}'
190
+ },
191
+ description: '{{description}}'
192
+ },
193
+ output: {
194
+ requestId: 'id',
195
+ status: 'status'
196
+ },
197
+ async: true,
198
+ confirmation: {
199
+ type: 'poll',
200
+ timeout: 86400,
201
+ pollInterval: 60
202
+ }
203
+ }
204
+ ],
205
+ errorHandling: {
206
+ retryOn: ['network_error'],
207
+ maxRetries: 3
208
+ }
209
+ },
210
+ {
211
+ templateId: 'stripe_connect_charge',
212
+ merchant: 'stripe.com',
213
+ version: '1.0.0',
214
+ description: 'Create charge through Stripe Connect',
215
+ prerequisites: {
216
+ apiKey: 'required',
217
+ webhookEndpoint: 'required'
218
+ },
219
+ steps: [
220
+ {
221
+ order: 1,
222
+ name: 'create_payment_intent',
223
+ command: 'stripe.paymentIntents.create',
224
+ params: {
225
+ amount: '{{amount}}',
226
+ currency: '{{currency}}',
227
+ customer: '{{customerId}}',
228
+ automatic_payment_methods: { enabled: true }
229
+ },
230
+ output: {
231
+ paymentIntentId: 'id',
232
+ clientSecret: 'client_secret',
233
+ status: 'status'
234
+ },
235
+ async: true
236
+ },
237
+ {
238
+ order: 2,
239
+ name: 'confirm_payment',
240
+ command: 'stripe.paymentIntents.confirm',
241
+ params: {
242
+ paymentIntentId: '{{paymentIntentId}}'
243
+ },
244
+ condition: 'requires_confirmation',
245
+ async: true,
246
+ confirmation: {
247
+ type: 'webhook',
248
+ events: ['payment_intent.succeeded', 'payment_intent.payment_failed'],
249
+ timeout: 600
250
+ }
251
+ }
252
+ ],
253
+ errorHandling: {
254
+ retryOn: ['network_error', 'idempotency_error'],
255
+ maxRetries: 3
256
+ }
257
+ }
258
+ ];
259
+ for (const template of defaultTemplates) {
260
+ const filePath = path.join(TEMPLATES_DIR, `${template.templateId}.json`);
261
+ fs.writeJsonSync(filePath, template, { spaces: 2 });
262
+ this.templates.set(template.templateId, template);
263
+ }
264
+ }
265
+ getTemplate(templateId) {
266
+ return this.templates.get(templateId) || null;
267
+ }
268
+ getAllTemplates() {
269
+ return Array.from(this.templates.values());
270
+ }
271
+ getTemplatesForMerchant(merchant) {
272
+ return this.getAllTemplates().filter(t => t.merchant === merchant);
273
+ }
274
+ async executeTemplate(templateId, params) {
275
+ const template = this.getTemplate(templateId);
276
+ if (!template) {
277
+ throw new Error(`Template '${templateId}' not found`);
278
+ }
279
+ // Check emergency stop
280
+ if (config_1.configManager.isEmergencyStopActive()) {
281
+ throw new Error('Emergency stop is active. Cannot execute template.');
282
+ }
283
+ // Create transaction record
284
+ const tx = transaction_1.transactionManager.createTransaction(template.merchant, templateId, parseFloat(params.amount) || 0, params.currency || 'EUR', { templateId, params });
285
+ try {
286
+ // Execute each step
287
+ const context = { ...params };
288
+ for (const step of template.steps.sort((a, b) => a.order - b.order)) {
289
+ await this.executeStep(step, context, tx);
290
+ }
291
+ transaction_1.transactionManager.updateTransactionStatus(tx.id, 'completed');
292
+ return tx;
293
+ }
294
+ catch (error) {
295
+ transaction_1.transactionManager.updateTransactionStatus(tx.id, 'failed', error.message);
296
+ throw error;
297
+ }
298
+ }
299
+ async executeStep(step, context, tx) {
300
+ // Replace template variables with actual values
301
+ const resolvedParams = this.resolveParams(step.params, context);
302
+ // Execute the command
303
+ const result = await this.executeCommand(step.command, resolvedParams);
304
+ // Store outputs in context for subsequent steps
305
+ if (step.output && result) {
306
+ for (const [key, path] of Object.entries(step.output)) {
307
+ context[key] = this.getNestedValue(result, path);
308
+ }
309
+ }
310
+ // Handle async steps
311
+ if (step.async && step.confirmation) {
312
+ await this.waitForConfirmation(step.confirmation, context, tx);
313
+ }
314
+ }
315
+ resolveParams(params, context) {
316
+ if (typeof params === 'string') {
317
+ // Replace {{variable}} with context value
318
+ return params.replace(/\{\{(\w+)\}\}/g, (match, key) => {
319
+ return context[key] !== undefined ? context[key] : match;
320
+ });
321
+ }
322
+ if (Array.isArray(params)) {
323
+ return params.map(p => this.resolveParams(p, context));
324
+ }
325
+ if (typeof params === 'object' && params !== null) {
326
+ const resolved = {};
327
+ for (const [key, value] of Object.entries(params)) {
328
+ resolved[key] = this.resolveParams(value, context);
329
+ }
330
+ return resolved;
331
+ }
332
+ return params;
333
+ }
334
+ getNestedValue(obj, path) {
335
+ return path.split('.').reduce((o, p) => o?.[p], obj);
336
+ }
337
+ async executeCommand(command, params) {
338
+ const [provider, method] = command.split('.');
339
+ switch (provider) {
340
+ case 'wise':
341
+ return this.executeWiseCommand(method, params);
342
+ case 'bunq':
343
+ return this.executeBunqCommand(method, params);
344
+ case 'stripe':
345
+ // Stripe implementation would go here
346
+ throw new Error('Stripe commands not yet implemented');
347
+ default:
348
+ throw new Error(`Unknown provider: ${provider}`);
349
+ }
350
+ }
351
+ async executeWiseCommand(method, params) {
352
+ const config = config_1.configManager.getProvider('wise');
353
+ if (!config) {
354
+ throw new Error('Wise not configured');
355
+ }
356
+ const client = new wise_1.WiseClient(config);
357
+ switch (method) {
358
+ case 'createQuote':
359
+ return client.createQuote(params.profileId, params.sourceCurrency, params.targetCurrency, parseFloat(params.sourceAmount));
360
+ case 'createTransfer':
361
+ return client.createTransfer(params.profileId, params.quoteId, params.targetAccountId, params.reference);
362
+ case 'fundTransfer':
363
+ return client.fundTransfer(params.profileId, params.transferId);
364
+ default:
365
+ throw new Error(`Unknown Wise command: ${method}`);
366
+ }
367
+ }
368
+ async executeBunqCommand(method, params) {
369
+ const config = config_1.configManager.getProvider('bunq');
370
+ if (!config) {
371
+ throw new Error('Bunq not configured');
372
+ }
373
+ const client = new bunq_1.BunqClient(config);
374
+ switch (method) {
375
+ case 'createPayment':
376
+ return client.createPayment(params.userId, params.accountId, params.amount, params.currency, params.counterpartyIban, params.counterpartyName, params.description);
377
+ case 'createRequestInquiry':
378
+ return client.createRequestInquiry(params.userId, params.accountId, params.amount, params.currency, params.counterpartyAlias, params.description);
379
+ default:
380
+ throw new Error(`Unknown Bunq command: ${method}`);
381
+ }
382
+ }
383
+ async waitForConfirmation(confirmation, context, tx) {
384
+ const { type, timeout, events, pollInterval } = confirmation;
385
+ if (type === 'webhook') {
386
+ // Webhook confirmation - wait for webhook handler to update
387
+ console.log(`Waiting for webhook confirmation (${timeout}s)...`);
388
+ // In real implementation, this would set up a promise that resolves on webhook
389
+ await new Promise(resolve => setTimeout(resolve, 5000));
390
+ }
391
+ else if (type === 'poll') {
392
+ // Polling confirmation
393
+ const startTime = Date.now();
394
+ const timeoutMs = (timeout || 300) * 1000;
395
+ while (Date.now() - startTime < timeoutMs) {
396
+ // Poll for status
397
+ await new Promise(resolve => setTimeout(resolve, (pollInterval || 5) * 1000));
398
+ // Check if confirmed
399
+ const updatedTx = transaction_1.transactionManager.getTransaction(tx.id);
400
+ if (updatedTx?.status === 'completed') {
401
+ return;
402
+ }
403
+ }
404
+ throw new Error('Confirmation timeout');
405
+ }
406
+ }
407
+ }
408
+ exports.TemplateEngine = TemplateEngine;
409
+ exports.templateEngine = new TemplateEngine();
410
+ //# sourceMappingURL=template-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-engine.js","sourceRoot":"","sources":["../../src/core/template-engine.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAC/B,2CAA6B;AAE7B,sCAAyC;AACzC,sCAAyC;AACzC,qCAAyC;AACzC,+CAAmD;AAEnD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAE9D,MAAa,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AAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC;aAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YAC3B,uBAAuB;YACvB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,MAAM,SAAS,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC;YAE1C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,SAAS,EAAE,CAAC;gBAC1C,kBAAkB;gBAClB,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBAE9E,qBAAqB;gBACrB,MAAM,SAAS,GAAG,gCAAkB,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;gBAC3D,IAAI,SAAS,EAAE,MAAM,KAAK,WAAW,EAAE,CAAC;oBACtC,OAAO;gBACT,CAAC;YACH,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF;AAjbD,wCAibC;AAEY,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Payment Skill - Transaction Manager
3
+ *
4
+ * Manages all transactions, their states, and lifecycle
5
+ */
6
+ import { Transaction, TransactionStatus } from '../types';
7
+ export declare class TransactionManager {
8
+ private transactions;
9
+ constructor();
10
+ private loadTransactions;
11
+ private saveTransactions;
12
+ createTransaction(provider: string, merchant: string, amount: number, currency: string, metadata?: Record<string, any>): Transaction;
13
+ private generateTransactionId;
14
+ private checkLimits;
15
+ private getDailyTotal;
16
+ private getHourlyTransactionCount;
17
+ updateTransactionStatus(transactionId: string, status: TransactionStatus, error?: string): Transaction;
18
+ getTransaction(transactionId: string): Transaction | null;
19
+ getTransactions(filters?: {
20
+ status?: TransactionStatus;
21
+ provider?: string;
22
+ merchant?: string;
23
+ from?: Date;
24
+ to?: Date;
25
+ }): Transaction[];
26
+ getPendingTransactions(): Transaction[];
27
+ cancelAllPending(): number;
28
+ deleteTransaction(transactionId: string): boolean;
29
+ }
30
+ export declare const transactionManager: TransactionManager;
31
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAM1D,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,YAAY,CAAuC;;IAM3D,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,gBAAgB;IAQxB,iBAAiB,CACf,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,WAAW;IA2Bd,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,WAAW;IAiCnB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,yBAAyB;IAYjC,uBAAuB,CACrB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,iBAAiB,EACzB,KAAK,CAAC,EAAE,MAAM,GACb,WAAW;IA8Bd,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAIzD,eAAe,CACb,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,iBAAiB,CAAC;QAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,EAAE,CAAC,EAAE,IAAI,CAAC;KACX,GACA,WAAW,EAAE;IAsBhB,sBAAsB,IAAI,WAAW,EAAE;IAIvC,gBAAgB,IAAI,MAAM;IAW1B,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;CAOlD;AAED,eAAO,MAAM,kBAAkB,oBAA2B,CAAC"}
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ /**
3
+ * Payment Skill - Transaction Manager
4
+ *
5
+ * Manages all transactions, their states, and lifecycle
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.transactionManager = exports.TransactionManager = void 0;
42
+ const fs = __importStar(require("fs-extra"));
43
+ const path = __importStar(require("path"));
44
+ const config_1 = require("./config");
45
+ const DATA_DIR = path.join(process.env.HOME || process.env.USERPROFILE || '.', '.payment-skill');
46
+ const TRANSACTIONS_FILE = path.join(DATA_DIR, 'transactions.json');
47
+ class TransactionManager {
48
+ constructor() {
49
+ this.transactions = new Map();
50
+ this.loadTransactions();
51
+ }
52
+ loadTransactions() {
53
+ if (fs.existsSync(TRANSACTIONS_FILE)) {
54
+ const data = fs.readJsonSync(TRANSACTIONS_FILE);
55
+ Object.entries(data).forEach(([id, tx]) => {
56
+ this.transactions.set(id, {
57
+ ...tx,
58
+ createdAt: new Date(tx.createdAt),
59
+ updatedAt: new Date(tx.updatedAt)
60
+ });
61
+ });
62
+ }
63
+ }
64
+ saveTransactions() {
65
+ const data = {};
66
+ this.transactions.forEach((tx, id) => {
67
+ data[id] = tx;
68
+ });
69
+ fs.writeJsonSync(TRANSACTIONS_FILE, data, { spaces: 2 });
70
+ }
71
+ createTransaction(provider, merchant, amount, currency, metadata) {
72
+ // Check emergency stop
73
+ if (config_1.configManager.isEmergencyStopActive()) {
74
+ throw new Error('Emergency stop is active. Cannot create new transactions.');
75
+ }
76
+ // Check limits
77
+ this.checkLimits(amount, currency);
78
+ const transaction = {
79
+ id: this.generateTransactionId(),
80
+ provider,
81
+ merchant,
82
+ amount,
83
+ currency: currency.toUpperCase(),
84
+ status: 'pending',
85
+ createdAt: new Date(),
86
+ updatedAt: new Date(),
87
+ metadata
88
+ };
89
+ this.transactions.set(transaction.id, transaction);
90
+ this.saveTransactions();
91
+ return transaction;
92
+ }
93
+ generateTransactionId() {
94
+ return `tx_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
95
+ }
96
+ checkLimits(amount, currency) {
97
+ const limits = config_1.configManager.getLimits();
98
+ // Check per-transaction limit
99
+ if (amount > limits.perTransaction) {
100
+ throw new Error(`Amount ${amount} exceeds per-transaction limit of ${limits.perTransaction}`);
101
+ }
102
+ // Check daily limit
103
+ const today = new Date().toDateString();
104
+ const dailyTotal = this.getDailyTotal(today);
105
+ if (dailyTotal + amount > limits.daily) {
106
+ throw new Error(`Daily limit of ${limits.daily} would be exceeded`);
107
+ }
108
+ // Check hourly transaction count
109
+ const hourlyCount = this.getHourlyTransactionCount();
110
+ if (hourlyCount >= limits.maxTransactionsPerHour) {
111
+ throw new Error(`Hourly transaction limit of ${limits.maxTransactionsPerHour} reached`);
112
+ }
113
+ // Check time window
114
+ const timeWindow = config_1.configManager.getTimeWindow();
115
+ if (timeWindow.enabled) {
116
+ const now = new Date();
117
+ const currentTime = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
118
+ if (currentTime < timeWindow.start || currentTime > timeWindow.end) {
119
+ throw new Error(`Transactions not allowed outside time window ${timeWindow.start}-${timeWindow.end}`);
120
+ }
121
+ }
122
+ }
123
+ getDailyTotal(date) {
124
+ let total = 0;
125
+ this.transactions.forEach(tx => {
126
+ if (tx.createdAt.toDateString() === date &&
127
+ (tx.status === 'completed' || tx.status === 'processing')) {
128
+ total += tx.amount;
129
+ }
130
+ });
131
+ return total;
132
+ }
133
+ getHourlyTransactionCount() {
134
+ const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);
135
+ let count = 0;
136
+ this.transactions.forEach(tx => {
137
+ if (tx.createdAt > oneHourAgo &&
138
+ (tx.status === 'pending' || tx.status === 'processing' || tx.status === 'completed')) {
139
+ count++;
140
+ }
141
+ });
142
+ return count;
143
+ }
144
+ updateTransactionStatus(transactionId, status, error) {
145
+ const tx = this.transactions.get(transactionId);
146
+ if (!tx) {
147
+ throw new Error(`Transaction ${transactionId} not found`);
148
+ }
149
+ // If emergency stop is active, only allow cancellation
150
+ if (config_1.configManager.isEmergencyStopActive() && status !== 'cancelled') {
151
+ throw new Error('Emergency stop is active. Only cancellation allowed.');
152
+ }
153
+ tx.status = status;
154
+ tx.updatedAt = new Date();
155
+ if (error) {
156
+ tx.error = error;
157
+ }
158
+ this.transactions.set(transactionId, tx);
159
+ this.saveTransactions();
160
+ // Update emergency stop pending list
161
+ if (status === 'processing') {
162
+ config_1.configManager.addPendingTransaction(transactionId);
163
+ }
164
+ else if (['completed', 'failed', 'cancelled'].includes(status)) {
165
+ config_1.configManager.removePendingTransaction(transactionId);
166
+ }
167
+ return tx;
168
+ }
169
+ getTransaction(transactionId) {
170
+ return this.transactions.get(transactionId) || null;
171
+ }
172
+ getTransactions(filters) {
173
+ let txs = Array.from(this.transactions.values());
174
+ if (filters?.status) {
175
+ txs = txs.filter(tx => tx.status === filters.status);
176
+ }
177
+ if (filters?.provider) {
178
+ txs = txs.filter(tx => tx.provider === filters.provider);
179
+ }
180
+ if (filters?.merchant) {
181
+ txs = txs.filter(tx => tx.merchant === filters.merchant);
182
+ }
183
+ if (filters?.from) {
184
+ txs = txs.filter(tx => tx.createdAt >= filters.from);
185
+ }
186
+ if (filters?.to) {
187
+ txs = txs.filter(tx => tx.createdAt <= filters.to);
188
+ }
189
+ return txs.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
190
+ }
191
+ getPendingTransactions() {
192
+ return this.getTransactions({ status: 'pending' });
193
+ }
194
+ cancelAllPending() {
195
+ let count = 0;
196
+ this.transactions.forEach((tx, id) => {
197
+ if (tx.status === 'pending' || tx.status === 'processing') {
198
+ this.updateTransactionStatus(id, 'cancelled', 'Cancelled by emergency stop');
199
+ count++;
200
+ }
201
+ });
202
+ return count;
203
+ }
204
+ deleteTransaction(transactionId) {
205
+ const deleted = this.transactions.delete(transactionId);
206
+ if (deleted) {
207
+ this.saveTransactions();
208
+ }
209
+ return deleted;
210
+ }
211
+ }
212
+ exports.TransactionManager = TransactionManager;
213
+ exports.transactionManager = new TransactionManager();
214
+ //# sourceMappingURL=transaction.js.map