@tagadapay/plugin-sdk 2.4.30 → 2.4.32

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,11 +1,10 @@
1
+ import type { CustomerInfos } from '../types';
1
2
  export interface UseCustomerInfosOptions {
2
3
  customerId?: string | null;
3
4
  enabled?: boolean;
4
5
  }
5
- export interface UseCustomerInfosResult<TData = {
6
- customer: any;
7
- }> {
8
- data: TData | null;
6
+ export interface UseCustomerInfosResult {
7
+ data: CustomerInfos | null;
9
8
  isLoading: boolean;
10
9
  error: Error | null;
11
10
  refetch: () => Promise<void>;
@@ -13,6 +12,4 @@ export interface UseCustomerInfosResult<TData = {
13
12
  /**
14
13
  * useCustomerInfos - Fetches customer infos from `/api/v1/customers/{customerId}` with `storeId` param
15
14
  */
16
- export declare function useCustomerInfos<TData = {
17
- customer: any;
18
- }>(options: UseCustomerInfosOptions): UseCustomerInfosResult<TData>;
15
+ export declare function useCustomerInfos(options: UseCustomerInfosOptions): UseCustomerInfosResult;
@@ -0,0 +1,56 @@
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;
@@ -0,0 +1,77 @@
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
+ }
@@ -8,6 +8,7 @@ export { useClubOffers } from './hooks/useClubOffers';
8
8
  export { useCurrency } from './hooks/useCurrency';
9
9
  export { useCustomer } from './hooks/useCustomer';
10
10
  export { useCustomerInfos } from './hooks/useCustomerInfos';
11
+ export { useCustomerSubscriptions } from './hooks/useCustomerSubscriptions';
11
12
  export { useDiscounts } from './hooks/useDiscounts';
12
13
  export { useEnvironment } from './hooks/useEnvironment';
13
14
  export { useGeoLocation } from './hooks/useGeoLocation';
@@ -38,7 +39,7 @@ export { useThreeds } from './hooks/useThreeds';
38
39
  export { useThreedsModal } from './hooks/useThreedsModal';
39
40
  export { useApplePay } from './hooks/useApplePay';
40
41
  export { ExpressPaymentProvider, useExpressPayment } from './hooks/useExpressPayment';
41
- export type { AuthState, Currency, Customer, Environment, EnvironmentConfig, Locale, Order, OrderAddress, OrderItem, OrderSummary, PickupPoint, Session, Store } from './types';
42
+ export type { AuthState, Currency, Customer, CustomerInfos, Environment, EnvironmentConfig, Locale, Order, OrderAddress, OrderItem, OrderSummary, PickupPoint, Session, Store } from './types';
42
43
  export type { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, CheckoutSessionPreview, Promotion, UseCheckoutOptions, UseCheckoutResult } from './hooks/useCheckout';
43
44
  export type { Discount, DiscountCodeValidation, UseDiscountsOptions, UseDiscountsResult } from './hooks/useDiscounts';
44
45
  export type { OrderBumpPreview, UseOrderBumpOptions, UseOrderBumpResult } from './hooks/useOrderBump';
@@ -11,6 +11,7 @@ export { useClubOffers } from './hooks/useClubOffers';
11
11
  export { useCurrency } from './hooks/useCurrency';
12
12
  export { useCustomer } from './hooks/useCustomer';
13
13
  export { useCustomerInfos } from './hooks/useCustomerInfos';
14
+ export { useCustomerSubscriptions } from './hooks/useCustomerSubscriptions';
14
15
  export { useDiscounts } from './hooks/useDiscounts';
15
16
  export { useEnvironment } from './hooks/useEnvironment';
16
17
  export { useGeoLocation } from './hooks/useGeoLocation';
@@ -150,3 +150,71 @@ export interface Order {
150
150
  };
151
151
  relatedOrders?: Order[];
152
152
  }
153
+ export interface CustomerAddress {
154
+ company?: string;
155
+ firstName: string;
156
+ lastName: string;
157
+ address1: string;
158
+ city: string;
159
+ country: string;
160
+ state: string;
161
+ postal: string;
162
+ phone?: string;
163
+ email?: string;
164
+ }
165
+ export interface CustomerOrderSummary {
166
+ id: string;
167
+ storeId: string;
168
+ accountId: string;
169
+ createdAt: string;
170
+ updatedAt: string;
171
+ status: string;
172
+ cancelledAt: string | null;
173
+ cancelledReason: string | null;
174
+ paidAt: string | null;
175
+ paidAmount: number | null;
176
+ openAt: string | null;
177
+ abandonedAt: string | null;
178
+ currency: string;
179
+ externalCustomerType: string | null;
180
+ externalCustomerId: string | null;
181
+ externalOrderId: string | null;
182
+ billingAddress: CustomerAddress;
183
+ shippingAddress: Omit<CustomerAddress, 'email'>;
184
+ pickupAddress: any | null;
185
+ taxesIncluded: boolean;
186
+ draft: boolean;
187
+ checkoutSessionId: string | null;
188
+ sessionHash: string | null;
189
+ customerId: string;
190
+ createdFrom: string | null;
191
+ paymentInstrumentId: string | null;
192
+ refundedAt: string | null;
193
+ refundedAmount: number | null;
194
+ metadata?: Record<string, any>;
195
+ }
196
+ export interface CustomerInfos {
197
+ customer: {
198
+ id: string;
199
+ email: string | null;
200
+ firstName: string | null;
201
+ lastName: string | null;
202
+ externalCustomerId: string | null;
203
+ lastOrderId: string | null;
204
+ accountId: string;
205
+ storeId: string;
206
+ billingAddress: CustomerAddress | null;
207
+ shippingAddress: Omit<CustomerAddress, 'email'> | null;
208
+ currency: string | null;
209
+ locale: string | null;
210
+ draft: boolean;
211
+ acceptsMarketing: boolean;
212
+ createdAt: string;
213
+ updatedAt: string;
214
+ metadata: Record<string, any>;
215
+ device: any | null;
216
+ orders: CustomerOrderSummary[];
217
+ subscriptions: any[];
218
+ };
219
+ promotionCodes: any[];
220
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.4.30",
3
+ "version": "2.4.32",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",