@tly-pay/vendure-plugin 0.0.0-stage → 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 (86) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/README.md +192 -2
  4. package/assets/coins/arb.svg +10 -0
  5. package/assets/coins/base.svg +4 -0
  6. package/assets/coins/bln.svg +4 -0
  7. package/assets/coins/bnb.svg +13 -0
  8. package/assets/coins/btc.svg +1 -0
  9. package/assets/coins/busd.svg +7 -0
  10. package/assets/coins/coin.svg +1 -0
  11. package/assets/coins/dai.svg +1 -0
  12. package/assets/coins/doge.svg +109 -0
  13. package/assets/coins/eth.svg +10 -0
  14. package/assets/coins/jst.svg +11 -0
  15. package/assets/coins/link.svg +4 -0
  16. package/assets/coins/ltc.svg +4 -0
  17. package/assets/coins/op.svg +12 -0
  18. package/assets/coins/pol.svg +11 -0
  19. package/assets/coins/shib.svg +18 -0
  20. package/assets/coins/sol.svg +15 -0
  21. package/assets/coins/sun.svg +71 -0
  22. package/assets/coins/trx.svg +4 -0
  23. package/assets/coins/uni.svg +10 -0
  24. package/assets/coins/usdc.svg +6 -0
  25. package/assets/coins/usdd.svg +18 -0
  26. package/assets/coins/usdt.svg +1 -0
  27. package/assets/coins/wbtc.svg +16 -0
  28. package/assets/coins/weth.svg +17 -0
  29. package/assets/tly-pay-mark.svg +31 -0
  30. package/dashboard/api.ts +167 -0
  31. package/dashboard/appearance.tsx +253 -0
  32. package/dashboard/banner.tsx +72 -0
  33. package/dashboard/i18n/en.po +584 -0
  34. package/dashboard/index.tsx +33 -0
  35. package/dashboard/logic.ts +219 -0
  36. package/dashboard/messages.tsx +90 -0
  37. package/dashboard/notice.tsx +15 -0
  38. package/dashboard/order-block.tsx +21 -0
  39. package/dashboard/orders.tsx +246 -0
  40. package/dashboard/page.tsx +174 -0
  41. package/dashboard/settings.tsx +186 -0
  42. package/dashboard/use-connect.ts +46 -0
  43. package/dist/api.d.ts +169 -0
  44. package/dist/api.js +541 -0
  45. package/dist/client-ref.d.ts +75 -0
  46. package/dist/client-ref.js +165 -0
  47. package/dist/connect-flow.d.ts +65 -0
  48. package/dist/connect-flow.js +177 -0
  49. package/dist/connection-check.d.ts +28 -0
  50. package/dist/connection-check.js +49 -0
  51. package/dist/connection.d.ts +140 -0
  52. package/dist/connection.js +361 -0
  53. package/dist/contracts.d.ts +66 -0
  54. package/dist/contracts.js +151 -0
  55. package/dist/creation-service.d.ts +136 -0
  56. package/dist/creation-service.js +242 -0
  57. package/dist/handler.d.ts +13 -0
  58. package/dist/handler.js +45 -0
  59. package/dist/hosted-checkout.d.ts +3 -0
  60. package/dist/hosted-checkout.js +25 -0
  61. package/dist/index.d.ts +11 -0
  62. package/dist/index.js +32 -0
  63. package/dist/ownership.d.ts +38 -0
  64. package/dist/ownership.js +38 -0
  65. package/dist/payment-sync.d.ts +45 -0
  66. package/dist/payment-sync.js +111 -0
  67. package/dist/persistence.d.ts +104 -0
  68. package/dist/persistence.js +405 -0
  69. package/dist/plugin.d.ts +26 -0
  70. package/dist/plugin.js +112 -0
  71. package/dist/public-api.d.ts +56 -0
  72. package/dist/public-api.js +221 -0
  73. package/dist/records.d.ts +53 -0
  74. package/dist/records.js +109 -0
  75. package/dist/release-config.d.ts +55 -0
  76. package/dist/release-config.js +107 -0
  77. package/dist/release-config.json +15 -0
  78. package/dist/secret-box.d.ts +19 -0
  79. package/dist/secret-box.js +65 -0
  80. package/dist/service.d.ts +267 -0
  81. package/dist/service.js +788 -0
  82. package/dist/signed-webhook.d.ts +67 -0
  83. package/dist/signed-webhook.js +119 -0
  84. package/dist/storefront/checkout.d.mts +86 -0
  85. package/dist/storefront/checkout.mjs +149 -0
  86. package/package.json +97 -4
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SITE_MODES = exports.RELEASE_ENV = exports.TEST_SITE_KEYS = exports.WIDGET_SCRIPT_PATH = exports.RELEASE_CONFIG_FILE = void 0;
4
+ exports.invalidReleaseKey = invalidReleaseKey;
5
+ exports.loadReleaseConfig = loadReleaseConfig;
6
+ exports.siteMode = siteMode;
7
+ exports.siteRelease = siteRelease;
8
+ exports.widgetScriptUrl = widgetScriptUrl;
9
+ exports.releaseConfig = releaseConfig;
10
+ const node_fs_1 = require("node:fs");
11
+ const node_path_1 = require("node:path");
12
+ const contracts_1 = require("./contracts");
13
+ exports.RELEASE_CONFIG_FILE = "release-config.json";
14
+ exports.WIDGET_SCRIPT_PATH = "/widget/crypto-pay.js";
15
+ const ORIGINS = ["consoleOrigin", "apiOrigin", "widgetOrigin", "testConsoleOrigin", "testApiOrigin",
16
+ "testWidgetOrigin"];
17
+ const RANGES = {
18
+ connectionTtlSecs: [60, 3600],
19
+ paymentRecoveryDelaySecs: [30, 86_400],
20
+ widgetActionTimeoutSecs: [5, 120],
21
+ apiTimeoutSecs: [1, 120],
22
+ apiMaxResponseBytes: [1024, 1_048_576],
23
+ webhookToleranceSecs: [1, 3600],
24
+ recoveryBatchSize: [1, 100],
25
+ };
26
+ /** Key of each test site Origin in `release/test-site.json`, fixed in the repository. */
27
+ exports.TEST_SITE_KEYS = {
28
+ testConsoleOrigin: "console_origin",
29
+ testApiOrigin: "api_origin",
30
+ testWidgetOrigin: "widget_origin",
31
+ };
32
+ /** Packaging environment name of each other release constant, shared with the other TLY Pay plugins. */
33
+ exports.RELEASE_ENV = {
34
+ consoleOrigin: "TLY_PAY_CONSOLE_ORIGIN",
35
+ apiOrigin: "TLY_PAY_API_ORIGIN",
36
+ widgetOrigin: "TLY_PAY_WIDGET_ORIGIN",
37
+ connectionTtlSecs: "TLY_PAY_CONNECTION_TTL_SECS",
38
+ paymentRecoveryDelaySecs: "TLY_PAY_PAYMENT_RECOVERY_DELAY_SECS",
39
+ widgetActionTimeoutSecs: "TLY_PAY_WIDGET_ACTION_TIMEOUT_SECS",
40
+ apiTimeoutSecs: "TLY_PAY_API_TIMEOUT_SECS",
41
+ apiMaxResponseBytes: "TLY_PAY_API_MAX_RESPONSE_BYTES",
42
+ webhookToleranceSecs: "TLY_PAY_WEBHOOK_TOLERANCE_SECS",
43
+ recoveryBatchSize: "TLY_PAY_RECOVERY_BATCH_SIZE",
44
+ };
45
+ function validOrigin(value) {
46
+ try {
47
+ return (0, contracts_1.requireHttpsOrigin)(value, "Origin") === value;
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }
53
+ /**
54
+ * Returns the first invalid key, or null. Packaging and runtime share this rule, so a package
55
+ * can only carry values the runtime accepts.
56
+ */
57
+ function invalidReleaseKey(value) {
58
+ if (value === null || typeof value !== "object" || Array.isArray(value)
59
+ || Object.keys(value).sort().join() !== [...ORIGINS, ...Object.keys(RANGES)].sort().join()) {
60
+ return "shape";
61
+ }
62
+ const config = value;
63
+ for (const key of ORIGINS)
64
+ if (!validOrigin(config[key]))
65
+ return key;
66
+ for (const [key, [min, max]] of Object.entries(RANGES)) {
67
+ const number = config[key];
68
+ if (typeof number !== "number" || !Number.isSafeInteger(number) || number < min || number > max) {
69
+ return key;
70
+ }
71
+ }
72
+ return null;
73
+ }
74
+ /** Reads the packaged release constants; a missing or invalid file yields null (fail closed). */
75
+ function loadReleaseConfig(dir) {
76
+ let value;
77
+ try {
78
+ value = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(dir, exports.RELEASE_CONFIG_FILE), "utf8"));
79
+ }
80
+ catch {
81
+ return null;
82
+ }
83
+ return invalidReleaseKey(value) === null ? value : null;
84
+ }
85
+ /** The TLY Pay site of Settings > Advanced: the packaged standard site (default) or the shared test site. */
86
+ exports.SITE_MODES = ["standard", "test"];
87
+ /** A stored site value; missing or unknown reads as `standard`. */
88
+ function siteMode(value) {
89
+ return value === "test" ? "test" : "standard";
90
+ }
91
+ /** The release constants with the Origins of `mode` in effect. */
92
+ function siteRelease(release, mode) {
93
+ return mode === "test"
94
+ ? { ...release, consoleOrigin: release.testConsoleOrigin, apiOrigin: release.testApiOrigin,
95
+ widgetOrigin: release.testWidgetOrigin }
96
+ : release;
97
+ }
98
+ function widgetScriptUrl(release) {
99
+ return release.widgetOrigin + exports.WIDGET_SCRIPT_PATH;
100
+ }
101
+ let cached;
102
+ /** The packaged release constants of this package, or null for an incomplete installation. */
103
+ function releaseConfig() {
104
+ if (cached === undefined)
105
+ cached = loadReleaseConfig(__dirname);
106
+ return cached;
107
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "consoleOrigin": "https://app.tlypay.com",
3
+ "apiOrigin": "https://api.tlypay.com",
4
+ "widgetOrigin": "https://pay.tlypay.com",
5
+ "connectionTtlSecs": 300,
6
+ "paymentRecoveryDelaySecs": 120,
7
+ "widgetActionTimeoutSecs": 15,
8
+ "apiTimeoutSecs": 15,
9
+ "apiMaxResponseBytes": 65536,
10
+ "webhookToleranceSecs": 300,
11
+ "recoveryBatchSize": 50,
12
+ "testConsoleOrigin": "https://app.ltypay.com",
13
+ "testApiOrigin": "https://api.ltypay.com",
14
+ "testWidgetOrigin": "https://pay.ltypay.com"
15
+ }
@@ -0,0 +1,19 @@
1
+ /** Shortest accepted `secretKey`: 32 characters, the size of a base64 encoded 192-bit random value. */
2
+ export declare const MIN_SECRET_KEY_LENGTH = 32;
3
+ /** The stored value cannot be opened, for example after `secretKey` changed. */
4
+ export declare class SealedValueUnreadable extends Error {
5
+ constructor();
6
+ }
7
+ /**
8
+ * Protects the stored connection (API Key, Webhook Secrets) and the pending authorization (PKCE
9
+ * verifier, exchanged credentials) with AES-256-GCM. The key is derived from the `secretKey` the
10
+ * Vendure host passes to `TlyPayPlugin.init()`; the record name is bound as additional data, so a
11
+ * sealed value cannot be moved to another record. Changing `secretKey` makes saved values unreadable
12
+ * and the shop must connect again.
13
+ */
14
+ export declare class SecretBox {
15
+ private readonly key;
16
+ constructor(secretKey: string);
17
+ seal(record: string, plaintext: string): string;
18
+ open(record: string, sealed: string): string;
19
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecretBox = exports.SealedValueUnreadable = exports.MIN_SECRET_KEY_LENGTH = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const PREFIX = "v1:";
6
+ const NONCE_BYTES = 12;
7
+ const TAG_BYTES = 16;
8
+ const MAX_PLAINTEXT_BYTES = 16_384;
9
+ /** Shortest accepted `secretKey`: 32 characters, the size of a base64 encoded 192-bit random value. */
10
+ exports.MIN_SECRET_KEY_LENGTH = 32;
11
+ /** The stored value cannot be opened, for example after `secretKey` changed. */
12
+ class SealedValueUnreadable extends Error {
13
+ constructor() { super("TLY Pay stored connection cannot be decrypted"); }
14
+ }
15
+ exports.SealedValueUnreadable = SealedValueUnreadable;
16
+ /**
17
+ * Protects the stored connection (API Key, Webhook Secrets) and the pending authorization (PKCE
18
+ * verifier, exchanged credentials) with AES-256-GCM. The key is derived from the `secretKey` the
19
+ * Vendure host passes to `TlyPayPlugin.init()`; the record name is bound as additional data, so a
20
+ * sealed value cannot be moved to another record. Changing `secretKey` makes saved values unreadable
21
+ * and the shop must connect again.
22
+ */
23
+ class SecretBox {
24
+ key;
25
+ constructor(secretKey) {
26
+ if (typeof secretKey !== "string" || secretKey.length < exports.MIN_SECRET_KEY_LENGTH || !/^[\x21-\x7e]+$/.test(secretKey)) {
27
+ throw new TypeError(`TLY Pay secretKey must be at least ${exports.MIN_SECRET_KEY_LENGTH} printable ASCII characters`);
28
+ }
29
+ this.key = (0, node_crypto_1.createHash)("sha256").update("TlyPay.Vendure.connection.v1:").update(secretKey).digest();
30
+ }
31
+ seal(record, plaintext) {
32
+ const data = Buffer.from(plaintext, "utf8");
33
+ if (data.byteLength < 1 || data.byteLength > MAX_PLAINTEXT_BYTES)
34
+ throw new TypeError("Invalid sealed value");
35
+ const nonce = (0, node_crypto_1.randomBytes)(NONCE_BYTES);
36
+ const cipher = (0, node_crypto_1.createCipheriv)("aes-256-gcm", this.key, nonce, { authTagLength: TAG_BYTES });
37
+ cipher.setAAD(aad(record));
38
+ const ciphertext = Buffer.concat([cipher.update(data), cipher.final()]);
39
+ return PREFIX + Buffer.concat([nonce, cipher.getAuthTag(), ciphertext]).toString("base64url");
40
+ }
41
+ open(record, sealed) {
42
+ if (typeof sealed !== "string" || !sealed.startsWith(PREFIX) || !/^[A-Za-z0-9_-]+$/.test(sealed.slice(PREFIX.length))) {
43
+ throw new SealedValueUnreadable();
44
+ }
45
+ const payload = Buffer.from(sealed.slice(PREFIX.length), "base64url");
46
+ if (payload.byteLength <= NONCE_BYTES + TAG_BYTES)
47
+ throw new SealedValueUnreadable();
48
+ try {
49
+ const decipher = (0, node_crypto_1.createDecipheriv)("aes-256-gcm", this.key, payload.subarray(0, NONCE_BYTES), { authTagLength: TAG_BYTES });
50
+ decipher.setAAD(aad(record));
51
+ decipher.setAuthTag(payload.subarray(NONCE_BYTES, NONCE_BYTES + TAG_BYTES));
52
+ const plaintext = Buffer.concat([decipher.update(payload.subarray(NONCE_BYTES + TAG_BYTES)), decipher.final()]);
53
+ return new TextDecoder("utf-8", { fatal: true }).decode(plaintext);
54
+ }
55
+ catch {
56
+ throw new SealedValueUnreadable();
57
+ }
58
+ }
59
+ }
60
+ exports.SecretBox = SecretBox;
61
+ function aad(record) {
62
+ if (!/^[a-z_]{1,32}$/.test(record))
63
+ throw new TypeError("Invalid sealed record name");
64
+ return Buffer.from(`TlyPay.Vendure.record.v1:${record}`);
65
+ }
@@ -0,0 +1,267 @@
1
+ import { OnModuleInit } from "@nestjs/common";
2
+ import { ActiveOrderService, ConfigService, EventBus, HistoryService, ID, JobQueueService, Order, OrderService, PaymentMethodService, RequestContext, RequestContextService, TransactionalConnection, TranslatorService } from "@vendure/core";
3
+ import { TlyPayCheckoutIconSettings, TlyPayCheckoutSettings, TlyPayClientRefService, TlyPayCoinNamesSettings, TlyPaySiteSettings } from "./client-ref";
4
+ import { ConnectFlow, ConnectResult } from "./connect-flow";
5
+ import { ConnectionService, ConnectionStatus } from "./connection";
6
+ import { WebhookAnswer } from "./connection-check";
7
+ import { PaymentAsset, PaymentView } from "./contracts";
8
+ import { StoredEvent, TypeOrmAssociationStore, TypeOrmEventInbox } from "./persistence";
9
+ import { PublicApiClient } from "./public-api";
10
+ import { ReleaseConfig } from "./release-config";
11
+ export declare const TLY_PAY_PLUGIN_OPTIONS: unique symbol;
12
+ export declare const HANDLER_CODE = "tly-pay";
13
+ export declare const CHECKER_CODE = "tly-pay-ready";
14
+ /**
15
+ * Coins TLY Pay supports, in the order checkout shows their icons. This is the only place that holds
16
+ * the catalog: the Dashboard and the Shop API receive it as checkout icon options. Each mark is labelled
17
+ * with its uppercase form and drawn from `assets/coins/<mark>.svg`; USDT0 shares `usdt` (see `assetMark`).
18
+ */
19
+ export declare const CHECKOUT_ICON_CATALOG: readonly string[];
20
+ /**
21
+ * The checkout icon mark of an asset symbol: its lowercase symbol, except USDT0 (Arbitrum One), which is
22
+ * Tether USD and shares the `usdt` mark, so USDT and USDT0 show one icon.
23
+ */
24
+ export declare function assetMark(symbol: string): string;
25
+ /** One checkout icon: a mark with its label and bundled artwork. */
26
+ export type CheckoutIcon = {
27
+ mark: string;
28
+ label: string;
29
+ iconUrl: string;
30
+ };
31
+ /** A checkout icon the merchant can choose, and whether the Store accepts its coin now. */
32
+ export type CheckoutIconOption = CheckoutIcon & {
33
+ accepted: boolean;
34
+ };
35
+ /**
36
+ * Marks the Store accepts now, in option order: catalog marks first, then the others in Store order.
37
+ * This is the selection while none was saved and the one Sync with TLY Pay store saves.
38
+ */
39
+ export declare function acceptedMarks(assets: PaymentAsset[]): string[];
40
+ /**
41
+ * Checkout icon options in the order checkout shows them: the catalog, then the other marks the Store
42
+ * accepts in Store order, then other chosen marks, so every chosen mark stays listed and can be removed.
43
+ * Each option is labelled with its uppercase mark (`USDT` for the Tether mark USDT0 shares).
44
+ */
45
+ export declare function checkoutIconOptions(assets: PaymentAsset[], chosen: string[], iconUrl: (mark: string) => string): CheckoutIconOption[];
46
+ /**
47
+ * Customer copy of the Shop API, in English. Each entry is looked up in Vendure's message catalogs as
48
+ * `tlyPay.<name>` first, so a host translates it with `I18nService.addTranslation()`. `listLocale` is
49
+ * the BCP 47 tag whose list format joins the coin names, so a translated sentence gets a list in its
50
+ * own language.
51
+ */
52
+ export declare const CHECKOUT_MESSAGES: {
53
+ readonly title: "Crypto payment";
54
+ readonly coinNames: "Pay with {list}.";
55
+ readonly coinNamesGeneric: "Pay with supported crypto assets through TLY Pay Checkout.";
56
+ readonly listLocale: "en";
57
+ };
58
+ /** Joins coin labels with the list format of a locale: "USDT and USDC", "USDT, USDC, and DAI" in English. */
59
+ export declare function coinList(labels: string[], locale: string): string;
60
+ /** Site-private values the Vendure host passes to `TlyPayPlugin.init()`. */
61
+ export type TlyPayPluginOptions = {
62
+ /**
63
+ * Public HTTPS URL under which this Vendure server's REST routes are reachable, for example
64
+ * `https://shop.example.com`; TLY Pay calls `<publicUrl>/tly-pay/webhook` and returns to
65
+ * `<publicUrl>/tly-pay/connect/return`.
66
+ */
67
+ publicUrl: string;
68
+ /** Secret of at least 32 characters that encrypts the saved connection at rest. */
69
+ secretKey: string;
70
+ };
71
+ /** Storefront presentation of the payment method for the current Channel and Order. */
72
+ export type CheckoutPresentation = {
73
+ available: boolean;
74
+ checkoutMode: string;
75
+ widgetScriptUrl: string;
76
+ widgetActionTimeoutSecs: number;
77
+ paidStatuses: string[];
78
+ /** The native name of the Channel's TLY Pay payment method, or the default "Crypto payment". */
79
+ title: string;
80
+ /** The sentence that names the coins under the title, or null while the merchant does not show it. */
81
+ coinNames: string | null;
82
+ /** The marks the merchant chose, in option order, whether or not the Store accepts them. */
83
+ icons: CheckoutIcon[];
84
+ };
85
+ export type PaymentSession = {
86
+ paymentId: string;
87
+ checkoutMode: string;
88
+ hostedUrl: string;
89
+ returnUrl: string | null;
90
+ widgetScriptUrl: string;
91
+ widgetActionTimeoutSecs: number;
92
+ paidStatuses: string[];
93
+ };
94
+ export type OrderRow = {
95
+ id: string;
96
+ orderCode: string;
97
+ orderId: string | null;
98
+ orderState: string | null;
99
+ state: string;
100
+ status: string | null;
101
+ statusVersion: number;
102
+ amountRaw: string;
103
+ currency: string;
104
+ checkoutMode: string;
105
+ paymentId: string | null;
106
+ err: string | null;
107
+ settleErr: string | null;
108
+ settledAt: Date | null;
109
+ createdAt: Date;
110
+ updatedAt: Date;
111
+ };
112
+ /**
113
+ * The plugin's runtime: connection, checkout, Webhook intake and Payment synchronization on Vendure's
114
+ * own services. Every request to TLY Pay uses the saved connection and the packaged release constants
115
+ * with the Origins of the site chosen in Settings > Advanced; an incomplete release fails closed.
116
+ */
117
+ export declare class TlyPayService implements OnModuleInit {
118
+ private readonly options;
119
+ private readonly connection;
120
+ private readonly clientRefs;
121
+ private readonly jobQueues;
122
+ private readonly requestContexts;
123
+ private readonly orders;
124
+ private readonly activeOrders;
125
+ private readonly paymentMethods;
126
+ private readonly history;
127
+ private readonly config;
128
+ private readonly translator;
129
+ private readonly events;
130
+ /** Packaged constants; the Origins in effect come from `release()`. */
131
+ private readonly packaged;
132
+ readonly connections: ConnectionService;
133
+ readonly flow: ConnectFlow;
134
+ readonly associations: TypeOrmAssociationStore;
135
+ readonly inbox: TypeOrmEventInbox;
136
+ readonly checkoutSettings: TlyPayCheckoutSettings;
137
+ readonly iconSettings: TlyPayCheckoutIconSettings;
138
+ readonly coinNameSettings: TlyPayCoinNamesSettings;
139
+ readonly siteSettings: TlyPaySiteSettings;
140
+ private readonly sync;
141
+ private readonly coins;
142
+ private queue;
143
+ constructor(options: TlyPayPluginOptions, connection: TransactionalConnection, clientRefs: TlyPayClientRefService, jobQueues: JobQueueService, requestContexts: RequestContextService, orders: OrderService, activeOrders: ActiveOrderService, paymentMethods: PaymentMethodService, history: HistoryService, config: ConfigService, translator: TranslatorService, events: EventBus);
144
+ onModuleInit(): Promise<void>;
145
+ /**
146
+ * After Vendure cancels an Order: cancels its TLY Pay Payments that are still open, so a cancelled Order
147
+ * cannot be paid (as the WooCommerce and Medusa plugins do). A Payment that received funds or is closed,
148
+ * or that belongs to another TLY Store than the connected one, is left as it is. The change reaches the
149
+ * Orders view through the notification and the queued sync. Answers the resulting status per Payment.
150
+ */
151
+ cancelForOrder(channelToken: string, orderCode: string): Promise<string[]>;
152
+ /** The release constants with the Origins of the stored site, or null for an incomplete release. */
153
+ release(): Promise<ReleaseConfig | null>;
154
+ api(apiKey: string): Promise<PublicApiClient>;
155
+ /** Base of the plugin's public routes under the host's public URL. */
156
+ publicBase(): string;
157
+ callbackUrl(): string;
158
+ /** The bundled icon file of a mark, or the neutral fallback. */
159
+ coinFile(mark: string): string;
160
+ /** Checkout icon options for the Store's assets and the chosen marks, with the plugin's public icon URLs. */
161
+ iconOptions(assets: PaymentAsset[], chosen: string[]): CheckoutIconOption[];
162
+ /** The marks the merchant chose, which may be none, or every mark the Store accepts while none was saved. */
163
+ chosenMarks(assets: PaymentAsset[]): Promise<string[]>;
164
+ /**
165
+ * Re-reads the Store through the connection check, then saves the coins it accepts now as the checkout
166
+ * icons. A failed check reports its code and keeps the previous choice; the coin names switch and the
167
+ * title are not changed.
168
+ */
169
+ syncCheckoutIcons(): Promise<ConnectResult>;
170
+ coinPath(file: string): string | null;
171
+ status(): Promise<ConnectionStatus>;
172
+ start(ctx: RequestContext, adminUrl: string, popup: boolean): Promise<{
173
+ url: string | null;
174
+ result: string;
175
+ }>;
176
+ complete(ctx: RequestContext, state: string, code: string | null): Promise<ConnectResult>;
177
+ disconnect(confirm: boolean): Promise<ConnectResult>;
178
+ refreshConnection(): Promise<void>;
179
+ /** Whether the payment method may be offered for this Order: see `ConnectionService.available`. */
180
+ eligible(order: Order): Promise<boolean>;
181
+ presentation(ctx: RequestContext): Promise<CheckoutPresentation>;
182
+ /**
183
+ * The checkout title and the payment method it belongs to. Vendure's native, translatable name of the
184
+ * Channel's TLY Pay payment method is the title source: it is what `eligiblePaymentMethods` and the
185
+ * Dashboard show, and the merchant edits it under Settings > Payment methods. The method is the one a
186
+ * Payment is created with (the enabled one, else the first); without a method or a name the title is
187
+ * the default.
188
+ */
189
+ checkoutTitle(ctx: RequestContext): Promise<{
190
+ title: string;
191
+ methodId: ID | null;
192
+ }>;
193
+ /**
194
+ * Creates or recovers the Payment of the active Order in `ArrangingPayment`, using the Channel's
195
+ * enabled TLY Pay payment method. The Order's existing Payment of the connected Store, for the same
196
+ * currency and amount, is continued even after the Store changed its pricing currency; a new Payment
197
+ * needs the connection to be available for the Order's currency.
198
+ */
199
+ createPayment(ctx: RequestContext, returnUrl: string | null): Promise<PaymentSession>;
200
+ /**
201
+ * Whether an admin context may add a verified paid Payment of this Order, Channel and total. Vendure
202
+ * runs the eligibility checker again when the plugin settles, so a Payment created before the Store
203
+ * changed its pricing currency or readiness still settles; customers are offered the method only
204
+ * while the connection is available.
205
+ */
206
+ settlable(ctx: RequestContext, order: Order): Promise<boolean>;
207
+ /**
208
+ * Validates the settlement the plugin itself requested for a verified paid Payment of this Order,
209
+ * Channel and amount; every other call is declined.
210
+ */
211
+ verifySettlement(ctx: RequestContext, order: Order, amount: number, paymentId: unknown): Promise<string | null>;
212
+ /**
213
+ * Handles one Webhook delivery and returns the answer to write: 401 for missing or malformed
214
+ * headers, a rejected signature or timestamp; 503 while not connected or while storage or creation
215
+ * recovery fails transiently; 400 for a verified body that is not a valid Event, a connection check
216
+ * naming another Endpoint, or invalid Payment fields of a known Payment; 200 with the site's facts
217
+ * and a signed acknowledgment for TLY Pay's connection check; and 204 once a local Event is stored,
218
+ * a foreign one is ignored or the signed event type is one this version does not know.
219
+ */
220
+ webhook(body: Uint8Array, headers: Record<string, string | undefined>): Promise<WebhookAnswer>;
221
+ /**
222
+ * The native payment method switch for the connection check: at least one PaymentMethod using the
223
+ * TLY Pay handler is enabled, in any Channel. The connection's readiness takes no part.
224
+ */
225
+ gatewayEnabled(): Promise<boolean>;
226
+ private receivePayment;
227
+ private enqueue;
228
+ /** One run of the recovery task: an early connection check, creation recovery and stored Events. */
229
+ recover(now?: Date): Promise<void>;
230
+ listOrders(ctx: RequestContext, filter: string, skip: number, take: number): Promise<{
231
+ items: OrderRow[];
232
+ totalItems: number;
233
+ counts: Record<string, number>;
234
+ }>;
235
+ /** Local facts, live status and stored Events of one intent; the live read happens once per call. */
236
+ orderDetail(ctx: RequestContext, id: string): Promise<{
237
+ row: OrderRow;
238
+ checkoutOrigin: string | null;
239
+ returnUrl: string | null;
240
+ clientRef: string | null;
241
+ live: PaymentView | null;
242
+ liveErr: string | null;
243
+ events: StoredEvent[];
244
+ } | null>;
245
+ /** The latest intent of a Vendure Order, for the Order detail block. */
246
+ intentForOrder(ctx: RequestContext, orderCode: string): Promise<string | null>;
247
+ reconcile(ctx: RequestContext, id: string): Promise<ConnectResult>;
248
+ /** `missing`, `disabled`, `no_checker` or `ready`. */
249
+ methodState(ctx: RequestContext): Promise<string>;
250
+ createMethod(ctx: RequestContext, name: string): Promise<ConnectResult>;
251
+ private creation;
252
+ private channelMethods;
253
+ /** Administrators of the default Channel see every Channel; others only their own. */
254
+ private channelScope;
255
+ private ordersByCode;
256
+ private row;
257
+ /**
258
+ * Adds the Settled Vendure Payment for a verified paid Payment, once. An Order back in `AddingItems`
259
+ * is moved to `ArrangingPayment` first. Vendure recalculates the Order on that transition and writes
260
+ * the new totals before it may refuse it (for example when the selected shipping method is no longer
261
+ * eligible). A refused transition (`order_transition_refused`) or a recalculated total that no
262
+ * longer equals the Payment (`amount_mismatch`) rolls the transaction back: no Vendure Payment is
263
+ * added and the Order keeps its state and totals.
264
+ */
265
+ private settleOrder;
266
+ private noteOrder;
267
+ }