@b3dotfun/sdk 0.1.65 → 0.1.66-alpha.0

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.
Files changed (116) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +2 -0
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +7 -16
  3. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -1
  4. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +151 -22
  5. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -50
  6. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +2 -0
  7. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +4 -2
  8. package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +3 -1
  9. package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +2 -2
  10. package/dist/cjs/anyspend/react/components/AnySpendWorkflowTrigger.d.ts +31 -0
  11. package/dist/cjs/anyspend/react/components/AnySpendWorkflowTrigger.js +14 -0
  12. package/dist/cjs/anyspend/react/components/QRDeposit.js +5 -13
  13. package/dist/cjs/anyspend/react/components/ccShopAbi.d.ts +113 -0
  14. package/dist/cjs/anyspend/react/components/ccShopAbi.js +63 -0
  15. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +1 -3
  16. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +3 -3
  17. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +1 -4
  18. package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +3 -57
  19. package/dist/cjs/anyspend/react/components/common/PaySection.js +1 -1
  20. package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
  21. package/dist/cjs/anyspend/react/components/index.js +3 -1
  22. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  23. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  24. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +1 -0
  25. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
  26. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +1 -0
  27. package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
  28. package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.js +27 -0
  29. package/dist/cjs/anyspend/services/anyspend.d.ts +2 -1
  30. package/dist/cjs/anyspend/services/anyspend.js +2 -1
  31. package/dist/cjs/anyspend/utils/chain.d.ts +1 -1
  32. package/dist/cjs/anyspend/utils/chain.js +72 -62
  33. package/dist/cjs/global-account/react/components/B3DynamicModal.js +4 -0
  34. package/dist/cjs/global-account/react/hooks/useUserQuery.js +10 -0
  35. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +37 -1
  36. package/dist/cjs/global-account/react/stores/userStore.js +1 -0
  37. package/dist/esm/anyspend/react/components/AnySpend.d.ts +2 -0
  38. package/dist/esm/anyspend/react/components/AnySpend.js +7 -16
  39. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -1
  40. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +152 -23
  41. package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -17
  42. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +2 -0
  43. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +4 -2
  44. package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +3 -1
  45. package/dist/esm/anyspend/react/components/AnySpendDeposit.js +2 -2
  46. package/dist/esm/anyspend/react/components/AnySpendWorkflowTrigger.d.ts +31 -0
  47. package/dist/esm/anyspend/react/components/AnySpendWorkflowTrigger.js +11 -0
  48. package/dist/esm/anyspend/react/components/QRDeposit.js +6 -14
  49. package/dist/esm/anyspend/react/components/ccShopAbi.d.ts +113 -0
  50. package/dist/esm/anyspend/react/components/ccShopAbi.js +60 -0
  51. package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +1 -3
  52. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +3 -3
  53. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +1 -4
  54. package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -56
  55. package/dist/esm/anyspend/react/components/common/PaySection.js +1 -1
  56. package/dist/esm/anyspend/react/components/index.d.ts +2 -0
  57. package/dist/esm/anyspend/react/components/index.js +1 -0
  58. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  59. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  60. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +1 -0
  61. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
  62. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +1 -0
  63. package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
  64. package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.js +24 -0
  65. package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
  66. package/dist/esm/anyspend/services/anyspend.js +2 -1
  67. package/dist/esm/anyspend/utils/chain.d.ts +1 -1
  68. package/dist/esm/anyspend/utils/chain.js +72 -62
  69. package/dist/esm/global-account/react/components/B3DynamicModal.js +4 -0
  70. package/dist/esm/global-account/react/hooks/useUserQuery.js +11 -1
  71. package/dist/esm/global-account/react/stores/useModalStore.d.ts +37 -1
  72. package/dist/esm/global-account/react/stores/userStore.js +1 -0
  73. package/dist/types/anyspend/react/components/AnySpend.d.ts +2 -0
  74. package/dist/types/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -1
  75. package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +2 -0
  76. package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +3 -1
  77. package/dist/types/anyspend/react/components/AnySpendWorkflowTrigger.d.ts +31 -0
  78. package/dist/types/anyspend/react/components/ccShopAbi.d.ts +113 -0
  79. package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +1 -3
  80. package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +1 -4
  81. package/dist/types/anyspend/react/components/index.d.ts +2 -0
  82. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  83. package/dist/types/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
  84. package/dist/types/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
  85. package/dist/types/anyspend/services/anyspend.d.ts +2 -1
  86. package/dist/types/anyspend/utils/chain.d.ts +1 -1
  87. package/dist/types/global-account/react/stores/useModalStore.d.ts +37 -1
  88. package/package.json +1 -1
  89. package/src/anyspend/README.md +14 -0
  90. package/src/anyspend/docs/checkout-sessions.md +228 -0
  91. package/src/anyspend/docs/components.md +26 -0
  92. package/src/anyspend/docs/examples.md +58 -0
  93. package/src/anyspend/docs/hooks.md +32 -0
  94. package/src/anyspend/llms.txt +185 -0
  95. package/src/anyspend/react/components/AnySpend.tsx +9 -17
  96. package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +206 -22
  97. package/src/anyspend/react/components/AnySpendCustom.tsx +3 -18
  98. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +5 -1
  99. package/src/anyspend/react/components/AnySpendDeposit.tsx +5 -0
  100. package/src/anyspend/react/components/AnySpendWorkflowTrigger.tsx +73 -0
  101. package/src/anyspend/react/components/QRDeposit.tsx +19 -15
  102. package/src/anyspend/react/components/ccShopAbi.ts +64 -0
  103. package/src/anyspend/react/components/common/CryptoPaySection.tsx +0 -5
  104. package/src/anyspend/react/components/common/OrderTokenAmount.tsx +1 -70
  105. package/src/anyspend/react/components/common/PaySection.tsx +0 -1
  106. package/src/anyspend/react/components/index.ts +2 -0
  107. package/src/anyspend/react/hooks/index.ts +1 -0
  108. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +1 -0
  109. package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +2 -0
  110. package/src/anyspend/react/hooks/useOnOrderSuccess.ts +36 -0
  111. package/src/anyspend/services/anyspend.ts +3 -0
  112. package/src/anyspend/utils/chain.ts +81 -65
  113. package/src/global-account/react/components/B3DynamicModal.tsx +4 -0
  114. package/src/global-account/react/hooks/useUserQuery.ts +12 -1
  115. package/src/global-account/react/stores/useModalStore.ts +39 -2
  116. package/src/global-account/react/stores/userStore.ts +1 -0
