@umituz/react-native-subscription 2.37.100 → 2.37.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.37.
|
|
3
|
+
"version": "2.37.102",
|
|
4
4
|
"description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -33,15 +33,22 @@ export async function deductCreditsOperation(
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
+
if (__DEV__) console.log('[DeductCreditsCommand] >>> starting transaction', { userId, cost, creditsRefPath: creditsRef.path });
|
|
37
|
+
|
|
36
38
|
const remaining = await runTransaction(async (tx: Transaction) => {
|
|
37
39
|
const docSnap = await tx.get(creditsRef);
|
|
38
40
|
|
|
41
|
+
if (__DEV__) console.log('[DeductCreditsCommand] doc exists:', docSnap.exists());
|
|
42
|
+
|
|
39
43
|
if (!docSnap.exists()) {
|
|
40
44
|
throw new Error(CREDIT_ERROR_CODES.NO_CREDITS);
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const rawCredits = docSnap.data().credits;
|
|
44
48
|
const current = typeof rawCredits === "number" && Number.isFinite(rawCredits) ? rawCredits : 0;
|
|
49
|
+
|
|
50
|
+
if (__DEV__) console.log('[DeductCreditsCommand] current credits:', current, 'cost:', cost);
|
|
51
|
+
|
|
45
52
|
if (current < cost) {
|
|
46
53
|
throw new Error(CREDIT_ERROR_CODES.CREDITS_EXHAUSTED);
|
|
47
54
|
}
|
|
@@ -52,9 +59,13 @@ export async function deductCreditsOperation(
|
|
|
52
59
|
lastUpdatedAt: serverTimestamp()
|
|
53
60
|
});
|
|
54
61
|
|
|
62
|
+
if (__DEV__) console.log('[DeductCreditsCommand] updated credits to:', updated);
|
|
63
|
+
|
|
55
64
|
return updated;
|
|
56
65
|
});
|
|
57
66
|
|
|
67
|
+
if (__DEV__) console.log('[DeductCreditsCommand] transaction SUCCESS, remaining:', remaining);
|
|
68
|
+
|
|
58
69
|
subscriptionEventBus.emit(SUBSCRIPTION_EVENTS.CREDITS_UPDATED, userId);
|
|
59
70
|
|
|
60
71
|
return {
|
|
@@ -68,6 +79,8 @@ export async function deductCreditsOperation(
|
|
|
68
79
|
? message
|
|
69
80
|
: CREDIT_ERROR_CODES.DEDUCT_ERR;
|
|
70
81
|
|
|
82
|
+
if (__DEV__) console.error('[DeductCreditsCommand] transaction FAILED:', { code, message });
|
|
83
|
+
|
|
71
84
|
return {
|
|
72
85
|
success: false,
|
|
73
86
|
remainingCredits: null,
|
|
@@ -19,6 +19,7 @@ export function createDeductCreditMutationConfig(
|
|
|
19
19
|
) {
|
|
20
20
|
return {
|
|
21
21
|
mutationFn: async (cost: number): Promise<DeductCreditsResult> => {
|
|
22
|
+
if (__DEV__) console.log('[deductCreditMutation] mutationFn called', { userId, cost });
|
|
22
23
|
if (!userId) throw new Error("User not authenticated");
|
|
23
24
|
return repository.deductCredit(userId, cost);
|
|
24
25
|
},
|
|
@@ -22,17 +22,21 @@ export const useDeductCredit = ({
|
|
|
22
22
|
mutateAsyncRef.current = mutation.mutateAsync;
|
|
23
23
|
|
|
24
24
|
const deductCredit = useCallback(async (cost: number = 1): Promise<boolean> => {
|
|
25
|
+
if (__DEV__) console.log('[useDeductCredit] >>> deductCredit called', { cost, userId });
|
|
25
26
|
try {
|
|
26
27
|
const res = await mutateAsyncRef.current(cost);
|
|
28
|
+
if (__DEV__) console.log('[useDeductCredit] mutation result:', JSON.stringify(res));
|
|
27
29
|
if (!res.success) {
|
|
30
|
+
if (__DEV__) console.log('[useDeductCredit] deduction FAILED:', res.error?.code, res.error?.message);
|
|
28
31
|
if (res.error?.code === "CREDITS_EXHAUSTED") {
|
|
29
32
|
onCreditsExhausted?.();
|
|
30
33
|
}
|
|
31
34
|
return false;
|
|
32
35
|
}
|
|
36
|
+
if (__DEV__) console.log('[useDeductCredit] deduction SUCCESS, remaining:', res.remainingCredits);
|
|
33
37
|
return true;
|
|
34
38
|
} catch (error) {
|
|
35
|
-
console.error('[useDeductCredit]
|
|
39
|
+
if (__DEV__) console.error('[useDeductCredit] UNEXPECTED ERROR during credit deduction', {
|
|
36
40
|
cost,
|
|
37
41
|
userId,
|
|
38
42
|
error: error instanceof Error ? error.message : String(error)
|