@doujins/payments-ui 0.1.3 → 0.1.4
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 +46 -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 +46 -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,9 @@ var createClient = (config) => {
|
|
|
92
87
|
return null;
|
|
93
88
|
}
|
|
94
89
|
};
|
|
95
|
-
const buildUrl = (path, query
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
const url = new URL(`${baseUrl}${normalizedPath}`);
|
|
90
|
+
const buildUrl = (path, query) => {
|
|
91
|
+
path = path.replace(/^\/+/, "");
|
|
92
|
+
const url = new URL(`${config.baseUrl.replace(/^\/+/, "")}${path.endsWith("v1") ? "" : "/v1"}${path}`);
|
|
99
93
|
if (query) {
|
|
100
94
|
Object.entries(query).forEach(([key, value]) => {
|
|
101
95
|
if (value === void 0 || value === null) return;
|
|
@@ -105,8 +99,7 @@ var createClient = (config) => {
|
|
|
105
99
|
return url.toString();
|
|
106
100
|
};
|
|
107
101
|
const request = async (method, path, options) => {
|
|
108
|
-
const
|
|
109
|
-
const url = buildUrl(path, options?.query, target);
|
|
102
|
+
const url = buildUrl(path, options?.query);
|
|
110
103
|
const headers = {
|
|
111
104
|
"Content-Type": "application/json",
|
|
112
105
|
...defaultHeaders,
|
|
@@ -152,52 +145,49 @@ var createClient = (config) => {
|
|
|
152
145
|
async listPaymentMethods(params) {
|
|
153
146
|
const result = await request(
|
|
154
147
|
"GET",
|
|
155
|
-
"/
|
|
148
|
+
"/me/payment-methods",
|
|
156
149
|
{
|
|
157
150
|
query: {
|
|
158
151
|
limit: params?.limit,
|
|
159
152
|
offset: params?.offset,
|
|
160
153
|
include_inactive: params?.includeInactive
|
|
161
|
-
}
|
|
162
|
-
target: "account"
|
|
154
|
+
}
|
|
163
155
|
}
|
|
164
156
|
);
|
|
165
157
|
return normalizeList(result);
|
|
166
158
|
},
|
|
167
159
|
createPaymentMethod(payload) {
|
|
168
|
-
return request("POST", "/
|
|
169
|
-
body: payload
|
|
170
|
-
target: "account"
|
|
160
|
+
return request("POST", "/me/payment-methods", {
|
|
161
|
+
body: payload
|
|
171
162
|
});
|
|
172
163
|
},
|
|
173
164
|
updatePaymentMethod(id, payload) {
|
|
174
165
|
return request("PUT", `/me/payment-methods/${id}`, {
|
|
175
|
-
body: payload
|
|
176
|
-
target: "account"
|
|
166
|
+
body: payload
|
|
177
167
|
});
|
|
178
168
|
},
|
|
179
169
|
deletePaymentMethod(id) {
|
|
180
|
-
return request("DELETE", `/me/payment-methods/${id}`, {
|
|
181
|
-
target: "account"
|
|
182
|
-
});
|
|
170
|
+
return request("DELETE", `/me/payment-methods/${id}`, {});
|
|
183
171
|
},
|
|
184
172
|
activatePaymentMethod(id) {
|
|
185
|
-
return request("PUT", `/me/payment-methods/${id}/activate`, {
|
|
186
|
-
target: "account"
|
|
187
|
-
});
|
|
173
|
+
return request("PUT", `/me/payment-methods/${id}/activate`, {});
|
|
188
174
|
},
|
|
189
|
-
checkout(payload) {
|
|
190
|
-
|
|
191
|
-
|
|
175
|
+
checkout(payload, idempotencyKey) {
|
|
176
|
+
const key = idempotencyKey ?? crypto.randomUUID();
|
|
177
|
+
return request("POST", "/me/checkout", {
|
|
178
|
+
body: payload,
|
|
179
|
+
headers: {
|
|
180
|
+
"Idempotency-Key": key
|
|
181
|
+
}
|
|
192
182
|
});
|
|
193
183
|
},
|
|
194
184
|
cancelSubscription(feedback) {
|
|
195
|
-
return request("POST", "/
|
|
185
|
+
return request("POST", "/me/subscriptions/cancel", {
|
|
196
186
|
body: feedback ? { feedback } : void 0
|
|
197
187
|
});
|
|
198
188
|
},
|
|
199
189
|
async getPaymentHistory(params) {
|
|
200
|
-
const result = await request("GET", "/
|
|
190
|
+
const result = await request("GET", "/me/payments", {
|
|
201
191
|
query: {
|
|
202
192
|
limit: params?.limit,
|
|
203
193
|
offset: params?.offset,
|
|
@@ -209,7 +199,7 @@ var createClient = (config) => {
|
|
|
209
199
|
async getSolanaTokens() {
|
|
210
200
|
const response = await request(
|
|
211
201
|
"GET",
|
|
212
|
-
"/
|
|
202
|
+
"/solana/tokens"
|
|
213
203
|
);
|
|
214
204
|
if (Array.isArray(response)) {
|
|
215
205
|
return response;
|
|
@@ -217,7 +207,7 @@ var createClient = (config) => {
|
|
|
217
207
|
return response.tokens ?? [];
|
|
218
208
|
},
|
|
219
209
|
async createSolanaPayIntent(payload) {
|
|
220
|
-
const response = await request("POST", "/
|
|
210
|
+
const response = await request("POST", "/solana/pay", {
|
|
221
211
|
body: {
|
|
222
212
|
price_id: payload.priceId,
|
|
223
213
|
token: payload.token,
|
|
@@ -2047,7 +2037,8 @@ var useSubscriptionActions = () => {
|
|
|
2047
2037
|
processor = "nmi",
|
|
2048
2038
|
provider,
|
|
2049
2039
|
paymentToken,
|
|
2050
|
-
billing
|
|
2040
|
+
billing,
|
|
2041
|
+
idempotencyKey
|
|
2051
2042
|
}) => {
|
|
2052
2043
|
const payload = {
|
|
2053
2044
|
price_id: ensurePrice(priceId),
|
|
@@ -2063,7 +2054,7 @@ var useSubscriptionActions = () => {
|
|
|
2063
2054
|
zip: billing.postalCode,
|
|
2064
2055
|
country: billing.country
|
|
2065
2056
|
};
|
|
2066
|
-
return client.checkout(payload);
|
|
2057
|
+
return client.checkout(payload, idempotencyKey);
|
|
2067
2058
|
},
|
|
2068
2059
|
[client]
|
|
2069
2060
|
);
|
|
@@ -2073,7 +2064,8 @@ var useSubscriptionActions = () => {
|
|
|
2073
2064
|
processor = "nmi",
|
|
2074
2065
|
provider,
|
|
2075
2066
|
paymentMethodId,
|
|
2076
|
-
email
|
|
2067
|
+
email,
|
|
2068
|
+
idempotencyKey
|
|
2077
2069
|
}) => {
|
|
2078
2070
|
const payload = {
|
|
2079
2071
|
price_id: ensurePrice(priceId),
|
|
@@ -2082,7 +2074,7 @@ var useSubscriptionActions = () => {
|
|
|
2082
2074
|
payment_method_id: paymentMethodId,
|
|
2083
2075
|
email
|
|
2084
2076
|
};
|
|
2085
|
-
return client.checkout(payload);
|
|
2077
|
+
return client.checkout(payload, idempotencyKey);
|
|
2086
2078
|
},
|
|
2087
2079
|
[client]
|
|
2088
2080
|
);
|
|
@@ -2094,7 +2086,8 @@ var useSubscriptionActions = () => {
|
|
|
2094
2086
|
lastName,
|
|
2095
2087
|
zipCode,
|
|
2096
2088
|
country,
|
|
2097
|
-
processor = "ccbill"
|
|
2089
|
+
processor = "ccbill",
|
|
2090
|
+
idempotencyKey
|
|
2098
2091
|
}) => {
|
|
2099
2092
|
const payload = {
|
|
2100
2093
|
price_id: ensurePrice(priceId),
|
|
@@ -2105,7 +2098,7 @@ var useSubscriptionActions = () => {
|
|
|
2105
2098
|
zip: zipCode,
|
|
2106
2099
|
country
|
|
2107
2100
|
};
|
|
2108
|
-
return client.checkout(payload);
|
|
2101
|
+
return client.checkout(payload, idempotencyKey);
|
|
2109
2102
|
},
|
|
2110
2103
|
[client]
|
|
2111
2104
|
);
|
|
@@ -2132,7 +2125,13 @@ var SubscriptionCheckoutModal = ({
|
|
|
2132
2125
|
initialMode = "cards"
|
|
2133
2126
|
}) => {
|
|
2134
2127
|
const [showSuccess, setShowSuccess] = useState(false);
|
|
2128
|
+
const [idempotencyKey, setIdempotencyKey] = useState(() => crypto.randomUUID());
|
|
2135
2129
|
const { subscribeWithCard, subscribeWithSavedMethod } = useSubscriptionActions();
|
|
2130
|
+
useEffect(() => {
|
|
2131
|
+
if (open) {
|
|
2132
|
+
setIdempotencyKey(crypto.randomUUID());
|
|
2133
|
+
}
|
|
2134
|
+
}, [open, priceId]);
|
|
2136
2135
|
const handleClose = useCallback(
|
|
2137
2136
|
(nextOpen) => {
|
|
2138
2137
|
onOpenChange(nextOpen);
|
|
@@ -2164,7 +2163,8 @@ var SubscriptionCheckoutModal = ({
|
|
|
2164
2163
|
priceId: ensurePrice(),
|
|
2165
2164
|
provider,
|
|
2166
2165
|
paymentToken: token,
|
|
2167
|
-
billing
|
|
2166
|
+
billing,
|
|
2167
|
+
idempotencyKey
|
|
2168
2168
|
});
|
|
2169
2169
|
assertCheckoutSuccess(response.status, response.message);
|
|
2170
2170
|
notifySuccess();
|
|
@@ -2174,7 +2174,8 @@ var SubscriptionCheckoutModal = ({
|
|
|
2174
2174
|
priceId: ensurePrice(),
|
|
2175
2175
|
provider,
|
|
2176
2176
|
paymentMethodId,
|
|
2177
|
-
email: userEmail ?? ""
|
|
2177
|
+
email: userEmail ?? "",
|
|
2178
|
+
idempotencyKey
|
|
2178
2179
|
});
|
|
2179
2180
|
assertCheckoutSuccess(response.status, response.message);
|
|
2180
2181
|
notifySuccess();
|
|
@@ -2404,11 +2405,10 @@ var PaymentProvider = ({
|
|
|
2404
2405
|
return config.fetcher(normalizedInput, init);
|
|
2405
2406
|
}) : void 0;
|
|
2406
2407
|
return createClient({
|
|
2407
|
-
|
|
2408
|
-
|
|
2408
|
+
fetch: wrappedFetch,
|
|
2409
|
+
baseUrl: config.baseUrl,
|
|
2409
2410
|
getAuthToken: authProvider,
|
|
2410
|
-
defaultHeaders: config.defaultHeaders
|
|
2411
|
-
fetch: wrappedFetch
|
|
2411
|
+
defaultHeaders: config.defaultHeaders
|
|
2412
2412
|
});
|
|
2413
2413
|
}, [config]);
|
|
2414
2414
|
const solanaEndpoint = useMemo(() => {
|