@@ -1,5 +1,5 @@
1
1
  import { components } from "@b3dotfun/sdk/anyspend/types/api";
2
- export declare function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect, canEditAmount, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, walletAddress, skipAutoMaxOnTokenChange, }: {
2
+ export declare function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect, canEditAmount, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, }: {
3
3
  disabled?: boolean;
4
4
  inputValue: string;
5
5
  onChangeInput: (value: string) => void;
@@ -18,7 +18,4 @@ export declare function OrderTokenAmount({ disabled, inputValue, onChangeInput,
18
18
  onTokenSelect?: (token: components["schemas"]["Token"], event: {
19
19
  preventDefault: () => void;
20
20
  }) => void;
21
- walletAddress?: string | undefined;
22
- /** When true, skip auto-setting max balance when token changes (used for fixed destination amount mode) */
23
- skipAutoMaxOnTokenChange?: boolean;
24
21
  }): import("react/jsx-runtime").JSX.Element;
@@ -8,6 +8,8 @@ export { AnySpendDeposit } from "./AnySpendDeposit";
8
8
  export type { AnySpendDepositProps, ChainConfig, DepositContractConfig } from "./AnySpendDeposit";
9
9
  export type { AnySpendAllClasses, AnySpendClasses, AnySpendCustomExactInClasses, AnySpendDepositClasses, CryptoPaymentMethodClasses, CryptoPaySectionClasses, CryptoReceiveSectionClasses, FiatPaymentMethodClasses, OrderDetailsClasses, PanelOnrampClasses, QRDepositClasses, RecipientSelectionClasses, } from "./types/classes";
10
10
  export { AnySpendDepositHype, HYPE_TOKEN_DETAILS } from "./AnyspendDepositHype";
11
+ export { AnySpendWorkflowTrigger } from "./AnySpendWorkflowTrigger";
12
+ export type { AnySpendWorkflowTriggerProps } from "./AnySpendWorkflowTrigger";
11
13
  export * from "./AnySpendFingerprintWrapper";
12
14
  export { AnySpendNFT } from "./AnySpendNFT";
13
15
  export { AnyspendSignatureMint } from "./AnyspendSignatureMint";
@@ -12,6 +12,7 @@ export * from "./useGasPrice";
12
12
  export * from "./useGeoOnrampOptions";
13
13
  export * from "./useGetGeo";
14
14
  export * from "./useHyperliquidTransfer";
15
+ export * from "./useOnOrderSuccess";
15
16
  export * from "./useRecipientAddressState";
16
17
  export * from "./useSigMint";
17
18
  export * from "./useStripeClientSecret";
@@ -18,6 +18,7 @@ export type CreateOrderParams = {
18
18
  creatorAddress?: string;
19
19
  payload?: any;
20
20
  metadata?: Record<string, any>;
21
+ callbackMetadata?: Record<string, unknown>;
21
22
  };
22
23
  export type UseAnyspendCreateOrderProps = {
23
24
  onSuccess?: (data: any) => void;
@@ -0,0 +1,10 @@
1
+ import { GetOrderAndTxsResponse } from "../../types/api_req_res";
2
+ /**
3
+ * Hook to call onSuccess callback when an order is executed.
4
+ * Handles fallback to relayTxs when executeTx is null.
5
+ */
6
+ export declare function useOnOrderSuccess({ orderData, orderId, onSuccess, }: {
7
+ orderData: GetOrderAndTxsResponse | undefined;
8
+ orderId: string | undefined;
9
+ onSuccess?: (txHash?: string) => void;
10
+ }): void;
@@ -6,7 +6,7 @@ export declare const anyspendService: {
6
6
  getTokenList: (chainId: number, query: string) => Promise<components["schemas"]["Token"][]>;
7
7
  getToken: (chainId: number, tokenAddress: string) => Promise<components["schemas"]["Token"]>;
8
8
  getQuote: (req: GetQuoteRequest, partnerId?: string) => Promise<GetQuoteResponse>;
9
- createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, }: {
9
+ createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, }: {
10
10
  recipientAddress: string;
11
11
  type: string;
12
12
  srcChain: number;
@@ -21,6 +21,7 @@ export declare const anyspendService: {
21
21
  partnerId?: string;
22
22
  clientReferenceId?: string;
23
23
  visitorData?: VisitorData;
24
+ callbackMetadata?: Record<string, unknown>;
24
25
  }) => Promise<{
25
26
  success: boolean;
26
27
  message: string;
@@ -82,7 +82,7 @@ export declare function isTestnet(chainId: number): boolean;
82
82
  export declare function getDefaultToken(chainId: number): components["schemas"]["Token"];
83
83
  export declare function getChainName(chainId: number): string;
84
84
  export declare function getCoingeckoName(chainId: number): string | null;
85
- export declare function getPaymentUrl(address: string, amount: bigint, currency: string, chainId: number, decimals?: number): string;
85
+ export declare function getPaymentUrl(address: string, amount: bigint | undefined, currency: string, chainId: number, decimals?: number): string;
86
86
  export declare function getExplorerTxUrl(chainId: number, txHash: string): string;
87
87
  export declare function getExplorerAddressUrl(chainId: number, address: string): string;
88
88
  export declare function getMulticall3Address(chainId: number): string;
@@ -470,11 +470,45 @@ export interface AnySpendCollectorClubPurchaseProps extends BaseModalProps {
470
470
  forceFiatPayment?: boolean;
471
471
  /** Staging environment support */
472
472
  isStaging?: boolean;
473
+ /** Optional discount code to apply to the purchase */
474
+ discountCode?: string;
473
475
  }
474
476
  /**
475
477
  * Props for the AnySpend Deposit modal
476
478
  * Flexible deposit component with optional chain selection
477
479
  */
480
+ /**
481
+ * Props for the AnySpend Workflow Trigger modal
482
+ * Handles payments that trigger b3os-workflow runs
483
+ */
484
+ export interface AnySpendWorkflowTriggerModalProps extends BaseModalProps {
485
+ /** Modal type identifier */
486
+ type: "anySpendWorkflowTrigger";
487
+ /** Payment recipient address (hex) */
488
+ recipientAddress: string;
489
+ /** Destination chain ID */
490
+ chainId: number;
491
+ /** Destination token address */
492
+ tokenAddress: string;
493
+ /** Required payment amount in token base units (wei) */
494
+ amount: string;
495
+ /** Workflow ID to trigger */
496
+ workflowId: string;
497
+ /** Organization ID that owns the workflow */
498
+ orgId: string;
499
+ /** Optional callback metadata */
500
+ callbackMetadata?: {
501
+ inputs?: Record<string, unknown>;
502
+ } & Record<string, unknown>;
503
+ /** Callback when payment succeeds */
504
+ onSuccess?: (amount: string) => void;
505
+ /** Callback when modal is closed */
506
+ onClose?: () => void;
507
+ /** Custom action label */
508
+ actionLabel?: string;
509
+ /** Custom class names */
510
+ classes?: AnySpendAllClasses;
511
+ }
478
512
  export interface AnySpendDepositModalProps extends BaseModalProps {
479
513
  /** Modal type identifier */
480
514
  type: "anySpendDeposit";
@@ -534,11 +568,13 @@ export interface AnySpendDepositModalProps extends BaseModalProps {
534
568
  classes?: AnySpendAllClasses;
535
569
  /** Whether to allow direct transfer without swap */
536
570
  allowDirectTransfer?: boolean;
571
+ /** Opaque metadata passed to the order for callbacks (e.g., workflow form data) */
572
+ callbackMetadata?: Record<string, unknown>;
537
573
  }
538
574
  /**
539
575
  * Union type of all possible modal content types
540
576
  */
541
- export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | LinkNewAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | DepositModalProps | SendModalProps | NotificationsModalProps | AnySpendCollectorClubPurchaseProps | AnySpendDepositModalProps;
577
+ export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | LinkNewAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | DepositModalProps | SendModalProps | NotificationsModalProps | AnySpendCollectorClubPurchaseProps | AnySpendDepositModalProps | AnySpendWorkflowTriggerModalProps;
542
578
  /**
543
579
  * State interface for the modal store
544
580
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.1.65",
3
+ "version": "0.1.66-alpha.0",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -81,6 +81,7 @@ That's it! Your users can now purchase NFTs with any token from any supported ch
81
81
  | [🧩 Components API](./docs/components.md) | Pre-built React components for common use cases |
82
82
  | [🪝 Hooks API](./docs/hooks.md) | React hooks for custom implementations |
83
83
  | [💡 Examples & Use Cases](./docs/examples.md) | Real-world integration examples |
84
+ | [🛒 Checkout Sessions](./docs/checkout-sessions.md) | Stripe-like checkout sessions for merchant integrations |
84
85
  | [⚠️ Error Handling](./docs/error-handling.md) | Error handling patterns and troubleshooting |
85
86
  | [🤝 Contributing](./docs/contributing.md) | How to contribute to AnySpend |
86
87
 
@@ -123,6 +124,19 @@ That's it! Your users can now purchase NFTs with any token from any supported ch
123
124
  />
124
125
  ```
125
126
 
127
+ ### Merchant Checkout Sessions
128
+ ```tsx
129
+ <AnySpend
130
+ defaultActiveTab="fiat"
131
+ destinationTokenAddress="0x..." // USDC
132
+ recipientAddress={userAddress}
133
+ checkoutSession={{
134
+ success_url: "https://myshop.com/success?session={SESSION_ID}",
135
+ metadata: { sku: "widget-1" },
136
+ }}
137
+ />
138
+ ```
139
+
126
140
  ## 🌐 Supported Networks
127
141
 
128
142
  - **Ethereum** (Mainnet & Sepolia)
@@ -0,0 +1,228 @@
1
+ # Checkout Sessions
2
+
3
+ Stripe-like checkout sessions for AnySpend. Sessions are decoupled from orders — create a session first, then create an order when the user is ready to pay.
4
+
5
+ ## Flow
6
+
7
+ ```
8
+ 1. Merchant creates session POST /checkout-sessions
9
+ <- { id, status: "open" }
10
+
11
+ 2. User picks payment method POST /orders { checkoutSessionId }
12
+ <- { id, globalAddress, oneClickBuyUrl }
13
+
14
+ 3. User pays Crypto: send to globalAddress
15
+ Onramp: redirect to oneClickBuyUrl
16
+
17
+ 4. Merchant polls for completion GET /checkout-sessions/:id
18
+ <- { status: "complete", order_id }
19
+ ```
20
+
21
+ ### Why Decoupled?
22
+
23
+ Session creation is instant (DB-only, no external calls). The order is created separately when the user commits to a payment method. This means:
24
+
25
+ - Payment method doesn't need to be known at session creation
26
+ - A hosted checkout page can let users choose how to pay
27
+ - Session creation never fails due to external API errors
28
+
29
+ ## Session Status Lifecycle
30
+
31
+ ```
32
+ open --> processing --> complete
33
+ |
34
+ └--> expired
35
+ ```
36
+
37
+ | Status | When |
38
+ |--------|------|
39
+ | `open` | Created, waiting for order/payment |
40
+ | `processing` | Payment received, order executing |
41
+ | `complete` | Order executed successfully |
42
+ | `expired` | TTL expired, payment failed, or manually expired |
43
+
44
+ ## API
45
+
46
+ ### `POST /checkout-sessions` — Create Session
47
+
48
+ Creates a lightweight session. No order, no external API calls.
49
+
50
+ ```json
51
+ {
52
+ "success_url": "https://merchant.com/success?session_id={SESSION_ID}",
53
+ "cancel_url": "https://merchant.com/cancel",
54
+ "metadata": { "sku": "widget-1" },
55
+ "client_reference_id": "merchant-order-456",
56
+ "expires_in": 1800
57
+ }
58
+ ```
59
+
60
+ All fields are optional. Payment config (amount, tokens, chains) lives on the order, not the session.
61
+
62
+ ### `POST /orders` — Create Order with Session Linking
63
+
64
+ Pass `checkoutSessionId` in the standard order creation request to link the order to a session.
65
+
66
+ ```json
67
+ {
68
+ "recipientAddress": "0x...",
69
+ "srcChain": 8453,
70
+ "dstChain": 8453,
71
+ "srcTokenAddress": "0x...",
72
+ "dstTokenAddress": "0x...",
73
+ "srcAmount": "1000000",
74
+ "type": "swap",
75
+ "payload": { "expectedDstAmount": "1000000" },
76
+ "checkoutSessionId": "550e8400-..."
77
+ }
78
+ ```
79
+
80
+ **Validation:**
81
+ - Session must exist (`400` if not found)
82
+ - Session must be `open` (`400` if expired/processing/complete)
83
+ - Session must not already have an order (`409 Conflict`)
84
+
85
+ ### `GET /checkout-sessions/:id` — Retrieve Session
86
+
87
+ Returns current session state. Status is synced from the underlying order on each retrieval.
88
+
89
+ | Query Param | Description |
90
+ |-------------|-------------|
91
+ | `include=order` | Embed the full order object with transactions |
92
+
93
+ ### `POST /checkout-sessions/:id/expire` — Manually Expire
94
+
95
+ Only works on sessions with status `open`.
96
+
97
+ ## Redirect URL Templates
98
+
99
+ Use template variables in `success_url` and `cancel_url`:
100
+
101
+ | Variable | Replaced with |
102
+ |----------|--------------|
103
+ | `{SESSION_ID}` | The checkout session UUID |
104
+ | `{ORDER_ID}` | Same value (alias) |
105
+
106
+ If no template variable is present, `?sessionId=<uuid>` is appended automatically.
107
+
108
+ ## SDK Integration
109
+
110
+ ### Service Methods
111
+
112
+ ```typescript
113
+ // Create a checkout session
114
+ const session = await anyspend.createCheckoutSession({
115
+ success_url: "https://mysite.com/success/{SESSION_ID}",
116
+ metadata: { sku: "widget-1" },
117
+ });
118
+
119
+ // Retrieve session status
120
+ const session = await anyspend.getCheckoutSession(sessionId);
121
+ ```
122
+
123
+ ### React Hooks
124
+
125
+ #### `useCreateCheckoutSession`
126
+
127
+ Mutation hook for creating sessions.
128
+
129
+ ```tsx
130
+ import { useCreateCheckoutSession } from "@b3dotfun/sdk/anyspend";
131
+
132
+ const { mutate: createSession, data, isPending } = useCreateCheckoutSession();
133
+ ```
134
+
135
+ #### `useCheckoutSession`
136
+
137
+ Query hook with auto-polling. Stops polling when status reaches `complete` or `expired`.
138
+
139
+ ```tsx
140
+ import { useCheckoutSession } from "@b3dotfun/sdk/anyspend";
141
+
142
+ const { data: session, isLoading } = useCheckoutSession(sessionId);
143
+ ```
144
+
145
+ ### Component `checkoutSession` Prop
146
+
147
+ The `<AnySpend>`, `<AnySpendCustom>`, and `<AnySpendCustomExactIn>` components accept an optional `checkoutSession` prop:
148
+
149
+ ```tsx
150
+ <AnySpend
151
+ defaultActiveTab="fiat"
152
+ destinationTokenAddress="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
153
+ destinationTokenChainId={8453}
154
+ recipientAddress="0x..."
155
+ checkoutSession={{
156
+ success_url: "https://myshop.com/success?session={SESSION_ID}",
157
+ cancel_url: "https://myshop.com/cancel",
158
+ metadata: { sku: "widget-1" },
159
+ }}
160
+ />
161
+ ```
162
+
163
+ When the `checkoutSession` prop is set, the component automatically creates a session before creating the order, and uses the session's `success_url` for redirects. Without the prop, existing flows are unchanged.
164
+
165
+ ## Examples
166
+
167
+ ### Crypto Payment
168
+
169
+ ```typescript
170
+ // 1. Create session
171
+ const session = await fetch("/checkout-sessions", {
172
+ method: "POST",
173
+ body: JSON.stringify({
174
+ success_url: "https://mysite.com/success/{SESSION_ID}",
175
+ metadata: { sku: "widget-1" },
176
+ }),
177
+ }).then(r => r.json());
178
+
179
+ // 2. Create order linked to session
180
+ const order = await fetch("/orders", {
181
+ method: "POST",
182
+ body: JSON.stringify({
183
+ recipientAddress: "0x...",
184
+ srcChain: 8453,
185
+ dstChain: 8453,
186
+ srcTokenAddress: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
187
+ dstTokenAddress: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
188
+ srcAmount: "1000000",
189
+ type: "swap",
190
+ payload: { expectedDstAmount: "1000000" },
191
+ checkoutSessionId: session.data.id,
192
+ }),
193
+ }).then(r => r.json());
194
+
195
+ // 3. User sends crypto to order.data.globalAddress
196
+
197
+ // 4. Poll session until complete
198
+ const poll = setInterval(async () => {
199
+ const s = await fetch(`/checkout-sessions/${session.data.id}`).then(r => r.json());
200
+ if (s.data.status === "complete") {
201
+ clearInterval(poll);
202
+ // redirect to success_url or show confirmation
203
+ }
204
+ }, 3000);
205
+ ```
206
+
207
+ ### Onramp Payment (Coinbase/Stripe)
208
+
209
+ ```typescript
210
+ // Steps 1-2 same as above, but include onramp config in order creation:
211
+ const order = await fetch("/orders", {
212
+ method: "POST",
213
+ body: JSON.stringify({
214
+ // ... same order fields ...
215
+ checkoutSessionId: session.data.id,
216
+ onramp: {
217
+ vendor: "coinbase",
218
+ payment_method: "card",
219
+ country: "US",
220
+ },
221
+ }),
222
+ }).then(r => r.json());
223
+
224
+ // Redirect user to vendor checkout page
225
+ window.location.href = order.data.oneClickBuyUrl;
226
+
227
+ // After vendor redirects back, poll GET /checkout-sessions/:id for completion
228
+ ```
@@ -207,6 +207,32 @@ const stakingCalldata = encodeFunctionData({
207
207
  />
208
208
  ```
209
209
 
210
+ ### Checkout Session Prop
211
+
212
+ The `<AnySpend>`, `<AnySpendCustom>`, and `<AnySpendCustomExactIn>` components accept an optional `checkoutSession` prop for merchant checkout flows. When set, the component creates a session before the order and uses the session's redirect URLs. See [Checkout Sessions](./checkout-sessions.md) for the full guide.
213
+
214
+ ```tsx
215
+ <AnySpend
216
+ defaultActiveTab="fiat"
217
+ destinationTokenAddress="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
218
+ destinationTokenChainId={8453}
219
+ recipientAddress="0x..."
220
+ checkoutSession={{
221
+ success_url: "https://myshop.com/success?session={SESSION_ID}",
222
+ cancel_url: "https://myshop.com/cancel",
223
+ metadata: { sku: "widget-1" },
224
+ }}
225
+ />
226
+ ```
227
+
228
+ | Prop | Type | Description |
229
+ |------|------|-------------|
230
+ | `checkoutSession.success_url` | `string` | Redirect URL on completion. Supports `{SESSION_ID}` template. |
231
+ | `checkoutSession.cancel_url` | `string` | Redirect URL on cancellation |
232
+ | `checkoutSession.metadata` | `Record<string, string>` | Custom metadata attached to the session |
233
+
234
+ ---
235
+
210
236
  ## Specialized Components
211
237
 
212
238
  ### `<AnySpendNFT>`
@@ -720,8 +720,66 @@ function PortfolioRebalancer() {
720
720
  }
721
721
  ```
722
722
 
723
+ ## 🛒 Checkout Sessions (Merchant Integration)
724
+
725
+ ### Hosted Checkout with Payment Choice
726
+
727
+ Let users choose their payment method (crypto or fiat) after session creation.
728
+
729
+ ```tsx
730
+ import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
731
+
732
+ function MerchantCheckout({ sku, price }: { sku: string; price: string }) {
733
+ const [userAddress] = useWallet();
734
+
735
+ return (
736
+ <AnySpend
737
+ defaultActiveTab="fiat"
738
+ destinationTokenAddress="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
739
+ destinationTokenChainId={8453}
740
+ recipientAddress={userAddress}
741
+ checkoutSession={{
742
+ success_url: "https://myshop.com/success?session={SESSION_ID}",
743
+ cancel_url: "https://myshop.com/cancel",
744
+ metadata: { sku, price },
745
+ }}
746
+ />
747
+ );
748
+ }
749
+ ```
750
+
751
+ ### Server-Side Session with Custom Polling
752
+
753
+ ```tsx
754
+ import {
755
+ useCreateCheckoutSession,
756
+ useCheckoutSession,
757
+ } from "@b3dotfun/sdk/anyspend";
758
+
759
+ function ServerCheckout() {
760
+ const { mutate: createSession, data: session } = useCreateCheckoutSession();
761
+ const { data: sessionStatus } = useCheckoutSession(session?.data?.id);
762
+
763
+ useEffect(() => {
764
+ createSession({
765
+ success_url: "https://mysite.com/success/{SESSION_ID}",
766
+ metadata: { sku: "widget-1" },
767
+ });
768
+ }, []);
769
+
770
+ if (sessionStatus?.data?.status === "complete") {
771
+ return <div>Payment complete!</div>;
772
+ }
773
+
774
+ // Render order creation UI...
775
+ }
776
+ ```
777
+
778
+ See [Checkout Sessions](./checkout-sessions.md) for the full guide including API details and the session lifecycle.
779
+
723
780
  ## Next Steps
724
781
 
782
+ - [Checkout Sessions →](./checkout-sessions.md)
725
783
  - [Error Handling Guide →](./error-handling.md)
726
784
  - [Components Reference →](./components.md)
727
785
  - [Hooks Reference →](./hooks.md)
@@ -385,6 +385,38 @@ Get Stripe payment intent for credit card payments.
385
385
  const { clientSecret, isLoadingClientSecret } = useStripeClientSecret(orderData);
386
386
  ```
387
387
 
388
+ ### `useCreateCheckoutSession`
389
+
390
+ Create checkout sessions for merchant integrations. See [Checkout Sessions](./checkout-sessions.md) for the full guide.
391
+
392
+ ```tsx
393
+ import { useCreateCheckoutSession } from "@b3dotfun/sdk/anyspend";
394
+
395
+ const { mutate: createSession, data, isPending } = useCreateCheckoutSession();
396
+
397
+ createSession({
398
+ success_url: "https://mysite.com/success/{SESSION_ID}",
399
+ cancel_url: "https://mysite.com/cancel",
400
+ metadata: { sku: "widget-1" },
401
+ });
402
+ ```
403
+
404
+ ---
405
+
406
+ ### `useCheckoutSession`
407
+
408
+ Poll a checkout session's status. Auto-polls while the session is `open` or `processing`, and stops when `complete` or `expired`.
409
+
410
+ ```tsx
411
+ import { useCheckoutSession } from "@b3dotfun/sdk/anyspend";
412
+
413
+ const { data: session, isLoading } = useCheckoutSession(sessionId);
414
+
415
+ // session.data.status: "open" | "processing" | "complete" | "expired"
416
+ ```
417
+
418
+ ---
419
+
388
420
  ## Hook Patterns
389
421
 
390
422
  ### Error Handling Pattern