AnhLedger commited on
Commit
1755ee0
·
1 Parent(s): ec8aeac

modify payment entity

Browse files
backend/package-lock.json CHANGED
@@ -31,7 +31,8 @@
31
  "pg": "^8.13.0",
32
  "reflect-metadata": "^0.2.0",
33
  "rxjs": "^7.8.1",
34
- "typeorm": "^0.3.20"
 
35
  },
36
  "devDependencies": {
37
  "@nestjs/cli": "^10.0.0",
@@ -7138,6 +7139,27 @@
7138
  "mkdirp": "bin/cmd.js"
7139
  }
7140
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7141
  "node_modules/ms": {
7142
  "version": "2.1.3",
7143
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -9594,6 +9616,7 @@
9594
  "version": "0.3.20",
9595
  "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.3.20.tgz",
9596
  "integrity": "sha512-sJ0T08dV5eoZroaq9uPKBoNcGslHBR4E4y+EBHs//SiGbblGe7IeduP/IH4ddCcj0qp3PHwDwGnuvqEAnKlq/Q==",
 
9597
  "dependencies": {
9598
  "@sqltools/formatter": "^1.2.5",
9599
  "app-root-path": "^3.1.0",
@@ -9878,6 +9901,16 @@
9878
  "node": ">= 0.8"
9879
  }
9880
  },
 
 
 
 
 
 
 
 
 
 
9881
  "node_modules/walker": {
9882
  "version": "1.0.8",
9883
  "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz",
 
31
  "pg": "^8.13.0",
32
  "reflect-metadata": "^0.2.0",
33
  "rxjs": "^7.8.1",
34
+ "typeorm": "^0.3.20",
35
+ "vnpay": "^1.6.0"
36
  },
37
  "devDependencies": {
38
  "@nestjs/cli": "^10.0.0",
 
7139
  "mkdirp": "bin/cmd.js"
7140
  }
7141
  },
7142
+ "node_modules/moment": {
7143
+ "version": "2.30.1",
7144
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz",
7145
+ "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
7146
+ "license": "MIT",
7147
+ "engines": {
7148
+ "node": "*"
7149
+ }
7150
+ },
7151
+ "node_modules/moment-timezone": {
7152
+ "version": "0.5.46",
7153
+ "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.46.tgz",
7154
+ "integrity": "sha512-ZXm9b36esbe7OmdABqIWJuBBiLLwAjrN7CE+7sYdCCx82Nabt1wHDj8TVseS59QIlfFPbOoiBPm6ca9BioG4hw==",
7155
+ "license": "MIT",
7156
+ "dependencies": {
7157
+ "moment": "^2.29.4"
7158
+ },
7159
+ "engines": {
7160
+ "node": "*"
7161
+ }
7162
+ },
7163
  "node_modules/ms": {
7164
  "version": "2.1.3",
7165
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
 
9616
  "version": "0.3.20",
9617
  "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.3.20.tgz",
9618
  "integrity": "sha512-sJ0T08dV5eoZroaq9uPKBoNcGslHBR4E4y+EBHs//SiGbblGe7IeduP/IH4ddCcj0qp3PHwDwGnuvqEAnKlq/Q==",
9619
+ "license": "MIT",
9620
  "dependencies": {
9621
  "@sqltools/formatter": "^1.2.5",
9622
  "app-root-path": "^3.1.0",
 
9901
  "node": ">= 0.8"
9902
  }
9903
  },
9904
+ "node_modules/vnpay": {
9905
+ "version": "1.6.0",
9906
+ "resolved": "https://registry.npmjs.org/vnpay/-/vnpay-1.6.0.tgz",
9907
+ "integrity": "sha512-+y1tdsJ1ClPC0cVGCG6v5lDi5rZZSzfUe1I670d4tqzxvHdgPbgmrYuH4LpLOEuiFs0Nwum9Thw7DfWgbztjBA==",
9908
+ "hasInstallScript": true,
9909
+ "license": "MIT",
9910
+ "dependencies": {
9911
+ "moment-timezone": "^0.5.43"
9912
+ }
9913
+ },
9914
  "node_modules/walker": {
9915
  "version": "1.0.8",
9916
  "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz",
backend/package.json CHANGED
@@ -47,7 +47,8 @@
47
  "pg": "^8.13.0",
48
  "reflect-metadata": "^0.2.0",
49
  "rxjs": "^7.8.1",
50
- "typeorm": "^0.3.20"
 
51
  },
52
  "devDependencies": {
53
  "@nestjs/cli": "^10.0.0",
 
47
  "pg": "^8.13.0",
48
  "reflect-metadata": "^0.2.0",
49
  "rxjs": "^7.8.1",
50
+ "typeorm": "^0.3.20",
51
+ "vnpay": "^1.6.0"
52
  },
