@khoimd/nestjs-vnpay
Version:
NestJS module wrapper for VNPay payment gateway integration based on the vnpay package
75 lines (74 loc) • 3.95 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var VnpayModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VnpayModule = void 0;
const common_1 = require("@nestjs/common");
const vnpay_constant_1 = require("./vnpay.constant");
const vnpay_service_1 = require("./vnpay.service");
let VnpayModule = VnpayModule_1 = class VnpayModule {
static register(options) {
return {
module: VnpayModule_1,
providers: [{ provide: vnpay_constant_1.VNPAY_MODULE_OPTIONS, useValue: options }, vnpay_service_1.VnpayService],
exports: [vnpay_service_1.VnpayService],
};
}
static registerAsync(options) {
var _a;
return {
module: VnpayModule_1,
imports: options === null || options === void 0 ? void 0 : options.imports,
providers: [
...VnpayModule_1.createAsyncProviders(options),
...((_a = options === null || options === void 0 ? void 0 : options.extraProviders) !== null && _a !== void 0 ? _a : []),
vnpay_service_1.VnpayService,
],
exports: [vnpay_service_1.VnpayService],
};
}
static createAsyncProviders(options) {
if ((options === null || options === void 0 ? void 0 : options.useExisting) || (options === null || options === void 0 ? void 0 : options.useFactory)) {
return [VnpayModule_1.createAsyncOptionsProvider(options)];
}
return [
VnpayModule_1.createAsyncOptionsProvider(options),
{
provide: options === null || options === void 0 ? void 0 : options.useClass,
useClass: options === null || options === void 0 ? void 0 : options.useClass,
},
];
}
static createAsyncOptionsProvider(options) {
if (options === null || options === void 0 ? void 0 : options.useFactory) {
return {
provide: vnpay_constant_1.VNPAY_MODULE_OPTIONS,
useFactory: options.useFactory,
inject: (options === null || options === void 0 ? void 0 : options.inject) || [],
};
}
return {
provide: vnpay_constant_1.VNPAY_MODULE_OPTIONS,
useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () { return optionsFactory.createVnpayOptions(); }),
inject: [(options === null || options === void 0 ? void 0 : options.useExisting) || (options === null || options === void 0 ? void 0 : options.useClass)],
};
}
};
exports.VnpayModule = VnpayModule;
exports.VnpayModule = VnpayModule = VnpayModule_1 = __decorate([
(0, common_1.Module)({})
], VnpayModule);