UNPKG

paypal-rest-api

Version:

A typescript module for integrating with PayPal REST APIs.

74 lines (73 loc) 3.12 kB
"use strict"; 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"); class WebhookEventModel extends abstracts_1.Model { constructor(model) { super(model); this.model = model; } static parseHeaders(headers) { const newHeaders = {}; Object.keys(headers).forEach((key) => { newHeaders[key.toLowerCase()] = headers[key]; }); return { auth_algo: newHeaders["paypal-auth-algo"], cert_url: newHeaders["paypal-cert-url"], transmission_id: newHeaders["paypal-transmission-id"], transmission_sig: newHeaders["paypal-transmission-sig"], transmission_time: newHeaders["paypal-transmission-time"], }; } 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.events.map((webhookEvent) => { return new this(webhookEvent); }); }); } static verify(webhookid, headers, webhookEvent, options = {}) { return __awaiter(this, void 0, void 0, function* () { options.body = Object.assign({ webhook_event: webhookEvent, webhook_id: webhookid }, WebhookEventModel.parseHeaders(headers)); return yield this.api.verify(options); }); } static simulate(payload, options = {}) { return __awaiter(this, void 0, void 0, function* () { options.body = payload; const response = yield this.api.simulate(options); return new this(response.body); }); } static init(client) { const api = new api_1.WebhookEventApi(client); WebhookEventModel.api = api; WebhookEventModel.prototype.api = api; } resend(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.resend(this.model.id, options); this.model = response.body; }); } } exports.WebhookEventModel = WebhookEventModel;