53
  "devDependencies": {
54
  "@nestjs/cli": "^10.0.0",
backend/src/common/enums/PaymentMethod.enum.ts CHANGED
@@ -1,5 +1,5 @@
1
  export enum PaymentMethod {
2
- CASH = 0,
3
- CARD = 1,
4
- ONLINE_PAYMENT = 2,
5
  }
 
1
  export enum PaymentMethod {
2
+ CASH = "CASH",
3
+ CARD = "CARD",
4
+ ONLINE_PAYMENT = "ONLINE_PAYMENT",
5
  }
backend/src/common/enums/VnpCardType.enum.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ export enum VnpCardType {
2
+ ATM = "ATM",
3
+ QRCODE = "QRCODE",
4
+ None = "None"
5
+ }
backend/src/entities/payment.entity.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
  } from 'typeorm';
9
  import { OrderEntity } from './order.entity.js';
10
  import { PaymentMethod } from '../common/enums/PaymentMethod.enum.js';
 
11
 
12
  @Entity('payments')
13
  export class PaymentEntity extends BaseEntity {
@@ -17,9 +18,36 @@ export class PaymentEntity extends BaseEntity {
17
  @OneToOne(() => OrderEntity, (a) => a.payment)
18
  order: Relation<OrderEntity>;
19
 
20
- @Column({ default: 0 })
21
- payment_method: number; // E.g., 'Cash', 'Credit Card', 'Online Payment'
22
 
23
  @Column()
24
- value: number;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
 
8
  } from 'typeorm';
9
  import { OrderEntity } from './order.entity.js';
10
  import { PaymentMethod } from '../common/enums/PaymentMethod.enum.js';
11
+ import { VnpCardType } from '../common/enums/VnpCardType.enum.js';
12
 
13
  @Entity('payments')
14
  export class PaymentEntity extends BaseEntity {
 
18
  @OneToOne(() => OrderEntity, (a) => a.payment)
19
  order: Relation<OrderEntity>;
20
 
21
+ @Column({ type: 'enum', enum: PaymentMethod, default: "CASH" })
22
+ payment_method: PaymentMethod; // E.g., 'Cash', 'Credit Card', 'Online Payment'
23
 
24
  @Column()
25
+ vnp_amount: number
26
+
27
+ @Column()
28
+ vnp_bank_code: string
29
+
30
+ @Column()
31
+ vnp_bank_tran_no:string
32
+
33
+ @Column({ type: 'enum', enum: VnpCardType, default: "None"})
34
+ vnp_card_type: VnpCardType // E.g., 'ATM', 'QRCODE', 'None'
35
+
36
+ @Column()
37
+ vnp_order_info: string
38
+
39
+ @Column()
40
+ vnp_paydate: string
41
+
42
+ @Column()
43
+ vnp_response_code: number
44
+
45
+ @Column()
46
+ vnp_transaction_no: string
47
+
48
+ @Column()
49
+ vnp_transaction_status: number
50
+
51
+ @Column()
52
+ vnp_securehash: string
53
  }
backend/src/migrations/1730647727322-modify_payment_entity.ts ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MigrationInterface, QueryRunner } from "typeorm";
2
+
3
+ export class ModifyPaymentEntity1730647727322 implements MigrationInterface {
4
+ name = 'ModifyPaymentEntity1730647727322'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "value"`);
8
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_amount" integer NOT NULL`);
9
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_bank_code" character varying NOT NULL`);
10
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_bank_tran_no" character varying NOT NULL`);
11
+ await queryRunner.query(`CREATE TYPE "public"."payments_vnp_card_type_enum" AS ENUM('ATM', 'QRCODE', 'None')`);
12
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_card_type" "public"."payments_vnp_card_type_enum" NOT NULL DEFAULT 'None'`);
13
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_order_info" character varying NOT NULL`);
14
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_paydate" character varying NOT NULL`);
15
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_response_code" integer NOT NULL`);
16
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_transaction_no" character varying NOT NULL`);
17
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_transaction_status" integer NOT NULL`);
18
+ await queryRunner.query(`ALTER TABLE "payments" ADD "vnp_securehash" character varying NOT NULL`);
19
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
20
+ await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('CASH', 'CARD', 'ONLINE_PAYMENT')`);
21
+ await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'CASH'`);
22
+ }
23
+
24
+ public async down(queryRunner: QueryRunner): Promise<void> {
25
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
26
+ await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
27
+ await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" integer NOT NULL DEFAULT '0'`);
28
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_securehash"`);
29
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_transaction_status"`);
30
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_transaction_no"`);
31
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_response_code"`);
32
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_paydate"`);
33
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_order_info"`);
34
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_card_type"`);
35
+ await queryRunner.query(`DROP TYPE "public"."payments_vnp_card_type_enum"`);
36
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_bank_tran_no"`);
37
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_bank_code"`);
38
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "vnp_amount"`);
39
+ await queryRunner.query(`ALTER TABLE "payments" ADD "value" integer NOT NULL`);
40
+ }
41
+
42
+ }