@orboni/vendure-plugin 0.0.0-stage → 1.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 1.0.1 - 2026-11-30
4
+
5
+ - A payment Vendure could not save whole is saved on the next try: the payment, the order's state and its history are saved in one transaction, and the webhook is answered 503 until they are, so Orboni sends it again. Before, a payment Vendure refused, or one Orboni could not be read for just then, was answered 200 and lost.
6
+ - A scheduled task, `orboni-check-payments`, every 15 minutes in the worker (Vendure 3.3 and later, with a scheduler such as `DefaultSchedulerPlugin`): it records a payment whose webhook was lost or failed, settles one that became final without its webhook, and for two days checks that a paid order is still paid on the chain. On older Vendure, call `OrboniService.checkPayments()` from a job of your own.
7
+ - Money that left the chain leaves its note once, whether its webhook or the check sees it first, and a second note when the order is paid in full again.
8
+ - The order's row is locked while a payment is recorded, so the webhook on two servers and the buyer's return at once record it once (PostgreSQL, MySQL and MariaDB; SQLite writes one transaction at a time).
9
+ - A payment Vendure declines (the order's total changed after its page opened) or cannot take (the order was cancelled) leaves one note, however often it is read again.
10
+
11
+ ## 1.0.0 - 2026-11-23
12
+
13
+ - First release: Orboni as a Vendure 3 payment method. `createOrboniPaymentIntent` in the Shop API opens the order's payment page; the payment is recorded by Orboni's signed webhook at `/payments/orboni/<channel token>`, or by `addPaymentToOrder` with `{ sessionId }` when the buyer is back — always read back from Orboni first.
14
+ - Paid: a Settled payment. On its way or held for review: an Authorized payment, settled once paid. A reversal leaves a private note on the order. Refunds made in Vendure are recorded in Orboni.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Orboni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,84 @@
1
- # Temporary Holding Version
1
+ # Orboni for Vendure
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Crypto payments for [Vendure](https://vendure.io): the buyer pays on Orboni's payment page, picking USDT, USDC, Bitcoin, Ethereum or another coin, from any wallet or exchange. The money goes straight to the wallets you set in the Orboni dashboard — Orboni never holds it — and the order is paid once the payment is final, by the webhook or the buyer's return, whichever comes first.
4
+
5
+ A payment plugin for Vendure 3, tested end to end on Vendure 3.8. Full guide: https://orboni.com/docs/vendure
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @orboni/vendure-plugin
11
+ ```
12
+
13
+ ```ts
14
+ // vendure-config.ts
15
+ import { OrboniPlugin } from '@orboni/vendure-plugin';
16
+
17
+ export const config: VendureConfig = {
18
+ // …
19
+ plugins: [
20
+ // …
21
+ OrboniPlugin.init(),
22
+ ],
23
+ };
24
+ ```
25
+
26
+ The plugin adds a scheduled task, `orboni-check-payments`, that records what a lost or failed webhook left out (below). Vendure 3.3 and later run it in the worker every 15 minutes when a scheduler is set up, as new projects have it: `DefaultSchedulerPlugin.init()` among the plugins. On Vendure before 3.3, call `OrboniService.checkPayments()` every 15 minutes from a job of your own.
27
+
28
+ ## Set it up
29
+
30
+ 1. In the Orboni dashboard, set the wallets you want to be paid to under Wallets, and copy a secret key under Developers → API keys — a test key (`sk_test_…`) first.
31
+ 2. In the Vendure dashboard, open Settings → Payment methods, create one with the **Orboni** handler (say, "Crypto (USDT, USDC, BTC and more)", code `crypto`), enter the Secret key and the Return address of your storefront's page for a paid order. Assign it to your channel.
32
+ 3. In the Orboni dashboard, under Developers → Webhooks, add an endpoint at `https://<your Vendure server>/payments/orboni/<channel token>` (the token is under Settings → Channels) with the `checkout.session.*` events, and enter its signing secret (`whsec_…`) as the payment method's Webhook signing secret.
33
+ 4. Place an order, and on its payment page, signed in to the Orboni dashboard, press **Simulate payment**: the order is paid. Then swap in your live key (`sk_live_…`) and the live endpoint's secret. The key decides test or live at Orboni.
34
+
35
+ ## The storefront
36
+
37
+ The storefront asks for the order's payment page, sends the buyer there, and records the payment when they come back. With a Return address such as `https://shop.example.com/order/{ORDER_CODE}?session={CHECKOUT_SESSION_ID}` the page knows both:
38
+
39
+ ```graphql
40
+ # The payment step: the order has its customer, address and shipping.
41
+ mutation {
42
+ createOrboniPaymentIntent(input: { paymentMethodCode: "crypto" }) {
43
+ url # send the buyer here
44
+ sessionId
45
+ }
46
+ }
47
+
48
+ # Back from the payment page:
49
+ mutation {
50
+ addPaymentToOrder(input: { method: "crypto", metadata: { sessionId: "cs_…" } }) {
51
+ ... on Order { code state } # PaymentSettled, or PaymentAuthorized
52
+ ... on ErrorResult { errorCode message }
53
+ }
54
+ }
55
+ ```
56
+
57
+ `createOrboniPaymentIntent` moves the active order to ArrangingPayment and also takes `successUrl` and `cancelUrl`, over the payment method's. Paying again opens the same page while the order's total stays the same. When the buyer is back before the money is final, `addPaymentToOrder` answers with an error that says why: show it, and let the buyer pay or choose another way. When the webhook was first, the order is no longer active: read it with `orderByCode`.
58
+
59
+ ## How orders move
60
+
61
+ | Payment | Orboni says | In Vendure |
62
+ | --- | --- | --- |
63
+ | Paid in full | `complete, paid` | A Settled payment naming the coin, the order PaymentSettled |
64
+ | On the chain, not final yet; or held for your review | `processing, held` | An Authorized payment, the order PaymentAuthorized; settled by the webhook once paid |
65
+ | Part paid | `partially_paid` | Nothing recorded; the payment page asks the buyer for the rest |
66
+ | Back before paying | `open, unpaid` | Nothing recorded, the buyer told so |
67
+ | Ran out unpaid | `expired` | Nothing recorded |
68
+ | Money that paid it left the chain | `payment_reversed` | A private note on the order not to ship it until the dashboard shows it paid again, and another when it is paid in full again; the scheduled task sees it too when its webhook is lost |
69
+
70
+ The plugin reads every payment back from Orboni with your key before Vendure records it, so a webhook sent twice, late or out of order changes nothing, and a storefront cannot record a payment that is not there. An order taken back to AddingItems and changed gets a new page for its new total, and the old one is closed.
71
+
72
+ A payment Vendure could not save whole is saved on the next try: the payment, the order's state and its history are saved together, and the webhook is answered 503 until they are, so Orboni sends it again. Every 15 minutes the scheduled task lists the sessions paid, on their way or held in the last three days and records those Vendure does not have, settles an Authorized payment that became final, and for two days reads a paid order again, so money that left the chain is seen without its webhook. One order it cannot save keeps no other waiting. A payment Vendure declines (the order's total changed after its page opened) or cannot take (the order was cancelled) gets one note on the order, however often it is read again.
73
+
74
+ ## Good to know
75
+
76
+ - The currency: the order's own — US dollars, euros, pounds, yen and 30-odd more. In a currency Orboni does not take, the intent fails with a reason.
77
+ - The least an order may be is worth $1.00; below it the intent fails with Orboni's reason.
78
+ - Refunds: the money is in your wallet, so send it back from there, then refund the payment in Vendure: it is recorded in Orboni, and nothing moves by itself.
79
+ - Several channels, or several Vendure servers, can share one Orboni project: each channel adds its own endpoint and acts only on its own orders. While a payment is recorded the order's row is locked (PostgreSQL, MySQL, MariaDB), so the webhook on two servers and the buyer's return at once record it once.
80
+ - What is sent: the order's outstanding amount and currency, its code, id and lines, the customer's email and the request's language. No address or phone number.
81
+
82
+ ## Licence
83
+
84
+ MIT. Source: https://github.com/orboni/vendure-plugin-orboni
@@ -0,0 +1,10 @@
1
+ export declare const ORBONI_PLUGIN_OPTIONS: unique symbol;
2
+ export declare const loggerCtx = "OrboniPlugin";
3
+ /** The handler's code, as a payment method names it in the dashboard. */
4
+ export declare const HANDLER_CODE = "orboni";
5
+ /** Where Orboni's webhook comes: `/payments/orboni/<channel token>`. */
6
+ export declare const WEBHOOK_ROUTE = "payments/orboni";
7
+ export interface OrboniPluginOptions {
8
+ /** The API's address: only for testing against another Orboni. */
9
+ apiUrl?: string;
10
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WEBHOOK_ROUTE = exports.HANDLER_CODE = exports.loggerCtx = exports.ORBONI_PLUGIN_OPTIONS = void 0;
4
+ exports.ORBONI_PLUGIN_OPTIONS = Symbol('ORBONI_PLUGIN_OPTIONS');
5
+ exports.loggerCtx = 'OrboniPlugin';
6
+ /** The handler's code, as a payment method names it in the dashboard. */
7
+ exports.HANDLER_CODE = 'orboni';
8
+ /** Where Orboni's webhook comes: `/payments/orboni/<channel token>`. */
9
+ exports.WEBHOOK_ROUTE = 'payments/orboni';
@@ -0,0 +1,7 @@
1
+ export { OrboniPlugin } from './orboni.plugin';
2
+ export { orboniPaymentHandler } from './orboni.handler';
3
+ export { OrboniService } from './orboni.service';
4
+ export type { OrboniArgs, PaymentIntent, PaymentIntentInput } from './orboni.service';
5
+ export type { OrboniPluginOptions } from './constants';
6
+ export { DECIMALS, fromOrboni, supports, toOrboni } from './money';
7
+ export { notPaidReason, paymentState } from './status';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paymentState = exports.notPaidReason = exports.toOrboni = exports.supports = exports.fromOrboni = exports.DECIMALS = exports.OrboniService = exports.orboniPaymentHandler = exports.OrboniPlugin = void 0;
4
+ var orboni_plugin_1 = require("./orboni.plugin");
5
+ Object.defineProperty(exports, "OrboniPlugin", { enumerable: true, get: function () { return orboni_plugin_1.OrboniPlugin; } });
6
+ var orboni_handler_1 = require("./orboni.handler");
7
+ Object.defineProperty(exports, "orboniPaymentHandler", { enumerable: true, get: function () { return orboni_handler_1.orboniPaymentHandler; } });
8
+ var orboni_service_1 = require("./orboni.service");
9
+ Object.defineProperty(exports, "OrboniService", { enumerable: true, get: function () { return orboni_service_1.OrboniService; } });
10
+ var money_1 = require("./money");
11
+ Object.defineProperty(exports, "DECIMALS", { enumerable: true, get: function () { return money_1.DECIMALS; } });
12
+ Object.defineProperty(exports, "fromOrboni", { enumerable: true, get: function () { return money_1.fromOrboni; } });
13
+ Object.defineProperty(exports, "supports", { enumerable: true, get: function () { return money_1.supports; } });
14
+ Object.defineProperty(exports, "toOrboni", { enumerable: true, get: function () { return money_1.toOrboni; } });
15
+ var status_1 = require("./status");
16
+ Object.defineProperty(exports, "notPaidReason", { enumerable: true, get: function () { return status_1.notPaidReason; } });
17
+ Object.defineProperty(exports, "paymentState", { enumerable: true, get: function () { return status_1.paymentState; } });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The currencies Orboni prices in, with the decimals of each: an amount goes
3
+ * to Orboni in the currency's smallest unit (cents; whole yen, won, krónur,
4
+ * pesos and dong).
5
+ *
6
+ * Vendure keeps every amount as an integer of hundredths, whatever the
7
+ * currency: $24.90 is 2490 and ¥1500 is 150000. So a two-decimal currency
8
+ * goes as it is, and a zero-decimal one is divided by 100.
9
+ */
10
+ export declare const DECIMALS: Readonly<Record<string, number>>;
11
+ export declare function supports(currency: string): boolean;
12
+ /** A Vendure amount (hundredths) in Orboni's smallest unit: 2490 → 2490 cents, 150000 → 1500 yen. */
13
+ export declare function toOrboni(amount: number, currency: string): number;
14
+ /** Orboni's smallest unit back in Vendure's hundredths: 1500 yen → 150000. */
15
+ export declare function fromOrboni(minor: number, currency: string): number;
package/dist/money.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DECIMALS = void 0;
4
+ exports.supports = supports;
5
+ exports.toOrboni = toOrboni;
6
+ exports.fromOrboni = fromOrboni;
7
+ /**
8
+ * The currencies Orboni prices in, with the decimals of each: an amount goes
9
+ * to Orboni in the currency's smallest unit (cents; whole yen, won, krónur,
10
+ * pesos and dong).
11
+ *
12
+ * Vendure keeps every amount as an integer of hundredths, whatever the
13
+ * currency: $24.90 is 2490 and ¥1500 is 150000. So a two-decimal currency
14
+ * goes as it is, and a zero-decimal one is divided by 100.
15
+ */
16
+ exports.DECIMALS = {
17
+ usd: 2, eur: 2, gbp: 2, chf: 2, pln: 2, czk: 2, huf: 2, ron: 2, dkk: 2,
18
+ sek: 2, nok: 2, isk: 0, try: 2, jpy: 0, krw: 0, cny: 2, hkd: 2, sgd: 2,
19
+ inr: 2, idr: 2, myr: 2, php: 2, thb: 2, ils: 2, aud: 2, nzd: 2, cad: 2,
20
+ mxn: 2, brl: 2, zar: 2, uah: 2, ars: 2, clp: 0, aed: 2, sar: 2, twd: 2,
21
+ vnd: 0,
22
+ };
23
+ function supports(currency) {
24
+ return Object.hasOwn(exports.DECIMALS, currency.toLowerCase());
25
+ }
26
+ /** A Vendure amount (hundredths) in Orboni's smallest unit: 2490 → 2490 cents, 150000 → 1500 yen. */
27
+ function toOrboni(amount, currency) {
28
+ if (!Number.isInteger(amount) || amount < 0) {
29
+ throw new RangeError(`Not an amount: ${amount}`);
30
+ }
31
+ const decimals = exports.DECIMALS[currency.toLowerCase()] ?? 2;
32
+ return decimals === 2 ? amount : Math.round(amount / 10 ** (2 - decimals));
33
+ }
34
+ /** Orboni's smallest unit back in Vendure's hundredths: 1500 yen → 150000. */
35
+ function fromOrboni(minor, currency) {
36
+ const decimals = exports.DECIMALS[currency.toLowerCase()] ?? 2;
37
+ return minor * 10 ** (2 - decimals);
38
+ }
@@ -0,0 +1,10 @@
1
+ import type { Request, Response } from 'express';
2
+ import { OrboniService } from './orboni.service';
3
+ /** Orboni's webhook: POST /payments/orboni/<channel token>. */
4
+ export declare class OrboniController {
5
+ private readonly service;
6
+ constructor(service: OrboniService);
7
+ webhook(channelToken: string, signature: string | undefined, request: Request & {
8
+ rawBody?: Buffer;
9
+ }, response: Response): Promise<void>;
10
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OrboniController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const orboni_service_1 = require("./orboni.service");
18
+ /** Orboni's webhook: POST /payments/orboni/<channel token>. */
19
+ let OrboniController = class OrboniController {
20
+ service;
21
+ constructor(service) {
22
+ this.service = service;
23
+ }
24
+ async webhook(channelToken, signature, request, response) {
25
+ const answer = await this.service.handleWebhook(channelToken, request.rawBody, signature);
26
+ response.status(answer.status).type('text/plain').send(answer.body);
27
+ }
28
+ };
29
+ exports.OrboniController = OrboniController;
30
+ __decorate([
31
+ (0, common_1.Post)('orboni/:channelToken'),
32
+ __param(0, (0, common_1.Param)('channelToken')),
33
+ __param(1, (0, common_1.Headers)('webhook-signature')),
34
+ __param(2, (0, common_1.Req)()),
35
+ __param(3, (0, common_1.Res)()),
36
+ __metadata("design:type", Function),
37
+ __metadata("design:paramtypes", [String, Object, Object, Object]),
38
+ __metadata("design:returntype", Promise)
39
+ ], OrboniController.prototype, "webhook", null);
40
+ exports.OrboniController = OrboniController = __decorate([
41
+ (0, common_1.Controller)('payments'),
42
+ __metadata("design:paramtypes", [orboni_service_1.OrboniService])
43
+ ], OrboniController);
@@ -0,0 +1,61 @@
1
+ import { LanguageCode, PaymentMethodHandler } from '@vendure/core';
2
+ /**
3
+ * Orboni as a Vendure payment method: the buyer pays on Orboni's payment
4
+ * page, in the coin and network they choose, straight to the merchant's own
5
+ * wallets. Its settings are entered per payment method in the dashboard.
6
+ */
7
+ export declare const orboniPaymentHandler: PaymentMethodHandler<{
8
+ apiKey: {
9
+ type: "string";
10
+ label: {
11
+ languageCode: LanguageCode;
12
+ value: string;
13
+ }[];
14
+ description: {
15
+ languageCode: LanguageCode;
16
+ value: string;
17
+ }[];
18
+ ui: {
19
+ component: string;
20
+ };
21
+ };
22
+ webhookSecret: {
23
+ type: "string";
24
+ required: false;
25
+ label: {
26
+ languageCode: LanguageCode;
27
+ value: string;
28
+ }[];
29
+ description: {
30
+ languageCode: LanguageCode;
31
+ value: string;
32
+ }[];
33
+ ui: {
34
+ component: string;
35
+ };
36
+ };
37
+ successUrl: {
38
+ type: "string";
39
+ required: false;
40
+ label: {
41
+ languageCode: LanguageCode;
42
+ value: string;
43
+ }[];
44
+ description: {
45
+ languageCode: LanguageCode;
46
+ value: string;
47
+ }[];
48
+ };
49
+ cancelUrl: {
50
+ type: "string";
51
+ required: false;
52
+ label: {
53
+ languageCode: LanguageCode;
54
+ value: string;
55
+ }[];
56
+ description: {
57
+ languageCode: LanguageCode;
58
+ value: string;
59
+ }[];
60
+ };
61
+ }>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.orboniPaymentHandler = void 0;
4
+ const core_1 = require("@vendure/core");
5
+ const constants_1 = require("./constants");
6
+ const orboni_service_1 = require("./orboni.service");
7
+ let service;
8
+ const en = (value) => [{ languageCode: core_1.LanguageCode.en, value }];
9
+ /**
10
+ * Orboni as a Vendure payment method: the buyer pays on Orboni's payment
11
+ * page, in the coin and network they choose, straight to the merchant's own
12
+ * wallets. Its settings are entered per payment method in the dashboard.
13
+ */
14
+ exports.orboniPaymentHandler = new core_1.PaymentMethodHandler({
15
+ code: constants_1.HANDLER_CODE,
16
+ description: en('Orboni: crypto payments (USDT, USDC, BTC and more) to your own wallets'),
17
+ args: {
18
+ apiKey: {
19
+ type: 'string',
20
+ label: en('Secret key'),
21
+ description: en('sk_live_… or sk_test_…, from Developers → API keys in the Orboni dashboard. The key decides test or live.'),
22
+ ui: { component: 'password-form-input' },
23
+ },
24
+ webhookSecret: {
25
+ type: 'string',
26
+ required: false,
27
+ label: en('Webhook signing secret'),
28
+ description: en('whsec_…, from the endpoint you add under Developers → Webhooks at https://<your Vendure server>/payments/orboni/<channel token>.'),
29
+ ui: { component: 'password-form-input' },
30
+ },
31
+ successUrl: {
32
+ type: 'string',
33
+ required: false,
34
+ label: en('Return address'),
35
+ description: en('Your storefront page the buyer comes back to once paid, unless the storefront passes its own. {ORDER_CODE} is replaced by the order code.'),
36
+ },
37
+ cancelUrl: {
38
+ type: 'string',
39
+ required: false,
40
+ label: en('Back address'),
41
+ description: en('Where the payment page\'s back link goes, unless the storefront passes its own. {ORDER_CODE} is replaced by the order code.'),
42
+ },
43
+ },
44
+ init(injector) {
45
+ service = injector.get(orboni_service_1.OrboniService);
46
+ },
47
+ createPayment(ctx, order, amount, args, metadata) {
48
+ return service.createPayment(ctx, order, amount, args, metadata);
49
+ },
50
+ settlePayment(ctx, order, payment, args) {
51
+ return service.settlePayment(payment, args);
52
+ },
53
+ createRefund(ctx, input, amount, order, payment, args) {
54
+ return service.createRefund(ctx, input.reason, amount, order, payment, args);
55
+ },
56
+ });
@@ -0,0 +1,18 @@
1
+ import { Type } from '@vendure/core';
2
+ import { OrboniPluginOptions } from './constants';
3
+ /**
4
+ * Crypto payments through Orboni.
5
+ *
6
+ * ```ts
7
+ * plugins: [OrboniPlugin.init()]
8
+ * ```
9
+ *
10
+ * Then add a payment method with the Orboni handler in the dashboard, and an
11
+ * Orboni webhook endpoint at /payments/orboni/<channel token>. On Vendure 3.3+
12
+ * with a scheduler (DefaultSchedulerPlugin) the plugin's task records what a
13
+ * lost or failed webhook left out, every 15 minutes in the worker.
14
+ */
15
+ export declare class OrboniPlugin {
16
+ static options: OrboniPluginOptions;
17
+ static init(options?: OrboniPluginOptions): Type<OrboniPlugin>;
18
+ }
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var OrboniPlugin_1;
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.OrboniPlugin = void 0;
44
+ const core = __importStar(require("@vendure/core"));
45
+ const core_1 = require("@vendure/core");
46
+ const body_parser_1 = require("body-parser");
47
+ const graphql_tag_1 = require("graphql-tag");
48
+ const constants_1 = require("./constants");
49
+ const orboni_controller_1 = require("./orboni.controller");
50
+ const orboni_handler_1 = require("./orboni.handler");
51
+ const orboni_resolver_1 = require("./orboni.resolver");
52
+ const orboni_service_1 = require("./orboni.service");
53
+ /** The webhook's body as it came, for its signature. */
54
+ const rawBody = (0, body_parser_1.raw)({
55
+ type: '*/*',
56
+ limit: '1mb',
57
+ verify(request, _response, buffer) {
58
+ request.rawBody = Buffer.from(buffer);
59
+ },
60
+ });
61
+ /**
62
+ * Vendure's scheduled task (3.3+): payments whose webhook was lost or failed,
63
+ * and paid ones checked for two days, every 15 minutes in the worker. Older
64
+ * Vendure has no tasks: there `OrboniService.checkPayments()` is the merchant's
65
+ * to call.
66
+ */
67
+ function checkTask() {
68
+ const ScheduledTask = core.ScheduledTask;
69
+ if (typeof ScheduledTask !== 'function') {
70
+ return null;
71
+ }
72
+ return new ScheduledTask({
73
+ id: 'orboni-check-payments',
74
+ description: 'Orboni: records payments whose webhook was lost or failed, and checks paid ones for two days',
75
+ schedule: (cron) => cron.every(15).minutes(),
76
+ timeout: '10m',
77
+ preventOverlap: true,
78
+ async execute({ injector }) {
79
+ const result = await injector.get(orboni_service_1.OrboniService).checkPayments();
80
+ core_1.Logger.verbose(`Payments checked: ${result}`, constants_1.loggerCtx);
81
+ return result;
82
+ },
83
+ });
84
+ }
85
+ const shopSchema = (0, graphql_tag_1.gql) `
86
+ input OrboniPaymentIntentInput {
87
+ "The code of an Orboni payment method eligible for the order."
88
+ paymentMethodCode: String!
89
+ "Where the buyer comes back once paid; {ORDER_CODE} is replaced. Default: the payment method's Return address."
90
+ successUrl: String
91
+ "Where the payment page's back link goes; {ORDER_CODE} is replaced. Default: the payment method's Back address."
92
+ cancelUrl: String
93
+ }
94
+
95
+ type OrboniPaymentIntent {
96
+ "The payment page: send the buyer there."
97
+ url: String!
98
+ "The Orboni session, cs_…: pass it as { sessionId } to addPaymentToOrder when the buyer is back."
99
+ sessionId: String!
100
+ expiresAt: DateTime!
101
+ }
102
+
103
+ extend type Mutation {
104
+ "Moves the active order to ArrangingPayment and returns its Orboni payment page."
105
+ createOrboniPaymentIntent(input: OrboniPaymentIntentInput!): OrboniPaymentIntent!
106
+ }
107
+ `;
108
+ /**
109
+ * Crypto payments through Orboni.
110
+ *
111
+ * ```ts
112
+ * plugins: [OrboniPlugin.init()]
113
+ * ```
114
+ *
115
+ * Then add a payment method with the Orboni handler in the dashboard, and an
116
+ * Orboni webhook endpoint at /payments/orboni/<channel token>. On Vendure 3.3+
117
+ * with a scheduler (DefaultSchedulerPlugin) the plugin's task records what a
118
+ * lost or failed webhook left out, every 15 minutes in the worker.
119
+ */
120
+ let OrboniPlugin = class OrboniPlugin {
121
+ static { OrboniPlugin_1 = this; }
122
+ static options = {};
123
+ static init(options = {}) {
124
+ OrboniPlugin_1.options = options;
125
+ return OrboniPlugin_1;
126
+ }
127
+ };
128
+ exports.OrboniPlugin = OrboniPlugin;
129
+ exports.OrboniPlugin = OrboniPlugin = OrboniPlugin_1 = __decorate([
130
+ (0, core_1.VendurePlugin)({
131
+ imports: [core_1.PluginCommonModule],
132
+ controllers: [orboni_controller_1.OrboniController],
133
+ providers: [{ provide: constants_1.ORBONI_PLUGIN_OPTIONS, useFactory: () => OrboniPlugin.options }, orboni_service_1.OrboniService],
134
+ configuration: (config) => {
135
+ config.paymentOptions.paymentMethodHandlers.push(orboni_handler_1.orboniPaymentHandler);
136
+ config.apiOptions.middleware.push({ route: `/${constants_1.WEBHOOK_ROUTE}`, handler: rawBody, beforeListen: true });
137
+ const task = checkTask();
138
+ const scheduler = config.schedulerOptions;
139
+ if (task && scheduler) {
140
+ scheduler.tasks = [...(scheduler.tasks ?? []), task];
141
+ }
142
+ return config;
143
+ },
144
+ shopApiExtensions: { schema: shopSchema, resolvers: [orboni_resolver_1.OrboniShopResolver] },
145
+ compatibility: '^3.0.0',
146
+ })
147
+ ], OrboniPlugin);
@@ -0,0 +1,7 @@
1
+ import { RequestContext } from '@vendure/core';
2
+ import { OrboniService, PaymentIntent, PaymentIntentInput } from './orboni.service';
3
+ export declare class OrboniShopResolver {
4
+ private readonly service;
5
+ constructor(service: OrboniService);
6
+ createOrboniPaymentIntent(ctx: RequestContext, input: PaymentIntentInput): Promise<PaymentIntent>;
7
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OrboniShopResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@vendure/core");
18
+ const orboni_service_1 = require("./orboni.service");
19
+ let OrboniShopResolver = class OrboniShopResolver {
20
+ service;
21
+ constructor(service) {
22
+ this.service = service;
23
+ }
24
+ createOrboniPaymentIntent(ctx, input) {
25
+ return this.service.createPaymentIntent(ctx, input);
26
+ }
27
+ };
28
+ exports.OrboniShopResolver = OrboniShopResolver;
29
+ __decorate([
30
+ (0, graphql_1.Mutation)(),
31
+ (0, core_1.Transaction)(),
32
+ (0, core_1.Allow)(core_1.Permission.Owner),
33
+ __param(0, (0, core_1.Ctx)()),
34
+ __param(1, (0, graphql_1.Args)('input')),
35
+ __metadata("design:type", Function),
36
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
37
+ __metadata("design:returntype", Promise)
38
+ ], OrboniShopResolver.prototype, "createOrboniPaymentIntent", null);
39
+ exports.OrboniShopResolver = OrboniShopResolver = __decorate([
40
+ (0, graphql_1.Resolver)(),
41
+ __metadata("design:paramtypes", [orboni_service_1.OrboniService])
42
+ ], OrboniShopResolver);