orb-billing
Version:
The official TypeScript library for the Orb API
84 lines • 3.29 kB
JavaScript
;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Coupons = void 0;
const tslib_1 = require("../../internal/tslib.js");
const resource_1 = require("../../core/resource.js");
const SubscriptionsAPI = tslib_1.__importStar(require("./subscriptions.js"));
const subscriptions_1 = require("./subscriptions.js");
const pagination_1 = require("../../core/pagination.js");
const path_1 = require("../../internal/utils/path.js");
/**
* A coupon represents a reusable discount configuration that can be applied either as a fixed or percentage amount to an invoice or subscription. Coupons are activated using a redemption code, which applies the discount to a subscription or invoice. The duration of a coupon determines how long it remains available for use by end users.
*/
class Coupons extends resource_1.APIResource {
constructor() {
super(...arguments);
this.subscriptions = new SubscriptionsAPI.Subscriptions(this._client);
}
/**
* This endpoint allows the creation of coupons, which can then be redeemed at
* subscription creation or plan change.
*
* @example
* ```ts
* const coupon = await client.coupons.create({
* discount: {
* discount_type: 'percentage',
* percentage_discount: 0,
* },
* redemption_code: 'HALFOFF',
* });
* ```
*/
create(body, options) {
return this._client.post('/coupons', { body, ...options });
}
/**
* This endpoint returns a list of all coupons for an account in a list format.
*
* The list of coupons is ordered starting from the most recently created coupon.
* The response also includes `pagination_metadata`, which lets the caller retrieve
* the next page of results if they exist.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const coupon of client.coupons.list()) {
* // ...
* }
* ```
*/
list(query = {}, options) {
return this._client.getAPIList('/coupons', (pagination_1.Page), { query, ...options });
}
/**
* This endpoint allows a coupon to be archived. Archived coupons can no longer be
* redeemed, and will be hidden from lists of active coupons. Additionally, once a
* coupon is archived, its redemption code can be reused for a different coupon.
*
* @example
* ```ts
* const coupon = await client.coupons.archive('coupon_id');
* ```
*/
archive(couponID, options) {
return this._client.post((0, path_1.path) `/coupons/${couponID}/archive`, options);
}
/**
* This endpoint retrieves a coupon by its ID. To fetch coupons by their redemption
* code, use the [List coupons](list-coupons) endpoint with the redemption_code
* parameter.
*
* @example
* ```ts
* const coupon = await client.coupons.fetch('coupon_id');
* ```
*/
fetch(couponID, options) {
return this._client.get((0, path_1.path) `/coupons/${couponID}`, options);
}
}
exports.Coupons = Coupons;
Coupons.Subscriptions = subscriptions_1.Subscriptions;
//# sourceMappingURL=coupons.js.map