@rozoai/intent-common 0.0.29 → 0.0.30

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.
@@ -0,0 +1,36 @@
1
+ import { ApiResponse } from "./base";
2
+ /**
3
+ * Fee response data type (success case)
4
+ */
5
+ export interface FeeResponseData {
6
+ appId: string;
7
+ amount: number;
8
+ currency: string;
9
+ fee: number;
10
+ feePercentage: string;
11
+ minimumFee: string;
12
+ amount_out: number;
13
+ }
14
+ /**
15
+ * Fee error response data type
16
+ */
17
+ export interface FeeErrorData {
18
+ error: string;
19
+ message: string;
20
+ received: number;
21
+ maxAllowed: number;
22
+ }
23
+ /**
24
+ * Fee request parameters
25
+ */
26
+ export interface GetFeeParams {
27
+ amount: number;
28
+ appId?: string;
29
+ currency?: string;
30
+ }
31
+ /**
32
+ * Gets fee calculation for a payment amount
33
+ * @param params - Fee calculation parameters (amount is required)
34
+ * @returns Promise with fee response or error
35
+ */
36
+ export declare const getFee: (params: GetFeeParams) => Promise<ApiResponse<FeeResponseData>>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFee = void 0;
4
+ /**
5
+ * Gets fee calculation for a payment amount
6
+ * @param params - Fee calculation parameters (amount is required)
7
+ * @returns Promise with fee response or error
8
+ */
9
+ const getFee = async (params) => {
10
+ const { amount, appId = "rozodemo", currency = "USDC" } = params;
11
+ try {
12
+ const queryParams = new URLSearchParams({
13
+ amount: amount.toString(),
14
+ appId,
15
+ currency,
16
+ });
17
+ const response = await fetch(`https://intentapi.rozo.ai/getFee?${queryParams.toString()}`);
18
+ const data = (await response.json());
19
+ // Check if response contains an error
20
+ if (!response.ok || "error" in data) {
21
+ const errorData = data;
22
+ return {
23
+ data: null,
24
+ error: new Error(errorData.message || errorData.error),
25
+ status: response.status,
26
+ };
27
+ }
28
+ return {
29
+ data: data,
30
+ error: null,
31
+ status: response.status,
32
+ };
33
+ }
34
+ catch (error) {
35
+ return {
36
+ data: null,
37
+ error: error instanceof Error ? error : new Error(String(error)),
38
+ status: null,
39
+ };
40
+ }
41
+ };
42
+ exports.getFee = getFee;
43
+ //# sourceMappingURL=fee.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fee.js","sourceRoot":"","sources":["../../src/api/fee.ts"],"names":[],"mappings":";;;AAkCA;;;;GAIG;AACI,MAAM,MAAM,GAAG,KAAK,EACzB,MAAoB,EACmB,EAAE;IACzC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,UAAU,EAAE,QAAQ,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IAEjE,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC;YACtC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;YACzB,KAAK;YACL,QAAQ;SACT,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,oCAAoC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAC7D,CAAC;QAEF,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAmC,CAAC;QAEvE,sCAAsC;QACtC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,SAAS,GAAG,IAAoB,CAAC;YACvC,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,KAAK,EAAE,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC;gBACtD,MAAM,EAAE,QAAQ,CAAC,MAAM;aACxB,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,IAAuB;YAC7B,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAxCW,QAAA,MAAM,UAwCjB"}
@@ -44,11 +44,11 @@ export declare const zBridgeTokenOutOptions: z.ZodArray<z.ZodObject<{
44
44
  token: z.ZodEffects<z.ZodString, `0x${string}`, string>;
45
45
  amount: z.ZodEffects<z.ZodEffects<z.ZodString, `${bigint}`, string>, bigint, string>;
46
46
  }, "strip", z.ZodTypeAny, {
47
- token: `0x${string}`;
48
47
  amount: bigint;
48
+ token: `0x${string}`;
49
49
  }, {
50
- token: string;
51
50
  amount: string;
51
+ token: string;
52
52
  }>, "many">;
53
53
  export type BridgeTokenOutOptions = z.infer<typeof zBridgeTokenOutOptions>;
54
54
  export declare const zRozoPayOrderMetadata: z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./api/fee";
1
2
  export * from "./api/payment";
2
3
  export * from "./assert";
3
4
  export * from "./bridge";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api/fee"), exports);
17
18
  __exportStar(require("./api/payment"), exports);
18
19
  __exportStar(require("./assert"), exports);
