@smartsoft001/revolut 2.75.0 → 2.80.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/index.js ADDED
@@ -0,0 +1,113 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
13
+
14
+ // packages/shared/revolut/src/lib/revolut.config.ts
15
+ var RevolutConfig = class {
16
+ };
17
+ var REVOLUT_CONFIG_PROVIDER = "REVOLUT_CONFIG_PROVIDER";
18
+ var IRevolutConfigProvider = class {
19
+ };
20
+
21
+ // packages/shared/revolut/src/lib/revolut.service.ts
22
+ import { Injectable, Logger, Optional } from "@nestjs/common";
23
+ var RevolutService = class {
24
+ constructor(httpService, moduleRef, config) {
25
+ this.httpService = httpService;
26
+ this.moduleRef = moduleRef;
27
+ this.config = config;
28
+ }
29
+ async create(obj) {
30
+ const config = await this.getConfig(obj.data);
31
+ const data = {
32
+ amount: obj.amount,
33
+ description: obj.name,
34
+ capture_mode: "AUTOMATIC",
35
+ merchant_order_ext_ref: obj.id,
36
+ customer_email: obj.email,
37
+ currency: "PLN"
38
+ };
39
+ const response = await this.httpService.post(this.getBaseUrl(config) + "/api/1.0/orders", data, {
40
+ headers: {
41
+ "Content-Type": "application/json",
42
+ Authorization: "Bearer " + config.token
43
+ },
44
+ maxRedirects: 0
45
+ }).toPromise();
46
+ return {
47
+ responseData: response.data,
48
+ orderId: response.data["public_id"]
49
+ };
50
+ }
51
+ async getStatus(trans) {
52
+ const config = await this.getConfig(trans.data);
53
+ const historyItem = trans.history.find((h) => h.status === "started");
54
+ const response = await this.httpService.get(
55
+ this.getBaseUrl(config) + "/api/1.0/orders/" + historyItem.data.responseData.id,
56
+ {
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ Authorization: "Bearer " + config.token
60
+ },
61
+ maxRedirects: 0
62
+ }
63
+ ).toPromise();
64
+ return {
65
+ data: response.data,
66
+ status: this.getStatusFromExternal(response.data["state"])
67
+ };
68
+ }
69
+ refund(trans, comment) {
70
+ return Promise.reject("Revolut does not support refund");
71
+ }
72
+ getBaseUrl(config) {
73
+ if (config.test)
74
+ return "https://sandbox-merchant.revolut.com";
75
+ return "https://merchant.revolut.com/api";
76
+ }
77
+ async getConfig(data) {
78
+ try {
79
+ const provider = this.moduleRef.get(
80
+ REVOLUT_CONFIG_PROVIDER,
81
+ { strict: false }
82
+ );
83
+ return await provider.get(data);
84
+ } catch (e) {
85
+ Logger.warn("Revolut config provider not found", RevolutService.name);
86
+ }
87
+ return this.config;
88
+ }
89
+ getStatusFromExternal(status) {
90
+ switch (status) {
91
+ case "PROCESSING":
92
+ return "completed";
93
+ case "CANCELLED":
94
+ return "canceled";
95
+ case "FAILED":
96
+ return "canceled";
97
+ case "PENDING":
98
+ return "pending";
99
+ default:
100
+ return status;
101
+ }
102
+ }
103
+ };
104
+ RevolutService = __decorateClass([
105
+ Injectable(),
106
+ __decorateParam(2, Optional())
107
+ ], RevolutService);
108
+ export {
109
+ IRevolutConfigProvider,
110
+ REVOLUT_CONFIG_PROVIDER,
111
+ RevolutConfig,
112
+ RevolutService
113
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartsoft001/revolut",
3
- "version": "2.75.0",
3
+ "version": "2.80.0",
4
4
  "description": "Utils for revolut",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,8 @@
1
+ export declare class RevolutConfig {
2
+ test?: boolean;
3
+ token: string;
4
+ }
5
+ export declare const REVOLUT_CONFIG_PROVIDER = "REVOLUT_CONFIG_PROVIDER";
6
+ export declare abstract class IRevolutConfigProvider {
7
+ abstract get(data: any): Promise<RevolutConfig>;
8
+ }
@@ -0,0 +1,32 @@
1
+ import { HttpService } from '@nestjs/axios';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { ITransPaymentSingleService, Trans, TransStatus } from '@smartsoft001/trans-domain';
4
+ import { RevolutConfig } from './revolut.config';
5
+ export declare class RevolutService implements ITransPaymentSingleService {
6
+ private readonly httpService;
7
+ private readonly moduleRef;
8
+ private readonly config;
9
+ constructor(httpService: HttpService, moduleRef: ModuleRef, config: RevolutConfig);
10
+ create(obj: {
11
+ id: string;
12
+ name: string;
13
+ amount: number;
14
+ firstName?: string;
15
+ lastName?: string;
16
+ email?: string;
17
+ contactPhone?: string;
18
+ clientIp: string;
19
+ data: any;
20
+ }): Promise<{
21
+ orderId: string;
22
+ responseData: any;
23
+ }>;
24
+ getStatus<T>(trans: Trans<T>): Promise<{
25
+ status: TransStatus;
26
+ data: any;
27
+ }>;
28
+ refund(trans: Trans<any>, comment: string): Promise<any>;
29
+ private getBaseUrl;
30
+ private getConfig;
31
+ private getStatusFromExternal;
32
+ }
package/.eslintrc DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../../.eslintrc.json",
3
- "ignorePatterns": ["!**/*"],
4
- "rules": {
5
-
6
- },
7
- "overrides": [
8
- {
9
- "files": ["*.json"],
10
- "parser": "jsonc-eslint-parser"
11
- }
12
- ]
13
- }
package/jest.config.ts DELETED
@@ -1,27 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'shared-revolut',
4
- globals: {},
5
- testEnvironment: 'node',
6
- transform: {
7
- '^.+\\.[tj]sx?$': [
8
- 'ts-jest',
9
- {
10
- tsConfig: '<rootDir>/tsconfig.spec.json',
11
- },
12
- ],
13
- },
14
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
15
- coverageDirectory: '../../../coverage/libs/shared/revolut',
16
- preset: '../../../jest.preset.js',
17
- /* TODO: Update to latest Jest snapshotFormat
18
- * By default Nx has kept the older style of Jest Snapshot formats
19
- * to prevent breaking of any existing tests with snapshots.
20
- * It's recommend you update to the latest format.
21
- * You can do this by removing snapshotFormat property
22
- * and running tests with --update-snapshot flag.
23
- * Example: From within the project directory, run "nx test --update-snapshot"
24
- * More info: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
25
- */
26
- snapshotFormat: { escapeString: true, printBasicPrototype: true },
27
- };
package/project.json DELETED
@@ -1,45 +0,0 @@
1
- {
2
- "name": "shared-revolut",
3
- "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "packages/shared/revolut/src",
5
- "projectType": "library",
6
- "tags": ["scope:shared", "type:util"],
7
- "generators": {},
8
- "targets": {
9
- "lint": {
10
- "executor": "@nx/eslint:lint",
11
- "options": {
12
- "lintFilePatterns": [
13
- "packages/shared/revolut/**/*.{ts,tsx,js,jsx}",
14
- "packages/shared/revolut/package.json"
15
- ]
16
- }
17
- },
18
- "test": {
19
- "executor": "@nx/jest:jest",
20
- "options": {
21
- "jestConfig": "packages/shared/revolut/jest.config.ts"
22
- },
23
- "outputs": ["{workspaceRoot}/coverage/packages/shared/revolut"]
24
- },
25
- "build": {
26
- "executor": "@nx/esbuild:esbuild",
27
- "outputs": ["{options.outputPath}"],
28
- "options": {
29
- "outputPath": "dist/packages/shared/revolut",
30
- "tsConfig": "packages/shared/revolut/tsconfig.lib.json",
31
- "packageJson": "packages/shared/revolut/package.json",
32
- "main": "packages/shared/revolut/src/index.ts",
33
- "assets": ["packages/shared/revolut/*.md"]
34
- }
35
- },
36
- "deploy": {
37
- "executor": "ngx-deploy-npm:deploy",
38
- "options": {
39
- "access": "public",
40
- "distFolderPath": "dist/packages/shared/revolut"
41
- },
42
- "dependsOn": ["build"]
43
- }
44
- }
45
- }
@@ -1,10 +0,0 @@
1
- export class RevolutConfig {
2
- test?: boolean;
3
- token: string;
4
- }
5
-
6
- export const REVOLUT_CONFIG_PROVIDER = 'REVOLUT_CONFIG_PROVIDER';
7
-
8
- export abstract class IRevolutConfigProvider {
9
- abstract get(data: any): Promise<RevolutConfig>;
10
- }
@@ -1,179 +0,0 @@
1
- import { HttpService } from '@nestjs/axios';
2
- import { ModuleRef } from '@nestjs/core';
3
- import { Test, TestingModule } from '@nestjs/testing';
4
- import { of } from 'rxjs';
5
-
6
- import { Trans } from '@smartsoft001/trans-domain';
7
-
8
- import { RevolutConfig } from './revolut.config';
9
- import { RevolutService } from './revolut.service';
10
-
11
- const mockHttpService = {
12
- post: jest.fn(),
13
- get: jest.fn(),
14
- };
15
-
16
- const mockModuleRef = {
17
- get: jest.fn(),
18
- };
19
-
20
- const mockRevolutConfig = {
21
- token: 'mock-token',
22
- test: true,
23
- };
24
-
25
- describe('revolut: RevolutService', () => {
26
- let service: RevolutService;
27
-
28
- beforeEach(async () => {
29
- const module: TestingModule = await Test.createTestingModule({
30
- providers: [
31
- RevolutService,
32
- { provide: RevolutConfig, useValue: mockRevolutConfig },
33
- { provide: HttpService, useValue: mockHttpService },
34
- { provide: ModuleRef, useValue: mockModuleRef },
35
- ],
36
- }).compile();
37
-
38
- service = module.get<RevolutService>(RevolutService);
39
- });
40
-
41
- afterEach(() => {
42
- jest.clearAllMocks();
43
- });
44
-
45
- describe('create', () => {
46
- it('should create a payment and return orderId and responseData', async () => {
47
- const mockResponse = {
48
- data: {
49
- public_id: 'test-order-id',
50
- id: 'test-internal-id',
51
- state: 'PENDING',
52
- },
53
- };
54
-
55
- mockHttpService.post.mockReturnValue(of(mockResponse));
56
-
57
- const result = await service.create({
58
- id: 'test-id',
59
- name: 'test-name',
60
- amount: 1000,
61
- email: 'test@example.com',
62
- clientIp: '127.0.0.1',
63
- data: {},
64
- });
65
-
66
- expect(result).toEqual({
67
- orderId: 'test-order-id',
68
- responseData: mockResponse.data,
69
- });
70
- });
71
-
72
- it('should use sandbox URL when test mode is enabled', async () => {
73
- const mockResponse = {
74
- data: {
75
- public_id: 'test-order-id',
76
- id: 'test-internal-id',
77
- state: 'PENDING',
78
- },
79
- };
80
-
81
- mockHttpService.post.mockReturnValue(of(mockResponse));
82
-
83
- await service.create({
84
- id: 'test-id',
85
- name: 'test-name',
86
- amount: 1000,
87
- email: 'test@example.com',
88
- clientIp: '127.0.0.1',
89
- data: {},
90
- });
91
-
92
- expect(mockHttpService.post).toHaveBeenCalledWith(
93
- 'https://sandbox-merchant.revolut.com/api/1.0/orders',
94
- expect.any(Object),
95
- expect.objectContaining({
96
- headers: expect.objectContaining({
97
- Authorization: 'Bearer mock-token',
98
- }),
99
- }),
100
- );
101
- });
102
- });
103
-
104
- describe('getStatus', () => {
105
- it('should return the status and data of a payment', async () => {
106
- const mockResponse = {
107
- data: {
108
- id: 'test-internal-id',
109
- state: 'PROCESSING',
110
- },
111
- };
112
-
113
- mockHttpService.get.mockReturnValue(of(mockResponse));
114
-
115
- const result = await service.getStatus({
116
- data: {},
117
- history: [
118
- {
119
- status: 'started',
120
- data: { responseData: { id: 'test-internal-id' } },
121
- },
122
- ],
123
- } as Trans<any>);
124
-
125
- expect(result).toEqual({
126
- status: 'completed',
127
- data: mockResponse.data,
128
- });
129
- });
130
-
131
- it('should map different states to correct statuses', async () => {
132
- const testCases = [
133
- { state: 'PROCESSING', expectedStatus: 'completed' },
134
- { state: 'CANCELLED', expectedStatus: 'canceled' },
135
- { state: 'FAILED', expectedStatus: 'canceled' },
136
- { state: 'PENDING', expectedStatus: 'pending' },
137
- { state: 'UNKNOWN', expectedStatus: 'UNKNOWN' },
138
- ];
139
-
140
- for (const testCase of testCases) {
141
- const mockResponse = {
142
- data: {
143
- id: 'test-internal-id',
144
- state: testCase.state,
145
- },
146
- };
147
-
148
- mockHttpService.get.mockReturnValue(of(mockResponse));
149
-
150
- const result = await service.getStatus({
151
- data: {},
152
- history: [
153
- {
154
- status: 'started',
155
- data: { responseData: { id: 'test-internal-id' } },
156
- },
157
- ],
158
- } as Trans<any>);
159
-
160
- expect(result.status).toBe(testCase.expectedStatus);
161
- }
162
- });
163
- });
164
-
165
- describe('refund', () => {
166
- it('should reject with "Revolut not support" message', async () => {
167
- await expect(
168
- service.refund(
169
- {
170
- amount: 1000,
171
- data: {},
172
- history: [],
173
- } as Trans<any>,
174
- 'test comment',
175
- ),
176
- ).rejects.toEqual('Revolut does not support refund');
177
- });
178
- });
179
- });
@@ -1,129 +0,0 @@
1
- import { HttpService } from '@nestjs/axios';
2
- import { Injectable, Logger, Optional } from '@nestjs/common';
3
- import { ModuleRef } from '@nestjs/core';
4
-
5
- import {
6
- ITransPaymentSingleService,
7
- Trans,
8
- TransStatus,
9
- } from '@smartsoft001/trans-domain';
10
-
11
- import {
12
- IRevolutConfigProvider,
13
- REVOLUT_CONFIG_PROVIDER,
14
- RevolutConfig,
15
- } from './revolut.config';
16
-
17
- @Injectable()
18
- export class RevolutService implements ITransPaymentSingleService {
19
- constructor(
20
- private readonly httpService: HttpService,
21
- private readonly moduleRef: ModuleRef,
22
- @Optional() private readonly config: RevolutConfig,
23
- ) {}
24
-
25
- async create(obj: {
26
- id: string;
27
- name: string;
28
- amount: number;
29
- firstName?: string;
30
- lastName?: string;
31
- email?: string;
32
- contactPhone?: string;
33
- clientIp: string;
34
- data: any;
35
- }): Promise<{ orderId: string; responseData: any }> {
36
- const config = await this.getConfig(obj.data);
37
-
38
- const data = {
39
- amount: obj.amount,
40
- description: obj.name,
41
- capture_mode: 'AUTOMATIC',
42
- merchant_order_ext_ref: obj.id,
43
- customer_email: obj.email,
44
- currency: 'PLN',
45
- };
46
-
47
- const response = await this.httpService
48
- .post(this.getBaseUrl(config) + '/api/1.0/orders', data, {
49
- headers: {
50
- 'Content-Type': 'application/json',
51
- Authorization: 'Bearer ' + config.token,
52
- },
53
- maxRedirects: 0,
54
- })
55
- .toPromise();
56
-
57
- return {
58
- responseData: response.data,
59
- orderId: response.data['public_id'],
60
- };
61
- }
62
-
63
- async getStatus<T>(
64
- trans: Trans<T>,
65
- ): Promise<{ status: TransStatus; data: any }> {
66
- const config = await this.getConfig(trans.data);
67
-
68
- const historyItem = trans.history.find((h) => h.status === 'started');
69
-
70
- const response = await this.httpService
71
- .get(
72
- this.getBaseUrl(config) +
73
- '/api/1.0/orders/' +
74
- (historyItem.data as any).responseData.id,
75
- {
76
- headers: {
77
- 'Content-Type': 'application/json',
78
- Authorization: 'Bearer ' + config.token,
79
- },
80
- maxRedirects: 0,
81
- },
82
- )
83
- .toPromise();
84
-
85
- return {
86
- data: response.data,
87
- status: this.getStatusFromExternal(response.data['state']),
88
- };
89
- }
90
-
91
- refund(trans: Trans<any>, comment: string): Promise<any> {
92
- return Promise.reject('Revolut does not support refund');
93
- }
94
-
95
- private getBaseUrl(config: RevolutConfig): string {
96
- if (config.test) return 'https://sandbox-merchant.revolut.com';
97
-
98
- return 'https://merchant.revolut.com/api';
99
- }
100
-
101
- private async getConfig(data: any): Promise<RevolutConfig> {
102
- try {
103
- const provider: IRevolutConfigProvider = this.moduleRef.get(
104
- REVOLUT_CONFIG_PROVIDER,
105
- { strict: false },
106
- );
107
- return await provider.get(data);
108
- } catch (e) {
109
- Logger.warn('Revolut config provider not found', RevolutService.name);
110
- }
111
-
112
- return this.config;
113
- }
114
-
115
- private getStatusFromExternal(status: string): any {
116
- switch (status) {
117
- case 'PROCESSING':
118
- return 'completed';
119
- case 'CANCELLED':
120
- return 'canceled';
121
- case 'FAILED':
122
- return 'canceled';
123
- case 'PENDING':
124
- return 'pending';
125
- default:
126
- return status;
127
- }
128
- }
129
- }
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "./tsconfig.lib.json"
8
- },
9
- {
10
- "path": "./tsconfig.spec.json"
11
- }
12
- ]
13
- }
package/tsconfig.lib.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "outDir": "../../../dist/out-tsc",
6
- "declaration": true,
7
- "types": ["node"]
8
- },
9
- "exclude": ["**/*.spec.ts", "**/*.test.ts", "jest.config.ts"],
10
- "include": ["**/*.ts"]
11
- }
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "**/*.spec.ts",
10
- "**/*.test.ts",
11
- "**/*.spec.tsx",
12
- "**/*.test.tsx",
13
- "**/*.spec.js",
14
- "**/*.test.js",
15
- "**/*.spec.jsx",
16
- "**/*.test.jsx",
17
- "**/*.d.ts",
18
- "jest.config.ts"
19
- ]
20
- }
File without changes
File without changes