Tích hợp Bên thứ ba
BANA tích hợp với các dịch vụ bên ngoài thông qua các thành phần (components) module hóa. Mỗi tích hợp được thiết kế như một thành phần độc lập có thể dễ dàng cấu hình và gắn vào ứng dụng của bạn.
Các Tích hợp Có sẵn
| Module | Gói | Mô tả | Nhà cung cấp |
|---|---|---|---|
| MQ-Pay | @nx-3rd/mq-pay | Xử lý thanh toán đa nhà cung cấp | VNPAY, Nội bộ |
| IIAPI | @nx-3rd/iiapi | Quản lý hóa đơn điện tử | Nhiều T-VAN |
| T-VAN | @nx-3rd/t-van | Tích hợp cơ quan thuế | CQT Việt Nam |
Kiến trúc Tích hợp
Tất cả các tích hợp bên thứ ba đều tuân theo mô hình Thành phần IGNIS:
Ứng dụng Của Bạn
preConfigure() {
// 1. Bind tùy chọn cấu hình
this.bind<IOptions>({ key: BindingKeys.OPTIONS })
.toValue({ ... });
// 2. Tải thành phần
this.component(IntegrationComponent);
}
// 1. Bind tùy chọn cấu hình
this.bind<IOptions>({ key: BindingKeys.OPTIONS })
.toValue({ ... });
// 2. Tải thành phần
this.component(IntegrationComponent);
}
▼ Tải
Thành phần Tích hợp
setupCustomBindings()→Providers, Registries
setupServices()→Dịch vụ logic nghiệp vụ
setupControllers()→REST API endpoints
▼ Đăng ký
Tài nguyên Có sẵn
DI Container
services.*→Dịch vụ có thể inject
repositories.*→Lớp truy cập dữ liệu
controllers.*→REST endpoints
AppRegistry (Singleton)
redis:*→Kết nối Redis
payment-provider:*→Nhà cung cấp thanh toán
bullmq:queue:*→Hàng đợi công việc
Mẫu Cấu hình Chung
Tất cả các tích hợp tuân theo một mẫu cấu hình tương tự:
typescript
// 1. Import thành phần và các loại
import {
IntegrationComponent,
BindingKeys,
IOptions
} from '@nx-3rd/integration';
// 2. Cấu hình trong preConfigure() của ứng dụng
class MyApplication extends BaseApplication {
preConfigure() {
// Bind tùy chọn trước khi tải thành phần
this.bind<IOptions>({ key: BindingKeys.OPTIONS })
.toValue({
enableControllers: true, // Tự động đăng ký REST endpoints
clients: [
{
name: 'default',
provider: 'PROVIDER_NAME',
// Cấu hình riêng của nhà cung cấp...
},
],
});
// Tải thành phần
this.component(IntegrationComponent);
}
}Biến Môi trường
Mỗi tích hợp sử dụng một tiền tố cụ thể cho các biến môi trường:
| Tích hợp | Tiền tố | Ví dụ |
|---|---|---|
| MQ-Pay | APP_ENV_MQ_PAY_* | APP_ENV_MQ_PAY_POSTGRES_HOST |
| IIAPI | APP_ENV_IIAPI_* | APP_ENV_IIAPI_API_KEY |
| T-VAN | APP_ENV_TVAN_* | APP_ENV_TVAN_TAX_CODE |
Truy cập Dịch vụ Tích hợp
Qua Dependency Injection
typescript
import { inject } from '@venizia/ignis';
import { PaymentService } from '@nx-3rd/mq-pay';
export class SaleOrderService {
constructor(
@inject({ key: 'services.PaymentService' })
private paymentService: PaymentService,
) {}
async checkout(orderId: string) {
return this.paymentService.makePayment({
source: { type: 'SaleOrder', id: orderId },
payment: { provider: 'VNPAY_QR_MMS', total: 100000 },
});
}
}Qua AppRegistry (cho Redis, Providers)
typescript
import { AppRegistry } from '@nx-3rd/mq-pay';
// Lấy instance Redis
const registry = AppRegistry.getInstance();
const redis = registry.getRedis({ name: 'redis:@nx-3rd/mq-pay/redis-cache' });
// Lấy Payment Provider
const provider = registry.getPaymentProvider({ name: 'VNPAY_QR_MMS' });Các bước Tiếp theo
Chọn một tích hợp để tìm hiểu thêm: