paypal-rest-api
Version:
A typescript module for integrating with PayPal REST APIs.
56 lines (55 loc) • 2.38 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 PaymentModel extends abstracts_1.Model {
constructor(model) {
super(model, PaymentModel.schema);
}
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.payments.map((payment) => {
return new this(payment);
});
});
}
static init(client) {
const api = new api_1.PaymentApi(client);
PaymentModel.api = api;
PaymentModel.prototype.api = api;
}
execute(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");
}
if (!this.model.payer.payer_info || !this.model.payer.payer_info.payer_id) {
throw new Error("Model does not have a payer id. Call get first");
}
options.body = Object.assign({}, options.body, {
payer_id: this.model.payer.payer_info.payer_id,
});
const response = yield this.api.execute(this.model.id, options);
this.model = response.body;
return this;
});
}
}
PaymentModel.schema = schemas_1.paymentSchema;
exports.PaymentModel = PaymentModel;