@paddle/paddle-node-sdk
Version:
A Node.js SDK that you can use to integrate Paddle Billing with applications written in server-side JavaScript.
86 lines (85 loc) • 4.49 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());
});
};
import { BaseResource, PathParameters, QueryParameters } from '../../internal/base/index.js';
import { Transaction, TransactionCollection, TransactionInvoicePDF, TransactionPreview } from '../../entities/index.js';
const TransactionPaths = {
list: '/transactions',
create: '/transactions',
get: '/transactions/{transaction_id}',
update: '/transactions/{transaction_id}',
getInvoicePDF: '/transactions/{transaction_id}/invoice',
preview: '/transactions/preview',
revise: '/transactions/{transaction_id}/revise',
};
export * from './operations/index.js';
export class TransactionsResource extends BaseResource {
list(queryParams) {
const queryParameters = new QueryParameters(queryParams);
return new TransactionCollection(this.client, TransactionPaths.list + queryParameters.toQueryString());
}
create(createTransactionParameters, queryParams) {
return __awaiter(this, void 0, void 0, function* () {
const queryParameters = new QueryParameters(queryParams);
const response = yield this.client.post(TransactionPaths.create + queryParameters.toQueryString(), createTransactionParameters);
const data = this.handleResponse(response);
return new Transaction(data);
});
}
update(transactionId, updateTransaction, queryParams) {
return __awaiter(this, void 0, void 0, function* () {
const queryParameters = new QueryParameters(queryParams);
const urlWithPathParams = new PathParameters(TransactionPaths.update, {
transaction_id: transactionId,
}).deriveUrl();
const response = yield this.client.patch(urlWithPathParams + queryParameters.toQueryString(), updateTransaction);
const data = this.handleResponse(response);
return new Transaction(data);
});
}
get(transactionId, queryParams) {
return __awaiter(this, void 0, void 0, function* () {
const queryParameters = new QueryParameters(queryParams);
const urlWithPathParams = new PathParameters(TransactionPaths.get, {
transaction_id: transactionId,
}).deriveUrl();
const response = yield this.client.get(urlWithPathParams, queryParameters);
const data = this.handleResponse(response);
return new Transaction(data);
});
}
getInvoicePDF(transactionId, queryParams) {
return __awaiter(this, void 0, void 0, function* () {
const queryParameters = new QueryParameters(queryParams);
const urlWithPathParams = new PathParameters(TransactionPaths.getInvoicePDF, {
transaction_id: transactionId,
}).deriveUrl();
const response = yield this.client.get(urlWithPathParams + queryParameters.toQueryString());
const data = this.handleResponse(response);
return new TransactionInvoicePDF(data);
});
}
preview(previewTransactionParameters) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.post(TransactionPaths.preview, previewTransactionParameters);
const data = this.handleResponse(response);
return new TransactionPreview(data);
});
}
revise(transactionId, reviseTransaction) {
return __awaiter(this, void 0, void 0, function* () {
const urlWithPathParams = new PathParameters(TransactionPaths.revise, {
transaction_id: transactionId,
}).deriveUrl();
const response = yield this.client.post(urlWithPathParams, reviseTransaction);
const data = this.handleResponse(response);
return new Transaction(data);
});
}
}