Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(GBB-129): integrate VNPAY e-wallet #15

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ DB_NAME=postgres
PORT=5432
DB_USER=postgres
DB_PASS=postgres
DB_DIALECT=postgres
DB_DIALECT=postgres

vnp_TmnCode=
vnp_HashSecret=
vnp_Url=
vnp_Api=
vnp_ReturnUrl=
50 changes: 40 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@
"es2021": true,
"node": true
},
"extends": ["airbnb-base", "prettier"],
"extends": [
"airbnb-base",
"prettier"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"plugins": ["prettier"],
"plugins": [
"prettier"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"quotes": ["error", "single"],
"semi": ["error", "always"],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"linebreak-style": 0,
"indent": ["error", 4, { "SwitchCase": 1 }],
"indent": [
"off",
4,
{
"SwitchCase": 1
}
],
"consistent-return": 0,
"no-underscore-dangle": 0,
"no-tabs": 0,
Expand All @@ -29,9 +46,20 @@
"no-param-reassign": "off",
"camelcase": "off",
"import/no-unresolved": "off",
"arrow-parens": ["error", "as-needed"],
"comma-dangle": ["error", "only-multiline"],
"no-trailing-spaces": ["error", { "ignoreComments": true }],
"arrow-parens": [
"error",
"as-needed"
],
"comma-dangle": [
"error",
"only-multiline"
],
"no-trailing-spaces": [
"error",
{
"ignoreComments": true
}
],
"eslint-plugin-import/no-commonjs": "off",
"eslint-plugin-import/no-amd": "off",
"import/extensions": "off",
Expand All @@ -49,6 +77,8 @@
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}
]
],
"strict": "off",
"no-prototype-builtins": "off"
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $ docker compose up init_db
$ npm run db:reset

# Create new migration file
$ npx migrate:make <migration_name_file.js>
$ npx sequelize-cli migration:generate --name <migration_name_file.js>

# Run the migration
$ npx sequelize-cli db:migrate
Expand All @@ -88,7 +88,7 @@ $ npx sequelize-cli seed:generate --name <migration_name_file.js>
$ npx sequelize-cli db:seed:all

