UNPKG

@squadco/js

Version:

Simplify the integration process with Squad's comprehensive payment solutions using the Squad JavaScript SDK.

88 lines (87 loc) 4.65 kB
"use strict"; 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 }); const wallet_balance_1 = __importDefault(require("./wallet-balance")); class SquadDisputeResolver extends wallet_balance_1.default { constructor(publicKey, privateKey, environment) { super(publicKey, privateKey, environment); this.baseDisputeUrl = "/dispute"; } /** * @desc This method is used to get all disputes on your transactions raised by your customers. */ getAllDisputes() { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { try { const squadResponse = yield this.Axios.get(this.baseDisputeUrl); return squadResponse.data; } catch (error) { console.warn((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message); return (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data; } }); } /** * @desc This method is used to get a unique URL to upload an evidence(file) which is a proof or reason to reject a dispute. This is only necessary when we want to reject a dispute. * * @arg {string} ticketId - The unique ID that identifies the dispute you want to reject or accept * @arg {string} fileName - The name of the file */ getDisputeFileUploadUrl(ticketId, fileName) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { if (typeof ticketId !== "string" || typeof fileName !== "string") throw new Error("Validation Error! Invalid arguments supplied!"); try { const squadResponse = yield this.Axios.get(`${this.baseDisputeUrl}/upload-url/${ticketId}/${fileName}`); return squadResponse.data; } catch (error) { console.warn((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message); return (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data; } }); } /** * This method is called to resolve a dispute. * * @param {string} ticketId - The unique ID that identifies the dispute you want to reject or accept * @param {string} action - The action taken for the dispute. Either "accepted" or "rejected" * @param {string} fileName - The name of the file uploaded. */ resolveDisputes(ticketId, action, fileName) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { if (typeof ticketId !== "string" || typeof action !== "string" || typeof fileName !== "string") throw new Error("Validation Error! Invalid arguments supplied!"); const dataToSend = { action, file_name: fileName, }; try { const squadResponse = yield this.Axios.get(`${this.baseDisputeUrl}/${ticketId}/resolve`, dataToSend); return squadResponse.data; } catch (error) { console.warn((_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message); return (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data; } }); } } exports.default = SquadDisputeResolver;