amberflo-metering-typescript
Version:
Amberflo metering client for TypeScript
66 lines • 3.25 kB
JavaScript
;
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 });
exports.CustomerPrepaidOrderClient = void 0;
const baseClient_1 = __importDefault(require("./baseClient"));
const constants_1 = require("./model/constants");
const customerPrepaidOrderApiPayload_1 = require("./model/customerPrepaidOrderApiPayload");
/**
* See: https://docs.amberflo.io/reference/post_payments-pricing-amberflo-customer-prepaid
*/
class CustomerPrepaidOrderClient extends baseClient_1.default {
/**
* Initialize a new `CustomerPrepaidOrderClient`
* `debug`: Whether to issue debug level logs or not.
* `retry`: Whether to retry idempotent requests on 5xx or network errors, or retry configuration (see https://github.com/softonic/axios-retry).
*/
constructor(apiKey, debug = false, retry = true) {
super(apiKey, debug, 'CustomerPrepaidOrderClient', retry);
this.path = '/payments/pricing/amberflo/customer-prepaid';
this.pathList = this.path + '/list';
}
/**
* List active prepaid orders of the given customer.
* See https://docs.amberflo.io/reference/get_payments-pricing-amberflo-customer-prepaid-list
*/
listActive(customerId, productId) {
return __awaiter(this, void 0, void 0, function* () {
const query = { CustomerId: customerId, ProductId: productId || constants_1.defaultProductId };
const values = yield this.doGet(this.pathList, query);
return values.map(this.deserialize);
});
}
/**
* Add a new prepaid order to a customer.
* See https://docs.amberflo.io/reference/post_payments-pricing-amberflo-customer-prepaid
*/
add(payload) {
return __awaiter(this, void 0, void 0, function* () {
payload.validate();
const value = yield this.doPost(this.path, payload);
return this.deserialize(value);
});
}
/**
* Make sure `BillingPeriod` is correctly instantiated.
* See https://aflo.atlassian.net/browse/MET-1600
*/
deserialize(plain) {
if (plain.recurrenceFrequency)
plain.recurrenceFrequency = new customerPrepaidOrderApiPayload_1.BillingPeriod(plain.recurrenceFrequency.intervalsCount, plain.recurrenceFrequency.interval);
return plain;
}
}
exports.CustomerPrepaidOrderClient = CustomerPrepaidOrderClient;
//# sourceMappingURL=customerPrepaidOrderClient.js.map