@voyantjs/plugin-netopia 0.1.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.
- package/LICENSE +109 -0
- package/README.md +56 -0
- package/dist/src/client.d.ts +10 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +71 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +4 -0
- package/dist/src/plugin.d.ts +709 -0
- package/dist/src/plugin.d.ts.map +1 -0
- package/dist/src/plugin.js +127 -0
- package/dist/src/service.d.ts +36 -0
- package/dist/src/service.d.ts.map +1 -0
- package/dist/src/service.js +313 -0
- package/dist/src/types.d.ts +160 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/src/validation.d.ts +448 -0
- package/dist/src/validation.d.ts.map +1 -0
- package/dist/src/validation.js +102 -0
- package/dist/tests/unit/client.test.d.ts +2 -0
- package/dist/tests/unit/client.test.d.ts.map +1 -0
- package/dist/tests/unit/client.test.js +254 -0
- package/dist/tests/unit/plugin.test.d.ts +2 -0
- package/dist/tests/unit/plugin.test.d.ts.map +1 -0
- package/dist/tests/unit/plugin.test.js +346 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 PixelMakers Studio SRL
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly
|
|
28
|
+
display and redistribute the Software for any Permitted Purpose identified
|
|
29
|
+
below.
|
|
30
|
+
|
|
31
|
+
### Permitted Purpose
|
|
32
|
+
|
|
33
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing
|
|
34
|
+
Use means making the Software available to others in a commercial product or
|
|
35
|
+
service that:
|
|
36
|
+
|
|
37
|
+
1. substitutes for the Software;
|
|
38
|
+
|
|
39
|
+
2. substitutes for any other product or service we offer using the Software
|
|
40
|
+
that exists as of the date we make the Software available; or
|
|
41
|
+
|
|
42
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
43
|
+
|
|
44
|
+
Permitted Purposes specifically include using the Software:
|
|
45
|
+
|
|
46
|
+
1. for your internal use and access;
|
|
47
|
+
|
|
48
|
+
2. for non-commercial education;
|
|
49
|
+
|
|
50
|
+
3. for non-commercial research; and
|
|
51
|
+
|
|
52
|
+
4. in connection with professional services that you provide to a licensee
|
|
53
|
+
using the Software in accordance with these Terms and Conditions.
|
|
54
|
+
|
|
55
|
+
### Patents
|
|
56
|
+
|
|
57
|
+
To the extent your use for a Permitted Purpose would necessarily infringe
|
|
58
|
+
our patents, the license grant above includes a license under our patents.
|
|
59
|
+
If you make a claim against any party that the Software infringes or
|
|
60
|
+
contributes to the infringement of any patent, then your patent license to
|
|
61
|
+
the Software ends immediately.
|
|
62
|
+
|
|
63
|
+
### Redistribution
|
|
64
|
+
|
|
65
|
+
The Terms and Conditions apply to all copies, modifications and derivatives
|
|
66
|
+
of the Software.
|
|
67
|
+
|
|
68
|
+
If you redistribute any copies, modifications or derivatives of the
|
|
69
|
+
Software, you must include a copy of or a link to these Terms and Conditions
|
|
70
|
+
and not remove any copyright notices provided in or with the Software.
|
|
71
|
+
|
|
72
|
+
### Disclaimer
|
|
73
|
+
|
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS
|
|
75
|
+
OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A
|
|
76
|
+
PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
77
|
+
|
|
78
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO
|
|
79
|
+
THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
|
|
80
|
+
DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
81
|
+
|
|
82
|
+
### Trademarks
|
|
83
|
+
|
|
84
|
+
Except for displaying the License Details and identifying us as the origin
|
|
85
|
+
of the Software, you have no right under these Terms and Conditions to use
|
|
86
|
+
our trademarks, trade names, service marks or product names.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Grant of Future License
|
|
91
|
+
|
|
92
|
+
We hereby irrevocably grant you an additional license to use the Software
|
|
93
|
+
under the Apache License, Version 2.0 that is effective on the second
|
|
94
|
+
anniversary of the date we make the Software available. On or after that
|
|
95
|
+
date, you may use the Software under the Apache License, Version 2.0, in
|
|
96
|
+
which case the following will apply:
|
|
97
|
+
|
|
98
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
99
|
+
use this file except in compliance with the License.
|
|
100
|
+
|
|
101
|
+
You may obtain a copy of the License at
|
|
102
|
+
|
|
103
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
104
|
+
|
|
105
|
+
Unless required by applicable law or agreed to in writing, software
|
|
106
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
107
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
108
|
+
License for the specific language governing permissions and limitations
|
|
109
|
+
under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# `@voyantjs/plugin-netopia`
|
|
2
|
+
|
|
3
|
+
Netopia hosted-card payment support for Voyant finance.
|
|
4
|
+
|
|
5
|
+
This package sits on top of `@voyantjs/finance` and its `payment_sessions` model. It does not replace finance state. It starts a hosted Netopia checkout, stores provider references on the session, and reconciles callback payloads back into Voyant payments, captures, authorizations, invoices, and booking payment schedules.
|
|
6
|
+
|
|
7
|
+
## Environment
|
|
8
|
+
|
|
9
|
+
The default finance extension resolves its runtime config from:
|
|
10
|
+
|
|
11
|
+
- `NETOPIA_URL`
|
|
12
|
+
- `NETOPIA_API_KEY`
|
|
13
|
+
- `NETOPIA_POS_SIGNATURE`
|
|
14
|
+
- `NETOPIA_NOTIFY_URL`
|
|
15
|
+
- `NETOPIA_REDIRECT_URL`
|
|
16
|
+
|
|
17
|
+
You can also override these programmatically via `createNetopiaFinanceExtension(options)`.
|
|
18
|
+
|
|
19
|
+
## Routes
|
|
20
|
+
|
|
21
|
+
Mounted as a finance extension, the package exposes:
|
|
22
|
+
|
|
23
|
+
- `POST /providers/netopia/payment-sessions/:sessionId/start`
|
|
24
|
+
- `POST /providers/netopia/bookings/:bookingId/payment-schedules/:scheduleId/collect`
|
|
25
|
+
- `POST /providers/netopia/bookings/:bookingId/guarantees/:guaranteeId/collect`
|
|
26
|
+
- `POST /providers/netopia/invoices/:invoiceId/collect`
|
|
27
|
+
- `POST /providers/netopia/callback`
|
|
28
|
+
- `GET /providers/netopia/config`
|
|
29
|
+
|
|
30
|
+
Because this is a finance extension, these routes mount under the finance module path in the app.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { createNetopiaFinanceExtension } from "@voyantjs/plugin-netopia"
|
|
36
|
+
|
|
37
|
+
const netopiaFinanceExtension = createNetopiaFinanceExtension()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then include the returned extension in `createApp({ extensions: [...] })`.
|
|
41
|
+
|
|
42
|
+
## Flow
|
|
43
|
+
|
|
44
|
+
1. Either create a finance `payment_session` yourself, or use one of the collect routes to create one from a booking schedule, guarantee, or invoice.
|
|
45
|
+
2. Start the hosted Netopia checkout.
|
|
46
|
+
3. Redirect the customer to the returned provider `paymentURL`.
|
|
47
|
+
4. Optionally send a payment-link or invoice notification as part of the collect flow.
|
|
48
|
+
5. Netopia calls the callback route.
|
|
49
|
+
6. The plugin completes, fails, or updates the session in finance.
|
|
50
|
+
|
|
51
|
+
## Notes
|
|
52
|
+
|
|
53
|
+
- Successful Netopia statuses default to `3` and `5`.
|
|
54
|
+
- In-flight statuses default to `1` and `15`.
|
|
55
|
+
- The callback path is idempotent for already-completed sessions.
|
|
56
|
+
- Amount/currency mismatch on a supposedly successful callback fails the session instead of silently accepting it.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NetopiaFetch, NetopiaRuntimeOptions, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, ResolvedNetopiaRuntimeOptions } from "./types.js";
|
|
2
|
+
export interface NetopiaClientApi {
|
|
3
|
+
startCardPayment(request: NetopiaStartPaymentRequest): Promise<NetopiaStartPaymentResponse>;
|
|
4
|
+
}
|
|
5
|
+
export interface NetopiaClientOptions extends Pick<ResolvedNetopiaRuntimeOptions, "apiUrl" | "apiKey"> {
|
|
6
|
+
fetch?: NetopiaFetch;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveNetopiaRuntimeOptions(bindings: Record<string, unknown> | undefined, options?: NetopiaRuntimeOptions): ResolvedNetopiaRuntimeOptions;
|
|
9
|
+
export declare function createNetopiaClient(options: NetopiaClientOptions): NetopiaClientApi;
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAA;CAC5F;AAED,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,6BAA6B,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACpG,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC7C,OAAO,GAAE,qBAA0B,GAClC,6BAA6B,CA0B/B;AAMD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CA+CnF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export function resolveNetopiaRuntimeOptions(bindings, options = {}) {
|
|
2
|
+
const env = bindings ?? {};
|
|
3
|
+
const apiUrl = options.apiUrl ?? coerceString(env.NETOPIA_URL);
|
|
4
|
+
const apiKey = options.apiKey ?? coerceString(env.NETOPIA_API_KEY);
|
|
5
|
+
const posSignature = options.posSignature ?? coerceString(env.NETOPIA_POS_SIGNATURE);
|
|
6
|
+
const notifyUrl = options.notifyUrl ?? coerceString(env.NETOPIA_NOTIFY_URL);
|
|
7
|
+
const redirectUrl = options.redirectUrl ?? coerceString(env.NETOPIA_REDIRECT_URL);
|
|
8
|
+
if (!apiUrl)
|
|
9
|
+
throw new Error("Missing Netopia config: NETOPIA_URL");
|
|
10
|
+
if (!apiKey)
|
|
11
|
+
throw new Error("Missing Netopia config: NETOPIA_API_KEY");
|
|
12
|
+
if (!posSignature)
|
|
13
|
+
throw new Error("Missing Netopia config: NETOPIA_POS_SIGNATURE");
|
|
14
|
+
if (!notifyUrl)
|
|
15
|
+
throw new Error("Missing Netopia config: NETOPIA_NOTIFY_URL");
|
|
16
|
+
if (!redirectUrl)
|
|
17
|
+
throw new Error("Missing Netopia config: NETOPIA_REDIRECT_URL");
|
|
18
|
+
return {
|
|
19
|
+
apiUrl,
|
|
20
|
+
apiKey,
|
|
21
|
+
posSignature,
|
|
22
|
+
notifyUrl,
|
|
23
|
+
redirectUrl,
|
|
24
|
+
emailTemplate: options.emailTemplate ?? "confirm",
|
|
25
|
+
language: options.language ?? "ro",
|
|
26
|
+
successStatuses: options.successStatuses ?? [3, 5],
|
|
27
|
+
processingStatuses: options.processingStatuses ?? [1, 15],
|
|
28
|
+
fetch: options.fetch,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function coerceString(value) {
|
|
32
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
33
|
+
}
|
|
34
|
+
export function createNetopiaClient(options) {
|
|
35
|
+
const apiUrl = options.apiUrl.replace(/\/$/, "");
|
|
36
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
37
|
+
async function request(method, path, body) {
|
|
38
|
+
if (!fetchImpl) {
|
|
39
|
+
throw new Error("Netopia client requires a fetch implementation");
|
|
40
|
+
}
|
|
41
|
+
const response = await fetchImpl(`${apiUrl}${path}`, {
|
|
42
|
+
method,
|
|
43
|
+
headers: {
|
|
44
|
+
Authorization: options.apiKey,
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Accept: "application/json",
|
|
47
|
+
},
|
|
48
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
49
|
+
});
|
|
50
|
+
let text = "";
|
|
51
|
+
let json = null;
|
|
52
|
+
try {
|
|
53
|
+
text = await response.text();
|
|
54
|
+
json = text ? JSON.parse(text) : null;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Surface raw text in the thrown error below.
|
|
58
|
+
}
|
|
59
|
+
return { ok: response.ok, status: response.status, json, text };
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
async startCardPayment(requestBody) {
|
|
63
|
+
const res = await request("POST", "/payment/card/start", requestBody);
|
|
64
|
+
const json = (res.json ?? {});
|
|
65
|
+
if (!res.ok || json.error) {
|
|
66
|
+
throw new Error(`Netopia start payment failed (${json.error?.code ?? res.status}): ${json.error?.message ?? res.text}`);
|
|
67
|
+
}
|
|
68
|
+
return json;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createNetopiaClient, resolveNetopiaRuntimeOptions, type NetopiaClientApi, type NetopiaClientOptions, } from "./client.js";
|
|
2
|
+
export { createNetopiaFinanceExtension, createNetopiaFinanceRoutes, netopiaFinanceExtension, netopiaHonoPlugin, } from "./plugin.js";
|
|
3
|
+
export { deriveNetopiaOrderId, mapNetopiaPaymentStatus, netopiaService, type NetopiaCallbackResult, type NetopiaCollectPaymentResult, type NetopiaStartPaymentResult, } from "./service.js";
|
|
4
|
+
export type { NetopiaBillingAddress, NetopiaBrowserData, NetopiaFetch, NetopiaInstallments, NetopiaPaymentInstrument, NetopiaPaymentOptions, NetopiaProductLine, NetopiaRuntimeOptions, NetopiaStartPaymentInput, NetopiaStartPaymentRequest, NetopiaStartPaymentResponse, NetopiaWebhookPayload, ResolvedNetopiaRuntimeOptions, } from "./types.js";
|
|
5
|
+
export { netopiaBillingAddressSchema, netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema, netopiaBrowserDataSchema, netopiaInstallmentsSchema, netopiaPaymentInstrumentSchema, netopiaPaymentOptionsSchema, netopiaProductLineSchema, netopiaStartPaymentSessionSchema, netopiaWebhookPayloadSchema, } from "./validation.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,GAC/B,MAAM,cAAc,CAAA;AACrB,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,2BAA2B,EAC3B,oCAAoC,EACpC,mCAAmC,EACnC,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createNetopiaClient, resolveNetopiaRuntimeOptions, } from "./client.js";
|
|
2
|
+
export { createNetopiaFinanceExtension, createNetopiaFinanceRoutes, netopiaFinanceExtension, netopiaHonoPlugin, } from "./plugin.js";
|
|
3
|
+
export { deriveNetopiaOrderId, mapNetopiaPaymentStatus, netopiaService, } from "./service.js";
|
|
4
|
+
export { netopiaBillingAddressSchema, netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema, netopiaBrowserDataSchema, netopiaInstallmentsSchema, netopiaPaymentInstrumentSchema, netopiaPaymentOptionsSchema, netopiaProductLineSchema, netopiaStartPaymentSessionSchema, netopiaWebhookPayloadSchema, } from "./validation.js";
|