UNPKG

easypay-nestjs

Version:
178 lines 6.97 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ZibalStrategy = void 0; const axios_1 = __importStar(require("axios")); class ZibalStrategy { constructor() { this.API_URLS = { sandbox: "https://gateway.zibal.ir/v1", production: "https://gateway.zibal.ir/v1", }; this.GATEWAY_URLS = { sandbox: "https://gateway.zibal.ir/start", production: "https://gateway.zibal.ir/start", }; } async request(data) { const options = data.options; const url = options.sandbox ? `${this.API_URLS.sandbox}/request` : `${this.API_URLS.production}/request`; const gatewayUrl = options.sandbox ? this.GATEWAY_URLS.sandbox : this.GATEWAY_URLS.production; try { const request = await axios_1.default.post(url, { merchant: options.merchant, amount: options.amount, callbackUrl: options.callbackUrl, description: options.description ?? undefined, orderId: options.orderId ?? undefined, mobile: options.mobile ?? undefined, allowedCards: options.allowedCards ?? undefined, ledgerId: options.ledgerId ?? undefined, nationalCode: options.nationalCode ?? undefined, checkMobileWithCard: options.checkMobileWithCard ?? undefined, }); const isSuccess = request.data.result === 100; return { success: isSuccess, code: request.data.result, message: request.data.message, data: isSuccess ? { trackId: request.data.trackId, url: `${gatewayUrl}/${request.data.trackId}`, } : null, raw: request.data, }; } catch (error) { return { success: false, code: 500, message: "خطایی نامشخص رخ داده است", data: null, raw: JSON.stringify(error.response), }; } } async verify(data) { const options = data.options; const url = options.sandbox ? `${this.API_URLS.sandbox}/verify` : `${this.API_URLS.production}/verify`; try { const request = await axios_1.default.post(url, { merchant: options.merchant, trackId: options.trackId, }); const isSuccess = request.data.result === 100 || request.data.result === 201; return { success: isSuccess, code: request.data.result, message: request.data.message, data: isSuccess ? { amount: request.data.amount, cardNumber: request.data.cardNumber, description: request.data.description, orderId: request.data.orderId, paidAt: request.data.paidAt, refNumber: request.data.refNumber, status: request.data.status, } : null, raw: request.data, }; } catch (error) { return { success: false, code: 500, message: "خطایی نامشخص رخ داده است", data: null, raw: JSON.stringify(error.response), }; } } async inquiry(data) { const options = data.options; const url = options.sandbox ? `${this.API_URLS.sandbox}/inquiry` : `${this.API_URLS.production}/inquiry`; try { const request = await axios_1.default.post(url, { merchant: options.merchant, trackId: options.trackId, }); return { success: true, code: request.data.result, message: request.data.message, data: { amount: request.data.amount, cardNumber: request.data.cardNumber, description: request.data.description, orderId: request.data.orderId, paidAt: request.data.paidAt, refNumber: request.data.refNumber, status: request.data.status, wage: request.data.wage, createdAt: request.data.createdAt, verifiedAt: request.data.verifiedAt, }, raw: request.data, }; } catch (error) { if (error instanceof axios_1.AxiosError) { const errorData = error?.response?.data; return { success: false, code: errorData.result, message: errorData.message, data: null, raw: error.response.data, }; } else { return { success: false, code: 500, message: "خطایی نامشخص رخ داده است", data: null, raw: JSON.stringify(error.response), }; } } } } exports.ZibalStrategy = ZibalStrategy; //# sourceMappingURL=zibal.strategy.js.map