@tagadapay/plugin-sdk 2.4.34 → 2.4.36

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.
@@ -1,15 +0,0 @@
1
- import type { CustomerInfos } from '../types';
2
- export interface UseCustomerInfosOptions {
3
- customerId?: string | null;
4
- enabled?: boolean;
5
- }
6
- export interface UseCustomerInfosResult {
7
- data: CustomerInfos | null;
8
- isLoading: boolean;
9
- error: Error | null;
10
- refetch: () => Promise<void>;
11
- }
12
- /**
13
- * useCustomerInfos - Fetches customer infos from `/api/v1/customers/{customerId}` with `storeId` param
14
- */
15
- export declare function useCustomerInfos(options: UseCustomerInfosOptions): UseCustomerInfosResult;
@@ -1,54 +0,0 @@
1
- 'use client';
2
- import { useCallback, useEffect, useMemo, useState } from 'react';
3
- import { useTagadaContext } from '../providers/TagadaProvider';
4
- import { usePluginConfig } from './usePluginConfig';
5
- /**
6
- * useCustomerInfos - Fetches customer infos from `/api/v1/customers/{customerId}` with `storeId` param
7
- */
8
- export function useCustomerInfos(options) {
9
- const { apiService } = useTagadaContext();
10
- const { storeId } = usePluginConfig();
11
- const stableOptions = useMemo(() => {
12
- return {
13
- customerId: options.customerId ?? null,
14
- enabled: options.enabled ?? true,
15
- };
16
- }, [options.customerId, options.enabled]);
17
- const isEnabled = useMemo(() => {
18
- return Boolean(stableOptions.enabled && stableOptions.customerId && storeId);
19
- }, [stableOptions.enabled, stableOptions.customerId, storeId]);
20
- const [data, setData] = useState(null);
21
- const [isLoading, setIsLoading] = useState(false);
22
- const [error, setError] = useState(null);
23
- const fetchCustomerInfos = useCallback(async () => {
24
- if (!isEnabled)
25
- return;
26
- if (!stableOptions.customerId || !storeId)
27
- return;
28
- setIsLoading(true);
29
- setError(null);
30
- try {
31
- const response = await apiService.fetch(`/api/v1/customers/${stableOptions.customerId}`, {
32
- method: 'GET',
33
- params: { storeId },
34
- });
35
- setData(response ?? null);
36
- }
37
- catch (err) {
38
- const safeError = err instanceof Error ? err : new Error('Failed to fetch customer infos');
39
- setError(safeError);
40
- }
41
- finally {
42
- setIsLoading(false);
43
- }
44
- }, [apiService, isEnabled, stableOptions.customerId, storeId]);
45
- useEffect(() => {
46
- void fetchCustomerInfos();
47
- }, [fetchCustomerInfos]);
48
- return {
49
- data,
50
- isLoading,
51
- error,
52
- refetch: fetchCustomerInfos,
53
- };
54
- }
@@ -1,14 +0,0 @@
1
- import type { OrderWithRelations } from '../types';
2
- export interface UseCustomerOrdersOptions {
3
- customerId?: string | null;
4
- enabled?: boolean;
5
- }
6
- export interface UseCustomerOrdersResult {
7
- data: {
8
- orders: OrderWithRelations[];
9
- } | null;
10
- isLoading: boolean;
11
- error: Error | null;
12
- refetch: () => Promise<void>;
13
- }
14
- export declare function useCustomerOrders(options: UseCustomerOrdersOptions): UseCustomerOrdersResult;
@@ -1,51 +0,0 @@
1
- 'use client';
2
- import { useCallback, useEffect, useMemo, useState } from 'react';
3
- import { useTagadaContext } from '../providers/TagadaProvider';
4
- import { usePluginConfig } from './usePluginConfig';
5
- export function useCustomerOrders(options) {
6
- const { apiService } = useTagadaContext();
7
- const { storeId } = usePluginConfig();
8
- const stableOptions = useMemo(() => {
9
- return {
10
- customerId: options.customerId ?? null,
11
- enabled: options.enabled ?? true,
12
- };
13
- }, [options.customerId, options.enabled]);
14
- const isEnabled = useMemo(() => {
15
- return Boolean(stableOptions.enabled && stableOptions.customerId && storeId);
16
- }, [stableOptions.enabled, stableOptions.customerId, storeId]);
17
- const [data, setData] = useState(null);
18
- const [isLoading, setIsLoading] = useState(false);
19
- const [error, setError] = useState(null);
20
- const fetchOrders = useCallback(async () => {
21
- if (!isEnabled)
22
- return;
23
- if (!stableOptions.customerId || !storeId)
24
- return;
25
- setIsLoading(true);
26
- setError(null);
27
- try {
28
- const response = await apiService.fetch(`/api/v1/orders/customer/${stableOptions.customerId}`, {
29
- method: 'GET',
30
- params: { storeId },
31
- });
32
- setData(response ?? null);
33
- }
34
- catch (err) {
35
- const safeError = err instanceof Error ? err : new Error('Failed to fetch customer orders');
36
- setError(safeError);
37
- }
38
- finally {
39
- setIsLoading(false);
40
- }
41
- }, [apiService, isEnabled, stableOptions.customerId, storeId]);
42
- useEffect(() => {
43
- void fetchOrders();
44
- }, [fetchOrders]);
45
- return {
46
- data,
47
- isLoading,
48
- error,
49
- refetch: fetchOrders,
50
- };
51
- }
@@ -1,56 +0,0 @@
1
- export interface Subscription {
2
- id: string;
3
- status: string;
4
- createdAt: string;
5
- currency: string;
6
- cancelAtPeriodEnd: boolean;
7
- currentPeriodEnd: string | null;
8
- currentPeriodStart: string | null;
9
- quantity: number;
10
- trialEnd: string | null;
11
- customerId: string;
12
- customerEmail: string;
13
- customerName: string;
14
- priceCurrencyOptions: Record<string, {
15
- rate: number;
16
- amount: number;
17
- lock: boolean;
18
- date: string;
19
- }>;
20
- priceInterval: string;
21
- priceIntervalCount: number;
22
- priceRecurring: boolean;
23
- productId: string;
24
- priceId: string;
25
- productTitle: string;
26
- }
27
- export interface SubscriptionsResponse {
28
- items: Subscription[];
29
- pagination: {
30
- page: number;
31
- pageSize: number;
32
- hasNext: boolean;
33
- nextPage: number | null;
34
- previousPage: number | null;
35
- totalItems: number;
36
- };
37
- }
38
- export interface UseCustomerSubscriptionsOptions {
39
- customerId?: string | null;
40
- enabled?: boolean;
41
- }
42
- export interface UseCustomerSubscriptionsResult {
43
- data: SubscriptionsResponse | null;
44
- isLoading: boolean;
45
- error: Error | null;
46
- refetch: () => Promise<void>;
47
- resumeSubscription: (subscriptionId: string) => Promise<{
48
- success: boolean;
49
- error?: string;
50
- }>;
51
- cancelSubscription: (subscriptionId: string) => Promise<{
52
- success: boolean;
53
- error?: string;
54
- }>;
55
- }
56
- export declare function useCustomerSubscriptions(options: UseCustomerSubscriptionsOptions): UseCustomerSubscriptionsResult;
@@ -1,77 +0,0 @@
1
- 'use client';
2
- import { useCallback, useEffect, useMemo, useState } from 'react';
3
- import { useTagadaContext } from '../providers/TagadaProvider';
4
- export function useCustomerSubscriptions(options) {
5
- const { apiService } = useTagadaContext();
6
- const stableOptions = useMemo(() => {
7
- return {
8
- customerId: options.customerId ?? null,
9
- enabled: options.enabled ?? true,
10
- };
11
- }, [options.customerId, options.enabled]);
12
- const isEnabled = useMemo(() => {
13
- return Boolean(stableOptions.enabled && stableOptions.customerId);
14
- }, [stableOptions.enabled, stableOptions.customerId]);
15
- const [data, setData] = useState(null);
16
- const [isLoading, setIsLoading] = useState(false);
17
- const [error, setError] = useState(null);
18
- const fetchSubscriptions = useCallback(async () => {
19
- if (!isEnabled)
20
- return;
21
- setIsLoading(true);
22
- setError(null);
23
- try {
24
- // Token-authenticated request; backend infers customer from token
25
- const response = await apiService.fetch(`/api/v1/subscriptions`, {
26
- method: 'GET',
27
- });
28
- setData(response ?? null);
29
- }
30
- catch (err) {
31
- const safeError = err instanceof Error ? err : new Error('Failed to fetch subscriptions');
32
- setError(safeError);
33
- }
34
- finally {
35
- setIsLoading(false);
36
- }
37
- }, [apiService, isEnabled]);
38
- useEffect(() => {
39
- void fetchSubscriptions();
40
- }, [fetchSubscriptions]);
41
- const resumeSubscription = useCallback(async (subscriptionId) => {
42
- try {
43
- await apiService.fetch(`/api/v1/subscriptions/resume`, {
44
- method: 'POST',
45
- body: { subscriptionId },
46
- });
47
- await fetchSubscriptions();
48
- return { success: true };
49
- }
50
- catch (err) {
51
- const errorMessage = err instanceof Error ? err.message : 'Failed to resume subscription';
52
- return { success: false, error: errorMessage };
53
- }
54
- }, [apiService, fetchSubscriptions]);
55
- const cancelSubscription = useCallback(async (subscriptionId) => {
56
- try {
57
- await apiService.fetch(`/api/v1/subscriptions/cancel`, {
58
- method: 'POST',
59
- body: { subscriptionId },
60
- });
61
- await fetchSubscriptions();
62
- return { success: true };
63
- }
64
- catch (err) {
65
- const errorMessage = err instanceof Error ? err.message : 'Failed to cancel subscription';
66
- return { success: false, error: errorMessage };
67
- }
68
- }, [apiService, fetchSubscriptions]);
69
- return {
70
- data,
71
- isLoading,
72
- error,
73
- refetch: fetchSubscriptions,
74
- resumeSubscription,
75
- cancelSubscription,
76
- };
77
- }