UNPKG

@paddle/paddle-node-sdk

Version:

A Node.js SDK that you can use to integrate Paddle Billing with applications written in server-side JavaScript.

133 lines (132 loc) 6.76 kB
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()); }); }; import { BaseResource, PathParameters, QueryParameters } from '../../internal/base/index.js'; import { Subscription, SubscriptionCollection, SubscriptionPreview, Transaction } from '../../entities/index.js'; const SubscriptionPaths = { get: '/subscriptions/{subscription_id}', update: '/subscriptions/{subscription_id}', updatePreview: '/subscriptions/{subscription_id}/preview', list: '/subscriptions', cancel: '/subscriptions/{subscription_id}/cancel', pause: '/subscriptions/{subscription_id}/pause', resume: '/subscriptions/{subscription_id}/resume', activate: '/subscriptions/{subscription_id}/activate', createOneTimeCharge: '/subscriptions/{subscription_id}/charge', previewOneTimeCharge: '/subscriptions/{subscription_id}/charge/preview', getTransactionToUpdatePaymentMethod: '/subscriptions/{subscription_id}/update-payment-method-transaction', }; export * from './operations/index.js'; export class SubscriptionsResource extends BaseResource { previewUpdate(subscriptionId, updateSubscription) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.updatePreview, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.patch(urlWithPathParams, updateSubscription); const data = this.handleResponse(response); return new SubscriptionPreview(data); }); } update(subscriptionId, updateSubscription) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.update, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.patch(urlWithPathParams, updateSubscription); const data = this.handleResponse(response); return new Subscription(data); }); } list(queryParams) { const queryParameters = new QueryParameters(queryParams); return new SubscriptionCollection(this.client, SubscriptionPaths.list + queryParameters.toQueryString()); } get(subscriptionId, queryParams) { return __awaiter(this, void 0, void 0, function* () { const queryParameters = new QueryParameters(queryParams); const urlWithPathParams = new PathParameters(SubscriptionPaths.get, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.get(urlWithPathParams, queryParameters); const data = this.handleResponse(response); return new Subscription(data); }); } activate(subscriptionId) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.activate, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.post(urlWithPathParams, undefined); const data = this.handleResponse(response); return new Subscription(data); }); } pause(subscriptionId, requestBody) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.pause, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.post(urlWithPathParams, requestBody); const data = this.handleResponse(response); return new Subscription(data); }); } resume(subscriptionId, requestBody) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.resume, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.post(urlWithPathParams, requestBody); const data = this.handleResponse(response); return new Subscription(data); }); } cancel(subscriptionId, requestBody) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.cancel, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.post(urlWithPathParams, requestBody); const data = this.handleResponse(response); return new Subscription(data); }); } createOneTimeCharge(subscriptionId, requestBody) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.createOneTimeCharge, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.post(urlWithPathParams, requestBody); const data = this.handleResponse(response); return new Subscription(data); }); } previewOneTimeCharge(subscriptionId, requestBody) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.previewOneTimeCharge, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.post(urlWithPathParams, requestBody); const data = this.handleResponse(response); return new SubscriptionPreview(data); }); } getPaymentMethodChangeTransaction(subscriptionId) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(SubscriptionPaths.getTransactionToUpdatePaymentMethod, { subscription_id: subscriptionId, }).deriveUrl(); const response = yield this.client.get(urlWithPathParams); const data = this.handleResponse(response); return new Transaction(data); }); } }