# Run specific seed file
$ npx sequelize-cli db:seed -- --seed <seed_file_name.js>
$ npx sequelize-cli db:seed --seed <seed_file_name.js>
```

For more information you can read at Sequelize docs
Expand Down
8 changes: 5 additions & 3 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
"@/*": [
"./src/*"
]
}
},
"exclude": [
"node_modules"
],
],
"include": [
"src/*"
"src/*"
]
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
"joi": "^17.12.3",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"nodemon": "^3.1.0",
"pg": "^8.11.5",
"pg-hstore": "^2.3.4",
"request": "^2.88.2",
"sequelize": "^6.37.3",
"sequelize-cli": "^6.6.2",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
"swagger-ui-express": "^5.0.1",
"uuid": "^10.0.0"
},
"devDependencies": {
"@babel/cli": "^7.24.7",
Expand Down
16 changes: 15 additions & 1 deletion src/config/app.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { env } from '@/utils/function.js';
import { env } from '@/utils/function';

const development = {
app: {
Expand All @@ -19,6 +19,13 @@ const development = {
password: env('DB_PASS', 'postgres'),
dialect: env('DB_DIALECT', 'postgres'),
},
payment: {
vnp_TmnCode: env('vnp_TmnCode'),
vnp_HashSecret: env('vnp_HashSecret'),
vnp_Url: env('vnp_Url'),
vnp_Api: env('vnp_Api'),
vnp_ReturnUrl: env('vnp_ReturnUrl'),
},
};
const production = {
app: {
Expand All @@ -38,6 +45,13 @@ const production = {
password: env('DB_PASS', 'postgres'),
dialect: env('DB_DIALECT', 'postgres'),
},
payment: {
vnp_TmnCode: env('vnp_TmnCode'),
vnp_HashSecret: env('vnp_HashSecret'),
vnp_Url: env('vnp_Url'),
vnp_Api: env('vnp_Api'),
vnp_ReturnUrl: env('vnp_ReturnUrl'),
},
};

const config = { development, production };
Expand Down
4 changes: 2 additions & 2 deletions src/controller/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RegisterDto, LoginDto } from '@/modules/auth/dto';
import { AuthService } from '@/modules/auth/service';
import { CreatedResponse, SuccessResponse } from '@/response/success.response.js';

class authController {
class AuthController {
static register = async (req, res) => {
new CreatedResponse({
data: await AuthService.register(RegisterDto(req.body)),
Expand All @@ -15,4 +15,4 @@ class authController {
}).send(res);
};
}
export default authController;
export default AuthController;
24 changes: 24 additions & 0 deletions src/controller/order.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CreatedResponse, SuccessResponse } from '@/response/success.response.js';
import { OrderService } from '@/modules/order/service';
import { CreateOrderDto } from '@/modules/order/dto';

class OrderController {
static createOrder = async (req, res) => {
const ipAddr = req.ip;
const { id: user_id } = req.user;
const body = { ...req.body, ipAddr, user_id };
new CreatedResponse({
data: await OrderService.createOrder(CreateOrderDto(body)),
}).send(res);
};

static updateOrder = async (req, res) => {
const { payment_order_id } = req.params;
const ipAddr = req.ip;
new SuccessResponse({
data: await OrderService.updateStatusOrder(payment_order_id, ipAddr),
}).send(res);
};

}
export default OrderController;
4 changes: 2 additions & 2 deletions src/controller/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UpdateUserByAdminDto, UpdateUserByOwnerDto } from '@/modules/user/dto';
import { UserService } from '@/modules/user/service';
import { NoContent, SuccessResponse } from '@/response/success.response.js';

class userController {
class UserController {
static updateUserByOwner = async (req, res) => {
const userId = req.user.id;
new SuccessResponse({
Expand Down Expand Up @@ -40,4 +40,4 @@ class userController {
}).send(res);
};
}
export default userController;
export default UserController;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('payment_methods', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
},
});

},

async down(queryInterface, Sequelize) {
await queryInterface.dropTable('payment_methods');
}
};
58 changes: 58 additions & 0 deletions src/database/migrations/20240713072615-create-orders-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('orders', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
user_id: {
type: Sequelize.INTEGER,
allowNull: false,
},
payment_method_id: {
type: Sequelize.INTEGER,
allowNull: false,
},
payment_order_id: {
type: Sequelize.UUIDV4,
unique: true
},
transaction_date: {
type: Sequelize.STRING,
},
customer_name: {
type: Sequelize.STRING,
},
customer_phone: {
type: Sequelize.STRING,
},
status: {
type: Sequelize.ENUM('PAID', 'UNPAID'),
defaultValue: 'UNPAID',
},
amount: {
type: Sequelize.BIGINT,
},
currency: {
type: Sequelize.STRING,
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
},
});
},

async down(queryInterface, Sequelize) {
await queryInterface.dropTable('orders');
}
};
57 changes: 57 additions & 0 deletions src/database/models/order.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';
import { Model } from 'sequelize';

module.exports = (sequelize, DataTypes) => {
class Order extends Model {
static associate(models) {
// define association here
Order.belongsTo(models.User, { foreignKey: 'user_id', as: 'user' });
Order.belongsTo(models.PaymentMethod, { foreignKey: 'payment_method_id', as: 'payment_method' });
}
}
Order.init(
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataTypes.INTEGER,
},
payment_method_id: {
type: DataTypes.INTEGER,
},
payment_order_id: {
type: DataTypes.UUID,
unique: true
},
transaction_date: {
type: DataTypes.STRING,
},
customer_name: {
type: DataTypes.STRING,
},
customer_phone: {
type: DataTypes.STRING,
},
status: {
type: DataTypes.ENUM('PAID', 'UNPAID'),
defaultValue: 'UNPAID',
},
amount: {
type: DataTypes.BIGINT,
},
currency: {
type: DataTypes.STRING,
},
},
{
sequelize,
modelName: 'Order',
tableName: 'orders',
timestamps: true,
},
);
return Order;
};
Loading