paypal-rest-api
Version:
A typescript module for integrating with PayPal REST APIs.
46 lines (45 loc) • 1.88 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 payment_1 = require("../payment");
const api_1 = require("./api");
class SaleModel extends abstracts_1.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 init(client) {
const api = new api_1.SaleApi(client);
SaleModel.api = api;
SaleModel.prototype.api = api;
}
constructor(model) {
if (model instanceof payment_1.PaymentModel) {
model = model.model.transactions[0].related_resources.map((resource) => {
return resource.sale;
})[0];
}
super(model);
}
refund(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.refund(this.model.id, options);
this.model = response.body;
return this;
});
}
}
exports.SaleModel = SaleModel;