@ngn-net/payment-provider-sdk 1.0.1 → 1.0.3
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 +1 -1
- package/package.json +6 -5
- package/src/dto/common.interface.ts +31 -10
- package/src/entity/crypto.entity.ts +51 -0
- package/src/payment.provider.ts +29 -8
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngn-net/payment-provider-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
-
"start": "nest start",
|
|
8
|
-
"start:dev": "nest start --watch",
|
|
9
7
|
"build": "tsc"
|
|
10
8
|
},
|
|
11
9
|
"keywords": [],
|
|
@@ -13,11 +11,14 @@
|
|
|
13
11
|
"license": "ISC",
|
|
14
12
|
"description": "",
|
|
15
13
|
"dependencies": {
|
|
14
|
+
"class-transformer": "^0.5.1",
|
|
15
|
+
"class-validator": "^0.15.1"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
16
18
|
"@golevelup/nestjs-rabbitmq": "^9.0.2",
|
|
17
19
|
"@nestjs/common": "^11.1.26",
|
|
18
20
|
"@nestjs/swagger": "^11.4.4",
|
|
19
|
-
"
|
|
20
|
-
"class-validator": "^0.15.1"
|
|
21
|
+
"@ngn-net/giftcard-shared": "*"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/node": "^25.9.2",
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FiatCurrency,
|
|
3
|
+
PayCurrency,
|
|
4
|
+
PaymentIntentStatus,
|
|
5
|
+
} from '../entity/crypto.entity';
|
|
6
|
+
|
|
1
7
|
export const RABBIT_URI = (): string[] => {
|
|
2
8
|
const rabbitUri =
|
|
3
|
-
process.env.RABBIT_URI ||
|
|
9
|
+
process.env.RABBIT_URI || 'amqp://sabi:password@localhost:5672';
|
|
4
10
|
|
|
5
|
-
const [creadential, hosts] = rabbitUri.split(
|
|
6
|
-
const hostList = hosts.split(
|
|
11
|
+
const [creadential, hosts] = rabbitUri.split('@');
|
|
12
|
+
const hostList = hosts.split(',');
|
|
7
13
|
|
|
8
14
|
return hostList.map((host) => {
|
|
9
15
|
return `${creadential}@${host}`;
|
|
@@ -14,7 +20,7 @@ export const rabbitUri = RABBIT_URI();
|
|
|
14
20
|
|
|
15
21
|
export interface RabbitAddress {
|
|
16
22
|
exchange: string;
|
|
17
|
-
type:
|
|
23
|
+
type: 'topic' | 'direct' | 'fanout';
|
|
18
24
|
routingkeys: {
|
|
19
25
|
[key: string]: {
|
|
20
26
|
key: string;
|
|
@@ -26,20 +32,23 @@ export interface RabbitAddress {
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
export const PaymentRabbitApi = {
|
|
29
|
-
exchange:
|
|
30
|
-
type:
|
|
35
|
+
exchange: 'payment',
|
|
36
|
+
type: 'topic',
|
|
31
37
|
routingkeys: {
|
|
32
38
|
default: {
|
|
33
|
-
key:
|
|
39
|
+
key: 'default',
|
|
34
40
|
},
|
|
35
41
|
events: {
|
|
36
|
-
key:
|
|
42
|
+
key: 'paymentEvents',
|
|
37
43
|
},
|
|
38
44
|
stripe_checkout: {
|
|
39
|
-
key:
|
|
45
|
+
key: 'stripeCheckout',
|
|
40
46
|
},
|
|
41
47
|
stripe_intent: {
|
|
42
|
-
key:
|
|
48
|
+
key: 'stripePaymentIntent',
|
|
49
|
+
},
|
|
50
|
+
crypto_intent: {
|
|
51
|
+
key: 'cryptoPaymentIntent',
|
|
43
52
|
},
|
|
44
53
|
},
|
|
45
54
|
};
|
|
@@ -59,3 +68,15 @@ export interface CreateStripePaymentIntentResponse {
|
|
|
59
68
|
clientSecret: string;
|
|
60
69
|
orderId: string;
|
|
61
70
|
}
|
|
71
|
+
|
|
72
|
+
export interface CreateCryptoIntentResponse {
|
|
73
|
+
id: string;
|
|
74
|
+
paymentId: string;
|
|
75
|
+
amountInFiat: number;
|
|
76
|
+
fiatCurrency: FiatCurrency;
|
|
77
|
+
payCurrency: PayCurrency;
|
|
78
|
+
payAddress: string;
|
|
79
|
+
payAmount: number;
|
|
80
|
+
status: PaymentIntentStatus;
|
|
81
|
+
orderId: string;
|
|
82
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export enum FiatCurrency {
|
|
2
|
+
usd = 'USD',
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export enum PayCurrency {
|
|
6
|
+
btc = 'BTC',
|
|
7
|
+
eth = 'ETH',
|
|
8
|
+
trx = 'TRX',
|
|
9
|
+
usdc = 'USDC',
|
|
10
|
+
usdt = 'USDT',
|
|
11
|
+
usdttrc20 = 'USDTTRC20',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum PaymentIntentStatus {
|
|
15
|
+
CREATED = 'CREATED',
|
|
16
|
+
WAITING = 'WAITING',
|
|
17
|
+
CONFIRMING = 'CONFIRMING',
|
|
18
|
+
CONFIRMED = 'CONFIRMED',
|
|
19
|
+
FAILED = 'FAILED',
|
|
20
|
+
EXPIRED = 'EXPIRED',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class CryptoIntent {
|
|
24
|
+
amountInFiat: number;
|
|
25
|
+
|
|
26
|
+
fiatCurrency: FiatCurrency;
|
|
27
|
+
|
|
28
|
+
payCurrency: PayCurrency;
|
|
29
|
+
|
|
30
|
+
status: PaymentIntentStatus;
|
|
31
|
+
|
|
32
|
+
providerPaymentId: string;
|
|
33
|
+
|
|
34
|
+
payAddress?: string;
|
|
35
|
+
|
|
36
|
+
payAmount?: number;
|
|
37
|
+
|
|
38
|
+
receivedAmount?: number;
|
|
39
|
+
|
|
40
|
+
purchaseId?: string;
|
|
41
|
+
|
|
42
|
+
includeFee: boolean;
|
|
43
|
+
|
|
44
|
+
fees?: Partial<{
|
|
45
|
+
depositFee: number;
|
|
46
|
+
serviceFee: number;
|
|
47
|
+
withdrawalFee: number;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
metaData?: {};
|
|
51
|
+
}
|
package/src/payment.provider.ts
CHANGED
|
@@ -1,32 +1,53 @@
|
|
|
1
|
-
import { Inject, Injectable } from
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
2
2
|
import {
|
|
3
3
|
CreateStripeCheckoutDto,
|
|
4
4
|
CreateStripePaymentIntentDto,
|
|
5
|
-
} from
|
|
6
|
-
import { AmqpConnection } from
|
|
5
|
+
} from './dto/stripe.dto';
|
|
6
|
+
import { AmqpConnection, RpcResponse } from '@golevelup/nestjs-rabbitmq';
|
|
7
7
|
import {
|
|
8
8
|
CreateStripeCheckoutResponse,
|
|
9
9
|
CreateStripePaymentIntentResponse,
|
|
10
10
|
PaymentRabbitApi,
|
|
11
|
-
} from
|
|
11
|
+
} from './dto/common.interface';
|
|
12
|
+
import { RPCResponse } from '@ngn-net/giftcard-shared';
|
|
12
13
|
|
|
13
14
|
@Injectable()
|
|
14
15
|
export class PaymentProvider {
|
|
15
16
|
constructor(private readonly rabbit: AmqpConnection) {}
|
|
16
17
|
|
|
17
|
-
createStripeCheckout(
|
|
18
|
-
|
|
18
|
+
async createStripeCheckout(
|
|
19
|
+
payload: CreateStripeCheckoutDto,
|
|
20
|
+
): Promise<CreateStripeCheckoutResponse> {
|
|
21
|
+
const res = await this.rabbit.request<
|
|
22
|
+
RPCResponse<CreateStripeCheckoutResponse>
|
|
23
|
+
>({
|
|
19
24
|
exchange: PaymentRabbitApi.exchange,
|
|
20
25
|
routingKey: PaymentRabbitApi.routingkeys.stripe_checkout.key,
|
|
21
26
|
payload,
|
|
22
27
|
});
|
|
28
|
+
|
|
29
|
+
if (res.code !== 200) {
|
|
30
|
+
throw new Error(res.message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return res.data;
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
createStripePaymentIntent(
|
|
26
|
-
|
|
36
|
+
async createStripePaymentIntent(
|
|
37
|
+
payload: CreateStripePaymentIntentDto,
|
|
38
|
+
): Promise<CreateStripePaymentIntentResponse> {
|
|
39
|
+
const res = await this.rabbit.request<
|
|
40
|
+
RPCResponse<CreateStripePaymentIntentResponse>
|
|
41
|
+
>({
|
|
27
42
|
exchange: PaymentRabbitApi.exchange,
|
|
28
43
|
routingKey: PaymentRabbitApi.routingkeys.stripe_intent.key,
|
|
29
44
|
payload,
|
|
30
45
|
});
|
|
46
|
+
|
|
47
|
+
if (res.code !== 200) {
|
|
48
|
+
throw new Error(res.message);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return res.data;
|
|
31
52
|
}
|
|
32
53
|
}
|