@doujins/payments-ui 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +47 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -17
- package/dist/index.d.ts +12 -17
- package/dist/index.js +47 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -17,12 +17,6 @@ interface PaymentUserDetails {
|
|
|
17
17
|
postalCode?: string;
|
|
18
18
|
country?: string;
|
|
19
19
|
}
|
|
20
|
-
interface PaymentEndpoints {
|
|
21
|
-
billingBaseUrl: string;
|
|
22
|
-
accountBaseUrl?: string;
|
|
23
|
-
billingBasePath?: string;
|
|
24
|
-
accountBasePath?: string;
|
|
25
|
-
}
|
|
26
20
|
interface PaymentFeatureFlags {
|
|
27
21
|
enableCardPayments?: boolean;
|
|
28
22
|
enableStoredMethods?: boolean;
|
|
@@ -52,7 +46,7 @@ interface PaymentSuccessPayload {
|
|
|
52
46
|
}
|
|
53
47
|
type PaymentFetcher = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
54
48
|
interface PaymentConfig {
|
|
55
|
-
|
|
49
|
+
baseUrl: string;
|
|
56
50
|
getAuthToken?: AuthTokenProvider;
|
|
57
51
|
fetcher?: PaymentFetcher;
|
|
58
52
|
defaultHeaders?: Record<string, string>;
|
|
@@ -342,7 +336,7 @@ interface PaymentMethodOption {
|
|
|
342
336
|
* Usage:
|
|
343
337
|
* ```ts
|
|
344
338
|
* const client = createClient({
|
|
345
|
-
*
|
|
339
|
+
* baseUrl: 'https://billing.example.com',
|
|
346
340
|
* getAuthToken: () => authStore.token,
|
|
347
341
|
* })
|
|
348
342
|
*
|
|
@@ -353,17 +347,15 @@ interface PaymentMethodOption {
|
|
|
353
347
|
|
|
354
348
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
355
349
|
interface ClientConfig {
|
|
356
|
-
|
|
357
|
-
accountBaseUrl?: string;
|
|
350
|
+
baseUrl: string;
|
|
358
351
|
getAuthToken?: () => string | null | Promise<string | null>;
|
|
359
352
|
defaultHeaders?: Record<string, string>;
|
|
360
353
|
fetch?: typeof fetch;
|
|
361
354
|
}
|
|
362
355
|
interface RequestOptions {
|
|
363
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
364
356
|
body?: unknown;
|
|
365
357
|
headers?: Record<string, string>;
|
|
366
|
-
|
|
358
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
367
359
|
}
|
|
368
360
|
interface PaginatedResponse<T> {
|
|
369
361
|
data: T[];
|
|
@@ -394,7 +386,7 @@ declare const createClient: (config: ClientConfig) => {
|
|
|
394
386
|
updatePaymentMethod(id: string, payload: CreatePaymentMethodPayload): Promise<PaymentMethod>;
|
|
395
387
|
deletePaymentMethod(id: string): Promise<void>;
|
|
396
388
|
activatePaymentMethod(id: string): Promise<void>;
|
|
397
|
-
checkout(payload: CheckoutRequestPayload): Promise<CheckoutResponse>;
|
|
389
|
+
checkout(payload: CheckoutRequestPayload, idempotencyKey?: string): Promise<CheckoutResponse>;
|
|
398
390
|
cancelSubscription(feedback?: string): Promise<{
|
|
399
391
|
message: string;
|
|
400
392
|
success: boolean;
|
|
@@ -807,6 +799,7 @@ interface SubscribeWithCardParams {
|
|
|
807
799
|
provider?: string;
|
|
808
800
|
paymentToken: string;
|
|
809
801
|
billing: BillingDetails;
|
|
802
|
+
idempotencyKey?: string;
|
|
810
803
|
}
|
|
811
804
|
interface SubscribeWithSavedMethodParams {
|
|
812
805
|
priceId?: string | null;
|
|
@@ -814,6 +807,7 @@ interface SubscribeWithSavedMethodParams {
|
|
|
814
807
|
provider?: string;
|
|
815
808
|
paymentMethodId: string;
|
|
816
809
|
email?: string;
|
|
810
|
+
idempotencyKey?: string;
|
|
817
811
|
}
|
|
818
812
|
interface SubscribeWithCCBillParams {
|
|
819
813
|
priceId?: string | null;
|
|
@@ -823,11 +817,12 @@ interface SubscribeWithCCBillParams {
|
|
|
823
817
|
zipCode: string;
|
|
824
818
|
country: string;
|
|
825
819
|
processor?: string;
|
|
820
|
+
idempotencyKey?: string;
|
|
826
821
|
}
|
|
827
822
|
declare const useSubscriptionActions: () => {
|
|
828
|
-
subscribeWithCard: ({ priceId, processor, provider, paymentToken, billing, }: SubscribeWithCardParams) => Promise<CheckoutResponse>;
|
|
829
|
-
subscribeWithSavedMethod: ({ priceId, processor, provider, paymentMethodId, email, }: SubscribeWithSavedMethodParams) => Promise<CheckoutResponse>;
|
|
830
|
-
subscribeWithCCBill: ({ priceId, email, firstName, lastName, zipCode, country, processor, }: SubscribeWithCCBillParams) => Promise<CheckoutResponse>;
|
|
823
|
+
subscribeWithCard: ({ priceId, processor, provider, paymentToken, billing, idempotencyKey, }: SubscribeWithCardParams) => Promise<CheckoutResponse>;
|
|
824
|
+
subscribeWithSavedMethod: ({ priceId, processor, provider, paymentMethodId, email, idempotencyKey, }: SubscribeWithSavedMethodParams) => Promise<CheckoutResponse>;
|
|
825
|
+
subscribeWithCCBill: ({ priceId, email, firstName, lastName, zipCode, country, processor, idempotencyKey, }: SubscribeWithCCBillParams) => Promise<CheckoutResponse>;
|
|
831
826
|
};
|
|
832
827
|
|
|
833
|
-
export { type AuthTokenProvider, type BillingAccessGrant, type BillingDetails, BillingHistory, type BillingHistoryProps, type BillingHistoryTranslations, type BillingStatus, BillingThemePortal, BillingThemeProvider, type BillingThemeProviderProps, type CCBillSubscribePayload, CancelMembershipDialog, type CancelMembershipDialogProps, type CancelMembershipDialogTranslations, CardDetailsForm, type CardDetailsFormProps, type CheckoutRequestPayload, type CheckoutResponse, type CheckoutStatus, type Client, ClientApiError, type ClientConfig, type CreatePaymentMethodPayload, type GeneratePaymentRequest, type GeneratePaymentResponse, type HttpMethod, type NmiSubscribePayload, type NotificationHandler, type NotificationPayload, type NotificationStatus, type PaginatedPaymentMethods, type PaginatedPayments, type PaginatedResponse, type Payment, type PaymentCallbacks, type PaymentConfig, PaymentContext, type PaymentContextValue, type
|
|
828
|
+
export { type AuthTokenProvider, type BillingAccessGrant, type BillingDetails, BillingHistory, type BillingHistoryProps, type BillingHistoryTranslations, type BillingStatus, BillingThemePortal, BillingThemeProvider, type BillingThemeProviderProps, type CCBillSubscribePayload, CancelMembershipDialog, type CancelMembershipDialogProps, type CancelMembershipDialogTranslations, CardDetailsForm, type CardDetailsFormProps, type CheckoutRequestPayload, type CheckoutResponse, type CheckoutStatus, type Client, ClientApiError, type ClientConfig, type CreatePaymentMethodPayload, type GeneratePaymentRequest, type GeneratePaymentResponse, type HttpMethod, type NmiSubscribePayload, type NotificationHandler, type NotificationPayload, type NotificationStatus, type PaginatedPaymentMethods, type PaginatedPayments, type PaginatedResponse, type Payment, type PaymentCallbacks, type PaymentConfig, PaymentContext, type PaymentContextValue, type PaymentError, PaymentExperience, type PaymentExperienceProps, type PaymentFeatureFlags, type PaymentFetcher, type PaymentMethod, type PaymentMethodOption, PaymentMethodsSection, type PaymentMethodsSectionProps, type PaymentMethodsSectionTranslations, type PaymentPlatform, PaymentProvider, type PaymentProviderProps, type PaymentSolanaConfig, type PaymentState, type PaymentStatusPayload, type PaymentStatusResponse, type PaymentStep, type PaymentSuccessPayload, type PaymentUserDetails, PaymentsDialogProvider, type RequestOptions, type SolanaFlowConfig, type SolanaPayQRCodeIntent, type SolanaPayStatusResponse, type SolanaPayTransaction, type SolanaPaymentMethod, SolanaPaymentSelector, type SolanaPaymentSelectorProps, SolanaPaymentView, type SolanaPaymentViewProps, type SolanaWallet, StoredPaymentMethods, type StoredPaymentMethodsProps, type SubmitPaymentRequest, type SubmitPaymentResponse, type SubscribeWithCCBillParams, type SubscribeWithCardParams, type SubscribeWithSavedMethodParams, SubscriptionCheckoutModal, type SubscriptionCheckoutModalProps, type SubscriptionCheckoutPayload, SubscriptionSuccessDialog, type SupportedTokensResponse, type TokenBalance, type TokenInfo, type TransactionStatus, type VerifyWalletResponse, type WalletChallengeResponse, type WalletConnectionState, WalletDialog, type WalletDialogProps, type WalletListResponse, WalletModal, type WalletModalProps, createClient, usePaymentContext, usePaymentDialogs, usePaymentMethods, usePaymentNotifications, usePaymentStatus, useSolanaQrPayment, useSubscriptionActions, useSupportedTokens, useTokenBalance };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,12 +17,6 @@ interface PaymentUserDetails {
|
|
|
17
17
|
postalCode?: string;
|
|
18
18
|
country?: string;
|
|
19
19
|
}
|
|
20
|
-
interface PaymentEndpoints {
|
|
21
|
-
billingBaseUrl: string;
|
|
22
|
-
accountBaseUrl?: string;
|
|
23
|
-
billingBasePath?: string;
|
|
24
|
-
accountBasePath?: string;
|
|
25
|
-
}
|
|
26
20
|
interface PaymentFeatureFlags {
|
|
27
21
|
enableCardPayments?: boolean;
|
|
28
22
|
enableStoredMethods?: boolean;
|
|
@@ -52,7 +46,7 @@ interface PaymentSuccessPayload {
|
|
|
52
46
|
}
|
|
53
47
|
type PaymentFetcher = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
54
48
|
interface PaymentConfig {
|
|
55
|
-
|
|
49
|
+
baseUrl: string;
|
|
56
50
|
getAuthToken?: AuthTokenProvider;
|
|
57
51
|
fetcher?: PaymentFetcher;
|
|
58
52
|
defaultHeaders?: Record<string, string>;
|
|
@@ -342,7 +336,7 @@ interface PaymentMethodOption {
|
|
|
342
336
|
* Usage:
|
|
343
337
|
* ```ts
|
|
344
338
|
* const client = createClient({
|
|
345
|
-
*
|
|
339
|
+
* baseUrl: 'https://billing.example.com',
|
|
346
340
|
* getAuthToken: () => authStore.token,
|
|
347
341
|
* })
|
|
348
342
|
*
|
|
@@ -353,17 +347,15 @@ interface PaymentMethodOption {
|
|
|
353
347
|
|
|
354
348
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
355
349
|
interface ClientConfig {
|
|
356
|
-
|
|
357
|
-
accountBaseUrl?: string;
|
|
350
|
+
baseUrl: string;
|
|
358
351
|
getAuthToken?: () => string | null | Promise<string | null>;
|
|
359
352
|
defaultHeaders?: Record<string, string>;
|
|
360
353
|
fetch?: typeof fetch;
|
|
361
354
|
}
|
|
362
355
|
interface RequestOptions {
|
|
363
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
364
356
|
body?: unknown;
|
|
365
357
|
headers?: Record<string, string>;
|
|
366
|
-
|
|
358
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
367
359
|
}
|
|
368
360
|
interface PaginatedResponse<T> {
|
|
369
361
|
data: T[];
|
|
@@ -394,7 +386,7 @@ declare const createClient: (config: ClientConfig) => {
|
|
|
394
386
|
updatePaymentMethod(id: string, payload: CreatePaymentMethodPayload): Promise<PaymentMethod>;
|
|
395
387
|
deletePaymentMethod(id: string): Promise<void>;
|
|
396
388
|
activatePaymentMethod(id: string): Promise<void>;
|
|
397
|
-
checkout(payload: CheckoutRequestPayload): Promise<CheckoutResponse>;
|
|
389
|
+
checkout(payload: CheckoutRequestPayload, idempotencyKey?: string): Promise<CheckoutResponse>;
|
|
398
390
|
cancelSubscription(feedback?: string): Promise<{
|
|
399
391
|
message: string;
|
|
400
392
|
success: boolean;
|
|
@@ -807,6 +799,7 @@ interface SubscribeWithCardParams {
|
|
|
807
799
|
provider?: string;
|
|
808
800
|
paymentToken: string;
|
|
809
801
|
billing: BillingDetails;
|
|
802
|
+
idempotencyKey?: string;
|
|
810
803
|
}
|
|
811
804
|
interface SubscribeWithSavedMethodParams {
|
|
812
805
|
priceId?: string | null;
|
|
@@ -814,6 +807,7 @@ interface SubscribeWithSavedMethodParams {
|
|
|
814
807
|
provider?: string;
|
|
815
808
|
paymentMethodId: string;
|
|
816
809
|
email?: string;
|
|
810
|
+
idempotencyKey?: string;
|
|
817
811
|
}
|
|
818
812
|
interface SubscribeWithCCBillParams {
|
|
819
813
|
priceId?: string | null;
|
|
@@ -823,11 +817,12 @@ interface SubscribeWithCCBillParams {
|
|
|
823
817
|
zipCode: string;
|
|
824
818
|
country: string;
|
|
825
819
|
processor?: string;
|
|
820
|
+
idempotencyKey?: string;
|
|
826
821
|
}
|
|
827
822
|
declare const useSubscriptionActions: () => {
|
|
828
|
-
subscribeWithCard: ({ priceId, processor, provider, paymentToken, billing, }: SubscribeWithCardParams) => Promise<CheckoutResponse>;
|
|
829
|
-
subscribeWithSavedMethod: ({ priceId, processor, provider, paymentMethodId, email, }: SubscribeWithSavedMethodParams) => Promise<CheckoutResponse>;
|
|
830
|
-
subscribeWithCCBill: ({ priceId, email, firstName, lastName, zipCode, country, processor, }: SubscribeWithCCBillParams) => Promise<CheckoutResponse>;
|
|
823
|
+
subscribeWithCard: ({ priceId, processor, provider, paymentToken, billing, idempotencyKey, }: SubscribeWithCardParams) => Promise<CheckoutResponse>;
|
|
824
|
+
subscribeWithSavedMethod: ({ priceId, processor, provider, paymentMethodId, email, idempotencyKey, }: SubscribeWithSavedMethodParams) => Promise<CheckoutResponse>;
|
|
825
|
+
subscribeWithCCBill: ({ priceId, email, firstName, lastName, zipCode, country, processor, idempotencyKey, }: SubscribeWithCCBillParams) => Promise<CheckoutResponse>;
|
|
831
826
|
};
|
|
832
827
|
|
|
833
|
-
export { type AuthTokenProvider, type BillingAccessGrant, type BillingDetails, BillingHistory, type BillingHistoryProps, type BillingHistoryTranslations, type BillingStatus, BillingThemePortal, BillingThemeProvider, type BillingThemeProviderProps, type CCBillSubscribePayload, CancelMembershipDialog, type CancelMembershipDialogProps, type CancelMembershipDialogTranslations, CardDetailsForm, type CardDetailsFormProps, type CheckoutRequestPayload, type CheckoutResponse, type CheckoutStatus, type Client, ClientApiError, type ClientConfig, type CreatePaymentMethodPayload, type GeneratePaymentRequest, type GeneratePaymentResponse, type HttpMethod, type NmiSubscribePayload, type NotificationHandler, type NotificationPayload, type NotificationStatus, type PaginatedPaymentMethods, type PaginatedPayments, type PaginatedResponse, type Payment, type PaymentCallbacks, type PaymentConfig, PaymentContext, type PaymentContextValue, type
|
|
828
|
+
export { type AuthTokenProvider, type BillingAccessGrant, type BillingDetails, BillingHistory, type BillingHistoryProps, type BillingHistoryTranslations, type BillingStatus, BillingThemePortal, BillingThemeProvider, type BillingThemeProviderProps, type CCBillSubscribePayload, CancelMembershipDialog, type CancelMembershipDialogProps, type CancelMembershipDialogTranslations, CardDetailsForm, type CardDetailsFormProps, type CheckoutRequestPayload, type CheckoutResponse, type CheckoutStatus, type Client, ClientApiError, type ClientConfig, type CreatePaymentMethodPayload, type GeneratePaymentRequest, type GeneratePaymentResponse, type HttpMethod, type NmiSubscribePayload, type NotificationHandler, type NotificationPayload, type NotificationStatus, type PaginatedPaymentMethods, type PaginatedPayments, type PaginatedResponse, type Payment, type PaymentCallbacks, type PaymentConfig, PaymentContext, type PaymentContextValue, type PaymentError, PaymentExperience, type PaymentExperienceProps, type PaymentFeatureFlags, type PaymentFetcher, type PaymentMethod, type PaymentMethodOption, PaymentMethodsSection, type PaymentMethodsSectionProps, type PaymentMethodsSectionTranslations, type PaymentPlatform, PaymentProvider, type PaymentProviderProps, type PaymentSolanaConfig, type PaymentState, type PaymentStatusPayload, type PaymentStatusResponse, type PaymentStep, type PaymentSuccessPayload, type PaymentUserDetails, PaymentsDialogProvider, type RequestOptions, type SolanaFlowConfig, type SolanaPayQRCodeIntent, type SolanaPayStatusResponse, type SolanaPayTransaction, type SolanaPaymentMethod, SolanaPaymentSelector, type SolanaPaymentSelectorProps, SolanaPaymentView, type SolanaPaymentViewProps, type SolanaWallet, StoredPaymentMethods, type StoredPaymentMethodsProps, type SubmitPaymentRequest, type SubmitPaymentResponse, type SubscribeWithCCBillParams, type SubscribeWithCardParams, type SubscribeWithSavedMethodParams, SubscriptionCheckoutModal, type SubscriptionCheckoutModalProps, type SubscriptionCheckoutPayload, SubscriptionSuccessDialog, type SupportedTokensResponse, type TokenBalance, type TokenInfo, type TransactionStatus, type VerifyWalletResponse, type WalletChallengeResponse, type WalletConnectionState, WalletDialog, type WalletDialogProps, type WalletListResponse, WalletModal, type WalletModalProps, createClient, usePaymentContext, usePaymentDialogs, usePaymentMethods, usePaymentNotifications, usePaymentStatus, useSolanaQrPayment, useSubscriptionActions, useSupportedTokens, useTokenBalance };
|
package/dist/index.js
CHANGED
|
@@ -67,7 +67,7 @@ var ClientApiError = class extends Error {
|
|
|
67
67
|
this.request = request;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
|
-
var
|
|
70
|
+
var getFetchFn = (fetchImpl) => {
|
|
71
71
|
if (fetchImpl) return fetchImpl;
|
|
72
72
|
if (typeof globalThis.fetch === "function") {
|
|
73
73
|
return globalThis.fetch.bind(globalThis);
|
|
@@ -75,12 +75,7 @@ var ensureFetch = (fetchImpl) => {
|
|
|
75
75
|
throw new Error("payments-ui: global fetch is not available");
|
|
76
76
|
};
|
|
77
77
|
var createClient = (config) => {
|
|
78
|
-
const fetchImpl =
|
|
79
|
-
const normalizeBase = (value) => value.replace(/\/$/, "");
|
|
80
|
-
const billingBaseUrl = normalizeBase(config.billingBaseUrl);
|
|
81
|
-
const accountBaseUrl = normalizeBase(
|
|
82
|
-
config.accountBaseUrl ?? config.billingBaseUrl
|
|
83
|
-
);
|
|
78
|
+
const fetchImpl = getFetchFn(config.fetch);
|
|
84
79
|
const defaultHeaders = config.defaultHeaders ?? {};
|
|
85
80
|
const resolveAuthToken = async () => {
|
|
86
81
|
if (!config.getAuthToken) return null;
|
|
@@ -92,10 +87,10 @@ var createClient = (config) => {
|
|
|
92
87
|
return null;
|
|
93
88
|
}
|
|
94
89
|
};
|
|
95
|
-
const buildUrl = (path, query
|
|
96
|
-
|
|
97
|
-
const baseUrl =
|
|
98
|
-
const url = new URL(`${baseUrl}${
|
|
90
|
+
const buildUrl = (path, query) => {
|
|
91
|
+
path = path.replace(/^\/+|\/+$/g, "");
|
|
92
|
+
const baseUrl = config.baseUrl.replace(/^\/+|\/+$/g, "");
|
|
93
|
+
const url = new URL(`${baseUrl}${path.endsWith("v1") ? "/" : "/v1/"}${path}`);
|
|
99
94
|
if (query) {
|
|
100
95
|
Object.entries(query).forEach(([key, value]) => {
|
|
101
96
|
if (value === void 0 || value === null) return;
|
|
@@ -105,8 +100,7 @@ var createClient = (config) => {
|
|
|
105
100
|
return url.toString();
|
|
106
101
|
};
|
|
107
102
|
const request = async (method, path, options) => {
|
|
108
|
-
const
|
|
109
|
-
const url = buildUrl(path, options?.query, target);
|
|
103
|
+
const url = buildUrl(path, options?.query);
|
|
110
104
|
const headers = {
|
|
111
105
|
"Content-Type": "application/json",
|
|
112
106
|
...defaultHeaders,
|
|
@@ -152,52 +146,49 @@ var createClient = (config) => {
|
|
|
152
146
|
async listPaymentMethods(params) {
|
|
153
147
|
const result = await request(
|
|
154
148
|
"GET",
|
|
155
|
-
"/
|
|
149
|
+
"/me/payment-methods",
|
|
156
150
|
{
|
|
157
151
|
query: {
|
|
158
152
|
limit: params?.limit,
|
|
159
153
|
offset: params?.offset,
|
|
160
154
|
include_inactive: params?.includeInactive
|
|
161
|
-
}
|
|
162
|
-
target: "account"
|
|
155
|
+
}
|
|
163
156
|
}
|
|
164
157
|
);
|
|
165
158
|
return normalizeList(result);
|
|
166
159
|
},
|
|
167
160
|
createPaymentMethod(payload) {
|
|
168
|
-
return request("POST", "/
|
|
169
|
-
body: payload
|
|
170
|
-
target: "account"
|
|
161
|
+
return request("POST", "/me/payment-methods", {
|
|
162
|
+
body: payload
|
|
171
163
|
});
|
|
172
164
|
},
|
|
173
165
|
updatePaymentMethod(id, payload) {
|
|
174
166
|
return request("PUT", `/me/payment-methods/${id}`, {
|
|
175
|
-
body: payload
|
|
176
|
-
target: "account"
|
|
167
|
+
body: payload
|
|
177
168
|
});
|
|
178
169
|
},
|
|
179
170
|
deletePaymentMethod(id) {
|
|
180
|
-
return request("DELETE", `/me/payment-methods/${id}`, {
|
|
181
|
-
target: "account"
|
|
182
|
-
});
|
|
171
|
+
return request("DELETE", `/me/payment-methods/${id}`, {});
|
|
183
172
|
},
|
|
184
173
|
activatePaymentMethod(id) {
|
|
185
|
-
return request("PUT", `/me/payment-methods/${id}/activate`, {
|
|
186
|
-
target: "account"
|
|
187
|
-
});
|
|
174
|
+
return request("PUT", `/me/payment-methods/${id}/activate`, {});
|
|
188
175
|
},
|
|
189
|
-
checkout(payload) {
|
|
190
|
-
|
|
191
|
-
|
|
176
|
+
checkout(payload, idempotencyKey) {
|
|
177
|
+
const key = idempotencyKey ?? crypto.randomUUID();
|
|
178
|
+
return request("POST", "/me/checkout", {
|
|
179
|
+
body: payload,
|
|
180
|
+
headers: {
|
|
181
|
+
"Idempotency-Key": key
|
|
182
|
+
}
|
|
192
183
|
});
|
|
193
184
|
},
|
|
194
185
|
cancelSubscription(feedback) {
|
|
195
|
-
return request("POST", "/
|
|
186
|
+
return request("POST", "/me/subscriptions/cancel", {
|
|
196
187
|
body: feedback ? { feedback } : void 0
|
|
197
188
|
});
|
|
198
189
|
},
|
|
199
190
|
async getPaymentHistory(params) {
|
|
200
|
-
const result = await request("GET", "/
|
|
191
|
+
const result = await request("GET", "/me/payments", {
|
|
201
192
|
query: {
|
|
202
193
|
limit: params?.limit,
|
|
203
194
|
offset: params?.offset,
|
|
@@ -209,7 +200,7 @@ var createClient = (config) => {
|
|
|
209
200
|
async getSolanaTokens() {
|
|
210
201
|
const response = await request(
|
|
211
202
|
"GET",
|
|
212
|
-
"/
|
|
203
|
+
"/solana/tokens"
|
|
213
204
|
);
|
|
214
205
|
if (Array.isArray(response)) {
|
|
215
206
|
return response;
|
|
@@ -217,7 +208,7 @@ var createClient = (config) => {
|
|
|
217
208
|
return response.tokens ?? [];
|
|
218
209
|
},
|
|
219
210
|
async createSolanaPayIntent(payload) {
|
|
220
|
-
const response = await request("POST", "/
|
|
211
|
+
const response = await request("POST", "/solana/pay", {
|
|
221
212
|
body: {
|
|
222
213
|
price_id: payload.priceId,
|
|
223
214
|
token: payload.token,
|
|
@@ -2047,7 +2038,8 @@ var useSubscriptionActions = () => {
|
|
|
2047
2038
|
processor = "nmi",
|
|
2048
2039
|
provider,
|
|
2049
2040
|
paymentToken,
|
|
2050
|
-
billing
|
|
2041
|
+
billing,
|
|
2042
|
+
idempotencyKey
|
|
2051
2043
|
}) => {
|
|
2052
2044
|
const payload = {
|
|
2053
2045
|
price_id: ensurePrice(priceId),
|
|
@@ -2063,7 +2055,7 @@ var useSubscriptionActions = () => {
|
|
|
2063
2055
|
zip: billing.postalCode,
|
|
2064
2056
|
country: billing.country
|
|
2065
2057
|
};
|
|
2066
|
-
return client.checkout(payload);
|
|
2058
|
+
return client.checkout(payload, idempotencyKey);
|
|
2067
2059
|
},
|
|
2068
2060
|
[client]
|
|
2069
2061
|
);
|
|
@@ -2073,7 +2065,8 @@ var useSubscriptionActions = () => {
|
|
|
2073
2065
|
processor = "nmi",
|
|
2074
2066
|
provider,
|
|
2075
2067
|
paymentMethodId,
|
|
2076
|
-
email
|
|
2068
|
+
email,
|
|
2069
|
+
idempotencyKey
|
|
2077
2070
|
}) => {
|
|
2078
2071
|
const payload = {
|
|
2079
2072
|
price_id: ensurePrice(priceId),
|
|
@@ -2082,7 +2075,7 @@ var useSubscriptionActions = () => {
|
|
|
2082
2075
|
payment_method_id: paymentMethodId,
|
|
2083
2076
|
email
|
|
2084
2077
|
};
|
|
2085
|
-
return client.checkout(payload);
|
|
2078
|
+
return client.checkout(payload, idempotencyKey);
|
|
2086
2079
|
},
|
|
2087
2080
|
[client]
|
|
2088
2081
|
);
|
|
@@ -2094,7 +2087,8 @@ var useSubscriptionActions = () => {
|
|
|
2094
2087
|
lastName,
|
|
2095
2088
|
zipCode,
|
|
2096
2089
|
country,
|
|
2097
|
-
processor = "ccbill"
|
|
2090
|
+
processor = "ccbill",
|
|
2091
|
+
idempotencyKey
|
|
2098
2092
|
}) => {
|
|
2099
2093
|
const payload = {
|
|
2100
2094
|
price_id: ensurePrice(priceId),
|
|
@@ -2105,7 +2099,7 @@ var useSubscriptionActions = () => {
|
|
|
2105
2099
|
zip: zipCode,
|
|
2106
2100
|
country
|
|
2107
2101
|
};
|
|
2108
|
-
return client.checkout(payload);
|
|
2102
|
+
return client.checkout(payload, idempotencyKey);
|
|
2109
2103
|
},
|
|
2110
2104
|
[client]
|
|
2111
2105
|
);
|
|
@@ -2132,7 +2126,13 @@ var SubscriptionCheckoutModal = ({
|
|
|
2132
2126
|
initialMode = "cards"
|
|
2133
2127
|
}) => {
|
|
2134
2128
|
const [showSuccess, setShowSuccess] = useState(false);
|
|
2129
|
+
const [idempotencyKey, setIdempotencyKey] = useState(() => crypto.randomUUID());
|
|
2135
2130
|
const { subscribeWithCard, subscribeWithSavedMethod } = useSubscriptionActions();
|
|
2131
|
+
useEffect(() => {
|
|
2132
|
+
if (open) {
|
|
2133
|
+
setIdempotencyKey(crypto.randomUUID());
|
|
2134
|
+
}
|
|
2135
|
+
}, [open, priceId]);
|
|
2136
2136
|
const handleClose = useCallback(
|
|
2137
2137
|
(nextOpen) => {
|
|
2138
2138
|
onOpenChange(nextOpen);
|
|
@@ -2164,7 +2164,8 @@ var SubscriptionCheckoutModal = ({
|
|
|
2164
2164
|
priceId: ensurePrice(),
|
|
2165
2165
|
provider,
|
|
2166
2166
|
paymentToken: token,
|
|
2167
|
-
billing
|
|
2167
|
+
billing,
|
|
2168
|
+
idempotencyKey
|
|
2168
2169
|
});
|
|
2169
2170
|
assertCheckoutSuccess(response.status, response.message);
|
|
2170
2171
|
notifySuccess();
|
|
@@ -2174,7 +2175,8 @@ var SubscriptionCheckoutModal = ({
|
|
|
2174
2175
|
priceId: ensurePrice(),
|
|
2175
2176
|
provider,
|
|
2176
2177
|
paymentMethodId,
|
|
2177
|
-
email: userEmail ?? ""
|
|
2178
|
+
email: userEmail ?? "",
|
|
2179
|
+
idempotencyKey
|
|
2178
2180
|
});
|
|
2179
2181
|
assertCheckoutSuccess(response.status, response.message);
|
|
2180
2182
|
notifySuccess();
|
|
@@ -2404,11 +2406,10 @@ var PaymentProvider = ({
|
|
|
2404
2406
|
return config.fetcher(normalizedInput, init);
|
|
2405
2407
|
}) : void 0;
|
|
2406
2408
|
return createClient({
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
+
fetch: wrappedFetch,
|
|
2410
|
+
baseUrl: config.baseUrl,
|
|
2409
2411
|
getAuthToken: authProvider,
|
|
2410
|
-
defaultHeaders: config.defaultHeaders
|
|
2411
|
-
fetch: wrappedFetch
|
|
2412
|
+
defaultHeaders: config.defaultHeaders
|
|
2412
2413
|
});
|
|
2413
2414
|
}, [config]);
|
|
2414
2415
|
const solanaEndpoint = useMemo(() => {
|