UNPKG

@ijodkor/nest-payme

Version:

NestJs ilovalar uchun Payme ETT bilan integratsiya qilish uchun kutubxona.

89 lines (88 loc) 4.07 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 __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 __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestService = void 0; const common_1 = require("@nestjs/common"); const axios_1 = __importDefault(require("axios")); const config_1 = require("@nestjs/config"); const encryption_1 = require("../modules/encryption"); let RequestService = class RequestService { constructor(configService, encryption) { this.configService = configService; this.encryption = encryption; this.cashId = configService.get("PAYME_MERCHANT_ID"); this.key = configService.get("PAYME_MERCHANT_KEY"); this.secure = configService.get("PAYME_ENCRYPTION_ENABLE"); const config = __rest({ baseURL: configService.get("PAYME_SUBSCRIPTION_API_URL"), headers: { 'X-Auth': this.cashId } }, []); this.axios = axios_1.default.create(config); } prepare(method, params) { return __awaiter(this, void 0, void 0, function* () { const { data } = yield this.axios.post("/", { id: new Date().getTime(), method, params }); return data; }); } checkout(method, params) { return __awaiter(this, void 0, void 0, function* () { const key = this.secure ? this.encryption.decrypt(this.key) : this.key; const { data } = yield this.axios.post("/", { id: new Date().getTime(), method, params }, { headers: { 'X-Auth': this.cashId.concat(":").concat(key) } }); return data; }); } }; exports.RequestService = RequestService; exports.RequestService = RequestService = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [config_1.ConfigService, encryption_1.EncryptionService]) ], RequestService);