@tagadapay/plugin-sdk 4.0.2 → 4.0.6
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/README.md +90 -0
- package/dist/external-tracker.js +1 -1
- package/dist/external-tracker.min.js +1 -1
- package/dist/tagada-react-sdk-minimal.min.js +1 -1
- package/dist/tagada-react-sdk-minimal.min.js.map +1 -1
- package/dist/tagada-react-sdk.js +18 -15
- package/dist/tagada-react-sdk.min.js +2 -2
- package/dist/tagada-react-sdk.min.js.map +3 -3
- package/dist/tagada-sdk.js +17 -11
- package/dist/tagada-sdk.min.js +2 -2
- package/dist/tagada-sdk.min.js.map +3 -3
- package/dist/v2/core/resources/offers.d.ts +2 -2
- package/dist/v2/core/resources/offers.js +10 -4
- package/dist/v2/react/hooks/useOfferQuery.d.ts +11 -0
- package/dist/v2/react/hooks/useOfferQuery.js +11 -0
- package/dist/v2/react/hooks/usePreviewOffer.js +3 -7
- package/dist/v2/react/index.d.ts +1 -0
- package/dist/v2/react/index.js +1 -0
- package/package.json +1 -1
|
@@ -286,11 +286,11 @@ export declare class OffersResource {
|
|
|
286
286
|
/**
|
|
287
287
|
* Pay with checkout session
|
|
288
288
|
*/
|
|
289
|
-
payWithCheckoutSession(checkoutSessionId: string, orderId?: string): Promise<void>;
|
|
289
|
+
payWithCheckoutSession(checkoutSessionId: string, orderId?: string, initiatedBy?: 'merchant' | 'customer'): Promise<void>;
|
|
290
290
|
/**
|
|
291
291
|
* Pay for an offer directly
|
|
292
292
|
*/
|
|
293
|
-
payOffer(offerId: string, orderId?: string): Promise<any>;
|
|
293
|
+
payOffer(offerId: string, orderId?: string, initiatedBy?: 'merchant' | 'customer'): Promise<any>;
|
|
294
294
|
/**
|
|
295
295
|
* Transform offer to checkout session with dynamic variant selection
|
|
296
296
|
* Uses lineItems from the offer to create a new checkout session
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Axios-based API client for offers endpoints
|
|
4
4
|
*/
|
|
5
5
|
import { isDraftMode } from '../utils/previewMode';
|
|
6
|
+
import { getAssignedPaymentInitiator } from '../funnelClient';
|
|
6
7
|
export class OffersResource {
|
|
7
8
|
constructor(apiClient) {
|
|
8
9
|
this.apiClient = apiClient;
|
|
@@ -69,13 +70,14 @@ export class OffersResource {
|
|
|
69
70
|
* @param mainOrderId - Optional main order ID (for upsells)
|
|
70
71
|
*/
|
|
71
72
|
async payPreviewedOffer(offerId, currency = '', lineItems, returnUrl, mainOrderId, initiatedBy) {
|
|
73
|
+
const effectiveInitiatedBy = initiatedBy ?? getAssignedPaymentInitiator();
|
|
72
74
|
console.log('💳 [OffersResource] Calling pay-preview API:', {
|
|
73
75
|
offerId,
|
|
74
76
|
currency,
|
|
75
77
|
lineItems,
|
|
76
78
|
returnUrl,
|
|
77
79
|
mainOrderId,
|
|
78
|
-
initiatedBy,
|
|
80
|
+
initiatedBy: effectiveInitiatedBy,
|
|
79
81
|
endpoint: `/api/v1/offers/${offerId}/pay-preview`,
|
|
80
82
|
});
|
|
81
83
|
const response = await this.apiClient.post(`/api/v1/offers/${offerId}/pay-preview`, {
|
|
@@ -84,7 +86,7 @@ export class OffersResource {
|
|
|
84
86
|
lineItems,
|
|
85
87
|
returnUrl: returnUrl || (typeof window !== 'undefined' ? window.location.href : ''),
|
|
86
88
|
mainOrderId,
|
|
87
|
-
...(
|
|
89
|
+
...(effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}),
|
|
88
90
|
});
|
|
89
91
|
console.log('📥 [OffersResource] Pay-preview API response:', response);
|
|
90
92
|
return response;
|
|
@@ -151,13 +153,15 @@ export class OffersResource {
|
|
|
151
153
|
/**
|
|
152
154
|
* Pay with checkout session
|
|
153
155
|
*/
|
|
154
|
-
async payWithCheckoutSession(checkoutSessionId, orderId) {
|
|
156
|
+
async payWithCheckoutSession(checkoutSessionId, orderId, initiatedBy) {
|
|
155
157
|
// 🎯 Check draft mode from URL, localStorage, or cookie
|
|
156
158
|
const draft = isDraftMode();
|
|
159
|
+
const effectiveInitiatedBy = initiatedBy ?? getAssignedPaymentInitiator();
|
|
157
160
|
await this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/pay`, {
|
|
158
161
|
checkoutSessionId,
|
|
159
162
|
draft, // 🎯 Use dynamic draft mode instead of hardcoded false
|
|
160
163
|
returnUrl: typeof window !== 'undefined' ? window.location.href : '',
|
|
164
|
+
...(effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}),
|
|
161
165
|
metadata: {
|
|
162
166
|
comingFromPostPurchase: true,
|
|
163
167
|
postOrder: orderId,
|
|
@@ -169,13 +173,15 @@ export class OffersResource {
|
|
|
169
173
|
/**
|
|
170
174
|
* Pay for an offer directly
|
|
171
175
|
*/
|
|
172
|
-
async payOffer(offerId, orderId) {
|
|
176
|
+
async payOffer(offerId, orderId, initiatedBy) {
|
|
173
177
|
// 🎯 Check draft mode from URL, localStorage, or cookie
|
|
174
178
|
const draft = isDraftMode();
|
|
179
|
+
const effectiveInitiatedBy = initiatedBy ?? getAssignedPaymentInitiator();
|
|
175
180
|
return this.apiClient.post(`/api/v1/offers/${offerId}/pay`, {
|
|
176
181
|
offerId,
|
|
177
182
|
draft, // 🎯 Use dynamic draft mode instead of hardcoded false
|
|
178
183
|
returnUrl: typeof window !== 'undefined' ? window.location.href : '',
|
|
184
|
+
...(effectiveInitiatedBy ? { initiatedBy: effectiveInitiatedBy } : {}),
|
|
179
185
|
metadata: orderId ? {
|
|
180
186
|
comingFromPostPurchase: true,
|
|
181
187
|
postOrder: orderId,
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* useOffer Hook - Single offer workflow with checkout session management
|
|
3
3
|
*
|
|
4
|
+
* @deprecated Use `usePreviewOffer` instead. `usePreviewOffer` is the
|
|
5
|
+
* supported hook for post-checkout upsell pages: it skips the upfront
|
|
6
|
+
* checkout-session round-trip, recomputes pricing client-side, and applies
|
|
7
|
+
* the CRM-configured MIT/CIT payment initiator automatically via the
|
|
8
|
+
* shared OffersResource auto-pickup. `useOfferQuery` (aliased as `useOffer`)
|
|
9
|
+
* remains exported for backwards compatibility but will be removed in a
|
|
10
|
+
* future major version.
|
|
11
|
+
*
|
|
4
12
|
* Behavior copied from useOffersQuery but simplified for a single offer:
|
|
5
13
|
* 1. Fetches offer data
|
|
6
14
|
* 2. Auto-initializes checkout session when mainOrderId is provided
|
|
@@ -106,4 +114,7 @@ export interface UseOfferQueryResult {
|
|
|
106
114
|
/** Whether variant is loading for a product */
|
|
107
115
|
isLoadingVariant: (productId: string) => boolean;
|
|
108
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated Use `usePreviewOffer` instead. See module-level JSDoc.
|
|
119
|
+
*/
|
|
109
120
|
export declare function useOfferQuery(options: UseOfferQueryOptions): UseOfferQueryResult;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* useOffer Hook - Single offer workflow with checkout session management
|
|
3
3
|
*
|
|
4
|
+
* @deprecated Use `usePreviewOffer` instead. `usePreviewOffer` is the
|
|
5
|
+
* supported hook for post-checkout upsell pages: it skips the upfront
|
|
6
|
+
* checkout-session round-trip, recomputes pricing client-side, and applies
|
|
7
|
+
* the CRM-configured MIT/CIT payment initiator automatically via the
|
|
8
|
+
* shared OffersResource auto-pickup. `useOfferQuery` (aliased as `useOffer`)
|
|
9
|
+
* remains exported for backwards compatibility but will be removed in a
|
|
10
|
+
* future major version.
|
|
11
|
+
*
|
|
4
12
|
* Behavior copied from useOffersQuery but simplified for a single offer:
|
|
5
13
|
* 1. Fetches offer data
|
|
6
14
|
* 2. Auto-initializes checkout session when mainOrderId is provided
|
|
@@ -14,6 +22,9 @@ import { OffersResource } from '../../core/resources/offers';
|
|
|
14
22
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
15
23
|
import { getGlobalApiClient } from './useApiQuery';
|
|
16
24
|
import { usePluginConfig } from './usePluginConfig';
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use `usePreviewOffer` instead. See module-level JSDoc.
|
|
27
|
+
*/
|
|
17
28
|
export function useOfferQuery(options) {
|
|
18
29
|
const { offerId, enabled = true, mainOrderId: rawMainOrderId } = options;
|
|
19
30
|
const { storeId } = usePluginConfig();
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { useQuery } from '@tanstack/react-query';
|
|
11
11
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
12
12
|
import { OffersResource } from '../../core/resources/offers';
|
|
13
|
-
import { getAssignedPaymentInitiator } from '../../core/funnelClient';
|
|
14
13
|
import { getGlobalApiClient } from './useApiQuery';
|
|
15
14
|
export function usePreviewOffer(options) {
|
|
16
15
|
const { offerId, currency: requestedCurrency = '', initialSelections = {} } = options;
|
|
@@ -235,12 +234,9 @@ export function usePreviewOffer(options) {
|
|
|
235
234
|
}
|
|
236
235
|
setIsPaying(true);
|
|
237
236
|
try {
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
// every consumer of usePreviewOffer without per-template wiring.
|
|
242
|
-
const initiatedBy = payOptions?.initiatedBy ?? getAssignedPaymentInitiator();
|
|
243
|
-
const result = await offersResource.payPreviewedOffer(offerId, effectiveCurrency, lineItemsForPreview, typeof window !== 'undefined' ? window.location.href : undefined, mainOrderId, initiatedBy);
|
|
237
|
+
// initiatedBy auto-picks from stepConfig.paymentInitiator inside
|
|
238
|
+
// OffersResource.payPreviewedOffer when not supplied here.
|
|
239
|
+
const result = await offersResource.payPreviewedOffer(offerId, effectiveCurrency, lineItemsForPreview, typeof window !== 'undefined' ? window.location.href : undefined, mainOrderId, payOptions?.initiatedBy);
|
|
244
240
|
console.log('[usePreviewOffer] Payment initiated:', result);
|
|
245
241
|
return {
|
|
246
242
|
checkoutUrl: result.checkout.checkoutUrl,
|
package/dist/v2/react/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export { queryKeys, useApiMutation, useApiQuery, useInvalidateQuery, usePreloadQ
|
|
|
33
33
|
export { useCheckoutQuery as useCheckout } from './hooks/useCheckoutQuery';
|
|
34
34
|
export { useCurrency } from './hooks/useCurrency';
|
|
35
35
|
export { useDiscountsQuery as useDiscounts } from './hooks/useDiscountsQuery';
|
|
36
|
+
/** @deprecated Use `usePreviewOffer` instead. */
|
|
36
37
|
export { useOfferQuery as useOffer } from './hooks/useOfferQuery';
|
|
37
38
|
export { useOrderBumpQuery as useOrderBump } from './hooks/useOrderBumpQuery';
|
|
38
39
|
export { useOrderQuery as useOrder } from './hooks/useOrderQuery';
|
package/dist/v2/react/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export { queryKeys, useApiMutation, useApiQuery, useInvalidateQuery, usePreloadQ
|
|
|
35
35
|
export { useCheckoutQuery as useCheckout } from './hooks/useCheckoutQuery';
|
|
36
36
|
export { useCurrency } from './hooks/useCurrency';
|
|
37
37
|
export { useDiscountsQuery as useDiscounts } from './hooks/useDiscountsQuery';
|
|
38
|
+
/** @deprecated Use `usePreviewOffer` instead. */
|
|
38
39
|
export { useOfferQuery as useOffer } from './hooks/useOfferQuery';
|
|
39
40
|
export { useOrderBumpQuery as useOrderBump } from './hooks/useOrderBumpQuery';
|
|
40
41
|
export { useOrderQuery as useOrder } from './hooks/useOrderQuery';
|