liqpay-nestjs 0.3.5 → 0.3.7
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/README.md +79 -100
- package/dist/core/clients/index.d.ts +0 -3
- package/dist/core/clients/index.js +0 -3
- package/dist/core/clients/liqpay.client.d.ts +2 -0
- package/dist/core/clients/liqpay.client.js +3 -0
- package/dist/core/clients/payments.client.js +1 -1
- package/dist/core/clients/refunds.client.d.ts +7 -0
- package/dist/core/clients/refunds.client.js +20 -0
- package/dist/core/clients/utils.client.d.ts +1 -1
- package/dist/core/clients/utils.client.js +2 -1
- package/dist/core/types/base/request.type.d.ts +3 -2
- package/dist/core/types/base/response.type.d.ts +3 -2
- package/dist/core/types/refund/index.d.ts +2 -0
- package/dist/core/types/refund/index.js +18 -0
- package/dist/nest/services/refunds.service.d.ts +7 -0
- package/dist/nest/services/refunds.service.js +13 -0
- package/package.json +3 -2
- package/dist/core/__devtypes/documented/checkout.callback.d.ts +0 -250
- package/dist/core/__devtypes/documented/checkout.callback.js +0 -2
- package/dist/core/__devtypes/documented/checkout.request.d.ts +0 -236
- package/dist/core/__devtypes/documented/checkout.request.js +0 -2
- package/dist/core/__devtypes/documented/detail-addenda.d.ts +0 -33
- package/dist/core/__devtypes/documented/detail-addenda.js +0 -2
- package/dist/core/__devtypes/documented/envelope.d.ts +0 -15
- package/dist/core/__devtypes/documented/envelope.js +0 -2
- package/dist/core/__devtypes/documented/fiscal-data.d.ts +0 -80
- package/dist/core/__devtypes/documented/fiscal-data.js +0 -2
- package/dist/core/__devtypes/documented/payment-status.request.d.ts +0 -23
- package/dist/core/__devtypes/documented/payment-status.request.js +0 -2
- package/dist/core/__devtypes/documented/payment-status.response.d.ts +0 -225
- package/dist/core/__devtypes/documented/payment-status.response.js +0 -2
- package/dist/core/__devtypes/documented/split-rule.d.ts +0 -29
- package/dist/core/__devtypes/documented/split-rule.js +0 -2
- package/dist/core/__devtypes/documented/types.d.ts +0 -287
- package/dist/core/__devtypes/documented/types.js +0 -199
- package/dist/core/__devtypes/payloads.d.ts +0 -158
- package/dist/core/__devtypes/payloads.js +0 -2
- package/dist/core/__devtypes/undocumented/checkout.callback.d.ts +0 -61
- package/dist/core/__devtypes/undocumented/checkout.callback.js +0 -2
- package/dist/core/__devtypes/undocumented/checkout.request.d.ts +0 -39
- package/dist/core/__devtypes/undocumented/checkout.request.js +0 -2
- package/dist/core/__devtypes/undocumented/detail-addenda.d.ts +0 -9
- package/dist/core/__devtypes/undocumented/detail-addenda.js +0 -2
- package/dist/core/__devtypes/undocumented/envelope.d.ts +0 -4
- package/dist/core/__devtypes/undocumented/envelope.js +0 -2
- package/dist/core/__devtypes/undocumented/fiscal-data.d.ts +0 -23
- package/dist/core/__devtypes/undocumented/fiscal-data.js +0 -2
- package/dist/core/__devtypes/undocumented/payment-status.request.d.ts +0 -6
- package/dist/core/__devtypes/undocumented/payment-status.request.js +0 -2
- package/dist/core/__devtypes/undocumented/payment-status.response.d.ts +0 -54
- package/dist/core/__devtypes/undocumented/payment-status.response.js +0 -2
- package/dist/core/__devtypes/undocumented/split-rule.d.ts +0 -9
- package/dist/core/__devtypes/undocumented/split-rule.js +0 -2
- package/dist/core/__devtypes/undocumented/types.d.ts +0 -181
- package/dist/core/__devtypes/undocumented/types.js +0 -160
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# liqpay-nestjs
|
|
2
2
|
|
|
3
|
-
NestJS module for LiqPay payments with typed request
|
|
3
|
+
NestJS module for LiqPay payments with typed request models, signed checkout payload generation, webhook callback parsing, and payment status lookups.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- NestJS module with `forRoot` and `forRootAsync`
|
|
8
8
|
- `LiqpayService` with `payments` and `webhooks` helpers
|
|
9
|
-
- Signed builders for
|
|
10
|
-
- HTML
|
|
11
|
-
-
|
|
12
|
-
-
|
|
9
|
+
- Signed checkout builders for standard payment, hold, and subscription flows
|
|
10
|
+
- HTML checkout button generation with LiqPay SDK markup
|
|
11
|
+
- Typed payment status requests and normalized responses
|
|
12
|
+
- TypeScript types exported from the package root
|
|
13
13
|
|
|
14
14
|
## Requirements
|
|
15
15
|
|
|
@@ -71,11 +71,16 @@ import { LiqPayModule } from 'liqpay-nestjs'
|
|
|
71
71
|
export class AppModule {}
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
###
|
|
74
|
+
### Inject and use `LiqpayService`
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
-
import { Body, Controller, Get,
|
|
78
|
-
import {
|
|
77
|
+
import { Body, Controller, Get, Post, Query } from '@nestjs/common'
|
|
78
|
+
import { LiqpayService } from 'liqpay-nestjs'
|
|
79
|
+
import type {
|
|
80
|
+
CheckoutInput,
|
|
81
|
+
LiqPayEnvelope,
|
|
82
|
+
PaymentStatusInput,
|
|
83
|
+
} from 'liqpay-nestjs'
|
|
79
84
|
|
|
80
85
|
@Controller('payments')
|
|
81
86
|
export class PaymentsController {
|
|
@@ -90,7 +95,7 @@ export class PaymentsController {
|
|
|
90
95
|
orderId: 'order-123',
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
const checkout = this.liqpay.payments.
|
|
98
|
+
const checkout = this.liqpay.payments.getCheckoutUrl(payload)
|
|
94
99
|
|
|
95
100
|
return {
|
|
96
101
|
url: checkout.url,
|
|
@@ -99,9 +104,10 @@ export class PaymentsController {
|
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
|
|
102
|
-
@Get('
|
|
103
|
-
getStatus(@
|
|
104
|
-
|
|
107
|
+
@Get('status')
|
|
108
|
+
getStatus(@Query('orderId') orderId: string) {
|
|
109
|
+
const payload: PaymentStatusInput = { orderId }
|
|
110
|
+
return this.liqpay.payments.getStatus(payload)
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
@Post('webhook')
|
|
@@ -113,12 +119,12 @@ export class PaymentsController {
|
|
|
113
119
|
|
|
114
120
|
## Typical Flow
|
|
115
121
|
|
|
116
|
-
1. Register `LiqPayModule` with your
|
|
117
|
-
2. Build a checkout payload with `liqpay.payments.
|
|
118
|
-
3. Redirect the
|
|
122
|
+
1. Register `LiqPayModule` with your public and private keys.
|
|
123
|
+
2. Build a checkout payload with `liqpay.payments.getCheckoutUrl(...)`, `hold(...)`, or `subscribe(...)`.
|
|
124
|
+
3. Redirect the customer to `result.url` or render the returned button HTML.
|
|
119
125
|
4. Receive the LiqPay callback envelope at your `serverUrl` endpoint.
|
|
120
126
|
5. Parse the callback with `liqpay.webhooks.parseCheckoutCallback(...)`.
|
|
121
|
-
6.
|
|
127
|
+
6. Query the current state later with `liqpay.payments.getStatus({ orderId })` when needed.
|
|
122
128
|
|
|
123
129
|
## Configuration
|
|
124
130
|
|
|
@@ -138,20 +144,20 @@ The async registration provider validates the resolved options and throws if `pu
|
|
|
138
144
|
|
|
139
145
|
`LiqpayService.payments` exposes five methods.
|
|
140
146
|
|
|
141
|
-
| Method
|
|
142
|
-
|
|
|
143
|
-
| `
|
|
144
|
-
| `hold(payload)`
|
|
145
|
-
| `subscribe(payload)`
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
147
|
+
| Method | Purpose | Notes |
|
|
148
|
+
| ------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------- |
|
|
149
|
+
| `getCheckoutUrl(payload)` | Builds a signed standard checkout payload. | Returns a full result object, not only the URL. |
|
|
150
|
+
| `hold(payload)` | Builds a signed checkout payload with action `hold`. | Local builder, no HTTP call. |
|
|
151
|
+
| `subscribe(payload)` | Builds a signed checkout payload with action `subscribe`. | Local builder, no HTTP call. |
|
|
152
|
+
| `getCheckoutButton(payload, buttonText?, buttonColor?)` | Returns LiqPay checkout HTML for the standard payment flow. | Uses action `pay`. |
|
|
153
|
+
| `getStatus(payload)` | Calls LiqPay status API. | Expects `PaymentStatusInput`. |
|
|
148
154
|
|
|
149
|
-
### `payments.
|
|
155
|
+
### `payments.getCheckoutUrl(payload)`
|
|
150
156
|
|
|
151
|
-
Use
|
|
157
|
+
Use this for a normal checkout flow.
|
|
152
158
|
|
|
153
159
|
```ts
|
|
154
|
-
import { CheckoutInput } from 'liqpay-nestjs'
|
|
160
|
+
import type { CheckoutInput } from 'liqpay-nestjs'
|
|
155
161
|
|
|
156
162
|
const payload: CheckoutInput = {
|
|
157
163
|
amount: 100,
|
|
@@ -160,23 +166,23 @@ const payload: CheckoutInput = {
|
|
|
160
166
|
orderId: 'order-123',
|
|
161
167
|
}
|
|
162
168
|
|
|
163
|
-
const checkout = liqpay.payments.
|
|
169
|
+
const checkout = liqpay.payments.getCheckoutUrl(payload)
|
|
164
170
|
|
|
165
171
|
console.log(checkout.url)
|
|
166
172
|
console.log(checkout.data)
|
|
167
173
|
console.log(checkout.signature)
|
|
168
174
|
```
|
|
169
175
|
|
|
170
|
-
|
|
176
|
+
Despite the method name, the return value is a signed checkout object containing:
|
|
171
177
|
|
|
172
|
-
- `url`: ready-to-use LiqPay
|
|
178
|
+
- `url`: ready-to-use LiqPay redirect URL
|
|
173
179
|
- `data`: Base64-encoded request payload
|
|
174
|
-
- `signature`:
|
|
175
|
-
-
|
|
180
|
+
- `signature`: signature generated from your private key
|
|
181
|
+
- the resolved checkout fields such as `action`, `version`, `publicKey`, and inherited `resultUrl` / `serverUrl`
|
|
176
182
|
|
|
177
183
|
### `payments.hold(payload)`
|
|
178
184
|
|
|
179
|
-
|
|
185
|
+
Builds the same signed result shape as `getCheckoutUrl(...)`, but with action `hold`.
|
|
180
186
|
|
|
181
187
|
```ts
|
|
182
188
|
const holdCheckout = liqpay.payments.hold({
|
|
@@ -189,7 +195,7 @@ const holdCheckout = liqpay.payments.hold({
|
|
|
189
195
|
|
|
190
196
|
### `payments.subscribe(payload)`
|
|
191
197
|
|
|
192
|
-
|
|
198
|
+
Builds the same signed result shape as `getCheckoutUrl(...)`, but with action `subscribe`.
|
|
193
199
|
|
|
194
200
|
```ts
|
|
195
201
|
const subscriptionCheckout = liqpay.payments.subscribe({
|
|
@@ -203,12 +209,12 @@ const subscriptionCheckout = liqpay.payments.subscribe({
|
|
|
203
209
|
})
|
|
204
210
|
```
|
|
205
211
|
|
|
206
|
-
### `payments.
|
|
212
|
+
### `payments.getCheckoutButton(payload, buttonText?, buttonColor?)`
|
|
207
213
|
|
|
208
|
-
Returns an HTML string containing a form and LiqPay `sdk-button` markup for the
|
|
214
|
+
Returns an HTML string containing a form and LiqPay `sdk-button` markup for the standard payment flow.
|
|
209
215
|
|
|
210
216
|
```ts
|
|
211
|
-
const html = liqpay.payments.
|
|
217
|
+
const html = liqpay.payments.getCheckoutButton(
|
|
212
218
|
{
|
|
213
219
|
amount: 100,
|
|
214
220
|
currency: 'UAH',
|
|
@@ -225,12 +231,15 @@ Defaults:
|
|
|
225
231
|
- `buttonText`: `Pay`
|
|
226
232
|
- `buttonColor`: `#77CC5D`
|
|
227
233
|
|
|
228
|
-
### `payments.
|
|
234
|
+
### `payments.getStatus(payload)`
|
|
229
235
|
|
|
230
236
|
Calls LiqPay's status API and returns `Promise<Result<PaymentStatusResponse>>`.
|
|
231
237
|
|
|
232
238
|
```ts
|
|
233
|
-
|
|
239
|
+
import type { PaymentStatusInput } from 'liqpay-nestjs'
|
|
240
|
+
|
|
241
|
+
const payload: PaymentStatusInput = { orderId: 'order-123' }
|
|
242
|
+
const result = await liqpay.payments.getStatus(payload)
|
|
234
243
|
|
|
235
244
|
if (result.error) {
|
|
236
245
|
console.error(result.error.code, result.error.description)
|
|
@@ -241,7 +250,7 @@ if (result.error) {
|
|
|
241
250
|
}
|
|
242
251
|
```
|
|
243
252
|
|
|
244
|
-
This is the only payments helper that performs an HTTP request.
|
|
253
|
+
This is the only payments helper that performs an HTTP request. The library fills `action: 'status'`, `version: 7`, and your configured `publicKey` automatically.
|
|
245
254
|
|
|
246
255
|
## Webhooks API
|
|
247
256
|
|
|
@@ -249,7 +258,8 @@ This is the only payments helper that performs an HTTP request.
|
|
|
249
258
|
|
|
250
259
|
```ts
|
|
251
260
|
import { Body, Controller, Post } from '@nestjs/common'
|
|
252
|
-
import {
|
|
261
|
+
import { LiqpayService } from 'liqpay-nestjs'
|
|
262
|
+
import type { LiqPayEnvelope } from 'liqpay-nestjs'
|
|
253
263
|
|
|
254
264
|
@Controller('payments')
|
|
255
265
|
export class WebhookController {
|
|
@@ -268,7 +278,7 @@ export class WebhookController {
|
|
|
268
278
|
}
|
|
269
279
|
```
|
|
270
280
|
|
|
271
|
-
|
|
281
|
+
`LiqPayEnvelope` is the callback wrapper sent by LiqPay:
|
|
272
282
|
|
|
273
283
|
```ts
|
|
274
284
|
type LiqPayEnvelope = {
|
|
@@ -279,20 +289,10 @@ type LiqPayEnvelope = {
|
|
|
279
289
|
|
|
280
290
|
## Checkout Types
|
|
281
291
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
| Type | Purpose |
|
|
285
|
-
| -------------------- | -------------------------------------------------------------------------------------------------- |
|
|
286
|
-
| `CheckoutInput` | The consumer-facing payload you pass into `pay`, `hold`, `subscribe`, or `getPayButton`. |
|
|
287
|
-
| `CheckoutRequest` | The enriched request after the library injects `action`, `version`, `publicKey`, and default URLs. |
|
|
288
|
-
| `RawCheckoutRequest` | The final wire-format payload sent to LiqPay after snake_case and value transformations. |
|
|
289
|
-
|
|
290
|
-
In most applications you should create `CheckoutInput` values and let the library build the rest.
|
|
291
|
-
|
|
292
|
-
### Minimal `CheckoutInput`
|
|
292
|
+
For library consumers, the main checkout type is `CheckoutInput`.
|
|
293
293
|
|
|
294
294
|
```ts
|
|
295
|
-
import { CheckoutInput } from 'liqpay-nestjs'
|
|
295
|
+
import type { CheckoutInput } from 'liqpay-nestjs'
|
|
296
296
|
|
|
297
297
|
const payload: CheckoutInput = {
|
|
298
298
|
amount: 100,
|
|
@@ -302,64 +302,43 @@ const payload: CheckoutInput = {
|
|
|
302
302
|
}
|
|
303
303
|
```
|
|
304
304
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
The public checkout input supports many LiqPay options, including:
|
|
305
|
+
Useful optional fields include:
|
|
308
306
|
|
|
309
307
|
- `resultUrl`, `serverUrl`
|
|
310
308
|
- `paytypes`, `language`, `expiredDate`
|
|
311
|
-
- `
|
|
309
|
+
- `verifyCode`
|
|
310
|
+
- `fiscalData`, `splitRules`, `detailAddenda`
|
|
311
|
+
- `customer`, `customerUserId`, `recurringByToken`
|
|
312
312
|
- `subscribe`, `subscribeDateStart`, `subscribePeriodicity`
|
|
313
|
-
- `fiscalData`, `detailAddenda`, `splitRules`
|
|
314
313
|
- sender metadata such as `senderFirstName`, `senderLastName`, `senderAddress`, and `senderCountryCode`
|
|
315
314
|
- product metadata such as `productName`, `productDescription`, `productCategory`, and `productUrl`
|
|
316
315
|
|
|
317
|
-
|
|
316
|
+
The source repository keeps the full request and response models under `src/core/types` if you need exact field-level reference.
|
|
318
317
|
|
|
319
|
-
|
|
318
|
+
## Type Exports
|
|
320
319
|
|
|
321
|
-
|
|
322
|
-
- Outgoing requests are serialized into LiqPay's expected field format.
|
|
323
|
-
- Checkout callbacks and payment status responses are transformed back into camelCase.
|
|
324
|
-
- Several values such as dates, booleans, and enum-backed fields are normalized during parsing.
|
|
325
|
-
- Some nested helper objects still use provider-specific field names defined by their exported schemas.
|
|
326
|
-
|
|
327
|
-
## Schemas and Types
|
|
328
|
-
|
|
329
|
-
All public schemas and types are exported from the package root.
|
|
320
|
+
The package root exports TypeScript types for request and response modeling, for example:
|
|
330
321
|
|
|
331
322
|
```ts
|
|
332
|
-
import {
|
|
323
|
+
import type {
|
|
333
324
|
CheckoutCallback,
|
|
334
|
-
CheckoutCallbackSchema,
|
|
335
325
|
CheckoutInput,
|
|
336
|
-
CheckoutInputSchema,
|
|
337
326
|
LiqPayEnvelope,
|
|
338
|
-
|
|
327
|
+
LiqPayError,
|
|
328
|
+
PaymentStatusInput,
|
|
339
329
|
PaymentStatusResponse,
|
|
340
|
-
PaymentStatusResponseSchema,
|
|
341
330
|
Result,
|
|
342
331
|
} from 'liqpay-nestjs'
|
|
343
332
|
```
|
|
344
333
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
- base: `LiqPayEnvelope`, `LiqPayEnvelopeSchema`, `Result<T>`, request and response unions
|
|
348
|
-
- checkout: `CheckoutInput`, `CheckoutInputSchema`, `CheckoutRequest`, `CheckoutCallback`, and raw request helpers
|
|
349
|
-
- payment status: `PaymentStatusRequest`, `PaymentStatusRequestSchema`, `PaymentStatusResponse`, `PaymentStatusResponseSchema`
|
|
350
|
-
- common: fiscal, split, and addenda schemas and their types
|
|
351
|
-
- enums: action, currency, language, paytype, version, payment status, and related schema exports
|
|
352
|
-
- error: LiqPay error response and error code schemas and types
|
|
353
|
-
- nest: `LiqPayModule`, `LiqpayService`, `LiqPayOptions`, `LiqPayAsyncOptions`, `LIQPAY_OPTIONS`
|
|
354
|
-
|
|
355
|
-
### Validate controller input with the exported schemas
|
|
334
|
+
It also exports these runtime values:
|
|
356
335
|
|
|
357
|
-
|
|
358
|
-
|
|
336
|
+
- `LiqPayModule`
|
|
337
|
+
- `LiqpayService`
|
|
338
|
+
- `LIQPAY_OPTIONS`
|
|
339
|
+
- `UnitEnum`
|
|
359
340
|
|
|
360
|
-
|
|
361
|
-
const checkout = liqpay.payments.pay(payload)
|
|
362
|
-
```
|
|
341
|
+
Note: the package root currently exports types, not Zod schema values. The schema implementations live in the source under `src/core/types`.
|
|
363
342
|
|
|
364
343
|
## Result Contract and Error Handling
|
|
365
344
|
|
|
@@ -373,29 +352,29 @@ type Result<T> =
|
|
|
373
352
|
|
|
374
353
|
This applies to:
|
|
375
354
|
|
|
376
|
-
- `liqpay.payments.
|
|
355
|
+
- `liqpay.payments.getStatus(...)`
|
|
377
356
|
- `liqpay.webhooks.parseCheckoutCallback(...)`
|
|
378
357
|
|
|
379
|
-
|
|
358
|
+
Errors can come from:
|
|
380
359
|
|
|
381
|
-
- LiqPay
|
|
360
|
+
- LiqPay API error responses
|
|
382
361
|
- invalid callback signatures
|
|
383
362
|
- Base64 decode failures
|
|
384
363
|
- invalid JSON responses
|
|
385
|
-
-
|
|
364
|
+
- response validation failures
|
|
386
365
|
- HTTP transport failures
|
|
387
366
|
|
|
388
367
|
Always check `result.error` before using `result.data`.
|
|
389
368
|
|
|
390
|
-
##
|
|
369
|
+
## Nest Exports
|
|
391
370
|
|
|
392
|
-
The package root
|
|
371
|
+
The package root exports:
|
|
393
372
|
|
|
373
|
+
- `LiqPayModule`
|
|
374
|
+
- `LiqpayService`
|
|
394
375
|
- `LIQPAY_OPTIONS`
|
|
395
|
-
- `
|
|
396
|
-
- `
|
|
397
|
-
|
|
398
|
-
These are useful if you want to build custom providers around the package token instead of using `LiqPayModule` directly.
|
|
376
|
+
- `LiqPayOptions`
|
|
377
|
+
- `LiqPayAsyncOptions`
|
|
399
378
|
|
|
400
379
|
## Build
|
|
401
380
|
|
|
@@ -15,6 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./liqpay.client"), exports);
|
|
18
|
-
__exportStar(require("./payments.client"), exports);
|
|
19
|
-
__exportStar(require("./utils.client"), exports);
|
|
20
|
-
__exportStar(require("./webhooks.client"), exports);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { PaymentsClient } from './payments.client';
|
|
2
|
+
import { RefundsClient } from './refunds.client';
|
|
2
3
|
import { WebhooksClient } from './webhooks.client';
|
|
3
4
|
export declare class LiqPayClient {
|
|
4
5
|
payments: PaymentsClient;
|
|
5
6
|
webhooks: WebhooksClient;
|
|
7
|
+
refunds: RefundsClient;
|
|
6
8
|
constructor(options: {
|
|
7
9
|
publicKey: string;
|
|
8
10
|
privateKey: string;
|
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiqPayClient = void 0;
|
|
4
4
|
const payments_client_1 = require("./payments.client");
|
|
5
|
+
const refunds_client_1 = require("./refunds.client");
|
|
5
6
|
const utils_client_1 = require("./utils.client");
|
|
6
7
|
const webhooks_client_1 = require("./webhooks.client");
|
|
7
8
|
class LiqPayClient {
|
|
8
9
|
payments;
|
|
9
10
|
webhooks;
|
|
11
|
+
refunds;
|
|
10
12
|
constructor(options) {
|
|
11
13
|
const { publicKey, privateKey, resultUrl, serverUrl } = options;
|
|
12
14
|
const utils = new utils_client_1.UtilsClient(publicKey, privateKey, resultUrl ?? '', serverUrl ?? '');
|
|
13
15
|
this.payments = new payments_client_1.PaymentsClient(utils);
|
|
14
16
|
this.webhooks = new webhooks_client_1.WebhooksClient(utils);
|
|
17
|
+
this.refunds = new refunds_client_1.RefundsClient(utils);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
exports.LiqPayClient = LiqPayClient;
|
|
@@ -82,7 +82,7 @@ class PaymentsClient {
|
|
|
82
82
|
version: 7,
|
|
83
83
|
publicKey: this.utils.publicKey,
|
|
84
84
|
};
|
|
85
|
-
return await this.utils.call(request, payment_status_1.RawPaymentStatusRequestSchema, payment_status_1.PaymentStatusResponseSchema
|
|
85
|
+
return await this.utils.call(request, payment_status_1.RawPaymentStatusRequestSchema, payment_status_1.PaymentStatusResponseSchema);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
exports.PaymentsClient = PaymentsClient;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefundsClient = void 0;
|
|
4
|
+
const refund_1 = require("../types/refund");
|
|
5
|
+
class RefundsClient {
|
|
6
|
+
utils;
|
|
7
|
+
constructor(utils) {
|
|
8
|
+
this.utils = utils;
|
|
9
|
+
}
|
|
10
|
+
refund(payload) {
|
|
11
|
+
const request = {
|
|
12
|
+
...payload,
|
|
13
|
+
version: 7,
|
|
14
|
+
publicKey: this.utils.publicKey,
|
|
15
|
+
action: 'refund',
|
|
16
|
+
};
|
|
17
|
+
this.utils.call(request, refund_1.RawRefundRequestSchema, refund_1.RefundResponseSchema);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RefundsClient = RefundsClient;
|
|
@@ -16,5 +16,5 @@ export declare class UtilsClient {
|
|
|
16
16
|
parseData<T>(schema: z.ZodType<T>, data: unknown): Result<T>;
|
|
17
17
|
parseError(data: unknown): Result<never> | null;
|
|
18
18
|
parseEnvelope<TResponse extends LiqPayResponse>(envelope: LiqPayEnvelope, schema: z.ZodType<TResponse>): Result<TResponse>;
|
|
19
|
-
call<TRequest extends LiqPayRequest, TRawRequest extends LiqPayRawRequest, TResponse extends LiqPayResponse>(payload: TRequest, rawSchema: z.ZodType<TRawRequest>, responseSchema: z.ZodType<TResponse>, url
|
|
19
|
+
call<TRequest extends LiqPayRequest, TRawRequest extends LiqPayRawRequest, TResponse extends LiqPayResponse>(payload: TRequest, rawSchema: z.ZodType<TRawRequest>, responseSchema: z.ZodType<TResponse>, url?: string): Promise<Result<TResponse>>;
|
|
20
20
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UtilsClient = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const common_1 = require("../types/common");
|
|
5
6
|
const error_1 = require("../types/error");
|
|
6
7
|
class UtilsClient {
|
|
7
8
|
publicKey;
|
|
@@ -70,7 +71,7 @@ class UtilsClient {
|
|
|
70
71
|
}
|
|
71
72
|
return this.parseData(schema, rawData);
|
|
72
73
|
}
|
|
73
|
-
async call(payload, rawSchema, responseSchema, url) {
|
|
74
|
+
async call(payload, rawSchema, responseSchema, url = common_1.REQUEST_URL) {
|
|
74
75
|
const raw = rawSchema.parse(payload);
|
|
75
76
|
const envelope = this.toEnvelope(raw);
|
|
76
77
|
const response = await fetch(url, {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CheckoutRequest, RawCheckoutRequest } from '../checkout';
|
|
2
2
|
import { PaymentStatusRequest, RawPaymentStatusRequest } from '../payment-status';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import { RawRefundRequest, RefundRequest } from '../refund';
|
|
4
|
+
export type LiqPayRequest = CheckoutRequest | PaymentStatusRequest | RefundRequest;
|
|
5
|
+
export type LiqPayRawRequest = RawCheckoutRequest | RawPaymentStatusRequest | RawRefundRequest;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CheckoutCallback, RawCheckoutCallback } from '../checkout';
|
|
2
2
|
import { LiqPayErrorResponse } from '../error';
|
|
3
3
|
import { PaymentStatusResponse, RawPaymentStatusResponse } from '../payment-status';
|
|
4
|
-
|
|
5
|
-
export type
|
|
4
|
+
import { RawRefundResponse, RefundResponse } from '../refund';
|
|
5
|
+
export type LiqPayResponse = CheckoutCallback | PaymentStatusResponse | RefundResponse;
|
|
6
|
+
export type LiqPayRawResponse = RawCheckoutCallback | RawPaymentStatusResponse | RawRefundResponse | LiqPayErrorResponse;
|
|
6
7
|
export type Result<T> = {
|
|
7
8
|
data: T;
|
|
8
9
|
error?: null;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./refund.request"), exports);
|
|
18
|
+
__exportStar(require("./refund.response"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefundsService = void 0;
|
|
4
|
+
class RefundsService {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async refund(payload) {
|
|
10
|
+
return this.client.refunds.refund(payload);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.RefundsService = RefundsService;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liqpay-nestjs",
|
|
3
3
|
"description": "LiqPay integration module for NestJS with support for payments, callbacks, and configuration via DI.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.7",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"nestjs-module"
|
|
16
16
|
],
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
19
20
|
],
|
|
20
21
|
"exports": {
|
|
21
22
|
".": {
|