@rozoai/intent-common 0.1.0-beta.1 → 0.1.0-beta.3

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,94 +1,262 @@
1
1
  import { ApiResponse } from "./base";
2
- import { DisplayInfo } from "./new-payment";
3
2
  /**
4
- * Payment display information
3
+ * FeeType, Fee calculation type:
4
+ * - exactIn (default): Fee deducted from input, recipient receives amount - fee
5
+ * - exactOut: Fee added to input, recipient receives exact amount
5
6
  */
6
- export interface PaymentDisplay {
7
- intent: string;
8
- paymentValue: string;
9
- currency: string;
7
+ export declare enum FeeType {
8
+ ExactIn = "exactIn",
9
+ ExactOut = "exactOut"
10
10
  }
11
11
  /**
12
- * Payment destination information
12
+ * PaymentStatus, Payment status
13
13
  */
14
- export interface PaymentDestination {
15
- destinationAddress?: string;
16
- chainId: string;
17
- amountUnits: string;
18
- tokenSymbol: string;
14
+ export declare enum PaymentStatus {
15
+ PaymentBounced = "payment_bounced",
16
+ PaymentCompleted = "payment_completed",
17
+ PaymentExpired = "payment_expired",
18
+ PaymentPayinCompleted = "payment_payin_completed",
19
+ PaymentPayoutCompleted = "payment_payout_completed",
20
+ PaymentRefunded = "payment_refunded",
21
+ PaymentStarted = "payment_started",
22
+ PaymentUnpaid = "payment_unpaid"
23
+ }
24
+ /**
25
+ * PaymentErrorCode, Error code (only present when status is payment_bounced)
26
+ */
27
+ export declare enum PaymentErrorCode {
28
+ AmountTooHigh = "amountTooHigh",
29
+ AmountTooLow = "amountTooLow",
30
+ ChainUnavailable = "chainUnavailable",
31
+ InsufficientLiquidity = "insufficientLiquidity",
32
+ InvalidRecipient = "invalidRecipient",
33
+ MissingTrustline = "missingTrustline",
34
+ NetworkError = "networkError",
35
+ ProviderError = "providerError",
36
+ ServiceMaintenance = "serviceMaintenance"
37
+ }
38
+ /**
39
+ * DestinationRequest
40
+ */
41
+ export interface DestinationRequest {
42
+ /**
43
+ * Receive amount (required for type=exactOut).
44
+ * For exactIn, this field is omitted in request and calculated in response.
45
+ */
46
+ amount?: string;
47
+ chainId: number;
48
+ /**
49
+ * Final recipient's wallet address
50
+ */
51
+ receiverAddress: string;
52
+ /**
53
+ * Memo for Stellar/Solana destinations
54
+ */
55
+ receiverMemo?: string;
56
+ /**
57
+ * Override default token address
58
+ */
19
59
  tokenAddress?: string;
20
- txHash?: string | null;
60
+ tokenSymbol: string;
61
+ [property: string]: any;
62
+ }
63
+ /**
64
+ * DisplayInfo
65
+ */
66
+ export interface DisplayInfo {
67
+ /**
68
+ * Display currency
69
+ */
70
+ currency: string;
71
+ /**
72
+ * Detailed description
73
+ */
74
+ description?: string;
75
+ /**
76
+ * Short title
77
+ */
78
+ title: string;
79
+ [property: string]: any;
21
80
  }
22
81
  /**
23
- * Payment source information
82
+ * SourceRequest
24
83
  */
25
- export interface PaymentSource {
26
- sourceAddress?: string;
27
- [key: string]: unknown;
84
+ export interface SourceRequest {
85
+ /**
86
+ * Pay-in amount (required for type=exactIn).
87
+ * For exactOut, this field is omitted in request and calculated in response.
88
+ */
89
+ amount?: string;
90
+ chainId: number;
91
+ /**
92
+ * Override default token address
93
+ */
94
+ tokenAddress?: string;
95
+ tokenSymbol: string;
96
+ [property: string]: any;
28
97
  }
29
98
  /**
30
- * Payment request data type
99
+ * PaymentRequest
31
100
  */
32
- export interface PaymentRequestData {
101
+ export interface CreatePaymentRequest {
102
+ /**
103
+ * Your application ID
104
+ */
33
105
  appId: string;
34
- display: PaymentDisplay;
35
- destination: PaymentDestination;
36
- externalId?: string;
37
- metadata?: Record<string, unknown>;
38
- [key: string]: unknown;
106
+ destination: DestinationRequest;
107
+ display: DisplayInfo;
108
+ /**
109
+ * Custom metadata (max 4 KB recommended)
110
+ */
111
+ metadata?: {
112
+ [key: string]: any;
113
+ };
114
+ /**
115
+ * Your order reference ID (for idempotency)
116
+ */
117
+ orderId?: string;
118
+ source: SourceRequest;
119
+ type?: FeeType;
120
+ /**
121
+ * Secret for HMAC-SHA256 signature verification.
122
+ * If not provided, a unique secret is auto-generated.
123
+ * The secret is returned in the response for you to store and use for verification.
124
+ */
125
+ webhookSecret?: string;
126
+ /**
127
+ * URL to receive payment status updates
128
+ */
129
+ webhookUrl?: string;
130
+ [property: string]: any;
131
+ }
132
+ /**
133
+ * DestinationResponse
134
+ */
135
+ export interface DestinationResponse {
136
+ /**
137
+ * Amount to be sent to recipient
138
+ */
139
+ amount?: string;
140
+ chainId?: number;
141
+ /**
142
+ * Withdrawal confirmation time
143
+ */
144
+ confirmedAt?: Date;
145
+ /**
146
+ * Final recipient's wallet
147
+ */
148
+ receiverAddress?: string;
149
+ /**
150
+ * Memo for Stellar/Solana
151
+ */
152
+ receiverMemo?: string;
153
+ /**
154
+ * Token contract address
155
+ */
156
+ tokenAddress?: string;
157
+ tokenSymbol?: string;
158
+ /**
159
+ * Withdrawal transaction hash
160
+ */
161
+ txHash?: string;
162
+ [property: string]: any;
163
+ }
164
+ /**
165
+ * SourceResponse
166
+ */
167
+ export interface SourceResponse {
168
+ /**
169
+ * Amount payer must send
170
+ */
171
+ amount?: string;
172
+ /**
173
+ * Actual amount received
174
+ */
175
+ amountReceived?: string;
176
+ chainId?: number;
177
+ /**
178
+ * Deposit confirmation time
179
+ */
180
+ confirmedAt?: Date;
181
+ /**
182
+ * Fee amount
183
+ */
184
+ fee?: string;
185
+ /**
186
+ * Deposit address (where payer sends funds)
187
+ */
188
+ receiverAddress?: string;
189
+ /**
190
+ * Memo for Stellar/Solana deposits
191
+ */
192
+ receiverMemo?: string;
193
+ /**
194
+ * Payer's wallet address (populated after deposit)
195
+ */
196
+ senderAddress?: string;
197
+ /**
198
+ * Token contract address
199
+ */
200
+ tokenAddress?: string;
201
+ tokenSymbol?: string;
202
+ /**
203
+ * Deposit transaction hash
204
+ */
205
+ txHash?: string;
206
+ [property: string]: any;
39
207
  }
40
208
  /**
41
- * Payment response data type
209
+ * PaymentResponse
42
210
  */
43
- export interface PaymentResponseData {
211
+ export interface PaymentResponse {
212
+ /**
213
+ * Your application ID
214
+ */
215
+ appId: string;
216
+ /**
217
+ * ISO 8601 timestamp
218
+ */
219
+ createdAt: Date;
220
+ destination: DestinationResponse;
221
+ display: DisplayInfo;
222
+ errorCode: PaymentErrorCode | null;
223
+ /**
224
+ * ISO 8601 timestamp (when payment expires)
225
+ */
226
+ expiresAt: Date;
227
+ /**
228
+ * Payment ID
229
+ */
44
230
  id: string;
45
- status: "payment_unpaid" | string;
46
- createdAt: string;
47
- updatedAt: string;
48
- expiresAt: string;
49
- display: {
50
- intent: string;
51
- currency: string;
52
- paymentValue?: string;
53
- } | DisplayInfo;
54
- source: PaymentSource | null;
55
- destination: {
56
- destinationAddress: string;
57
- txHash: string | null;
58
- chainId: string;
59
- amountUnits: string;
60
- tokenSymbol: string;
61
- tokenAddress: string;
62
- };
63
231
  metadata: {
64
- daimoOrderId?: string;
65
- intent: string;
66
- items: unknown[];
67
- payer: Record<string, unknown>;
68
- appId: string;
69
- orderDate: string;
70
- webhookUrl: string;
71
- provider: string;
72
- receivingAddress: string;
73
- memo: string | null;
74
- payinchainid: string;
75
- payintokenaddress: string;
76
- preferredChain: string;
77
- preferredToken: string;
78
- preferredTokenAddress: string;
79
- source_tx_hash?: string;
80
- [key: string]: unknown;
81
- };
82
- url: string;
83
- [key: string]: unknown;
232
+ [key: string]: any;
233
+ } | null;
234
+ /**
235
+ * Your order reference ID
236
+ */
237
+ orderId: string | null;
238
+ source: SourceResponse;
239
+ status: PaymentStatus;
240
+ type: FeeType;
241
+ /**
242
+ * ISO 8601 timestamp
243
+ */
244
+ updatedAt: Date;
245
+ /**
246
+ * Secret for webhook signature verification.
247
+ * Only present when webhookUrl was provided in the request.
248
+ * Store this securely to verify incoming webhook signatures.
249
+ */
250
+ webhookSecret: string | null;
251
+ [property: string]: any;
84
252
  }
85
253
  /**
86
- * Simplified interface for creating a payment bridge
254
+ * Parameters for creating a new payment using the new backend interface
87
255
  */
88
- export interface CreatePaymentBridgeParams {
256
+ export interface CreateNewPaymentParams {
89
257
  /** App ID for authentication */
90
258
  appId: string;
91
- /** Destination chain ID (e.g., 8453 for Base, 900 for Solana, 10001 for Stellar) */
259
+ /** Destination chain ID (e.g., 8453 for Base, 900 for Solana, 1500 for Stellar) */
92
260
  toChain: number;
93
261
  /** Destination token address */
94
262
  toToken: string;
@@ -102,93 +270,50 @@ export interface CreatePaymentBridgeParams {
102
270
  toUnits?: string;
103
271
  /** Additional metadata to include */
104
272
  metadata?: Record<string, unknown>;
273
+ /** Display title for the payment */
274
+ title?: string;
275
+ /** Display description for the payment */
276
+ description?: string;
277
+ /** Order reference ID (for idempotency) */
278
+ orderId?: string;
279
+ /** Fee calculation type (exactIn or exactOut) */
280
+ type?: FeeType;
281
+ /** Webhook URL to receive payment status updates */
282
+ webhookUrl?: string;
283
+ /** Secret for HMAC-SHA256 signature verification */
284
+ webhookSecret?: string;
285
+ /** Memo for Stellar/Solana destinations */
286
+ receiverMemo?: string;
105
287
  }
106
288
  /**
107
- * Gets payment details by ID
108
- * @param paymentId - Payment ID
109
- * @returns Promise with payment response
110
- */
111
- export declare const getRozoPayment: (paymentId: string) => Promise<ApiResponse<PaymentResponseData>>;
112
- /**
113
- * Creates a payment bridge configuration and initiates a Rozo payment
289
+ * Creates a payment using the new backend interface
114
290
  *
115
- * This function combines the payment bridge configuration logic with payment creation,
116
- * handling cross-chain payment routing and metadata merging. It provides a simplified
117
- * API that doesn't require understanding internal types like WalletPaymentOption.
291
+ * This function creates a payment using the new backend API structure with
292
+ * separate source and destination objects, enum-based chain IDs and token symbols.
118
293
  *
119
- * @param params - Payment bridge creation parameters
294
+ * @param params - Payment creation parameters
120
295
  * @returns Promise resolving to the payment response data
121
296
  * @throws Error if payment creation fails or required parameters are missing
122
297
  *
123
298
  * @example
124
299
  * ```typescript
125
300
  * // Simple same-chain payment
126
- * const payment = await createPaymentBridge({
301
+ * const payment = await createPayment({
127
302
  * toChain: 8453, // Base
128
303
  * toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
129
304
  * toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
130
- * preferredChainId: 8453, // User pays from Base
131
- * preferredToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
305
+ * preferredChain: 8453, // User pays from Base
306
+ * preferredTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
132
307
  * toUnits: "1", // 1 USDC
133
308
  * appId: "my-app-id",
134
- * intent: "Pay",
135
- * });
136
- * ```
137
- *
138
- * @example
139
- * ```typescript
140
- * // Cross-chain payment: Polygon to Base
141
- * const payment = await createPaymentBridge({
142
- * toChain: 8453, // Base (destination)
143
- * toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
144
- * toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
145
- * preferredChainId: 137, // Polygon (user pays from)
146
- * preferredToken: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Polygon USDC
147
- * toUnits: "1",
148
- * appId: "my-app-id",
149
- * });
150
- * ```
151
- *
152
- * @example
153
- * ```typescript
154
- * // Payment to Solana address (payout → Solana)
155
- * const payment = await createPaymentBridge({
156
- * toChain: 900, // Solana
157
- * toToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // Solana USDC
158
- * toAddress: "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU", // Solana address
159
- * preferredChainId: 8453, // User pays from Base
160
- * preferredToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
161
- * toUnits: "1",
162
- * appId: "my-app-id",
163
- * });
164
- * ```
165
- *
166
- * @example
167
- * ```typescript
168
- * // Payment paid in from Stellar account
169
- * const payment = await createPaymentBridge({
170
- * toChain: 8453, // Payout on Base
171
- * toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
172
- * toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb", // EVM address
173
- * preferredChainId: 1500, // Pay in from Stellar
174
- * preferredToken: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar USDC (token format: code:issuer)
175
- * toUnits: "10",
176
- * appId: "my-app-id",
177
- * });
178
- * ```
179
- *
180
- * @example
181
- * ```typescript
182
- * // Payment paying out to Stellar address (payout → Stellar)
183
- * const payment = await createPaymentBridge({
184
- * toChain: 1500, // Stellar
185
- * toToken: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar USDC (token format: code:issuer)
186
- * toAddress: "GA5ZSEPRY3STUGUUXZGHV5CDEQ2AJGEAAUUMSZK2QIPICFL2JVP4X6T4", // Stellar address
187
- * preferredChainId: 8453, // User pays from Base
188
- * preferredToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
189
- * toUnits: "1",
190
- * appId: "my-app-id",
309
+ * title: "Payment",
191
310
  * });
192
311
  * ```
193
312
  */
194
- export declare function createRozoPayment(params: CreatePaymentBridgeParams): Promise<PaymentResponseData>;
313
+ export declare function createPayment(params: CreateNewPaymentParams): Promise<PaymentResponse>;
314
+ /**
315
+ * Gets payment details by ID using the new backend API
316
+ * @param paymentId - Payment ID
317
+ * @returns Promise with payment response
318
+ */
319
+ export declare const getPayment: (paymentId: string) => Promise<ApiResponse<PaymentResponse>>;
@@ -1,108 +1,79 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRozoPayment = void 0;
4
- exports.createRozoPayment = createRozoPayment;
5
- const bridge_1 = require("../bridge");
3
+ exports.getPayment = exports.PaymentErrorCode = exports.PaymentStatus = exports.FeeType = void 0;
4
+ exports.createPayment = createPayment;
5
+ const bridge_utils_1 = require("../bridge-utils");
6
+ const chain_1 = require("../chain");
7
+ const token_1 = require("../token");
6
8
  const base_1 = require("./base");
7
9
  /**
8
- * Gets payment details by ID
9
- * @param paymentId - Payment ID
10
- * @returns Promise with payment response
10
+ * FeeType, Fee calculation type:
11
+ * - exactIn (default): Fee deducted from input, recipient receives amount - fee
12
+ * - exactOut: Fee added to input, recipient receives exact amount
11
13
  */
12
- const getRozoPayment = (paymentId) => {
13
- const isMugglePay = paymentId.includes("mugglepay_order");
14
- const endpoint = isMugglePay
15
- ? `payment-api/${paymentId}`
16
- : `payment/id/${paymentId}`;
17
- return base_1.apiClient.get(endpoint);
18
- };
19
- exports.getRozoPayment = getRozoPayment;
14
+ var FeeType;
15
+ (function (FeeType) {
16
+ FeeType["ExactIn"] = "exactIn";
17
+ FeeType["ExactOut"] = "exactOut";
18
+ })(FeeType || (exports.FeeType = FeeType = {}));
20
19
  /**
21
- * Creates a payment bridge configuration and initiates a Rozo payment
20
+ * PaymentStatus, Payment status
21
+ */
22
+ var PaymentStatus;
23
+ (function (PaymentStatus) {
24
+ PaymentStatus["PaymentBounced"] = "payment_bounced";
25
+ PaymentStatus["PaymentCompleted"] = "payment_completed";
26
+ PaymentStatus["PaymentExpired"] = "payment_expired";
27
+ PaymentStatus["PaymentPayinCompleted"] = "payment_payin_completed";
28
+ PaymentStatus["PaymentPayoutCompleted"] = "payment_payout_completed";
29
+ PaymentStatus["PaymentRefunded"] = "payment_refunded";
30
+ PaymentStatus["PaymentStarted"] = "payment_started";
31
+ PaymentStatus["PaymentUnpaid"] = "payment_unpaid";
32
+ })(PaymentStatus || (exports.PaymentStatus = PaymentStatus = {}));
33
+ /**
34
+ * PaymentErrorCode, Error code (only present when status is payment_bounced)
35
+ */
36
+ var PaymentErrorCode;
37
+ (function (PaymentErrorCode) {
38
+ PaymentErrorCode["AmountTooHigh"] = "amountTooHigh";
39
+ PaymentErrorCode["AmountTooLow"] = "amountTooLow";
40
+ PaymentErrorCode["ChainUnavailable"] = "chainUnavailable";
41
+ PaymentErrorCode["InsufficientLiquidity"] = "insufficientLiquidity";
42
+ PaymentErrorCode["InvalidRecipient"] = "invalidRecipient";
43
+ PaymentErrorCode["MissingTrustline"] = "missingTrustline";
44
+ PaymentErrorCode["NetworkError"] = "networkError";
45
+ PaymentErrorCode["ProviderError"] = "providerError";
46
+ PaymentErrorCode["ServiceMaintenance"] = "serviceMaintenance";
47
+ })(PaymentErrorCode || (exports.PaymentErrorCode = PaymentErrorCode = {}));
48
+ /**
49
+ * Creates a payment using the new backend interface
22
50
  *
23
- * This function combines the payment bridge configuration logic with payment creation,
24
- * handling cross-chain payment routing and metadata merging. It provides a simplified
25
- * API that doesn't require understanding internal types like WalletPaymentOption.
51
+ * This function creates a payment using the new backend API structure with
52
+ * separate source and destination objects, enum-based chain IDs and token symbols.
26
53
  *
27
- * @param params - Payment bridge creation parameters
54
+ * @param params - Payment creation parameters
28
55
  * @returns Promise resolving to the payment response data
29
56
  * @throws Error if payment creation fails or required parameters are missing
30
57
  *
31
58
  * @example
32
59
  * ```typescript
33
60
  * // Simple same-chain payment
34
- * const payment = await createPaymentBridge({
61
+ * const payment = await createPayment({
35
62
  * toChain: 8453, // Base
36
63
  * toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
37
64
  * toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
38
- * preferredChainId: 8453, // User pays from Base
39
- * preferredToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
65
+ * preferredChain: 8453, // User pays from Base
66
+ * preferredTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
40
67
  * toUnits: "1", // 1 USDC
41
68
  * appId: "my-app-id",
42
- * intent: "Pay",
43
- * });
44
- * ```
45
- *
46
- * @example
47
- * ```typescript
48
- * // Cross-chain payment: Polygon to Base
49
- * const payment = await createPaymentBridge({
50
- * toChain: 8453, // Base (destination)
51
- * toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
52
- * toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
53
- * preferredChainId: 137, // Polygon (user pays from)
54
- * preferredToken: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", // Polygon USDC
55
- * toUnits: "1",
56
- * appId: "my-app-id",
57
- * });
58
- * ```
59
- *
60
- * @example
61
- * ```typescript
62
- * // Payment to Solana address (payout → Solana)
63
- * const payment = await createPaymentBridge({
64
- * toChain: 900, // Solana
65
- * toToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // Solana USDC
66
- * toAddress: "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU", // Solana address
67
- * preferredChainId: 8453, // User pays from Base
68
- * preferredToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
69
- * toUnits: "1",
70
- * appId: "my-app-id",
71
- * });
72
- * ```
73
- *
74
- * @example
75
- * ```typescript
76
- * // Payment paid in from Stellar account
77
- * const payment = await createPaymentBridge({
78
- * toChain: 8453, // Payout on Base
79
- * toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
80
- * toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb", // EVM address
81
- * preferredChainId: 1500, // Pay in from Stellar
82
- * preferredToken: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar USDC (token format: code:issuer)
83
- * toUnits: "10",
84
- * appId: "my-app-id",
85
- * });
86
- * ```
87
- *
88
- * @example
89
- * ```typescript
90
- * // Payment paying out to Stellar address (payout → Stellar)
91
- * const payment = await createPaymentBridge({
92
- * toChain: 1500, // Stellar
93
- * toToken: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN", // Stellar USDC (token format: code:issuer)
94
- * toAddress: "GA5ZSEPRY3STUGUUXZGHV5CDEQ2AJGEAAUUMSZK2QIPICFL2JVP4X6T4", // Stellar address
95
- * preferredChainId: 8453, // User pays from Base
96
- * preferredToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // Base USDC
97
- * toUnits: "1",
98
- * appId: "my-app-id",
69
+ * title: "Payment",
99
70
  * });
100
71
  * ```
101
72
  */
102
- async function createRozoPayment(params) {
103
- const { toChain, toToken, toAddress, preferredChain, preferredTokenAddress, toUnits, appId, metadata, } = params;
73
+ async function createPayment(params) {
74
+ const { toChain, toToken, toAddress, preferredChain, preferredTokenAddress, toUnits, appId, metadata, title, description, orderId, type, webhookUrl, webhookSecret, receiverMemo, } = params;
104
75
  // Create payment bridge configuration
105
- const { preferred, destination, isIntentPayment } = (0, bridge_1.createPaymentBridgeConfig)({
76
+ const { preferred, destination } = (0, bridge_utils_1.createPaymentBridgeConfig)({
106
77
  toChain,
107
78
  toToken,
108
79
  toAddress,
@@ -111,18 +82,44 @@ async function createRozoPayment(params) {
111
82
  preferredChain,
112
83
  preferredTokenAddress,
113
84
  });
114
- // Build payment request data
85
+ const sourceChain = (0, chain_1.getChainById)(Number(preferred.preferredChain));
86
+ const sourceToken = (0, token_1.getKnownToken)(Number(preferred.preferredChain), preferred.preferredTokenAddress);
87
+ const destinationChain = (0, chain_1.getChainById)(Number(destination.chainId));
88
+ const destinationToken = (0, token_1.getKnownToken)(Number(destination.chainId), destination.tokenAddress);
89
+ if (!sourceToken || !destinationToken) {
90
+ throw new Error("Source or destination token not found");
91
+ }
92
+ // Build payment request data matching new backend interface
115
93
  const paymentData = {
116
94
  appId,
95
+ type: type ?? FeeType.ExactIn,
96
+ ...(orderId ? { orderId } : {}),
97
+ source: {
98
+ chainId: sourceChain.chainId,
99
+ tokenSymbol: sourceToken.symbol,
100
+ amount: destination.amountUnits, // Use same amount for source
101
+ ...(preferred.preferredTokenAddress
102
+ ? { tokenAddress: preferred.preferredTokenAddress }
103
+ : {}),
104
+ },
105
+ destination: {
106
+ chainId: destinationChain.chainId,
107
+ receiverAddress: destination.destinationAddress ?? toAddress,
108
+ tokenSymbol: destinationToken.symbol,
109
+ amount: destination.amountUnits,
110
+ ...(destination.tokenAddress
111
+ ? { tokenAddress: destination.tokenAddress }
112
+ : {}),
113
+ ...(receiverMemo ? { receiverMemo } : {}),
114
+ },
117
115
  display: {
118
- intent: "",
119
- paymentValue: String(toUnits ?? ""),
120
116
  currency: "USD",
117
+ title: title ?? "Pay",
118
+ ...(description ? { description } : {}),
121
119
  },
122
- destination,
123
- ...preferred,
124
- ...(metadata ?? {}),
125
- ...(isIntentPayment ? { intents: true } : {}),
120
+ ...(metadata ? { metadata } : {}),
121
+ ...(webhookUrl ? { webhookUrl } : {}),
122
+ ...(webhookSecret ? { webhookSecret } : {}),
126
123
  };
127
124
  // Create payment via API
128
125
  const response = await base_1.apiClient.post("/payment-api", paymentData);
@@ -131,4 +128,13 @@ async function createRozoPayment(params) {
131
128
  }
132
129
  return response.data;
133
130
  }
131
+ /**
132
+ * Gets payment details by ID using the new backend API
133
+ * @param paymentId - Payment ID
134
+ * @returns Promise with payment response
135
+ */
136
+ const getPayment = (paymentId) => {
137
+ return base_1.apiClient.get(`/payment-api/payments/${paymentId}`);
138
+ };
139
+ exports.getPayment = getPayment;
134
140
  //# sourceMappingURL=payment.js.map