@tagadapay/plugin-sdk 4.0.4 → 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.js +1 -1
- package/dist/tagada-react-sdk.min.js +1 -1
- package/dist/tagada-sdk.js +1 -1
- package/dist/tagada-sdk.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ A comprehensive React SDK for building plugins on the TagadaPay platform. Create
|
|
|
14
14
|
- **[V2 Examples](#-v2-examples)** - Complete examples using the new V2 hooks
|
|
15
15
|
- **[useCheckout (V2)](#usecheckout)** - TanStack Query-based checkout management
|
|
16
16
|
- **[useOffers (V2)](#useoffers)** - Dynamic pricing with automatic caching
|
|
17
|
+
- **[usePreviewOffer (V2)](#usepreviewoffer)** - Post-checkout upsell page (auto-applies MIT/CIT)
|
|
17
18
|
- **[useProducts (V2)](#useproducts)** - Product data management
|
|
18
19
|
- **[useStoreConfig (V2)](#usestoreconfig)** - Store configuration with automatic caching
|
|
19
20
|
- **[usePayment (V2)](#usepayment)** - Payment processing with 3DS support
|
|
@@ -677,6 +678,95 @@ const {
|
|
|
677
678
|
} = useOffers({ storeId, enabled });
|
|
678
679
|
```
|
|
679
680
|
|
|
681
|
+
> ⚠️ **`useOffer` (singular) is deprecated.** Use `usePreviewOffer` for upsell
|
|
682
|
+
> pages — it skips the upfront checkout-session round-trip, recomputes
|
|
683
|
+
> pricing client-side, and auto-applies the CRM-configured MIT/CIT payment
|
|
684
|
+
> initiator. `useOffer` will be removed in a future major version.
|
|
685
|
+
|
|
686
|
+
#### usePreviewOffer()
|
|
687
|
+
|
|
688
|
+
Lightweight hook for post-checkout upsell pages. Fetches an offer with a
|
|
689
|
+
precomputed pricing summary, lets the customer pick variants and quantities,
|
|
690
|
+
and recomputes totals client-side without round-tripping the backend on every
|
|
691
|
+
change. Pay once the customer accepts.
|
|
692
|
+
|
|
693
|
+
```typescript
|
|
694
|
+
const {
|
|
695
|
+
// Query state
|
|
696
|
+
offer, // Offer | null
|
|
697
|
+
isLoading, // boolean
|
|
698
|
+
isFetching, // boolean
|
|
699
|
+
isPaying, // boolean
|
|
700
|
+
error, // Error | null
|
|
701
|
+
|
|
702
|
+
// Pricing
|
|
703
|
+
summary, // { items, totalAmount, totalAdjustedAmount, currency, options }
|
|
704
|
+
selections, // Record<lineItemId, { variantId, quantity, priceId? }>
|
|
705
|
+
|
|
706
|
+
// Selection methods (by lineItemId)
|
|
707
|
+
selectVariant, // (lineItemId, variantId) => void
|
|
708
|
+
updateQuantity, // (lineItemId, quantity) => void
|
|
709
|
+
// Selection methods (by productId — convenience for single-line steps)
|
|
710
|
+
selectVariantByProduct,
|
|
711
|
+
updateQuantityByProduct,
|
|
712
|
+
getAvailableVariants, // (productId) => Array<{ variantId, variantName, unitAmount, currency, imageUrl }>
|
|
713
|
+
|
|
714
|
+
// Actions
|
|
715
|
+
pay, // (mainOrderId?, options?: { initiatedBy }) => Promise<{ checkoutUrl }>
|
|
716
|
+
toCheckout, // (mainOrderId?) => Promise<{ checkoutToken, customerId, status }>
|
|
717
|
+
} = usePreviewOffer({
|
|
718
|
+
offerId, // required
|
|
719
|
+
currency, // optional override; defaults to ?currency= URL param or funnel context
|
|
720
|
+
initialSelections, // optional preselected variants/quantities
|
|
721
|
+
});
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
**Example — accept-or-skip upsell page:**
|
|
725
|
+
|
|
726
|
+
```tsx
|
|
727
|
+
import { usePreviewOffer } from '@tagadapay/plugin-sdk/v2';
|
|
728
|
+
|
|
729
|
+
function UpsellOffer({ offerId, mainOrderId }: { offerId: string; mainOrderId: string }) {
|
|
730
|
+
const { offer, summary, pay, isPaying } = usePreviewOffer({ offerId });
|
|
731
|
+
|
|
732
|
+
const handleAccept = async () => {
|
|
733
|
+
const { checkoutUrl } = await pay(mainOrderId);
|
|
734
|
+
if (checkoutUrl) window.location.href = checkoutUrl;
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
return (
|
|
738
|
+
<div>
|
|
739
|
+
<h2>{offer?.name}</h2>
|
|
740
|
+
<p>Total: {summary?.totalAdjustedAmount} {summary?.currency}</p>
|
|
741
|
+
<button onClick={handleAccept} disabled={isPaying}>
|
|
742
|
+
{isPaying ? 'Processing…' : 'Add to my order'}
|
|
743
|
+
</button>
|
|
744
|
+
</div>
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
**MIT vs CIT auto-pickup**
|
|
750
|
+
|
|
751
|
+
`pay()` reads `stepConfig.paymentInitiator` from the runtime
|
|
752
|
+
`window.__TGD_STEP_CONFIG__` injection and applies it automatically:
|
|
753
|
+
|
|
754
|
+
- `paymentInitiator: 'merchant'` (default) → **MIT**, sent to Stripe as
|
|
755
|
+
`off_session: true`. No 3DS challenge, higher conversion.
|
|
756
|
+
- `paymentInitiator: 'customer'` → **CIT**, sent as
|
|
757
|
+
`setup_future_usage: 'off_session'`. May trigger 3DS — useful when MIT
|
|
758
|
+
charges are being declined by the issuer.
|
|
759
|
+
|
|
760
|
+
Merchants flip the toggle from the CRM step config; no plugin code change is
|
|
761
|
+
required. To override per call, pass `{ initiatedBy }`:
|
|
762
|
+
|
|
763
|
+
```tsx
|
|
764
|
+
await pay(mainOrderId, { initiatedBy: 'customer' });
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
`OffersResource.payOffer()` and `OffersResource.payWithCheckoutSession()` share
|
|
768
|
+
the same auto-pickup under the hood.
|
|
769
|
+
|
|
680
770
|
#### usePromotions()
|
|
681
771
|
|
|
682
772
|
Hook for managing promotion codes in checkout sessions with TanStack Query.
|
package/dist/external-tracker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TagadaPay React SDK MINIMAL v4.0.
|
|
2
|
+
* TagadaPay React SDK MINIMAL v4.0.6
|
|
3
3
|
* CDN Bundle - Slim checkout SDK (TagadaProvider + essential hooks only)
|
|
4
4
|
* Requires: React 18+ loaded before this script
|
|
5
5
|
* For full SDK with all hooks, use tagada-react-sdk.min.js instead
|
package/dist/tagada-react-sdk.js
CHANGED
package/dist/tagada-sdk.js
CHANGED
package/dist/tagada-sdk.min.js
CHANGED