@ngn-net/payment-provider-sdk 1.0.2 → 1.0.5

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.
@@ -1,8 +1,9 @@
1
+ import { FiatCurrency, PayCurrency, PaymentIntentStatus } from '../entity/crypto.entity';
1
2
  export declare const RABBIT_URI: () => string[];
2
3
  export declare const rabbitUri: string[];
3
4
  export interface RabbitAddress {
4
5
  exchange: string;
5
- type: "topic" | "direct" | "fanout";
6
+ type: 'topic' | 'direct' | 'fanout';
6
7
  routingkeys: {
7
8
  [key: string]: {
8
9
  key: string;
@@ -28,6 +29,9 @@ export declare const PaymentRabbitApi: {
28
29
  stripe_intent: {
29
30
  key: string;
30
31
  };
32
+ crypto_intent: {
33
+ key: string;
34
+ };
31
35
  };
32
36
  };
33
37
  export interface CreateStripeCheckoutResponse {
@@ -44,3 +48,35 @@ export interface CreateStripePaymentIntentResponse {
44
48
  clientSecret: string;
45
49
  orderId: string;
46
50
  }
51
+ export interface StripePaymentCompleteEvent {
52
+ id: string;
53
+ paymentId: string;
54
+ orderId: string;
55
+ amount: number;
56
+ amountRecieved: number;
57
+ }
58
+ export interface CreateCryptoIntentResponse {
59
+ id: string;
60
+ paymentId: string;
61
+ amountInFiat: number;
62
+ fiatCurrency: FiatCurrency;
63
+ payCurrency: PayCurrency;
64
+ payAddress: string;
65
+ payAmount: number;
66
+ status: PaymentIntentStatus;
67
+ orderId: string;
68
+ }
69
+ interface EventDataMap {
70
+ stripe_succeeded: StripePaymentCompleteEvent;
71
+ }
72
+ export type StripeEvent<T extends keyof EventDataMap = keyof EventDataMap> = {
73
+ id: string;
74
+ type: T;
75
+ data: EventDataMap[T];
76
+ };
77
+ export interface RPCResponse<T> {
78
+ code: number;
79
+ message: string;
80
+ data: T;
81
+ }
82
+ export {};
@@ -2,30 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PaymentRabbitApi = exports.rabbitUri = exports.RABBIT_URI = void 0;
4
4
  const RABBIT_URI = () => {
5
- const rabbitUri = process.env.RABBIT_URI || "amqp://sabi:password@localhost:5672";
6
- const [creadential, hosts] = rabbitUri.split("@");
7
- const hostList = hosts.split(",");
8
- return hostList.map((host) => {
5
+ const rabbitUri = process.env.RABBIT_URI || 'amqp://user:pass@localhost:5672';
6
+ const [creadential, hosts] = rabbitUri.split('@');
7
+ const hostList = hosts.split(',');
8
+ return hostList.map((host, index) => {
9
9
  return `${creadential}@${host}`;
10
10
  });
11
11
  };
12
12
  exports.RABBIT_URI = RABBIT_URI;
13
13
  exports.rabbitUri = (0, exports.RABBIT_URI)();
14
14
  exports.PaymentRabbitApi = {
15
- exchange: "payment",
16
- type: "topic",
15
+ exchange: 'payment',
16
+ type: 'topic',
17
17
  routingkeys: {
18
18
  default: {
19
- key: "default",
19
+ key: 'default',
20
20
  },
21
21
  events: {
22
- key: "paymentEvents",
22
+ key: 'paymentEvents',
23
23
  },
24
24
  stripe_checkout: {
25
- key: "stripeCheckout",
25
+ key: 'stripeCheckout',
26
26
  },
27
27
  stripe_intent: {
28
- key: "stripePaymentIntent",
28
+ key: 'stripePaymentIntent',
29
+ },
30
+ crypto_intent: {
31
+ key: 'cryptoPaymentIntent',
29
32
  },
30
33
  },
31
34
  };
@@ -0,0 +1,37 @@
1
+ export declare enum FiatCurrency {
2
+ usd = "USD"
3
+ }
4
+ export declare enum PayCurrency {
5
+ btc = "BTC",
6
+ eth = "ETH",
7
+ trx = "TRX",
8
+ usdc = "USDC",
9
+ usdt = "USDT",
10
+ usdttrc20 = "USDTTRC20"
11
+ }
12
+ export declare enum PaymentIntentStatus {
13
+ CREATED = "CREATED",
14
+ WAITING = "WAITING",
15
+ CONFIRMING = "CONFIRMING",
16
+ CONFIRMED = "CONFIRMED",
17
+ FAILED = "FAILED",
18
+ EXPIRED = "EXPIRED"
19
+ }
20
+ export declare class CryptoIntent {
21
+ amountInFiat: number;
22
+ fiatCurrency: FiatCurrency;
23
+ payCurrency: PayCurrency;
24
+ status: PaymentIntentStatus;
25
+ providerPaymentId: string;
26
+ payAddress?: string;
27
+ payAmount?: number;
28
+ receivedAmount?: number;
29
+ purchaseId?: string;
30
+ includeFee: boolean;
31
+ fees?: Partial<{
32
+ depositFee: number;
33
+ serviceFee: number;
34
+ withdrawalFee: number;
35
+ }>;
36
+ metaData?: {};
37
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptoIntent = exports.PaymentIntentStatus = exports.PayCurrency = exports.FiatCurrency = void 0;
4
+ var FiatCurrency;
5
+ (function (FiatCurrency) {
6
+ FiatCurrency["usd"] = "USD";
7
+ })(FiatCurrency || (exports.FiatCurrency = FiatCurrency = {}));
8
+ var PayCurrency;
9
+ (function (PayCurrency) {
10
+ PayCurrency["btc"] = "BTC";
11
+ PayCurrency["eth"] = "ETH";
12
+ PayCurrency["trx"] = "TRX";
13
+ PayCurrency["usdc"] = "USDC";
14
+ PayCurrency["usdt"] = "USDT";
15
+ PayCurrency["usdttrc20"] = "USDTTRC20";
16
+ })(PayCurrency || (exports.PayCurrency = PayCurrency = {}));
17
+ var PaymentIntentStatus;
18
+ (function (PaymentIntentStatus) {
19
+ PaymentIntentStatus["CREATED"] = "CREATED";
20
+ PaymentIntentStatus["WAITING"] = "WAITING";
21
+ PaymentIntentStatus["CONFIRMING"] = "CONFIRMING";
22
+ PaymentIntentStatus["CONFIRMED"] = "CONFIRMED";
23
+ PaymentIntentStatus["FAILED"] = "FAILED";
24
+ PaymentIntentStatus["EXPIRED"] = "EXPIRED";
25
+ })(PaymentIntentStatus || (exports.PaymentIntentStatus = PaymentIntentStatus = {}));
26
+ class CryptoIntent {
27
+ }
28
+ exports.CryptoIntent = CryptoIntent;
@@ -1,6 +1,6 @@
1
- import { CreateStripeCheckoutDto, CreateStripePaymentIntentDto } from "./dto/stripe.dto";
2
- import { AmqpConnection } from "@golevelup/nestjs-rabbitmq";
3
- import { CreateStripeCheckoutResponse, CreateStripePaymentIntentResponse } from "./dto/common.interface";
1
+ import { CreateStripeCheckoutDto, CreateStripePaymentIntentDto } from './dto/stripe.dto';
2
+ import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
3
+ import { CreateStripeCheckoutResponse, CreateStripePaymentIntentResponse } from './dto/common.interface';
4
4
  export declare class PaymentProvider {
5
5
  private readonly rabbit;
6
6
  constructor(rabbit: AmqpConnection);
@@ -17,19 +17,27 @@ let PaymentProvider = class PaymentProvider {
17
17
  constructor(rabbit) {
18
18
  this.rabbit = rabbit;
19
19
  }
20
- createStripeCheckout(payload) {
21
- return this.rabbit.request({
20
+ async createStripeCheckout(payload) {
21
+ const res = await this.rabbit.request({
22
22
  exchange: common_interface_1.PaymentRabbitApi.exchange,
23
23
  routingKey: common_interface_1.PaymentRabbitApi.routingkeys.stripe_checkout.key,
24
24
  payload,
25
25
  });
26
+ if (res.code !== 200) {
27
+ throw new Error(res.message);
28
+ }
29
+ return res.data;
26
30
  }
27
- createStripePaymentIntent(payload) {
28
- return this.rabbit.request({
31
+ async createStripePaymentIntent(payload) {
32
+ const res = await this.rabbit.request({
29
33
  exchange: common_interface_1.PaymentRabbitApi.exchange,
30
34
  routingKey: common_interface_1.PaymentRabbitApi.routingkeys.stripe_intent.key,
31
35
  payload,
32
36
  });
37
+ if (res.code !== 200) {
38
+ throw new Error(res.message);
39
+ }
40
+ return res.data;
33
41
  }
34
42
  };
35
43
  exports.PaymentProvider = PaymentProvider;
package/package.json CHANGED
@@ -1,23 +1,28 @@
1
1
  {
2
2
  "name": "@ngn-net/payment-provider-sdk",
3
- "version": "1.0.2",
4
- "main": "index.js",
3
+ "version": "1.0.5",
4
+ "description": "Payment provider SDK",
5
+ "main": "dist/main.js",
6
+ "types": "dist/main.d.ts",
5
7
  "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1",
7
- "start": "nest start",
8
- "start:dev": "nest start --watch",
9
- "build": "tsc"
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build"
10
10
  },
11
11
  "keywords": [],
12
12
  "author": "",
13
13
  "license": "ISC",
14
- "description": "",
14
+ "files": [
15
+ "dist"
16
+ ],
15
17
  "dependencies": {
18
+ "class-transformer": "^0.5.1",
19
+ "class-validator": "^0.15.1"
20
+ },
21
+ "peerDependencies": {
16
22
  "@golevelup/nestjs-rabbitmq": "^9.0.2",
17
23
  "@nestjs/common": "^11.1.26",
18
24
  "@nestjs/swagger": "^11.4.4",
19
- "class-transformer": "^0.5.1",
20
- "class-validator": "^0.15.1"
25
+ "@ngn-net/giftcard-shared": "*"
21
26
  },
22
27
  "devDependencies": {
23
28
  "@types/node": "^25.9.2",
@@ -1,61 +0,0 @@
1
- export const RABBIT_URI = (): string[] => {
2
- const rabbitUri =
3
- process.env.RABBIT_URI || "amqp://sabi:password@localhost:5672";
4
-
5
- const [creadential, hosts] = rabbitUri.split("@");
6
- const hostList = hosts.split(",");
7
-
8
- return hostList.map((host) => {
9
- return `${creadential}@${host}`;
10
- });
11
- };
12
-
13
- export const rabbitUri = RABBIT_URI();
14
-
15
- export interface RabbitAddress {
16
- exchange: string;
17
- type: "topic" | "direct" | "fanout";
18
- routingkeys: {
19
- [key: string]: {
20
- key: string;
21
- messages?: {
22
- [key: string]: string;
23
- };
24
- };
25
- };
26
- }
27
-
28
- export const PaymentRabbitApi = {
29
- exchange: "payment",
30
- type: "topic",
31
- routingkeys: {
32
- default: {
33
- key: "default",
34
- },
35
- events: {
36
- key: "paymentEvents",
37
- },
38
- stripe_checkout: {
39
- key: "stripeCheckout",
40
- },
41
- stripe_intent: {
42
- key: "stripePaymentIntent",
43
- },
44
- },
45
- };
46
-
47
- export interface CreateStripeCheckoutResponse {
48
- id: string;
49
- checkoutId: string;
50
- amount: number;
51
- url: string;
52
- orderId: string;
53
- }
54
-
55
- export interface CreateStripePaymentIntentResponse {
56
- id: string;
57
- paymentId: string;
58
- amount: number;
59
- clientSecret: string;
60
- orderId: string;
61
- }
@@ -1,33 +0,0 @@
1
- import { ApiProperty } from "@nestjs/swagger";
2
- import { IsNotEmpty, IsNumber, IsString, Min } from "class-validator";
3
-
4
- export class CreateStripeCheckoutDto {
5
- @ApiProperty()
6
- @IsNotEmpty()
7
- @IsNumber()
8
- @Min(50)
9
- amount!: number;
10
-
11
- @ApiProperty()
12
- @IsNotEmpty()
13
- @IsString()
14
- orderId!: string;
15
-
16
- @ApiProperty()
17
- @IsNotEmpty()
18
- @IsString()
19
- productName!: string;
20
- }
21
-
22
- export class CreateStripePaymentIntentDto {
23
- @ApiProperty()
24
- @IsNotEmpty()
25
- @IsNumber()
26
- @Min(50)
27
- amount!: number;
28
-
29
- @ApiProperty()
30
- @IsNotEmpty()
31
- @IsString()
32
- orderId!: string;
33
- }
package/src/main.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "./payment.module";
2
- export * from "./payment.provider";
3
-
4
- export * from "./dto/stripe.dto";
5
- export * from "./dto/common.interface";
@@ -1,9 +0,0 @@
1
- import { Global, Module } from "@nestjs/common";
2
- import { PaymentProvider } from "./payment.provider";
3
-
4
- @Global()
5
- @Module({
6
- providers: [PaymentProvider],
7
- exports: [PaymentProvider],
8
- })
9
- export class PaymentModule {}
@@ -1,32 +0,0 @@
1
- import { Inject, Injectable } from "@nestjs/common";
2
- import {
3
- CreateStripeCheckoutDto,
4
- CreateStripePaymentIntentDto,
5
- } from "./dto/stripe.dto";
6
- import { AmqpConnection } from "@golevelup/nestjs-rabbitmq";
7
- import {
8
- CreateStripeCheckoutResponse,
9
- CreateStripePaymentIntentResponse,
10
- PaymentRabbitApi,
11
- } from "./dto/common.interface";
12
-
13
- @Injectable()
14
- export class PaymentProvider {
15
- constructor(private readonly rabbit: AmqpConnection) {}
16
-
17
- createStripeCheckout(payload: CreateStripeCheckoutDto) {
18
- return this.rabbit.request<CreateStripeCheckoutResponse>({
19
- exchange: PaymentRabbitApi.exchange,
20
- routingKey: PaymentRabbitApi.routingkeys.stripe_checkout.key,
21
- payload,
22
- });
23
- }
24
-
25
- createStripePaymentIntent(payload: CreateStripePaymentIntentDto) {
26
- return this.rabbit.request<CreateStripePaymentIntentResponse>({
27
- exchange: PaymentRabbitApi.exchange,
28
- routingKey: PaymentRabbitApi.routingkeys.stripe_intent.key,
29
- payload,
30
- });
31
- }
32
- }
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
-
9
- "strict": true,
10
-
11
- "experimentalDecorators": true,
12
- "emitDecoratorMetadata": true,
13
-
14
- "esModuleInterop": true,
15
-
16
- "types": ["node"],
17
-
18
- "skipLibCheck": true
19
- },
20
- "include": ["src/**/*"]
21
- }