Skip to content

Commit 37191aa

Browse files
author
FalkWolsky
committed
Update of Subscription Apis to enable user cleanup possibility.
1 parent 155bab4 commit 37191aa

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

client/packages/lowcoder/src/api/subscriptionApi.ts

+16
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@ export const createCustomer = async (subscriptionCustomer: LowcoderNewCustomer)
182182
}
183183
};
184184

185+
export const cleanupCustomer = async (subscriptionCustomer: LowcoderSearchCustomer) => {
186+
const apiBody = {
187+
path: "webhook/secure/cleanup-customer",
188+
data: subscriptionCustomer,
189+
method: "post",
190+
headers: lcHeaders
191+
};
192+
try {
193+
const result = await SubscriptionApi.secureRequest(apiBody, 15000);
194+
return result?.data as any;
195+
} catch (error) {
196+
console.error("Error creating customer:", error);
197+
throw error;
198+
}
199+
};
200+
185201
export const getProduct = async (productId : string) => {
186202
const apiBody = {
187203
path: "webhook/secure/get-product",

client/packages/lowcoder/src/redux/sagas/subscriptionSagas.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { Subscription, LowcoderSearchCustomer } from '@lowcoder-ee/constants/sub
1111
function* fetchSubscriptionsSaga(action: ReturnType<typeof fetchSubscriptionsAction>) {
1212
try {
1313
const user: User = yield select(getUser);
14-
const currentUser: CurrentUser = yield select(getCurrentUser);
1514
const orgID = user.currentOrgId;
16-
const domain = `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`;
1715
const deploymentId: string = yield select(getDeploymentId);
1816

1917
const subscriptionSearchCustomer: LowcoderSearchCustomer = {

client/packages/lowcoder/src/util/context/SubscriptionContext.tsx

+4-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createCheckoutLink, createCustomer, getProducts, searchCustomer } from "@lowcoder-ee/api/subscriptionApi";
1+
import { createCheckoutLink, cleanupCustomer } from "@lowcoder-ee/api/subscriptionApi";
22
import { StripeCustomer, SubscriptionProduct, InitSubscriptionProducts, LowcoderSearchCustomer, LowcoderNewCustomer, Subscription } from "@lowcoder-ee/constants/subscriptionConstants";
33
import { getDeploymentId } from "@lowcoder-ee/redux/selectors/configSelectors";
44
import { getFetchSubscriptionsFinished, getSubscriptions, getSubscriptionsError } from "@lowcoder-ee/redux/selectors/subscriptionSelectors";
@@ -78,17 +78,6 @@ export const SubscriptionContextProvider = (props: {
7878
userId: user.id,
7979
};
8080

81-
const subscriptionNewCustomer: LowcoderNewCustomer = {
82-
hostname: domain,
83-
hostId: deploymentId,
84-
email: currentUser.email,
85-
orgId: orgID,
86-
userId: user.id,
87-
userName: user.username,
88-
type: admin,
89-
companyName: currentOrg?.name || "Unknown",
90-
};
91-
9281
useEffect(() => {
9382
// If products are already loaded in the outer context, reuse them
9483
if (productsLoaded) {
@@ -104,28 +93,11 @@ export const SubscriptionContextProvider = (props: {
10493
const initializeCustomer = async () => {
10594
if (existingCustomer) {
10695
setCustomer(existingCustomer);
96+
97+
cleanupCustomer(subscriptionSearchCustomer);
98+
10799
return;
108100
}
109-
110-
/* try {
111-
setIsCreatingCustomer(true);
112-
const subscriptionSearchCustomer: LowcoderSearchCustomer = {
113-
hostId: deploymentId,
114-
orgId: orgID,
115-
userId: user.id,
116-
};
117-
const existingCustomer = await searchCustomer(subscriptionSearchCustomer);
118-
if (existingCustomer) {
119-
setCustomer(existingCustomer);
120-
} else {
121-
const newCustomer = await createCustomer(subscriptionNewCustomer);
122-
setCustomer(newCustomer);
123-
}
124-
} catch (error) {
125-
setCustomerDataError(true);
126-
} finally {
127-
setIsCreatingCustomer(false);
128-
} */
129101
};
130102

131103
if (!customer && isCustomerInitializationComplete) {

0 commit comments

Comments
 (0)