19
20
  __exportStar(require("./bridge"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,gDAA8B;AAC9B,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rozoai/intent-common",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "Intent Pay shared types and utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/api/README.md CHANGED
@@ -30,7 +30,7 @@ These defaults are automatically used by the API client, so you can start making
30
30
  ```bash
31
31
  api/
32
32
  ├── base.ts # Core API client functionality
33
- ├── index.ts # Re-exports all API modules
33
+ ├── fee.ts # Fee calculation endpoint
34
34
  ├── payment.ts # Payment-specific endpoints
35
35
  └── README.md # Documentation
36
36
  ```
@@ -67,83 +67,313 @@ const response = await apiClient.get("/some-endpoint", {
67
67
 
68
68
  ## Using Payment API
69
69
 
70
- The payment module provides typed functions for payment operations:
70
+ The payment module provides typed functions for payment operations. The `createRozoPayment` function is the core method for creating cross-chain payments.
71
+
72
+ ### Creating a Payment
73
+
74
+ The `createRozoPayment` function requires a `PaymentRequestData` object with the following structure:
71
75
 
72
76
  ```typescript
73
77
  import {
74
78
  createRozoPayment,
75
79
  getRozoPayment,
76
- createRozoPaymentRequest,
80
+ createPaymentBridgeConfig,
81
+ mergedMetadata,
82
+ PaymentRequestData,
77
83
  } from "@rozoai/intent-common";
78
84
 
79
- // Create a payment
85
+ // Basic payment creation
80
86
  const handleSubmitPayment = async () => {
81
- const paymentData = createRozoPaymentRequest({
87
+ // First, create payment bridge configuration
88
+ // This determines the preferred payment method and destination
89
+ // payInTokenAddress can be: USDC Base, USDC Polygon, USDC Solana, USDC Stellar, or USDT BNB
90
+ const { preferred, destination } = createPaymentBridgeConfig({
91
+ toChain: 8453, // Base chain
92
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
93
+ toAddress: "0x1234567890123456789012345678901234567890",
94
+ toUnits: "1000000", // 1 USDC (6 decimals)
95
+ payInTokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Polygon USDC
96
+ });
97
+
98
+ // Construct payment data
99
+ const paymentData: PaymentRequestData = {
82
100
  appId: "your-app-id",
83
101
  display: {
84
102
  intent: "Pay for product",
85
- paymentValue: "100.00",
103
+ paymentValue: "1.00", // Display value in USD
86
104
  currency: "USD",
87
105
  },
88
106
  destination: {
89
- chainId: "8453",
90
- amountUnits: "100000000",
91
- tokenSymbol: "USDC",
92
- tokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
107
+ destinationAddress: destination.destinationAddress,
108
+ chainId: destination.chainId,
109
+ amountUnits: destination.amountUnits,
110
+ tokenSymbol: destination.tokenSymbol,
111
+ tokenAddress: destination.tokenAddress,
93
112
  },
94
- });
113
+ // Spread preferred payment configuration
114
+ ...preferred,
115
+ // Optional: external ID for tracking
116
+ externalId: "order-123",
117
+ // Optional: metadata
118
+ metadata: {
119
+ preferredChain: preferred.preferredChain,
120
+ preferredToken: preferred.preferredToken,
121
+ preferredTokenAddress: preferred.preferredTokenAddress,
122
+ // Merge additional metadata
123
+ ...mergedMetadata({
124
+ customField: "value",
125
+ }),
126
+ },
127
+ };
95
128
 
129
+ // Create the payment
96
130
  const response = await createRozoPayment(paymentData);
97
131
 
98
132
  if (response.data) {
99
133
  console.log("Payment created:", response.data.id);
134
+ console.log("Payment status:", response.data.status);
135
+ console.log("Payment URL:", response.data.url);
100
136
  } else if (response.error) {
101
137
  console.error("Error creating payment:", response.error.message);
102
138
  }
103
139
  };
140
+ ```
141
+
142
+ ### Example: Pay Out to Stellar
143
+
144
+ ```typescript
145
+ // Paying out to a Stellar address
146
+ const { preferred, destination } = createPaymentBridgeConfig({
147
+ toStellarAddress: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // REQUIRED: Stellar address
148
+ toAddress: "0x1234567890123456789012345678901234567890", // REQUIRED: any valid EVM address
149
+ // toChain and toToken are optional (default to USDC Base)
150
+ toUnits: "1000000", // 1 USDC
151
+ payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
152
+ });
153
+
154
+ const paymentData: PaymentRequestData = {
155
+ appId: "your-app-id",
156
+ display: {
157
+ intent: "Pay to Stellar wallet",
158
+ paymentValue: "1.00",
159
+ currency: "USD",
160
+ },
161
+ ...preferred,
162
+ destination,
163
+ };
164
+
165
+ const response = await createRozoPayment(paymentData);
166
+ ```
167
+
168
+ ### Example: Pay Out to Solana
169
+
170
+ ```typescript
171
+ // Paying out to a Solana address
172
+ const { preferred, destination } = createPaymentBridgeConfig({
173
+ toSolanaAddress: "So11111111111111111111111111111111111111112", // REQUIRED: Solana address
174
+ toAddress: "0x1234567890123456789012345678901234567890", // REQUIRED: any valid EVM address
175
+ // toChain and toToken are optional (default to USDC Base)
176
+ toUnits: "1000000", // 1 USDC
177
+ payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
178
+ });
179
+
180
+ const paymentData: PaymentRequestData = {
181
+ appId: "your-app-id",
182
+ display: {
183
+ intent: "Pay to Solana wallet",
184
+ paymentValue: "1.00",
185
+ currency: "USD",
186
+ },
187
+ ...preferred,
188
+ destination,
189
+ };
190
+
191
+ const response = await createRozoPayment(paymentData);
192
+ ```
193
+
194
+ ### Payment Request Data Structure
195
+
196
+ The `PaymentRequestData` interface includes:
197
+
198
+ - **`appId`** (required): Your application identifier
199
+ - **`display`** (required): Payment display information
200
+ - `intent`: Description of the payment
201
+ - `paymentValue`: Amount as a string (e.g., "100.00")
202
+ - `currency`: Currency code (e.g., "USD")
203
+ - **`destination`** (required): Payment destination configuration
204
+ - `destinationAddress`: Recipient address
205
+ - `chainId`: Destination chain ID as string
206
+ - `amountUnits`: Amount in smallest token unit (as string)
207
+ - `tokenSymbol`: Token symbol (e.g., "USDC")
208
+ - `tokenAddress`: Token contract address
209
+ - **`preferredChain`** (optional): Preferred source chain ID
210
+ - **`preferredToken`** (optional): Preferred source token symbol
211
+ - **`preferredTokenAddress`** (optional): Preferred source token address
212
+ - **`externalId`** (optional): External identifier for tracking
213
+ - **`metadata`** (optional): Additional metadata object
214
+
215
+ ### Using createPaymentBridgeConfig
216
+
217
+ The `createPaymentBridgeConfig` helper function simplifies cross-chain payment configuration. It determines the preferred payment method based on the `payInTokenAddress` parameter.
218
+
219
+ **Important Notes:**
220
+
221
+ - **For EVM chain payouts (Base, Polygon, etc.)**: Provide `toAddress` with the destination EVM address. `toChain` and `toToken` are optional but default to USDC Base.
222
+ - **For Stellar payouts**: You **must** provide `toStellarAddress` with the Stellar address. You **must** also provide `toAddress` with any valid EVM address (required for internal routing). `toChain` and `toToken` are optional but default to USDC Base.
223
+ - **For Solana payouts**: You **must** provide `toSolanaAddress` with the Solana address. You **must** also provide `toAddress` with any valid EVM address (required for internal routing). `toChain` and `toToken` are optional but default to USDC Base.
224
+
225
+ **Supported `payInTokenAddress` values:**
226
+
227
+ - **USDC Base** - Base chain USDC token
228
+ - **USDC Polygon** - Polygon chain USDC token
229
+ - **USDC Solana** - Solana USDC token
230
+ - **USDC Stellar** - Stellar USDC token (format: `USDC:issuerPK` or issuer public key)
231
+ - **USDT BNB** - BSC (Binance Smart Chain) USDT token
232
+
233
+ ```typescript
234
+ import { createPaymentBridgeConfig } from "@rozoai/intent-common";
235
+
236
+ // Example: User pays with Polygon USDC, receives on Base
237
+ const { preferred, destination } = createPaymentBridgeConfig({
238
+ toChain: 8453, // Base
239
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
240
+ toAddress: "0x...",
241
+ toUnits: "1000000", // 1 USDC
242
+ payInTokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Polygon USDC
243
+ });
244
+
245
+ // preferred contains: preferredChain, preferredToken, preferredTokenAddress
246
+ // destination contains: destinationAddress, chainId, amountUnits, tokenSymbol, tokenAddress
247
+ ```
248
+
249
+ **More examples:**
250
+
251
+ ```typescript
252
+ // Pay with Base USDC
253
+ const { preferred, destination } = createPaymentBridgeConfig({
254
+ toChain: 8453,
255
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
256
+ toAddress: "0x...",
257
+ toUnits: "1000000",
258
+ payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
259
+ });
260
+
261
+ // Pay with Solana USDC - Pay Out to Solana
262
+ // Note: toSolanaAddress is REQUIRED, toAddress is REQUIRED (any valid EVM address)
263
+ // toChain and toToken are optional (default to USDC Base)
264
+ const { preferred, destination } = createPaymentBridgeConfig({
265
+ toSolanaAddress: "So11111111111111111111111111111111111111112", // Solana destination address
266
+ toAddress: "0x1234567890123456789012345678901234567890", // Required: any valid EVM address
267
+ // toChain and toToken are optional, default to USDC Base
268
+ toUnits: "1000000",
269
+ payInTokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // Solana USDC
270
+ });
104
271
 
105
- // Get payment details
272
+ // Pay with Stellar USDC - Pay Out to Stellar
273
+ // Note: toStellarAddress is REQUIRED, toAddress is REQUIRED (any valid EVM address)
274
+ // toChain and toToken are optional (default to USDC Base)
275
+ const { preferred, destination } = createPaymentBridgeConfig({
276
+ toStellarAddress: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar destination address
277
+ toAddress: "0x1234567890123456789012345678901234567890", // Required: any valid EVM address
278
+ // toChain and toToken are optional, default to USDC Base
279
+ toUnits: "1000000",
280
+ payInTokenAddress:
281
+ "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar USDC
282
+ });
283
+
284
+ // Pay with BSC USDT
285
+ const { preferred, destination } = createPaymentBridgeConfig({
286
+ toChain: 8453,
287
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
288
+ toAddress: "0x...",
289
+ toUnits: "1000000",
290
+ payInTokenAddress: "0x55d398326f99059fF775485246999027B3197955", // BSC USDT
291
+ });
292
+ ```
293
+
294
+ ### Getting Payment Details
295
+
296
+ ```typescript
297
+ // Get payment by ID
106
298
  const fetchPaymentDetails = async (paymentId: string) => {
107
299
  const response = await getRozoPayment(paymentId);
108
300
 
109
301
  if (response.data) {
110
302
  console.log("Payment status:", response.data.status);
303
+ console.log("Payment intent:", response.data.display.intent);
304
+ console.log(
305
+ "Destination address:",
306
+ response.data.destination.destinationAddress
307
+ );
308
+ console.log("Transaction hash:", response.data.destination.txHash);
309
+ } else if (response.error) {
310
+ console.error("Error fetching payment:", response.error.message);
111
311
  }
112
312
  };
113
313
  ```
114
314
 
315
+ ### Real-World Usage Pattern
316
+
317
+ In the SDK, `createRozoPayment` is typically used within payment flow effects:
318
+
319
+ ```typescript
320
+ // Example from paymentEffects.ts
321
+ const paymentData: PaymentRequestData = {
322
+ appId: payParams?.rozoAppId ?? payParams?.appId ?? DEFAULT_ROZO_APP_ID,
323
+ display: {
324
+ intent: order?.metadata?.intent ?? "",
325
+ paymentValue: String(toUnits),
326
+ currency: "USD",
327
+ },
328
+ ...preferred, // Spread preferred config from createPaymentBridgeConfig
329
+ destination, // Destination config from createPaymentBridgeConfig
330
+ externalId: order?.externalId ?? "",
331
+ metadata: {
332
+ preferredChain: preferred.preferredChain,
333
+ preferredToken: preferred.preferredToken,
334
+ preferredTokenAddress: preferred.preferredTokenAddress,
335
+ ...mergedMetadata({
336
+ ...(payParams?.metadata ?? {}),
337
+ ...(order?.metadata ?? {}),
338
+ ...(order.userMetadata ?? {}),
339
+ }),
340
+ },
341
+ };
342
+
343
+ const rozoPayment = await createRozoPayment(paymentData);
344
+ if (!rozoPayment?.data?.id) {
345
+ throw new Error(rozoPayment?.error?.message ?? "Payment creation failed");
346
+ }
347
+ ```
348
+
115
349
  ## React Hooks
116
350
 
117
- React hooks for these APIs are available in the `@rozoai/intent-pay` package:
351
+ React hooks for these APIs are available in the `@rozoai/intent-pay` package. The SDK handles payment creation internally through the payment state machine, but you can access payment state using hooks:
118
352
 
119
353
  ```typescript
120
354
  // In @rozoai/intent-pay
121
- import {
122
- useCreateRozoPayment,
123
- useRozoPayment,
124
- useRozoPayments
125
- } from '@rozoai/intent-pay';
355
+ import { useRozoPay, useRozoPayStatus, useRozoPayUI } from "@rozoai/intent-pay";
126
356
 
127
357
  // Use in React components
128
- const PaymentForm = () => {
129
- const [paymentState, submitPayment] = useCreateRozoPayment();
130
-
131
- const handleSubmit = (formData) => {
132
- submitPayment({
133
- appId: 'your-app-id',
134
- display: { ... },
135
- destination: { ... }
136
- });
137
- };
358
+ const PaymentComponent = () => {
359
+ const { createPreviewOrder, payWallet } = useRozoPay();
360
+ const { paymentStatus } = useRozoPayStatus();
361
+ const { isOpen, openRozoPay, closeRozoPay } = useRozoPayUI();
362
+
363
+ // Payment creation is handled internally by the SDK
364
+ // when using RozoPayButton or calling createPreviewOrder
365
+ // The SDK automatically uses createRozoPayment under the hood
138
366
 
139
- if (paymentState.isLoading) return <div>Processing...</div>;
140
- if (paymentState.isError) return <div>Error: {paymentState.error?.message}</div>;
141
- if (paymentState.isSuccess) return <div>Success! ID: {paymentState.data?.id}</div>;
367
+ if (paymentStatus === "payment_completed") {
368
+ return <div>Payment successful!</div>;
369
+ }
142
370
 
143
- return <FormComponent onSubmit={handleSubmit} />;
371
+ return <RozoPayButton {...paymentProps} />;
144
372
  };
145
373
  ```
146
374
 
375
+ Note: The SDK's payment flow automatically handles `createRozoPayment` calls internally. You typically don't need to call it directly when using the SDK components.
376
+
147
377
  ## Error Handling
148
378
 
149
379
  All API responses include standardized error handling:
@@ -181,17 +411,25 @@ const response: ApiResponse<PaymentResponseData> = await getRozoPayment(
181
411
  The API client is pre-configured with production RozoAI settings, so you can use it immediately:
182
412
 
183
413
  ```typescript
184
- import { createRozoPayment } from "@rozoai/intent-common";
414
+ import {
415
+ createRozoPayment,
416
+ createPaymentBridgeConfig,
417
+ } from "@rozoai/intent-common";
185
418
 
186
419
  // Works out of the box with default configuration
420
+ const { preferred, destination } = createPaymentBridgeConfig({
421
+ toChain: 8453,
422
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
423
+ toAddress: "0x...",
424
+ toUnits: "10000000",
425
+ payInTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
426
+ });
427
+
187
428
  const response = await createRozoPayment({
188
429
  appId: "your-app-id",
189
430
  display: { intent: "Payment", paymentValue: "10.00", currency: "USD" },
190
- destination: {
191
- chainId: "8453",
192
- amountUnits: "10000000",
193
- tokenSymbol: "USDC",
194
- },
431
+ ...preferred,
432
+ destination,
195
433
  });
196
434
  ```
197
435
 
@@ -256,15 +494,56 @@ setApiConfig({
256
494
  });
257
495
  ```
258
496
 
497
+ ## Using Fee API
498
+
499
+ The fee module provides a function to calculate fees for payment amounts:
500
+
501
+ ```typescript
502
+ import { getFee } from "@rozoai/intent-common";
503
+
504
+ // Get fee calculation (only amount is required)
505
+ const calculateFee = async () => {
506
+ const response = await getFee({
507
+ amount: 0.1,
508
+ // Optional parameters with defaults:
509
+ // appId: "rozodemo",
510
+ // currency: "USDC"
511
+ });
512
+
513
+ if (response.data) {
514
+ console.log("Fee:", response.data.fee);
515
+ console.log("Fee Percentage:", response.data.feePercentage);
516
+ console.log("Amount Out:", response.data.amount_out);
517
+ console.log("Minimum Fee:", response.data.minimumFee);
518
+ } else if (response.error) {
519
+ console.error("Error calculating fee:", response.error.message);
520
+ // Error response includes details like max allowed amount
521
+ }
522
+ };
523
+
524
+ // With custom appId and currency
525
+ const response = await getFee({
526
+ amount: 100,
527
+ appId: "myapp",
528
+ currency: "USDC",
529
+ });
530
+ ```
531
+
259
532
  ## Available Payment Functions
260
533
 
261
- - `createRozoPayment(paymentData)` - Create a new payment
262
- - `getRozoPayment(paymentId)` - Get payment by ID
263
- - `getRozoPaymentByExternalId(externalId)` - Get payment by external ID
264
- - `updateRozoPayment(paymentId, paymentData)` - Update a payment
265
- - `cancelRozoPayment(paymentId)` - Cancel a payment
266
- - `listRozoPayments(params?)` - List all payments with optional filters
267
- - `createRozoPaymentRequest(options)` - Create a payment request payload
534
+ - **`createRozoPayment(paymentData: PaymentRequestData)`** - Create a new cross-chain payment. Requires `appId`, `display`, and `destination`. Use `createPaymentBridgeConfig` to generate `preferred` and `destination` configurations. Returns `ApiResponse<PaymentResponseData>` with payment ID, status, and URL.
535
+
536
+ - **`getRozoPayment(paymentId: string)`** - Get payment details by ID. Automatically handles both standard payment IDs and MugglePay order IDs. Returns `ApiResponse<PaymentResponseData>` with full payment information including status, destination, and transaction hashes.
537
+
538
+ ### Helper Functions
539
+
540
+ - **`createPaymentBridgeConfig(config: PaymentBridgeConfig)`** - Creates payment bridge configuration for cross-chain payments. Determines preferred payment method (source chain/token) and destination configuration. The `payInTokenAddress` parameter supports: USDC Base, USDC Polygon, USDC Solana, USDC Stellar, and USDT BNB. Returns `{ preferred: PreferredPaymentConfig, destination: DestinationConfig }`.
541
+
542
+ - **`mergedMetadata(...metadataObjects)`** - Utility function to merge multiple metadata objects while handling conflicts and filtering sensitive fields.
543
+
544
+ ## Available Fee Functions
545
+
546
+ - `getFee(params)` - Calculate fee for a payment amount (amount required, appId and currency optional)
268
547
 
269
548
  ## Best Practices
270
549
 
package/src/api/fee.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { ApiResponse } from "./base";
2
+
3
+ /**
4
+ * Fee response data type (success case)
5
+ */
6
+ export interface FeeResponseData {
7
+ appId: string;
8
+ amount: number;
9
+ currency: string;
10
+ fee: number;
11
+ feePercentage: string;
12
+ minimumFee: string;
13
+ amount_out: number;
14
+ }
15
+
16
+ /**
17
+ * Fee error response data type
18
+ */
19
+ export interface FeeErrorData {
20
+ error: string;
21
+ message: string;
22
+ received: number;
23
+ maxAllowed: number;
24
+ }
25
+
26
+ /**
27
+ * Fee request parameters
28
+ */
29
+ export interface GetFeeParams {
30
+ amount: number;
31
+ appId?: string;
32
+ currency?: string;
33
+ }
34
+
35
+ /**
36
+ * Gets fee calculation for a payment amount
37
+ * @param params - Fee calculation parameters (amount is required)
38
+ * @returns Promise with fee response or error
39
+ */
40
+ export const getFee = async (
41
+ params: GetFeeParams
42
+ ): Promise<ApiResponse<FeeResponseData>> => {
43
+ const { amount, appId = "rozodemo", currency = "USDC" } = params;
44
+
45
+ try {
46
+ const queryParams = new URLSearchParams({
47
+ amount: amount.toString(),
48
+ appId,
49
+ currency,
50
+ });
51
+
52
+ const response = await fetch(
53
+ `https://intentapi.rozo.ai/getFee?${queryParams.toString()}`
54
+ );
55
+
56
+ const data = (await response.json()) as FeeResponseData | FeeErrorData;
57
+
58
+ // Check if response contains an error
59
+ if (!response.ok || "error" in data) {
60
+ const errorData = data as FeeErrorData;
61
+ return {
62
+ data: null,
63
+ error: new Error(errorData.message || errorData.error),
64
+ status: response.status,
65
+ };
66
+ }
67
+
68
+ return {
69
+ data: data as FeeResponseData,
70
+ error: null,
71
+ status: response.status,
72
+ };
73
+ } catch (error) {
74
+ return {
75
+ data: null,
76
+ error: error instanceof Error ? error : new Error(String(error)),
77
+ status: null,
78
+ };
79
+ }
80
+ };
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./api/fee";
1
2
  export * from "./api/payment";
2
3
  export * from "./assert";
3
4
  export * from "./bridge";