@coin-voyage/shared 2.3.5-beta.2 → 2.3.5-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,5 +1,5 @@
1
1
  import { type PayOrder, PayOrderMode } from "../types";
2
- import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, UpdateWebhookRequest, WebhookResponse } from "../types/api";
2
+ import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PaymentMethodsResponse, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, UpdateWebhookRequest, WebhookResponse } from "../types/api";
3
3
  import { type APIEnvironment } from "./config";
4
4
  import { type APIResponse } from "./fetcher";
5
5
  type Opts = {
@@ -30,6 +30,17 @@ export declare class ApiClient {
30
30
  * const { data: payOrder, error } = await getPayOrder('123456');
31
31
  */
32
32
  getPayOrder(payOrderId: string): Promise<APIResponse<PayOrder>>;
33
+ /**
34
+ * Fetches payment method availability for a PayOrder.
35
+ *
36
+ * Retrieves the currently available payment methods for the provided PayOrder ID,
37
+ * including optional availability reasons and minimum fiat amounts.
38
+ *
39
+ * @param {string} payOrderId - The unique identifier of the PayOrder.
40
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
41
+ * @returns {Promise<APIResponse<PaymentMethodsResponse>>} - Payment method availability wrapped in an API response.
42
+ */
43
+ getPayOrderPaymentMethods(payOrderId: string, opts?: Opts): Promise<APIResponse<PaymentMethodsResponse>>;
33
44
  /**
34
45
  * Creates a `DEPOSIT` PayOrder.
35
46
  *
@@ -175,9 +186,10 @@ export declare class ApiClient {
175
186
  *
176
187
  * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
177
188
  * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
189
+ * @param {PaymentRail} [params.payment_rail] - (Optional) The payment rail for which to fetch the payment details. default: CRYPTO.
178
190
  * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
179
- * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
180
- * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
191
+ * @param {string} [params.quote_id] - (Optional) The quote ID for the PayOrder.
192
+ * @param {string} [params.refund_address] - (Optional) The address where funds will be refunded in case of a failed transaction.
181
193
  * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
182
194
  *
183
195
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
@@ -40,6 +40,25 @@ export class ApiClient {
40
40
  async getPayOrder(payOrderId) {
41
41
  return this.request({ path: `/pay-orders/${payOrderId}` });
42
42
  }
43
+ /**
44
+ * Fetches payment method availability for a PayOrder.
45
+ *
46
+ * Retrieves the currently available payment methods for the provided PayOrder ID,
47
+ * including optional availability reasons and minimum fiat amounts.
48
+ *
49
+ * @param {string} payOrderId - The unique identifier of the PayOrder.
50
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
51
+ * @returns {Promise<APIResponse<PaymentMethodsResponse>>} - Payment method availability wrapped in an API response.
52
+ */
53
+ async getPayOrderPaymentMethods(payOrderId, opts) {
54
+ return this.request({
55
+ path: `/pay-orders/${payOrderId}/payment-methods`,
56
+ options: {
57
+ method: "GET",
58
+ headers: opts?.headers,
59
+ },
60
+ });
61
+ }
43
62
  /**
44
63
  * Creates a `DEPOSIT` PayOrder.
45
64
  *
@@ -278,9 +297,10 @@ export class ApiClient {
278
297
  *
279
298
  * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
280
299
  * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
300
+ * @param {PaymentRail} [params.payment_rail] - (Optional) The payment rail for which to fetch the payment details. default: CRYPTO.
281
301
  * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
282
- * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
283
- * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
302
+ * @param {string} [params.quote_id] - (Optional) The quote ID for the PayOrder.
303
+ * @param {string} [params.refund_address] - (Optional) The address where funds will be refunded in case of a failed transaction.
284
304
  * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
285
305
  *
286
306
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
@@ -8,6 +8,7 @@ export * from "./debug";
8
8
  export * from "./format";
9
9
  export * from "./local-storage";
10
10
  export * from "./organization";
11
+ export * from "./payment-steps";
11
12
  export * from "./plural";
12
13
  export * from "./time";
13
14
  export * from "./validation";
@@ -8,6 +8,7 @@ export * from "./debug";
8
8
  export * from "./format";
9
9
  export * from "./local-storage";
10
10
  export * from "./organization";
11
+ export * from "./payment-steps";
11
12
  export * from "./plural";
12
13
  export * from "./time";
13
14
  export * from "./validation";
@@ -0,0 +1,12 @@
1
+ import { BitcoinPaymentData, type CryptoPaymentData, EVMPaymentData, type FiatPaymentData, type PaymentData, type PaymentStep, SolanaPaymentData, SuiPaymentData } from "../types";
2
+ export declare function getFiatPaymentStep(payment?: PaymentData): PaymentStep | undefined;
3
+ export declare function getFiatPaymentData(payment?: PaymentData): FiatPaymentData | undefined;
4
+ export declare function getCryptoDepositStep(payment?: PaymentData): PaymentStep | undefined;
5
+ export declare function getCryptoTransactionStep(payment?: PaymentData): PaymentStep | undefined;
6
+ export declare function getWalletPaymentStep(payment?: PaymentData): PaymentStep | undefined;
7
+ export declare function getWalletPaymentData(payment?: PaymentData): CryptoPaymentData | undefined;
8
+ export declare function getDepositAddress(payment?: PaymentData): string | undefined;
9
+ export declare function getEvmPaymentData(paymentData?: CryptoPaymentData): EVMPaymentData | undefined;
10
+ export declare function getBitcoinPaymentData(paymentData?: CryptoPaymentData): BitcoinPaymentData | undefined;
11
+ export declare function getSolanaPaymentData(paymentData?: CryptoPaymentData): SolanaPaymentData | undefined;
12
+ export declare function getSuiPaymentData(paymentData?: CryptoPaymentData): SuiPaymentData | undefined;
@@ -0,0 +1,53 @@
1
+ import { PaymentRail, StepKind, } from "../types";
2
+ export function getFiatPaymentStep(payment) {
3
+ return payment?.steps.find((step) => {
4
+ return (step.rail === PaymentRail.FIAT || step.kind === StepKind.KIND_STRIPE_ONRAMP) && step.data?.fiat;
5
+ });
6
+ }
7
+ export function getFiatPaymentData(payment) {
8
+ const data = getFiatPaymentStep(payment)?.data;
9
+ return data?.fiat;
10
+ }
11
+ export function getCryptoDepositStep(payment) {
12
+ return payment?.steps.find((step) => {
13
+ return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_DEPOSIT;
14
+ });
15
+ }
16
+ export function getCryptoTransactionStep(payment) {
17
+ return payment?.steps.find((step) => {
18
+ return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_TRANSACTION && step.data?.crypto;
19
+ });
20
+ }
21
+ export function getWalletPaymentStep(payment) {
22
+ return getCryptoTransactionStep(payment) ?? getCryptoDepositStep(payment);
23
+ }
24
+ export function getWalletPaymentData(payment) {
25
+ const data = getCryptoTransactionStep(payment)?.data;
26
+ return data?.crypto;
27
+ }
28
+ export function getDepositAddress(payment) {
29
+ const depositStep = getCryptoDepositStep(payment);
30
+ if (depositStep?.deposit_address) {
31
+ return depositStep.deposit_address;
32
+ }
33
+ if (getCryptoTransactionStep(payment)) {
34
+ return undefined;
35
+ }
36
+ return payment?.deposit_address;
37
+ }
38
+ export function getEvmPaymentData(paymentData) {
39
+ const data = paymentData;
40
+ return data?.evm;
41
+ }
42
+ export function getBitcoinPaymentData(paymentData) {
43
+ const data = paymentData;
44
+ return data?.bitcoin;
45
+ }
46
+ export function getSolanaPaymentData(paymentData) {
47
+ const data = paymentData;
48
+ return data?.solana;
49
+ }
50
+ export function getSuiPaymentData(paymentData) {
51
+ const data = paymentData;
52
+ return data?.sui;
53
+ }
@@ -1,7 +1,7 @@
1
1
  import { FiatCurrency } from "../common/currencies";
2
- import { ChainId, ChainType, PayOrderStatus } from "./enums";
2
+ import { ChainId, ChainType, PaymentMethod, PaymentRail, PayOrderStatus } from "./enums";
3
3
  import { PayOrderEvent } from "./events";
4
- import { CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
4
+ import { CurrencyAmount, CurrencyBase, CurrencyWithAmount, FiatAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
5
5
  export type PayOrderParams = {
6
6
  /**
7
7
  * Intent of the order.
@@ -17,12 +17,21 @@ export type PayOrderQuoteParams = {
17
17
  chain_type: ChainType;
18
18
  chain_id?: ChainId;
19
19
  };
20
- export type PaymentDetailsParams = {
20
+ type PaymentDetailsBaseParams = {
21
21
  payorder_id: string;
22
- } & ({
22
+ payment_rail?: PaymentRail;
23
+ };
24
+ export type PaymentDetailsParams = (PaymentDetailsBaseParams & {
25
+ source_currency?: never;
26
+ refund_address?: never;
27
+ quote_id?: never;
28
+ }) | (PaymentDetailsBaseParams & {
23
29
  source_currency: CurrencyBase;
24
30
  refund_address?: string;
25
- } | {
31
+ quote_id?: never;
32
+ }) | (PaymentDetailsBaseParams & {
33
+ source_currency?: never;
34
+ refund_address?: never;
26
35
  quote_id: string;
27
36
  });
28
37
  export type PaymentDetails = {
@@ -30,6 +39,15 @@ export type PaymentDetails = {
30
39
  status: PayOrderStatus;
31
40
  data: PaymentData;
32
41
  };
42
+ export type PaymentMethodAvailability = {
43
+ method: PaymentMethod;
44
+ available: boolean;
45
+ reason?: string;
46
+ minimum_amount?: FiatAmount;
47
+ };
48
+ export type PaymentMethodsResponse = {
49
+ methods: PaymentMethodAvailability[];
50
+ };
33
51
  export type PayOrderIntent = {
34
52
  /**
35
53
  * Desired fulfillment asset.
@@ -26,6 +26,20 @@ export declare enum ChainId {
26
26
  SUI = 30000000000002,
27
27
  TRX = 30000000000003
28
28
  }
29
+ export declare enum PaymentMethod {
30
+ WALLET = "WALLET",
31
+ DEPOSIT_ADDRESS = "DEPOSIT_ADDRESS",
32
+ CARD = "CARD"
33
+ }
34
+ export declare enum PaymentRail {
35
+ CRYPTO = "CRYPTO",
36
+ FIAT = "FIAT"
37
+ }
38
+ export declare enum StepKind {
39
+ KIND_DEPOSIT = "deposit",
40
+ KIND_TRANSACTION = "transaction",
41
+ KIND_STRIPE_ONRAMP = "stripe_onramp"
42
+ }
29
43
  export declare enum PayOrderMode {
30
44
  SALE = "SALE",
31
45
  DEPOSIT = "DEPOSIT",
@@ -36,6 +36,23 @@ export var ChainId;
36
36
  ChainId[ChainId["TRX"] = 30000000000003] = "TRX";
37
37
  // XRPL = 30000000000004,
38
38
  })(ChainId || (ChainId = {}));
39
+ export var PaymentMethod;
40
+ (function (PaymentMethod) {
41
+ PaymentMethod["WALLET"] = "WALLET";
42
+ PaymentMethod["DEPOSIT_ADDRESS"] = "DEPOSIT_ADDRESS";
43
+ PaymentMethod["CARD"] = "CARD";
44
+ })(PaymentMethod || (PaymentMethod = {}));
45
+ export var PaymentRail;
46
+ (function (PaymentRail) {
47
+ PaymentRail["CRYPTO"] = "CRYPTO";
48
+ PaymentRail["FIAT"] = "FIAT";
49
+ })(PaymentRail || (PaymentRail = {}));
50
+ export var StepKind;
51
+ (function (StepKind) {
52
+ StepKind["KIND_DEPOSIT"] = "deposit";
53
+ StepKind["KIND_TRANSACTION"] = "transaction";
54
+ StepKind["KIND_STRIPE_ONRAMP"] = "stripe_onramp";
55
+ })(StepKind || (StepKind = {}));
39
56
  export var PayOrderMode;
40
57
  (function (PayOrderMode) {
41
58
  PayOrderMode["SALE"] = "SALE";
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { zPayOrderMetadata } from "../common/validation";
3
2
  import { FiatCurrency } from "../common/currencies";
4
- import { ChainId, PayOrderMode, PayOrderStatus, ProviderStatus } from "./enums";
3
+ import { zPayOrderMetadata } from "../common/validation";
4
+ import { ChainId, PaymentRail, PayOrderMode, PayOrderStatus, ProviderStatus, StepKind } from "./enums";
5
5
  export type PayOrder = {
6
6
  id: string;
7
7
  mode: PayOrderMode;
@@ -51,6 +51,54 @@ export interface FeeBreakdown {
51
51
  protocol_fee?: CurrencyAmount;
52
52
  custom_fee?: CurrencyAmount;
53
53
  }
54
+ export interface FiatQuoteData {
55
+ source_currency: string;
56
+ source_amount: string;
57
+ source_total_amount: string;
58
+ destination_currency: string;
59
+ destination_network: string;
60
+ destination_amount: string;
61
+ network_fee_amount?: string;
62
+ transaction_fee_amount?: string;
63
+ }
64
+ export interface FiatPaymentData {
65
+ session_id: string;
66
+ stripe_publishable_key: string;
67
+ client_secret: string;
68
+ status: string;
69
+ source_currency?: string;
70
+ destination_currency?: string;
71
+ destination_network?: string;
72
+ destination_amount?: string;
73
+ wallet_address?: string;
74
+ quote?: FiatQuoteData;
75
+ }
76
+ export type SerializedSuiTransaction = unknown;
77
+ export type SerializedSolanaTransaction = unknown;
78
+ export interface CryptoPaymentData {
79
+ evm?: EVMPaymentData;
80
+ bitcoin?: BitcoinPaymentData;
81
+ solana?: SolanaPaymentData;
82
+ sui?: SuiPaymentData;
83
+ }
84
+ export interface SuiPaymentData {
85
+ transaction: SerializedSuiTransaction;
86
+ }
87
+ export interface SolanaPaymentData {
88
+ transaction: SerializedSolanaTransaction;
89
+ }
90
+ export interface BitcoinPaymentData {
91
+ psbt: string;
92
+ }
93
+ export interface EVMPaymentData {
94
+ from: string;
95
+ to: string;
96
+ data: string;
97
+ value: string;
98
+ chainId: ChainId;
99
+ maxFeePerGas?: string;
100
+ maxPriorityFeePerGas?: string;
101
+ }
54
102
  export type TokenAmount = {
55
103
  ui_amount: number;
56
104
  raw_amount: BigIntStr;
@@ -84,8 +132,19 @@ export type PaymentData = {
84
132
  destination_tx_hash?: string;
85
133
  refund_tx_hash?: string;
86
134
  fee_tx_hash?: string;
135
+ steps: PaymentStep[];
87
136
  expires_at: Date;
88
137
  };
138
+ export type PaymentStep = {
139
+ rail: PaymentRail;
140
+ kind: StepKind;
141
+ deposit_address?: string;
142
+ data?: PaymentStepData;
143
+ };
144
+ export type PaymentStepData = {
145
+ crypto?: CryptoPaymentData;
146
+ fiat?: FiatPaymentData;
147
+ };
89
148
  export type ExecutionStep = {
90
149
  id: string;
91
150
  status: ProviderStatus;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.3.5-beta.2",
4
+ "version": "2.3.5-beta.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {