@paritydeals/node-sdk
Version:
Node.js SDK for interacting with the ParityDeals API.
54 lines • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckoutOperations = void 0;
const constants_1 = require("./constants");
// import { InvalidRequestError } from './exceptions'; // Only if doing runtime Zod validation here
// import { CreateCheckoutSessionPayloadSchema } from './models'; // If using Zod
/**
* Handles 'checkout' related API operations.
* This class is instantiated by the ParityDeals client and accessed
* via `client.checkout`. All methods are asynchronous.
*/
class CheckoutOperations {
constructor(client) {
this.client = client;
this.client.logger.debug("CheckoutOperations initialized.");
}
/**
* Creates a new checkout session.
* @param params - Parameters for creating a checkout session, matching the CreateCheckoutSessionPayload interface.
* - pricingTableId: string
* - ruleId: string
* - chargePeriod: ChargePeriod
* - customerId: string
* - features: FeatureListItem[]
* - planIdentifier: string
* - successUrl: string
* - offeringId?: string | null
* - ipAddress?: string | null
* @returns A Promise resolving to CreateCheckoutSessionResponse.
*/
async createSession(
// The 'params' object directly matches the CreateCheckoutSessionPayload interface
params) {
this.client.logger.info(`Initiating createCheckoutSession for customerId: ${params.customerId}, pricingTableId: ${params.pricingTableId}`);
// The 'params' object is already the payload.
// If CreateCheckoutSessionPayload interface exactly matches what the method should accept,
// no further internal construction of a 'payload' object is needed here.
// It's passed directly to the client._request method.
// Optional: Add runtime validation using Zod here if desired
// try {
// CreateCheckoutSessionPayloadSchema.parse(params); // Assuming Zod schema
// } catch (error: any) {
// this.client.logger.warn(`Runtime validation failed for createSession: ${JSON.stringify(error.errors)}`);
// throw new InvalidRequestError("Invalid parameters for createSession", undefined, error.errors);
// }
const endpointModulePath = `${constants_1.CHECKOUT_MODULE_PREFIX}/`; // POST to /checkout/
this.client.logger.debug(`CreateCheckoutSession payload (camelCase, before client processing): ${JSON.stringify(params)}`);
// The client._request method will handle converting payload keys to snake_case
return this.client._request("POST", endpointModulePath, params // Pass the params object directly as the payload
);
}
}
exports.CheckoutOperations = CheckoutOperations;
//# sourceMappingURL=checkout.js.map