adding tests for new attach flows
This commit is contained in:
6
shared/enums/APIVersion.ts
Normal file
6
shared/enums/APIVersion.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export enum APIVersion {
|
||||
v1 = 1,
|
||||
v1_1 = 1.1,
|
||||
v1_2 = 1.2,
|
||||
v1_4 = 1.4,
|
||||
}
|
||||
@@ -129,3 +129,4 @@ export * from "./enums/SuccessCode.js";
|
||||
export * from "./enums/ErrCode.js";
|
||||
export * from "./enums/LoggerAction.js";
|
||||
export * from "./enums/AttachErrCode.js";
|
||||
export * from "./enums/APIVersion.js";
|
||||
|
||||
@@ -12,4 +12,5 @@ export interface AttachConfig {
|
||||
branch: AttachBranch;
|
||||
proration: ProrationBehavior;
|
||||
disableTrial: boolean;
|
||||
invoiceOnly: boolean;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
import { AttachBranch } from "./attachEnums/AttachBranch.js";
|
||||
|
||||
export interface PreviewLineItem {
|
||||
amount: number;
|
||||
description: string;
|
||||
price: string;
|
||||
}
|
||||
|
||||
export interface AttachPreview {
|
||||
branch: AttachBranch;
|
||||
options: any;
|
||||
new_items: any;
|
||||
due_today: {
|
||||
line_items: PreviewLineItem[];
|
||||
total: string;
|
||||
};
|
||||
due_next_cycle: {
|
||||
line_items: PreviewLineItem[];
|
||||
due_at: number;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ export const CusProductSchema = z.object({
|
||||
.optional(),
|
||||
|
||||
quantity: z.number().default(1),
|
||||
api_version: z.number().nullish(),
|
||||
});
|
||||
|
||||
export const FullCusProductSchema = CusProductSchema.extend({
|
||||
|
||||
@@ -47,6 +47,7 @@ export const customerProducts = pgTable(
|
||||
// Optional...
|
||||
customer_id: text("customer_id"),
|
||||
entity_id: text("entity_id"),
|
||||
api_version: numeric({ mode: "number" }),
|
||||
},
|
||||
(table) => [
|
||||
foreignKey({
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
export enum APIVersion {
|
||||
v1 = 1,
|
||||
v1_1 = 1.1,
|
||||
v1_2 = 1.2,
|
||||
}
|
||||
|
||||
export enum AppEnv {
|
||||
Sandbox = "sandbox",
|
||||
Live = "live",
|
||||
|
||||
@@ -21,7 +21,7 @@ export const UsagePriceConfigSchema = z.object({
|
||||
internal_feature_id: z.string(),
|
||||
feature_id: z.string(),
|
||||
usage_tiers: z.array(UsageTierSchema),
|
||||
interval: z.nativeEnum(BillingInterval).optional(),
|
||||
interval: z.nativeEnum(BillingInterval),
|
||||
|
||||
// For usage in arrear
|
||||
stripe_meter_id: z.string().nullish(),
|
||||
|
||||
@@ -55,6 +55,10 @@ export const getSingularAndPlural = ({
|
||||
};
|
||||
};
|
||||
|
||||
export const numberWithCommas = (x: number) => {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
};
|
||||
|
||||
export const getFeatureInvoiceDescription = ({
|
||||
feature,
|
||||
usage,
|
||||
@@ -66,11 +70,12 @@ export const getFeatureInvoiceDescription = ({
|
||||
}) => {
|
||||
const { singular, plural } = getSingularAndPlural({ feature });
|
||||
|
||||
const usageStr = numberWithCommas(usage);
|
||||
if (billingUnits == 1) {
|
||||
if (usage == 1)
|
||||
return `${usage} ${singular}`; // eg. 1 credit
|
||||
else return `${usage} ${plural}`; // eg. 4 credits
|
||||
return `${usageStr} ${singular}`; // eg. 1 credit
|
||||
else return `${usageStr} ${plural}`; // eg. 4 credits
|
||||
} else {
|
||||
return `${usage} x ${billingUnits} ${plural}`; // eg. 4 x 100 credits
|
||||
return `${usageStr} x ${billingUnits} ${plural}`; // eg. 4 x 100 credits
|
||||
}
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ export function useAxiosInstance(params?: { env?: AppEnv; isAuth?: boolean }) {
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
config.headers["app_env"] = trueEnv;
|
||||
config.headers["api_version"] = "1.2";
|
||||
config.headers["x-api-version"] = "1.2";
|
||||
}
|
||||
|
||||
return config;
|
||||
|
||||
@@ -104,7 +104,6 @@ export default function CustomerProductView() {
|
||||
const attachState = useAttachState({
|
||||
product,
|
||||
setProduct,
|
||||
preview: data?.preview,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@@ -134,16 +133,12 @@ export default function CustomerProductView() {
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading) return <LoadingScreen />;
|
||||
if (isLoading || !product) return <LoadingScreen />;
|
||||
|
||||
if (!customer_id || !product_id) {
|
||||
return <div>Customer or product not found</div>;
|
||||
}
|
||||
|
||||
if (!product) {
|
||||
return <div>Product not found</div>;
|
||||
}
|
||||
|
||||
const { customer } = data;
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user