@deenruv/przelewy24-plugin 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.
- package/LICENSE +23 -0
- package/README.md +52 -0
- package/dist/plugin-server/constants.d.ts +5 -0
- package/dist/plugin-server/constants.js +5 -0
- package/dist/plugin-server/controllers/przelewy24.controller.d.ts +9 -0
- package/dist/plugin-server/controllers/przelewy24.controller.js +148 -0
- package/dist/plugin-server/e2e/plugin.e2e.test.d.ts +1 -0
- package/dist/plugin-server/e2e/plugin.e2e.test.js +66 -0
- package/dist/plugin-server/email-events.d.ts +6 -0
- package/dist/plugin-server/email-events.js +8 -0
- package/dist/plugin-server/extensions/index.d.ts +1 -0
- package/dist/plugin-server/extensions/index.js +1 -0
- package/dist/plugin-server/extensions/przelewy24-shop.extension.d.ts +1 -0
- package/dist/plugin-server/extensions/przelewy24-shop.extension.js +27 -0
- package/dist/plugin-server/handlers/przelewy24-blik.handler.d.ts +2 -0
- package/dist/plugin-server/handlers/przelewy24-blik.handler.js +28 -0
- package/dist/plugin-server/handlers/przelewy24.handler.d.ts +2 -0
- package/dist/plugin-server/handlers/przelewy24.handler.js +22 -0
- package/dist/plugin-server/index.d.ts +7 -0
- package/dist/plugin-server/index.js +49 -0
- package/dist/plugin-server/resolvers/index.d.ts +1 -0
- package/dist/plugin-server/resolvers/index.js +1 -0
- package/dist/plugin-server/resolvers/przelewy24-shop.resolver.d.ts +15 -0
- package/dist/plugin-server/resolvers/przelewy24-shop.resolver.js +151 -0
- package/dist/plugin-server/services/przelewy24.service.d.ts +40 -0
- package/dist/plugin-server/services/przelewy24.service.js +241 -0
- package/dist/plugin-server/types.d.ts +36 -0
- package/dist/plugin-server/types.js +1 -0
- package/dist/plugin-server/ui/providers.d.ts +2 -0
- package/dist/plugin-server/ui/providers.js +1 -0
- package/dist/plugin-server/ui/zeus/const.d.ts +6 -0
- package/dist/plugin-server/ui/zeus/const.js +3775 -0
- package/dist/plugin-server/ui/zeus/index.d.ts +19239 -0
- package/dist/plugin-server/ui/zeus/index.js +443 -0
- package/dist/plugin-server/ui/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-server/ui/zeus/typedDocumentNode.js +9 -0
- package/dist/plugin-server/ui.d.ts +2 -0
- package/dist/plugin-server/ui.js +10 -0
- package/dist/plugin-server/utils.d.ts +6 -0
- package/dist/plugin-server/utils.js +28 -0
- package/dist/plugin-server/verify/index.d.ts +2 -0
- package/dist/plugin-server/verify/index.js +39 -0
- package/dist/plugin-server/zeus/const.d.ts +6 -0
- package/dist/plugin-server/zeus/const.js +3775 -0
- package/dist/plugin-server/zeus/index.d.ts +19239 -0
- package/dist/plugin-server/zeus/index.js +443 -0
- package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-server/zeus/typedDocumentNode.js +9 -0
- package/dist/plugin-ui/index.d.ts +1 -0
- package/dist/plugin-ui/index.js +5 -0
- package/dist/plugin-ui/tsconfig.json +18 -0
- package/dist/plugin-ui/zeus/const.d.ts +6 -0
- package/dist/plugin-ui/zeus/const.js +3775 -0
- package/dist/plugin-ui/zeus/index.d.ts +19239 -0
- package/dist/plugin-ui/zeus/index.js +459 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
- package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# License 1
|
|
2
|
+
|
|
3
|
+
The MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025-present Aexol
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
12
|
+
|
|
13
|
+
# License 2
|
|
14
|
+
|
|
15
|
+
The MIT License
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2018-2025 Michael Bromley
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @deenruv/przelewy24-plugin
|
|
2
|
+
|
|
3
|
+
A payment plugin that integrates the [Przelewy24](https://www.przelewy24.pl/) Polish payment gateway with your Deenruv server, supporting both standard card/bank payments and BLIK instant payments.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @deenruv/przelewy24-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Przelewy24Plugin } from '@deenruv/przelewy24-plugin';
|
|
15
|
+
|
|
16
|
+
// In your Deenruv server config:
|
|
17
|
+
plugins: [
|
|
18
|
+
Przelewy24Plugin.init({
|
|
19
|
+
apiUrl: 'https://secure.przelewy24.pl',
|
|
20
|
+
przelewy24Host: 'https://your-server.com',
|
|
21
|
+
returnUrl: async (ctx, { order }) => `https://your-store.com/order/${order.code}`,
|
|
22
|
+
PL: {
|
|
23
|
+
PRZELEWY24_POS_ID: process.env.P24_POS_ID,
|
|
24
|
+
PRZELEWY24_CRC: process.env.P24_CRC,
|
|
25
|
+
PRZELEWY24_CLIENT_SECRET: process.env.P24_CLIENT_SECRET,
|
|
26
|
+
},
|
|
27
|
+
// Optional: map currency codes to market channels
|
|
28
|
+
currencyCodeToChannel: (currencyCode) => 'PL',
|
|
29
|
+
}),
|
|
30
|
+
]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- Standard Przelewy24 payment method handler for card and bank transfers
|
|
36
|
+
- BLIK instant payment method handler with real-time status polling
|
|
37
|
+
- Multi-market support with per-channel credentials
|
|
38
|
+
- Webhook controller for processing Przelewy24 payment notifications
|
|
39
|
+
- Shop API extensions for initiating payments and checking BLIK status
|
|
40
|
+
- Email event integration for payment confirmations
|
|
41
|
+
|
|
42
|
+
## Admin UI
|
|
43
|
+
|
|
44
|
+
This plugin extends the admin UI with a Przelewy24 management interface for viewing payment transaction details and statuses.
|
|
45
|
+
|
|
46
|
+
## API Extensions
|
|
47
|
+
|
|
48
|
+
The plugin extends the **Shop API** with:
|
|
49
|
+
|
|
50
|
+
- Mutations and queries for creating Przelewy24 payment intents
|
|
51
|
+
- BLIK payment status polling
|
|
52
|
+
- Przelewy24 payment verification
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const loggerCtx = "Przelewy24 Payment Handler";
|
|
2
|
+
export declare const PRZELEWY24_PLUGIN_OPTIONS: unique symbol;
|
|
3
|
+
export declare const ALLOWED_MARKETS: readonly ["pl-channel"];
|
|
4
|
+
export declare const PRZELEWY24_METHOD_NAME = "przelewy24";
|
|
5
|
+
export declare const BLIK_METHOD_NAME = "blik";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const loggerCtx = "Przelewy24 Payment Handler";
|
|
2
|
+
export const PRZELEWY24_PLUGIN_OPTIONS = Symbol("PRZELEWY24_PLUGIN_OPTIONS");
|
|
3
|
+
export const ALLOWED_MARKETS = ["pl-channel"];
|
|
4
|
+
export const PRZELEWY24_METHOD_NAME = "przelewy24";
|
|
5
|
+
export const BLIK_METHOD_NAME = "blik";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RequestContext } from "@deenruv/core";
|
|
2
|
+
import { Przelewy24Service } from "../services/przelewy24.service.js";
|
|
3
|
+
import { Przelewy24NotificationBody } from "../types.js";
|
|
4
|
+
export declare class Przelewy24Controller {
|
|
5
|
+
private readonly przelewy24Service;
|
|
6
|
+
constructor(przelewy24Service: Przelewy24Service);
|
|
7
|
+
blikVerify(ctx: RequestContext, body: Przelewy24NotificationBody): Promise<void>;
|
|
8
|
+
settle(ctx: RequestContext, body: Przelewy24NotificationBody): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Ctx, RequestContext, Logger } from "@deenruv/core";
|
|
14
|
+
import { Body, Controller, HttpCode, Post, UnauthorizedException, } from "@nestjs/common";
|
|
15
|
+
import { Przelewy24Service } from "../services/przelewy24.service.js";
|
|
16
|
+
import { loggerCtx } from "../constants.js";
|
|
17
|
+
const BLIK_PAYMENT_METHOD = "PRZELEWY24-BLIK";
|
|
18
|
+
/** Payment states considered final - no further webhook processing needed */
|
|
19
|
+
const FINAL_PAYMENT_STATES = ["Settled", "Failed", "Cancelled", "Error"];
|
|
20
|
+
let Przelewy24Controller = class Przelewy24Controller {
|
|
21
|
+
constructor(przelewy24Service) {
|
|
22
|
+
this.przelewy24Service = przelewy24Service;
|
|
23
|
+
}
|
|
24
|
+
async blikVerify(ctx, body) {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
26
|
+
Logger.debug(`BLIK additional notification received: ${JSON.stringify(body)}`, loggerCtx);
|
|
27
|
+
// Verify webhook signature
|
|
28
|
+
if (!this.przelewy24Service.verifyWebhookSignature(body)) {
|
|
29
|
+
Logger.warn(`Invalid webhook signature for sessionId: ${body.sessionId}`, loggerCtx);
|
|
30
|
+
throw new UnauthorizedException("Invalid webhook signature");
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const payment = await this.przelewy24Service.findPaymentByTransactionId(ctx, body.sessionId);
|
|
34
|
+
// Idempotency: If payment is already in a final state, return early
|
|
35
|
+
if (FINAL_PAYMENT_STATES.includes(payment.state)) {
|
|
36
|
+
Logger.debug(`Payment ${payment.id} already in final state ${payment.state}, skipping`, loggerCtx);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const isBlikPayment = ((_b = (_a = payment.metadata) === null || _a === void 0 ? void 0 : _a.public) === null || _b === void 0 ? void 0 : _b.paymentMethod) === BLIK_PAYMENT_METHOD;
|
|
40
|
+
// Check if BLIK status is already final
|
|
41
|
+
const currentBlikStatus = (_d = (_c = payment.metadata) === null || _c === void 0 ? void 0 : _c.public) === null || _d === void 0 ? void 0 : _d.blikStatus;
|
|
42
|
+
if (isBlikPayment &&
|
|
43
|
+
currentBlikStatus &&
|
|
44
|
+
["success", "failed", "timeout"].includes(currentBlikStatus)) {
|
|
45
|
+
Logger.debug(`BLIK payment ${payment.id} already has final status ${currentBlikStatus}, skipping`, loggerCtx);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const status = await this.przelewy24Service.verifyPayment(body);
|
|
49
|
+
if (status === "success") {
|
|
50
|
+
// Update BLIK status before settling
|
|
51
|
+
if (isBlikPayment) {
|
|
52
|
+
await this.przelewy24Service.updateBlikStatus(ctx, payment.id, "success");
|
|
53
|
+
}
|
|
54
|
+
await this.przelewy24Service.settlePayment(ctx, payment.id);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
if (isBlikPayment) {
|
|
58
|
+
await this.przelewy24Service.updateBlikStatus(ctx, payment.id, "failed");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
64
|
+
Logger.error(`Error processing BLIK additional notification: ${errorMessage}`, loggerCtx);
|
|
65
|
+
// Try to mark BLIK payment as failed if we can extract payment info
|
|
66
|
+
try {
|
|
67
|
+
const payment = await this.przelewy24Service.findPaymentByTransactionId(ctx, body.sessionId);
|
|
68
|
+
const isBlikPayment = ((_f = (_e = payment.metadata) === null || _e === void 0 ? void 0 : _e.public) === null || _f === void 0 ? void 0 : _f.paymentMethod) === BLIK_PAYMENT_METHOD;
|
|
69
|
+
const currentBlikStatus = (_h = (_g = payment.metadata) === null || _g === void 0 ? void 0 : _g.public) === null || _h === void 0 ? void 0 : _h.blikStatus;
|
|
70
|
+
// Only update if not already in final status
|
|
71
|
+
if (isBlikPayment &&
|
|
72
|
+
(!currentBlikStatus ||
|
|
73
|
+
!["success", "failed", "timeout"].includes(currentBlikStatus))) {
|
|
74
|
+
await this.przelewy24Service.updateBlikStatus(ctx, payment.id, "failed");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (_j) {
|
|
78
|
+
// Ignore - we already logged the main error
|
|
79
|
+
}
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async settle(ctx, body) {
|
|
84
|
+
var _a, _b, _c, _d;
|
|
85
|
+
// Verify webhook signature
|
|
86
|
+
if (!this.przelewy24Service.verifyWebhookSignature(body)) {
|
|
87
|
+
Logger.warn(`Invalid webhook signature for sessionId: ${body.sessionId}`, loggerCtx);
|
|
88
|
+
throw new UnauthorizedException("Invalid webhook signature");
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const payment = await this.przelewy24Service.findPaymentByTransactionId(ctx, body.sessionId);
|
|
92
|
+
// Idempotency: If payment is already in a final state, return early
|
|
93
|
+
if (FINAL_PAYMENT_STATES.includes(payment.state)) {
|
|
94
|
+
Logger.debug(`Payment ${payment.id} already in final state ${payment.state}, skipping settle`, loggerCtx);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const isBlikPayment = ((_b = (_a = payment.metadata) === null || _a === void 0 ? void 0 : _a.public) === null || _b === void 0 ? void 0 : _b.paymentMethod) === BLIK_PAYMENT_METHOD;
|
|
98
|
+
// Check if BLIK status is already final (for BLIK payments)
|
|
99
|
+
const currentBlikStatus = (_d = (_c = payment.metadata) === null || _c === void 0 ? void 0 : _c.public) === null || _d === void 0 ? void 0 : _d.blikStatus;
|
|
100
|
+
if (isBlikPayment &&
|
|
101
|
+
currentBlikStatus &&
|
|
102
|
+
["success", "failed", "timeout"].includes(currentBlikStatus)) {
|
|
103
|
+
// For BLIK, if status is already success/failed/timeout, skip
|
|
104
|
+
// (the additional endpoint already handled this)
|
|
105
|
+
Logger.debug(`BLIK payment ${payment.id} already has final status ${currentBlikStatus}, checking if needs settle`, loggerCtx);
|
|
106
|
+
// If status is success but payment not settled, proceed to settle
|
|
107
|
+
if (currentBlikStatus !== "success") {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const status = await this.przelewy24Service.verifyPayment(body);
|
|
112
|
+
if (status === "success") {
|
|
113
|
+
// Update BLIK status before settling (defensive - in case additional wasn't called)
|
|
114
|
+
if (isBlikPayment && currentBlikStatus !== "success") {
|
|
115
|
+
await this.przelewy24Service.updateBlikStatus(ctx, payment.id, "success");
|
|
116
|
+
}
|
|
117
|
+
await this.przelewy24Service.settlePayment(ctx, payment.id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
Logger.error(`Can't find order id ${body.sessionId}`, loggerCtx);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
__decorate([
|
|
127
|
+
Post("additional"),
|
|
128
|
+
HttpCode(200),
|
|
129
|
+
__param(0, Ctx()),
|
|
130
|
+
__param(1, Body()),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", [RequestContext, Object]),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], Przelewy24Controller.prototype, "blikVerify", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
Post("settle"),
|
|
137
|
+
HttpCode(200),
|
|
138
|
+
__param(0, Ctx()),
|
|
139
|
+
__param(1, Body()),
|
|
140
|
+
__metadata("design:type", Function),
|
|
141
|
+
__metadata("design:paramtypes", [RequestContext, Object]),
|
|
142
|
+
__metadata("design:returntype", Promise)
|
|
143
|
+
], Przelewy24Controller.prototype, "settle", null);
|
|
144
|
+
Przelewy24Controller = __decorate([
|
|
145
|
+
Controller("przelewy24"),
|
|
146
|
+
__metadata("design:paramtypes", [Przelewy24Service])
|
|
147
|
+
], Przelewy24Controller);
|
|
148
|
+
export { Przelewy24Controller };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LanguageCode } from "@deenruv/core";
|
|
2
|
+
import { createTestEnvironment, PostgresInitializer, registerInitializer, testConfig, } from "@deenruv/testing";
|
|
3
|
+
import { after, before, describe } from "node:test";
|
|
4
|
+
import { Przelewy24Plugin } from "../index.js";
|
|
5
|
+
import { Przelewy24Service } from "../services/przelewy24.service.js";
|
|
6
|
+
registerInitializer("postgres", new PostgresInitializer());
|
|
7
|
+
//@ts-expect-error - this is a test and we can return undefined if the env vars are not set
|
|
8
|
+
const envConfig = (() => {
|
|
9
|
+
const { CARD_MARKET_APP_TOKEN: appToken, CARD_MARKET_APP_SECRET: appSecret, CARD_MARKET_ACCESS_TOKEN_SECRET: accessTokenSecret, CARD_MARKET_ACCESS_TOKEN: accessToken, } = process.env;
|
|
10
|
+
if (appToken && appSecret && accessToken && accessTokenSecret) {
|
|
11
|
+
return {
|
|
12
|
+
"pl-channel": {
|
|
13
|
+
PRZELEWY24_CLIENT_SECRET: "",
|
|
14
|
+
PRZELEWY24_CRC: "",
|
|
15
|
+
PRZELEWY24_POS_ID: "",
|
|
16
|
+
},
|
|
17
|
+
returnUrl: () => "http://localhost:4200",
|
|
18
|
+
apiUrl: "https://sincere-swift-oddly.ngrok-free.app",
|
|
19
|
+
przelewy24Host: "https://sandbox.przelewy24.pl",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
23
|
+
describe("test cardmarket plugin", { skip: !envConfig }, async () => {
|
|
24
|
+
const config = Object.assign(Object.assign({}, testConfig), { dbConnectionOptions: {
|
|
25
|
+
type: "postgres",
|
|
26
|
+
}, plugins: [Przelewy24Plugin.init(envConfig)] });
|
|
27
|
+
const { server } = createTestEnvironment(config);
|
|
28
|
+
let przelewy24Service;
|
|
29
|
+
before(async () => {
|
|
30
|
+
await server.init({
|
|
31
|
+
initialData: {
|
|
32
|
+
defaultLanguage: LanguageCode.en,
|
|
33
|
+
defaultZone: "Europe",
|
|
34
|
+
countries: [{ name: "Poland", code: "PL", zone: "Europe" }],
|
|
35
|
+
taxRates: [],
|
|
36
|
+
shippingMethods: [],
|
|
37
|
+
paymentMethods: [],
|
|
38
|
+
collections: [],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
przelewy24Service = server.app.get(Przelewy24Service);
|
|
42
|
+
});
|
|
43
|
+
after(async () => {
|
|
44
|
+
await server.destroy();
|
|
45
|
+
});
|
|
46
|
+
// await test("get product by id", async () => {
|
|
47
|
+
// await doesNotReject(cardMarketService.getProduct(261421));
|
|
48
|
+
// });
|
|
49
|
+
// await test("list products", async () => {
|
|
50
|
+
// await doesNotReject(cardMarketService.productList());
|
|
51
|
+
// });
|
|
52
|
+
// await test("check if stock exports", async () => {
|
|
53
|
+
// await doesNotReject(cardMarketService.requestStockExport());
|
|
54
|
+
// });
|
|
55
|
+
// await test("fetch stock exports", async () => {
|
|
56
|
+
// await doesNotReject(cardMarketService.fetchStockExports());
|
|
57
|
+
// });
|
|
58
|
+
// await test("decrease stock", async () => {
|
|
59
|
+
// await doesNotReject(cardMarketService.stockDecrease([{ articleId: 1718498926, quantity: 1 }]));
|
|
60
|
+
// });
|
|
61
|
+
// await test("decrease stock", async () => {
|
|
62
|
+
// await doesNotReject(
|
|
63
|
+
// cardMarketService.stockIncrease([{ articleId: 1718498926, quantity: 1 }])
|
|
64
|
+
// );
|
|
65
|
+
// });
|
|
66
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./przelewy24-shop.extension.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./przelewy24-shop.extension.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Przelewy24ShopExtension: import("graphql").DocumentNode;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
export const Przelewy24ShopExtension = gql `
|
|
3
|
+
enum BlikStatus {
|
|
4
|
+
pending
|
|
5
|
+
success
|
|
6
|
+
failed
|
|
7
|
+
timeout
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type BlikStatusResponse {
|
|
11
|
+
status: BlikStatus!
|
|
12
|
+
orderState: String
|
|
13
|
+
message: String
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
extend type Query {
|
|
17
|
+
przelewy24BlikStatus(code: String!, blik: String): BlikStatusResponse!
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
extend type Mutation {
|
|
21
|
+
"""
|
|
22
|
+
Mark a BLIK payment attempt as failed.
|
|
23
|
+
Use when user switches from BLIK to standard P24 payment.
|
|
24
|
+
"""
|
|
25
|
+
przelewy24BlikFail(code: String!, blik: String): BlikStatusResponse!
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LanguageCode, PaymentMethodHandler } from "@deenruv/core";
|
|
2
|
+
import { Przelewy24Service } from "../services/przelewy24.service.js";
|
|
3
|
+
let service;
|
|
4
|
+
export const przelewy24BlikPaymentMethodHandler = new PaymentMethodHandler({
|
|
5
|
+
code: "przelewy24BlikPaymentMethodHandler",
|
|
6
|
+
description: [
|
|
7
|
+
{
|
|
8
|
+
languageCode: LanguageCode.en,
|
|
9
|
+
value: "BLIK Payment handler (by Przelewy24)",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
languageCode: LanguageCode.pl,
|
|
13
|
+
value: "Obsługa płatności BLIK (przez Przelewy24)",
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
args: {},
|
|
17
|
+
init: (injector) => {
|
|
18
|
+
service = injector.get(Przelewy24Service);
|
|
19
|
+
},
|
|
20
|
+
async createPayment(ctx, order, amount, args, metadata, method) {
|
|
21
|
+
return service.createPayment(ctx, order, amount, args, metadata, method);
|
|
22
|
+
},
|
|
23
|
+
async settlePayment() {
|
|
24
|
+
return {
|
|
25
|
+
success: true,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LanguageCode, PaymentMethodHandler } from "@deenruv/core";
|
|
2
|
+
import { Przelewy24Service } from "../services/przelewy24.service.js";
|
|
3
|
+
let service;
|
|
4
|
+
export const przelewy24PaymentMethodHandler = new PaymentMethodHandler({
|
|
5
|
+
code: "przelewy24PaymentMethodHandler",
|
|
6
|
+
description: [
|
|
7
|
+
{ languageCode: LanguageCode.en, value: "Przelewy24 Payment handler" },
|
|
8
|
+
{ languageCode: LanguageCode.pl, value: "Obsługa płatności Przelewy24" },
|
|
9
|
+
],
|
|
10
|
+
args: {},
|
|
11
|
+
init: (injector) => {
|
|
12
|
+
service = injector.get(Przelewy24Service);
|
|
13
|
+
},
|
|
14
|
+
async createPayment(ctx, order, amount, args, metadata, method) {
|
|
15
|
+
return service.createPayment(ctx, order, amount, args, metadata, method);
|
|
16
|
+
},
|
|
17
|
+
async settlePayment() {
|
|
18
|
+
return {
|
|
19
|
+
success: true,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Przelewy24PluginConfiguration } from "./types.js";
|
|
2
|
+
import { Przelewy24RegularPaymentEvent } from "./email-events.js";
|
|
3
|
+
declare class Przelewy24Plugin {
|
|
4
|
+
static options: Przelewy24PluginConfiguration;
|
|
5
|
+
static init(options: Przelewy24PluginConfiguration): typeof Przelewy24Plugin;
|
|
6
|
+
}
|
|
7
|
+
export { Przelewy24Plugin, Przelewy24RegularPaymentEvent };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { PluginCommonModule, DeenruvPlugin } from "@deenruv/core";
|
|
8
|
+
import { Przelewy24Controller } from "./controllers/przelewy24.controller.js";
|
|
9
|
+
import { PRZELEWY24_PLUGIN_OPTIONS } from "./constants.js";
|
|
10
|
+
import { Przelewy24Service } from "./services/przelewy24.service.js";
|
|
11
|
+
import { przelewy24BlikPaymentMethodHandler } from "./handlers/przelewy24-blik.handler.js";
|
|
12
|
+
import { przelewy24PaymentMethodHandler } from "./handlers/przelewy24.handler.js";
|
|
13
|
+
import { Przelewy24RegularPaymentEvent } from "./email-events.js";
|
|
14
|
+
import { Przelewy24ShopExtension } from "./extensions/index.js";
|
|
15
|
+
import { Przelewy24ShopResolver } from "./resolvers/index.js";
|
|
16
|
+
let Przelewy24Plugin = class Przelewy24Plugin {
|
|
17
|
+
static init(options) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
Przelewy24Plugin = __decorate([
|
|
23
|
+
DeenruvPlugin({
|
|
24
|
+
compatibility: "0.0.1",
|
|
25
|
+
imports: [PluginCommonModule],
|
|
26
|
+
controllers: [Przelewy24Controller],
|
|
27
|
+
shopApiExtensions: {
|
|
28
|
+
schema: Przelewy24ShopExtension,
|
|
29
|
+
resolvers: [Przelewy24ShopResolver],
|
|
30
|
+
},
|
|
31
|
+
providers: [
|
|
32
|
+
Przelewy24Service,
|
|
33
|
+
{
|
|
34
|
+
provide: PRZELEWY24_PLUGIN_OPTIONS,
|
|
35
|
+
useFactory: () => Przelewy24Plugin.options,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
configuration: (config) => {
|
|
39
|
+
[
|
|
40
|
+
przelewy24BlikPaymentMethodHandler,
|
|
41
|
+
przelewy24PaymentMethodHandler,
|
|
42
|
+
].forEach((handler) => {
|
|
43
|
+
config.paymentOptions.paymentMethodHandlers.push(handler);
|
|
44
|
+
});
|
|
45
|
+
return config;
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
], Przelewy24Plugin);
|
|
49
|
+
export { Przelewy24Plugin, Przelewy24RegularPaymentEvent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./przelewy24-shop.resolver.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./przelewy24-shop.resolver.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RequestContext } from "@deenruv/core";
|
|
2
|
+
import { Przelewy24Service } from "../services/przelewy24.service.js";
|
|
3
|
+
import { BlikStatusResponse } from "../types.js";
|
|
4
|
+
export declare class Przelewy24ShopResolver {
|
|
5
|
+
private readonly przelewy24Service;
|
|
6
|
+
constructor(przelewy24Service: Przelewy24Service);
|
|
7
|
+
przelewy24BlikStatus(ctx: RequestContext, args: {
|
|
8
|
+
code: string;
|
|
9
|
+
blik?: string;
|
|
10
|
+
}): Promise<BlikStatusResponse>;
|
|
11
|
+
przelewy24BlikFail(ctx: RequestContext, args: {
|
|
12
|
+
code: string;
|
|
13
|
+
blik?: string;
|
|
14
|
+
}): Promise<BlikStatusResponse>;
|
|
15
|
+
}
|