paypal-rest-api
Version:
A typescript module for integrating with PayPal REST APIs.
51 lines (50 loc) • 2.1 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const abstracts_1 = require("../abstracts");
const api_1 = require("./api");
const schemas_1 = require("./schemas");
class WebhookModel extends abstracts_1.Model {
constructor(model) {
super(model, WebhookModel.schema);
this.model = model;
}
static get(id, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.api.get(id, options);
return new this(response.body);
});
}
static list(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.api.list(options);
return response.body.webhooks.map((webhook) => {
return new this(webhook);
});
});
}
static init(client) {
const api = new api_1.WebhookApi(client);
WebhookModel.api = api;
WebhookModel.prototype.api = api;
}
events(options = {}) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.model.id) {
throw new Error("Model does not have an id. Call create first");
}
const response = yield this.api.events(this.model.id, options);
this.model.event_types = response.body.event_types;
return this;
});
}
}
WebhookModel.schema = schemas_1.webhookSchema;
exports.WebhookModel = WebhookModel;