UNPKG

@wiqotech/nestjs-digiflazz

Version:
202 lines (201 loc) 8.37 kB
"use strict"; 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 __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DigiflazzService = void 0; const common_1 = require("@nestjs/common"); const axios_1 = __importDefault(require("axios")); const crypto_1 = __importDefault(require("crypto")); const digiflazz_module_definition_1 = require("./digiflazz.module-definition"); const base_service_1 = require("./base.service"); let DigiflazzService = class DigiflazzService extends base_service_1.BaseService { constructor(config) { super(); this.config = config; this.init(); this.config; } init() { const baseUrl = 'https://api.digiflazz.com'; this.httpClient = axios_1.default.create({ baseURL: baseUrl, headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, }); } signHash(config, type) { const encryt = crypto_1.default.createHash('md5'); const encryted = encryt.update(config.username + config.apikey + type); const signature = encryted.digest('hex'); return signature; } getBalance() { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/cek-saldo', { params: { cmd: 'deposit', username: this.config.username, sign: this.signHash(this.config, 'depo'), }, }); return data; }); } charge(payload, testing = false) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/transaction', { params: { username: this.config.username, customer_no: payload.refNo, buyer_sku_code: payload.skuCode, ref_id: payload.refId, sign: this.signHash(this.config, payload.refId), testing, }, }); return data; }); } checkStatusPrepaid(payload, testing = false) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/transaction', { params: { username: this.config.username, customer_no: payload.refNo, buyer_sku_code: payload.skuCode, ref_id: payload.refId, sign: this.signHash(this.config, payload.refId), testing }, }); return data; }); } checkStatusPostpaid(payload, testing = false) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/transaction', { params: { commands: 'status-pasca', username: this.config.username, customer_no: payload.refNo, buyer_sku_code: payload.skuCode, ref_id: payload.refId, sign: this.signHash(this.config, payload.refId), testing }, }); return data; }); } getProductPricePrepaid() { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/price-list', { params: { cmd: 'prepaid', username: this.config.username, sign: this.signHash(this.config, 'pricelist'), }, }); return data; }); } getProductPricePasca() { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/price-list', { params: { cmd: 'pasca', username: this.config.username, sign: this.signHash(this.config, 'pricelist'), }, }); return data; }); } createDeposit(payload) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/deposit', { params: { amount: payload.amount, Bank: payload.bankCode, owner_name: payload.paymentName, username: this.config.username, sign: this.signHash(this.config, 'deposit'), }, }); return data; }); } checkBill(payload, testing = false) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/transaction', { params: { commands: 'inq-pasca', username: this.config.username, buyer_sku_code: payload.skuCode, customer_no: payload.refNo, ref_id: payload.refId, sign: this.signHash(this.config, payload.refId), testing }, }); return data; }); } payBill(payload, testing = false) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/transaction', { params: { commands: 'pay-pasca', username: this.config.username, customer_no: payload.refNo, buyer_sku_code: payload.skuCode, ref_id: payload.refId, sign: this.signHash(this.config, payload.refId), testing }, }); return data; }); } InquiryPLN(payload) { return __awaiter(this, void 0, void 0, function* () { const data = yield this.handleRequest('post', '/v1/transaction', { params: { commands: 'pln-subscribe', customer_no: payload.refNo }, }); return data; }); } }; exports.DigiflazzService = DigiflazzService; exports.DigiflazzService = DigiflazzService = __decorate([ (0, common_1.Injectable)(), __param(0, (0, common_1.Inject)(digiflazz_module_definition_1.MODULE_OPTIONS_TOKEN)), __metadata("design:paramtypes", [Object]) ], DigiflazzService);