@paddle/paddle-mcp
Version:
MCP Server for Paddle Billing
940 lines (939 loc) • 28.7 kB
JavaScript
const paginationData = (collection) => ({
hasMore: collection.hasMore,
estimatedTotal: collection.estimatedTotal,
});
// Transform comparison operator query parameters from underscore format to square bracket format
// Example: created_at_lt becomes created_at[LT], updated_at_gte becomes updated_at[GTE]
// Other parameters like customer_id, collection_mode are left unchanged
const transformParams = (params) => {
const operators = ["lt", "lte", "gt", "gte"];
return Object.entries(params).reduce((acc, [key, value]) => {
const parts = key.split("_");
const lastPart = parts[parts.length - 1];
if (parts.length >= 2 && operators.includes(lastPart)) {
const operator = parts.pop();
const base = parts.join("_");
acc[`${base}[${operator.toUpperCase()}]`] = value;
}
else {
acc[key] = value;
}
return acc;
}, {});
};
export const listProducts = async (paddle, params) => {
try {
const collection = paddle.products.list(params);
const products = await collection.next();
const pagination = paginationData(collection);
return { pagination, products };
}
catch (error) {
return error;
}
};
export const createProduct = async (paddle, params) => {
try {
const product = await paddle.products.create(params);
return product;
}
catch (error) {
return error;
}
};
export const getProduct = async (paddle, params) => {
try {
const { productId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const product = await paddle.products.get(productId, hasQueryParams ? queryParams : undefined);
return product;
}
catch (error) {
return error;
}
};
export const updateProduct = async (paddle, params) => {
try {
const { productId, ...updateData } = params;
const product = await paddle.products.update(productId, updateData);
return product;
}
catch (error) {
return error;
}
};
export const listPrices = async (paddle, params) => {
try {
const collection = paddle.prices.list(params);
const prices = await collection.next();
const pagination = paginationData(collection);
return { pagination, prices };
}
catch (error) {
return error;
}
};
export const createPrice = async (paddle, params) => {
try {
const price = await paddle.prices.create(params);
return price;
}
catch (error) {
return error;
}
};
export const getPrice = async (paddle, params) => {
try {
const { priceId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const price = await paddle.prices.get(priceId, hasQueryParams ? queryParams : undefined);
return price;
}
catch (error) {
return error;
}
};
export const updatePrice = async (paddle, params) => {
try {
const { priceId, ...updateData } = params;
const price = await paddle.prices.update(priceId, updateData);
return price;
}
catch (error) {
return error;
}
};
export const listTransactions = async (paddle, params) => {
try {
const transformedParams = transformParams(params);
const collection = paddle.transactions.list(transformedParams);
const transactions = await collection.next();
const pagination = paginationData(collection);
return { pagination, transactions };
}
catch (error) {
return error;
}
};
export const createTransaction = async (paddle, params) => {
try {
const transaction = await paddle.transactions.create(params);
return transaction;
}
catch (error) {
return error;
}
};
export const previewPrices = async (paddle, params) => {
try {
const pricingPreview = await paddle.pricingPreview.preview(params);
return pricingPreview;
}
catch (error) {
return error;
}
};
export const previewTransactionCreate = async (paddle, params) => {
try {
const transaction = await paddle.transactions.preview(params);
return transaction;
}
catch (error) {
return error;
}
};
export const getTransaction = async (paddle, params) => {
try {
const { transactionId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const transaction = await paddle.transactions.get(transactionId, hasQueryParams ? queryParams : undefined);
return transaction;
}
catch (error) {
return error;
}
};
export const updateTransaction = async (paddle, params) => {
try {
const { transactionId, include, ...updateData } = params;
const queryParams = include ? { include } : undefined;
const transaction = await paddle.transactions.update(transactionId, updateData, queryParams);
return transaction;
}
catch (error) {
return error;
}
};
export const reviseTransaction = async (paddle, params) => {
try {
const { transactionId, ...updateData } = params;
const transaction = await paddle.transactions.revise(transactionId, updateData);
return transaction;
}
catch (error) {
return error;
}
};
export const listAdjustments = async (paddle, params) => {
try {
const collection = paddle.adjustments.list(params);
const adjustments = await collection.next();
const pagination = paginationData(collection);
return { pagination, adjustments };
}
catch (error) {
return error;
}
};
export const createAdjustment = async (paddle, params) => {
try {
const adjustment = await paddle.adjustments.create(params);
return adjustment;
}
catch (error) {
return error;
}
};
export const getAdjustmentCreditNote = async (paddle, params) => {
try {
const { adjustmentId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const adjustment = await paddle.adjustments.getCreditNotePDF(adjustmentId, hasQueryParams ? queryParams : undefined);
return adjustment;
}
catch (error) {
return error;
}
};
export const listCreditBalances = async (paddle, params) => {
try {
const { customerId, ...queryParams } = params;
const result = await paddle.customers.getCreditBalance(customerId, queryParams);
return result;
}
catch (error) {
return error;
}
};
export const listCustomers = async (paddle, params) => {
try {
const collection = paddle.customers.list(params);
const customers = await collection.next();
const pagination = paginationData(collection);
return { pagination, customers };
}
catch (error) {
return error;
}
};
export const createCustomer = async (paddle, params) => {
try {
const customer = await paddle.customers.create(params);
return customer;
}
catch (error) {
return error;
}
};
export const getCustomer = async (paddle, params) => {
try {
const { customerId } = params;
const customer = await paddle.customers.get(customerId);
return customer;
}
catch (error) {
return error;
}
};
export const updateCustomer = async (paddle, params) => {
try {
const { customerId, ...updateData } = params;
const customer = await paddle.customers.update(customerId, updateData);
return customer;
}
catch (error) {
return error;
}
};
export const listAddresses = async (paddle, params) => {
try {
const { customerId, ...queryParams } = params;
const collection = paddle.addresses.list(customerId, queryParams);
const addresses = await collection.next();
const pagination = paginationData(collection);
return { pagination, addresses };
}
catch (error) {
return error;
}
};
export const createAddress = async (paddle, params) => {
try {
const { customerId, ...updateData } = params;
const address = await paddle.addresses.create(customerId, updateData);
return address;
}
catch (error) {
return error;
}
};
export const getAddress = async (paddle, params) => {
try {
const { customerId, addressId } = params;
const address = await paddle.addresses.get(customerId, addressId);
return address;
}
catch (error) {
return error;
}
};
export const updateAddress = async (paddle, params) => {
try {
const { customerId, addressId, ...updateData } = params;
const address = await paddle.addresses.update(customerId, addressId, updateData);
return address;
}
catch (error) {
return error;
}
};
export const listBusinesses = async (paddle, params) => {
try {
const { customerId, ...queryParams } = params;
const collection = paddle.businesses.list(customerId, queryParams);
const businesses = await collection.next();
const pagination = paginationData(collection);
return { pagination, businesses };
}
catch (error) {
return error;
}
};
export const createBusiness = async (paddle, params) => {
try {
const { customerId, ...updateData } = params;
const business = await paddle.businesses.create(customerId, updateData);
return business;
}
catch (error) {
return error;
}
};
export const getBusiness = async (paddle, params) => {
try {
const { customerId, businessId } = params;
const business = await paddle.businesses.get(customerId, businessId);
return business;
}
catch (error) {
return error;
}
};
export const updateBusiness = async (paddle, params) => {
try {
const { customerId, businessId, ...updateData } = params;
const business = await paddle.businesses.update(customerId, businessId, updateData);
return business;
}
catch (error) {
return error;
}
};
export const listSavedPaymentMethods = async (paddle, params) => {
try {
const { customerId, ...queryParams } = params;
const collection = paddle.paymentMethods.list(customerId, queryParams);
const paymentMethods = await collection.next();
const pagination = paginationData(collection);
return { pagination, paymentMethods };
}
catch (error) {
return error;
}
};
export const getSavedPaymentMethod = async (paddle, params) => {
try {
const { customerId, paymentMethodId } = params;
const paymentMethod = await paddle.paymentMethods.get(customerId, paymentMethodId);
return paymentMethod;
}
catch (error) {
return error;
}
};
export const deleteSavedPaymentMethod = async (paddle, params) => {
try {
const { customerId, paymentMethodId } = params;
const paymentMethod = await paddle.paymentMethods.delete(customerId, paymentMethodId);
return paymentMethod;
}
catch (error) {
return error;
}
};
export const createCustomerPortalSession = async (paddle, params) => {
try {
const { customerId, subscriptionIds } = params;
const customerPortalSession = await paddle.customerPortalSessions.create(customerId, subscriptionIds);
return customerPortalSession;
}
catch (error) {
return error;
}
};
export const listNotificationSettings = async (paddle, params) => {
try {
const result = await paddle.notificationSettings.list(params);
return result;
}
catch (error) {
return error;
}
};
export const createNotificationSetting = async (paddle, params) => {
try {
const notificationSetting = await paddle.notificationSettings.create(params);
return notificationSetting;
}
catch (error) {
return error;
}
};
export const getNotificationSetting = async (paddle, params) => {
try {
const { notificationSettingId } = params;
const notificationSetting = await paddle.notificationSettings.get(notificationSettingId);
return notificationSetting;
}
catch (error) {
return error;
}
};
export const updateNotificationSetting = async (paddle, params) => {
try {
const { notificationSettingId, ...updateData } = params;
const notificationSetting = await paddle.notificationSettings.update(notificationSettingId, updateData);
return notificationSetting;
}
catch (error) {
return error;
}
};
export const deleteNotificationSetting = async (paddle, params) => {
try {
const { notificationSettingId } = params;
const notificationSetting = await paddle.notificationSettings.delete(notificationSettingId);
return notificationSetting;
}
catch (error) {
return error;
}
};
export const listEvents = async (paddle, params) => {
try {
const collection = paddle.events.list(params);
const events = await collection.next();
const pagination = paginationData(collection);
return { pagination, events };
}
catch (error) {
return error;
}
};
export const listNotifications = async (paddle, params) => {
try {
const collection = paddle.notifications.list(params);
const notifications = await collection.next();
const pagination = paginationData(collection);
return { pagination, notifications };
}
catch (error) {
return error;
}
};
export const getNotification = async (paddle, params) => {
try {
const { notificationId } = params;
const notification = await paddle.notifications.get(notificationId);
return notification;
}
catch (error) {
return error;
}
};
export const listNotificationLogs = async (paddle, params) => {
try {
const { notificationId, ...queryParams } = params;
const collection = paddle.notifications.getLogs(notificationId, queryParams);
const notifications = await collection.next();
const pagination = paginationData(collection);
return { pagination, notifications };
}
catch (error) {
return error;
}
};
export const replayNotification = async (paddle, params) => {
try {
const { notificationId } = params;
const notification = await paddle.notifications.replay(notificationId);
return notification;
}
catch (error) {
return error;
}
};
export const listSimulations = async (paddle, params) => {
try {
const collection = paddle.simulations.list(params);
const simulations = await collection.next();
const pagination = paginationData(collection);
return { pagination, simulations };
}
catch (error) {
return error;
}
};
export const createSimulation = async (paddle, params) => {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const simulation = await paddle.simulations.create(params);
return simulation;
}
catch (error) {
return error;
}
};
export const getSimulation = async (paddle, params) => {
try {
const { simulationId } = params;
const simulation = await paddle.simulations.get(simulationId);
return simulation;
}
catch (error) {
return error;
}
};
export const updateSimulation = async (paddle, params) => {
try {
const { simulationId, ...updateData } = params;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const simulation = await paddle.simulations.update(simulationId, updateData);
return simulation;
}
catch (error) {
return error;
}
};
export const listSimulationRuns = async (paddle, params) => {
try {
const { simulationId, ...queryParams } = params;
const collection = paddle.simulationRuns.list(simulationId, queryParams);
const simulationRuns = await collection.next();
const pagination = paginationData(collection);
return { pagination, simulationRuns };
}
catch (error) {
return error;
}
};
export const createSimulationRun = async (paddle, params) => {
try {
const { simulationId } = params;
const simulationRun = await paddle.simulationRuns.create(simulationId);
return simulationRun;
}
catch (error) {
return error;
}
};
export const getSimulationRun = async (paddle, params) => {
try {
const { simulationId, simulationRunId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const simulationRun = await paddle.simulationRuns.get(simulationId, simulationRunId, hasQueryParams ? queryParams : undefined);
return simulationRun;
}
catch (error) {
return error;
}
};
export const listSimulationRunEvents = async (paddle, params) => {
try {
const { simulationId, simulationRunId, ...queryParams } = params;
const collection = paddle.simulationRunEvents.list(simulationId, simulationRunId, queryParams);
const simulationRunEvents = await collection.next();
const pagination = paginationData(collection);
return { pagination, simulationRunEvents };
}
catch (error) {
return error;
}
};
export const getSimulationRunEvent = async (paddle, params) => {
try {
const { simulationId, simulationRunId, simulationEventId } = params;
const simulationRunEvent = await paddle.simulationRunEvents.get(simulationId, simulationRunId, simulationEventId);
return simulationRunEvent;
}
catch (error) {
return error;
}
};
export const replaySimulationRunEvent = async (paddle, params) => {
try {
const { simulationId, simulationRunId, simulationEventId } = params;
const simulationRunEvent = await paddle.simulationRunEvents.replay(simulationId, simulationRunId, simulationEventId);
return simulationRunEvent;
}
catch (error) {
return error;
}
};
export const getTransactionInvoice = async (paddle, params) => {
try {
const { transactionId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const transaction = await paddle.transactions.getInvoicePDF(transactionId, hasQueryParams ? queryParams : undefined);
return transaction;
}
catch (error) {
return error;
}
};
export const listDiscounts = async (paddle, params) => {
try {
const collection = paddle.discounts.list(params);
const discounts = await collection.next();
const pagination = paginationData(collection);
return { pagination, discounts };
}
catch (error) {
return error;
}
};
export const createDiscount = async (paddle, params) => {
try {
const discount = await paddle.discounts.create(params);
return discount;
}
catch (error) {
return error;
}
};
export const getDiscount = async (paddle, params) => {
try {
const { discountId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const discount = await paddle.discounts.get(discountId, hasQueryParams ? queryParams : undefined);
return discount;
}
catch (error) {
return error;
}
};
export const updateDiscount = async (paddle, params) => {
try {
const { discountId, ...updateData } = params;
const discount = await paddle.discounts.update(discountId, updateData);
return discount;
}
catch (error) {
return error;
}
};
export const getDiscountGroup = async (paddle, params) => {
try {
const { discountGroupId } = params;
const discountGroup = await paddle.discountGroups.get(discountGroupId);
return discountGroup;
}
catch (error) {
return error;
}
};
export const updateDiscountGroup = async (paddle, params) => {
try {
const { discountGroupId, ...updateData } = params;
const discountGroup = await paddle.discountGroups.update(discountGroupId, updateData);
return discountGroup;
}
catch (error) {
return error;
}
};
export const listDiscountGroups = async (paddle, params) => {
try {
const collection = paddle.discountGroups.list(params);
const discountGroups = await collection.next();
const pagination = paginationData(collection);
return { pagination, discountGroups };
}
catch (error) {
return error;
}
};
export const createDiscountGroup = async (paddle, params) => {
try {
const discountGroup = await paddle.discountGroups.create(params);
return discountGroup;
}
catch (error) {
return error;
}
};
export const archiveDiscountGroup = async (paddle, params) => {
try {
const { discountGroupId } = params;
const discountGroup = await paddle.discountGroups.archive(discountGroupId);
return discountGroup;
}
catch (error) {
return error;
}
};
export const getSubscription = async (paddle, params) => {
try {
const { subscriptionId, ...queryParams } = params;
const hasQueryParams = Object.keys(queryParams).length > 0;
const subscription = await paddle.subscriptions.get(subscriptionId, hasQueryParams ? queryParams : undefined);
return subscription;
}
catch (error) {
return error;
}
};
export const updateSubscription = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.update(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const listSubscriptions = async (paddle, params) => {
try {
const collection = paddle.subscriptions.list(params);
const subscriptions = await collection.next();
const pagination = paginationData(collection);
return { pagination, subscriptions };
}
catch (error) {
return error;
}
};
export const cancelSubscription = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.cancel(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const pauseSubscription = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.pause(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const resumeSubscription = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.resume(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const activateSubscription = async (paddle, params) => {
try {
const { subscriptionId } = params;
const subscription = await paddle.subscriptions.activate(subscriptionId);
return subscription;
}
catch (error) {
return error;
}
};
export const previewSubscriptionUpdate = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.previewUpdate(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const createSubscriptionCharge = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.createOneTimeCharge(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const previewSubscriptionCharge = async (paddle, params) => {
try {
const { subscriptionId, ...updateData } = params;
const subscription = await paddle.subscriptions.previewOneTimeCharge(subscriptionId, updateData);
return subscription;
}
catch (error) {
return error;
}
};
export const listReports = async (paddle, params) => {
try {
const collection = paddle.reports.list(params);
const reports = await collection.next();
const pagination = paginationData(collection);
return { pagination, reports };
}
catch (error) {
return error;
}
};
export const createReport = async (paddle, params) => {
try {
const report = await paddle.reports.create(params);
return report;
}
catch (error) {
return error;
}
};
export const getReportCsv = async (paddle, params) => {
try {
const { reportId } = params;
const report = await paddle.reports.getReportCsv(reportId);
return report;
}
catch (error) {
return error;
}
};
export const getReport = async (paddle, params) => {
try {
const { reportId } = params;
const report = await paddle.reports.get(reportId);
return report;
}
catch (error) {
return error;
}
};
export const createClientSideToken = async (paddle, params) => {
try {
const clientSideToken = await paddle.clientTokens.create(params);
return clientSideToken;
}
catch (error) {
return error;
}
};
export const getClientSideToken = async (paddle, params) => {
try {
const { clientTokenId } = params;
const clientSideToken = await paddle.clientTokens.get(clientTokenId);
return clientSideToken;
}
catch (error) {
return error;
}
};
export const revokeClientSideToken = async (paddle, params) => {
try {
const { clientTokenId } = params;
const clientSideToken = await paddle.clientTokens.revoke(clientTokenId);
return clientSideToken;
}
catch (error) {
return error;
}
};
export const listClientSideTokens = async (paddle, params) => {
try {
const collection = paddle.clientTokens.list(params);
const clientSideTokens = await collection.next();
const pagination = paginationData(collection);
return { pagination, clientSideTokens };
}
catch (error) {
return error;
}
};
export const getActiveSubscribers = async (paddle, params) => {
try {
const activeSubscribers = await paddle.metrics.getActiveSubscribers(params);
return activeSubscribers;
}
catch (error) {
return error;
}
};
export const getMonthlyRecurringRevenue = async (paddle, params) => {
try {
const monthlyRecurringRevenue = await paddle.metrics.getMonthlyRecurringRevenue(params);
return monthlyRecurringRevenue;
}
catch (error) {
return error;
}
};
export const getRevenue = async (paddle, params) => {
try {
const revenue = await paddle.metrics.getRevenue(params);
return revenue;
}
catch (error) {
return error;
}
};
export const getRefunds = async (paddle, params) => {
try {
const refunds = await paddle.metrics.getRefunds(params);
return refunds;
}
catch (error) {
return error;
}
};
export const getChargebacks = async (paddle, params) => {
try {
const chargebacks = await paddle.metrics.getChargebacks(params);
return chargebacks;
}
catch (error) {
return error;
}
};
export const getCheckoutConversion = async (paddle, params) => {
try {
const checkoutConversion = await paddle.metrics.getCheckoutConversion(params);
return checkoutConversion;
}
catch (error) {
return error;
}
};
export const getMonthlyRecurringRevenueChange = async (paddle, params) => {
try {
const monthlyRecurringRevenueChange = await paddle.metrics.getMonthlyRecurringRevenueChange(params);
return monthlyRecurringRevenueChange;
}
catch (error) {
return error;
}
};