@blocklet/payment-react-headless 1.26.0

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.
Files changed (250) hide show
  1. package/.eslintrc.js +18 -0
  2. package/build.config.ts +30 -0
  3. package/es/checkout/context/CheckoutProvider.d.ts +6 -0
  4. package/es/checkout/context/CheckoutProvider.js +209 -0
  5. package/es/checkout/context/CustomerFormContext.d.ts +4 -0
  6. package/es/checkout/context/CustomerFormContext.js +9 -0
  7. package/es/checkout/context/ExchangeRateContext.d.ts +11 -0
  8. package/es/checkout/context/ExchangeRateContext.js +9 -0
  9. package/es/checkout/context/PaymentMethodContext.d.ts +26 -0
  10. package/es/checkout/context/PaymentMethodContext.js +9 -0
  11. package/es/checkout/context/SessionContext.d.ts +45 -0
  12. package/es/checkout/context/SessionContext.js +9 -0
  13. package/es/checkout/context/SubmitContext.d.ts +4 -0
  14. package/es/checkout/context/SubmitContext.js +9 -0
  15. package/es/checkout/context/index.d.ts +6 -0
  16. package/es/checkout/context/index.js +6 -0
  17. package/es/checkout/core/billingInterval.d.ts +15 -0
  18. package/es/checkout/core/billingInterval.js +36 -0
  19. package/es/checkout/core/crossSell.d.ts +4 -0
  20. package/es/checkout/core/crossSell.js +30 -0
  21. package/es/checkout/core/customerForm.d.ts +5 -0
  22. package/es/checkout/core/customerForm.js +105 -0
  23. package/es/checkout/core/exchangeRate.d.ts +11 -0
  24. package/es/checkout/core/exchangeRate.js +25 -0
  25. package/es/checkout/core/index.d.ts +10 -0
  26. package/es/checkout/core/index.js +55 -0
  27. package/es/checkout/core/lineItems.d.ts +7 -0
  28. package/es/checkout/core/lineItems.js +59 -0
  29. package/es/checkout/core/paymentMethod.d.ts +23 -0
  30. package/es/checkout/core/paymentMethod.js +85 -0
  31. package/es/checkout/core/pricing.d.ts +32 -0
  32. package/es/checkout/core/pricing.js +221 -0
  33. package/es/checkout/core/promotion.d.ts +10 -0
  34. package/es/checkout/core/promotion.js +39 -0
  35. package/es/checkout/core/session.d.ts +26 -0
  36. package/es/checkout/core/session.js +50 -0
  37. package/es/checkout/core/submit.d.ts +40 -0
  38. package/es/checkout/core/submit.js +66 -0
  39. package/es/checkout/hooks/index.d.ts +34 -0
  40. package/es/checkout/hooks/index.js +19 -0
  41. package/es/checkout/hooks/useBillingInterval.d.ts +14 -0
  42. package/es/checkout/hooks/useBillingInterval.js +50 -0
  43. package/es/checkout/hooks/useCheckout.d.ts +2 -0
  44. package/es/checkout/hooks/useCheckout.js +212 -0
  45. package/es/checkout/hooks/useCheckoutSession.d.ts +58 -0
  46. package/es/checkout/hooks/useCheckoutSession.js +107 -0
  47. package/es/checkout/hooks/useCheckoutStatus.d.ts +10 -0
  48. package/es/checkout/hooks/useCheckoutStatus.js +16 -0
  49. package/es/checkout/hooks/useCrossSell.d.ts +8 -0
  50. package/es/checkout/hooks/useCrossSell.js +57 -0
  51. package/es/checkout/hooks/useCustomerForm.d.ts +14 -0
  52. package/es/checkout/hooks/useCustomerForm.js +116 -0
  53. package/es/checkout/hooks/useCustomerFormFeature.d.ts +2 -0
  54. package/es/checkout/hooks/useCustomerFormFeature.js +4 -0
  55. package/es/checkout/hooks/useExchangeRate.d.ts +11 -0
  56. package/es/checkout/hooks/useExchangeRate.js +15 -0
  57. package/es/checkout/hooks/useLineItems.d.ts +22 -0
  58. package/es/checkout/hooks/useLineItems.js +139 -0
  59. package/es/checkout/hooks/usePaymentMethod.d.ts +26 -0
  60. package/es/checkout/hooks/usePaymentMethod.js +101 -0
  61. package/es/checkout/hooks/usePaymentMethodFeature.d.ts +2 -0
  62. package/es/checkout/hooks/usePaymentMethodFeature.js +4 -0
  63. package/es/checkout/hooks/usePricing.d.ts +57 -0
  64. package/es/checkout/hooks/usePricing.js +174 -0
  65. package/es/checkout/hooks/usePricingFeature.d.ts +28 -0
  66. package/es/checkout/hooks/usePricingFeature.js +36 -0
  67. package/es/checkout/hooks/useProduct.d.ts +32 -0
  68. package/es/checkout/hooks/useProduct.js +5 -0
  69. package/es/checkout/hooks/usePromotion.d.ts +12 -0
  70. package/es/checkout/hooks/usePromotion.js +48 -0
  71. package/es/checkout/hooks/useSlippage.d.ts +8 -0
  72. package/es/checkout/hooks/useSlippage.js +29 -0
  73. package/es/checkout/hooks/useSubmit.d.ts +38 -0
  74. package/es/checkout/hooks/useSubmit.js +493 -0
  75. package/es/checkout/hooks/useSubmitFeature.d.ts +2 -0
  76. package/es/checkout/hooks/useSubmitFeature.js +4 -0
  77. package/es/checkout/hooks/useUpsell.d.ts +5 -0
  78. package/es/checkout/hooks/useUpsell.js +25 -0
  79. package/es/checkout/index.d.ts +37 -0
  80. package/es/checkout/index.js +28 -0
  81. package/es/checkout/types.d.ts +262 -0
  82. package/es/checkout/types.js +0 -0
  83. package/es/index.d.ts +1 -0
  84. package/es/index.js +28 -0
  85. package/es/shared/api.d.ts +41 -0
  86. package/es/shared/api.js +81 -0
  87. package/es/shared/format.d.ts +38 -0
  88. package/es/shared/format.js +229 -0
  89. package/es/shared/polling.d.ts +15 -0
  90. package/es/shared/polling.js +20 -0
  91. package/es/shared/types.d.ts +10 -0
  92. package/es/shared/types.js +0 -0
  93. package/es/shared/validation.d.ts +38 -0
  94. package/es/shared/validation.js +190 -0
  95. package/es/types/checkout-augmented.d.ts +42 -0
  96. package/es/types/checkout-augmented.js +17 -0
  97. package/es/types/external.d.ts +18 -0
  98. package/examples/01-basic-checkout.tsx +159 -0
  99. package/examples/01-credit-recharge.tsx +19 -0
  100. package/examples/02-subscription.tsx +40 -0
  101. package/examples/03-upsell.tsx +60 -0
  102. package/examples/04-cross-sell.tsx +54 -0
  103. package/examples/05-full-checkout.tsx +126 -0
  104. package/jest.config.js +15 -0
  105. package/lib/checkout/context/CheckoutProvider.d.ts +6 -0
  106. package/lib/checkout/context/CheckoutProvider.js +181 -0
  107. package/lib/checkout/context/CustomerFormContext.d.ts +4 -0
  108. package/lib/checkout/context/CustomerFormContext.js +16 -0
  109. package/lib/checkout/context/ExchangeRateContext.d.ts +11 -0
  110. package/lib/checkout/context/ExchangeRateContext.js +16 -0
  111. package/lib/checkout/context/PaymentMethodContext.d.ts +26 -0
  112. package/lib/checkout/context/PaymentMethodContext.js +16 -0
  113. package/lib/checkout/context/SessionContext.d.ts +45 -0
  114. package/lib/checkout/context/SessionContext.js +16 -0
  115. package/lib/checkout/context/SubmitContext.d.ts +4 -0
  116. package/lib/checkout/context/SubmitContext.js +16 -0
  117. package/lib/checkout/context/index.d.ts +6 -0
  118. package/lib/checkout/context/index.js +77 -0
  119. package/lib/checkout/core/billingInterval.d.ts +15 -0
  120. package/lib/checkout/core/billingInterval.js +42 -0
  121. package/lib/checkout/core/crossSell.d.ts +4 -0
  122. package/lib/checkout/core/crossSell.js +43 -0
  123. package/lib/checkout/core/customerForm.d.ts +5 -0
  124. package/lib/checkout/core/customerForm.js +106 -0
  125. package/lib/checkout/core/exchangeRate.d.ts +11 -0
  126. package/lib/checkout/core/exchangeRate.js +45 -0
  127. package/lib/checkout/core/index.d.ts +10 -0
  128. package/lib/checkout/core/index.js +297 -0
  129. package/lib/checkout/core/lineItems.d.ts +7 -0
  130. package/lib/checkout/core/lineItems.js +76 -0
  131. package/lib/checkout/core/paymentMethod.d.ts +23 -0
  132. package/lib/checkout/core/paymentMethod.js +114 -0
  133. package/lib/checkout/core/pricing.d.ts +32 -0
  134. package/lib/checkout/core/pricing.js +216 -0
  135. package/lib/checkout/core/promotion.d.ts +10 -0
  136. package/lib/checkout/core/promotion.js +62 -0
  137. package/lib/checkout/core/session.d.ts +26 -0
  138. package/lib/checkout/core/session.js +58 -0
  139. package/lib/checkout/core/submit.d.ts +40 -0
  140. package/lib/checkout/core/submit.js +84 -0
  141. package/lib/checkout/hooks/index.d.ts +34 -0
  142. package/lib/checkout/hooks/index.js +138 -0
  143. package/lib/checkout/hooks/useBillingInterval.d.ts +14 -0
  144. package/lib/checkout/hooks/useBillingInterval.js +63 -0
  145. package/lib/checkout/hooks/useCheckout.d.ts +2 -0
  146. package/lib/checkout/hooks/useCheckout.js +190 -0
  147. package/lib/checkout/hooks/useCheckoutSession.d.ts +58 -0
  148. package/lib/checkout/hooks/useCheckoutSession.js +119 -0
  149. package/lib/checkout/hooks/useCheckoutStatus.d.ts +10 -0
  150. package/lib/checkout/hooks/useCheckoutStatus.js +28 -0
  151. package/lib/checkout/hooks/useCrossSell.d.ts +8 -0
  152. package/lib/checkout/hooks/useCrossSell.js +75 -0
  153. package/lib/checkout/hooks/useCustomerForm.d.ts +14 -0
  154. package/lib/checkout/hooks/useCustomerForm.js +135 -0
  155. package/lib/checkout/hooks/useCustomerFormFeature.d.ts +2 -0
  156. package/lib/checkout/hooks/useCustomerFormFeature.js +10 -0
  157. package/lib/checkout/hooks/useExchangeRate.d.ts +11 -0
  158. package/lib/checkout/hooks/useExchangeRate.js +29 -0
  159. package/lib/checkout/hooks/useLineItems.d.ts +22 -0
  160. package/lib/checkout/hooks/useLineItems.js +142 -0
  161. package/lib/checkout/hooks/usePaymentMethod.d.ts +26 -0
  162. package/lib/checkout/hooks/usePaymentMethod.js +101 -0
  163. package/lib/checkout/hooks/usePaymentMethodFeature.d.ts +2 -0
  164. package/lib/checkout/hooks/usePaymentMethodFeature.js +10 -0
  165. package/lib/checkout/hooks/usePricing.d.ts +57 -0
  166. package/lib/checkout/hooks/usePricing.js +168 -0
  167. package/lib/checkout/hooks/usePricingFeature.d.ts +28 -0
  168. package/lib/checkout/hooks/usePricingFeature.js +48 -0
  169. package/lib/checkout/hooks/useProduct.d.ts +32 -0
  170. package/lib/checkout/hooks/useProduct.js +21 -0
  171. package/lib/checkout/hooks/usePromotion.d.ts +12 -0
  172. package/lib/checkout/hooks/usePromotion.js +57 -0
  173. package/lib/checkout/hooks/useSlippage.d.ts +8 -0
  174. package/lib/checkout/hooks/useSlippage.js +39 -0
  175. package/lib/checkout/hooks/useSubmit.d.ts +38 -0
  176. package/lib/checkout/hooks/useSubmit.js +504 -0
  177. package/lib/checkout/hooks/useSubmitFeature.d.ts +2 -0
  178. package/lib/checkout/hooks/useSubmitFeature.js +10 -0
  179. package/lib/checkout/hooks/useUpsell.d.ts +5 -0
  180. package/lib/checkout/hooks/useUpsell.js +40 -0
  181. package/lib/checkout/index.d.ts +37 -0
  182. package/lib/checkout/index.js +182 -0
  183. package/lib/checkout/types.d.ts +262 -0
  184. package/lib/checkout/types.js +1 -0
  185. package/lib/index.d.ts +1 -0
  186. package/lib/index.js +162 -0
  187. package/lib/shared/api.d.ts +41 -0
  188. package/lib/shared/api.js +88 -0
  189. package/lib/shared/format.d.ts +38 -0
  190. package/lib/shared/format.js +262 -0
  191. package/lib/shared/polling.d.ts +15 -0
  192. package/lib/shared/polling.js +32 -0
  193. package/lib/shared/types.d.ts +10 -0
  194. package/lib/shared/types.js +1 -0
  195. package/lib/shared/validation.d.ts +38 -0
  196. package/lib/shared/validation.js +212 -0
  197. package/lib/types/checkout-augmented.d.ts +42 -0
  198. package/lib/types/checkout-augmented.js +24 -0
  199. package/lib/types/external.d.ts +18 -0
  200. package/package.json +64 -0
  201. package/src/checkout/context/CheckoutProvider.tsx +269 -0
  202. package/src/checkout/context/CustomerFormContext.ts +14 -0
  203. package/src/checkout/context/ExchangeRateContext.ts +21 -0
  204. package/src/checkout/context/PaymentMethodContext.ts +36 -0
  205. package/src/checkout/context/SessionContext.ts +49 -0
  206. package/src/checkout/context/SubmitContext.ts +14 -0
  207. package/src/checkout/context/index.ts +6 -0
  208. package/src/checkout/core/billingInterval.ts +62 -0
  209. package/src/checkout/core/crossSell.ts +52 -0
  210. package/src/checkout/core/customerForm.ts +122 -0
  211. package/src/checkout/core/exchangeRate.ts +38 -0
  212. package/src/checkout/core/index.ts +60 -0
  213. package/src/checkout/core/lineItems.ts +106 -0
  214. package/src/checkout/core/paymentMethod.ts +113 -0
  215. package/src/checkout/core/pricing.ts +347 -0
  216. package/src/checkout/core/promotion.ts +59 -0
  217. package/src/checkout/core/session.ts +62 -0
  218. package/src/checkout/core/submit.ts +109 -0
  219. package/src/checkout/hooks/index.ts +41 -0
  220. package/src/checkout/hooks/useBillingInterval.ts +71 -0
  221. package/src/checkout/hooks/useCheckout.ts +267 -0
  222. package/src/checkout/hooks/useCheckoutSession.ts +217 -0
  223. package/src/checkout/hooks/useCheckoutStatus.ts +31 -0
  224. package/src/checkout/hooks/useCrossSell.ts +80 -0
  225. package/src/checkout/hooks/useCustomerForm.ts +156 -0
  226. package/src/checkout/hooks/useCustomerFormFeature.ts +7 -0
  227. package/src/checkout/hooks/useExchangeRate.ts +28 -0
  228. package/src/checkout/hooks/useLineItems.ts +191 -0
  229. package/src/checkout/hooks/usePaymentMethod.ts +165 -0
  230. package/src/checkout/hooks/usePaymentMethodFeature.ts +8 -0
  231. package/src/checkout/hooks/usePricing.ts +274 -0
  232. package/src/checkout/hooks/usePricingFeature.ts +73 -0
  233. package/src/checkout/hooks/useProduct.ts +32 -0
  234. package/src/checkout/hooks/usePromotion.ts +67 -0
  235. package/src/checkout/hooks/useSlippage.ts +39 -0
  236. package/src/checkout/hooks/useSubmit.ts +684 -0
  237. package/src/checkout/hooks/useSubmitFeature.ts +7 -0
  238. package/src/checkout/hooks/useUpsell.ts +35 -0
  239. package/src/checkout/index.ts +65 -0
  240. package/src/checkout/types.ts +292 -0
  241. package/src/index.ts +64 -0
  242. package/src/shared/api.ts +118 -0
  243. package/src/shared/format.ts +318 -0
  244. package/src/shared/polling.ts +49 -0
  245. package/src/shared/types.ts +13 -0
  246. package/src/shared/validation.ts +254 -0
  247. package/src/types/checkout-augmented.ts +77 -0
  248. package/src/types/external.d.ts +18 -0
  249. package/tools/jest.js +1 -0
  250. package/tsconfig.json +18 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CheckoutProvider", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _context.CheckoutProvider;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getPriceUnitAmountByCurrency", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _format.getPriceUnitAmountByCurrency;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "useBillingInterval", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _useBillingInterval.useBillingInterval;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useCheckout", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _useCheckout.useCheckout;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "useCheckoutSession", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _useCheckoutSession.useCheckoutSession;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "useCheckoutStatus", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _useCheckoutStatus.useCheckoutStatus;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "useCrossSell", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _useCrossSell.useCrossSell;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "useCustomerForm", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _useCustomerForm.useCustomerForm;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "useCustomerFormContext", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _context.useCustomerFormContext;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "useCustomerFormFeature", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _useCustomerFormFeature.useCustomerFormFeature;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "useExchangeRate", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _useExchangeRate.useExchangeRate;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "useExchangeRateContext", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _context.useExchangeRateContext;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "useLineItems", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _useLineItems.useLineItems;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "usePaymentMethod", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _usePaymentMethod.usePaymentMethod;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "usePaymentMethodContext", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _context.usePaymentMethodContext;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "usePaymentMethodFeature", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _usePaymentMethodFeature.usePaymentMethodFeature;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "usePricing", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _usePricing.usePricing;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, "usePricingFeature", {
109
+ enumerable: true,
110
+ get: function () {
111
+ return _usePricingFeature.usePricingFeature;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, "useProduct", {
115
+ enumerable: true,
116
+ get: function () {
117
+ return _useProduct.useProduct;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "usePromotion", {
121
+ enumerable: true,
122
+ get: function () {
123
+ return _usePromotion.usePromotion;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, "useSessionContext", {
127
+ enumerable: true,
128
+ get: function () {
129
+ return _context.useSessionContext;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, "useSlippage", {
133
+ enumerable: true,
134
+ get: function () {
135
+ return _useSlippage.useSlippage;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, "useSubmit", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _useSubmit.useSubmit;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "useSubmitContext", {
145
+ enumerable: true,
146
+ get: function () {
147
+ return _context.useSubmitContext;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, "useSubmitFeature", {
151
+ enumerable: true,
152
+ get: function () {
153
+ return _useSubmitFeature.useSubmitFeature;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "useUpsell", {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _useUpsell.useUpsell;
160
+ }
161
+ });
162
+ var _context = require("./context");
163
+ var _useCheckout = require("./hooks/useCheckout");
164
+ var _useCheckoutSession = require("./hooks/useCheckoutSession");
165
+ var _usePaymentMethod = require("./hooks/usePaymentMethod");
166
+ var _usePricing = require("./hooks/usePricing");
167
+ var _useCustomerForm = require("./hooks/useCustomerForm");
168
+ var _useSubmit = require("./hooks/useSubmit");
169
+ var _useProduct = require("./hooks/useProduct");
170
+ var _useLineItems = require("./hooks/useLineItems");
171
+ var _useBillingInterval = require("./hooks/useBillingInterval");
172
+ var _useUpsell = require("./hooks/useUpsell");
173
+ var _useCrossSell = require("./hooks/useCrossSell");
174
+ var _usePromotion = require("./hooks/usePromotion");
175
+ var _useExchangeRate = require("./hooks/useExchangeRate");
176
+ var _useSlippage = require("./hooks/useSlippage");
177
+ var _useCheckoutStatus = require("./hooks/useCheckoutStatus");
178
+ var _usePricingFeature = require("./hooks/usePricingFeature");
179
+ var _usePaymentMethodFeature = require("./hooks/usePaymentMethodFeature");
180
+ var _useCustomerFormFeature = require("./hooks/useCustomerFormFeature");
181
+ var _useSubmitFeature = require("./hooks/useSubmitFeature");
182
+ var _format = require("../shared/format");
@@ -0,0 +1,262 @@
1
+ import type { TLineItemExpanded, TPaymentMethodExpanded, TPaymentCurrency, TPrice, TCheckoutSessionExpanded, TPaymentIntent, TCustomer } from '@blocklet/payment-types';
2
+ export type SubmitStatus = 'idle' | 'submitting' | 'confirming_price' | 'confirming_fast_pay' | 'credit_insufficient' | 'waiting_did' | 'waiting_stripe' | 'completed' | 'failed';
3
+ export type SubmitContext = {
4
+ type: 'price_change';
5
+ changePercent: number;
6
+ } | {
7
+ type: 'fast_pay';
8
+ payType: 'balance' | 'delegation' | 'credit';
9
+ amount: string;
10
+ payer: string;
11
+ } | {
12
+ type: 'credit_insufficient';
13
+ available: string;
14
+ required: string;
15
+ } | {
16
+ type: 'stripe';
17
+ clientSecret: string;
18
+ intentType?: 'payment_intent' | 'setup_intent';
19
+ } | {
20
+ type: 'did_connect';
21
+ action: string;
22
+ checkpointId: string;
23
+ extraParams: Record<string, unknown>;
24
+ } | {
25
+ type: 'error';
26
+ message: string;
27
+ code?: string;
28
+ } | null;
29
+ export interface FieldConfig {
30
+ name: string;
31
+ type: 'text' | 'email' | 'phone' | 'select' | 'country';
32
+ required: boolean;
33
+ options?: Array<{
34
+ value: string;
35
+ label: string;
36
+ }>;
37
+ group?: string;
38
+ }
39
+ export type CheckoutFormData = {
40
+ customer_name: string;
41
+ customer_email?: string;
42
+ customer_phone?: string;
43
+ payment_method: string;
44
+ payment_currency: string;
45
+ billing_address?: {
46
+ country: string;
47
+ state?: string;
48
+ city?: string;
49
+ line1?: string;
50
+ line2?: string;
51
+ postal_code: string;
52
+ };
53
+ };
54
+ export type CheckoutResult = {
55
+ checkoutSession: TCheckoutSessionExpanded;
56
+ paymentMethods: TPaymentMethodExpanded[];
57
+ paymentIntent?: TPaymentIntent;
58
+ customer?: TCustomer;
59
+ quotes?: Record<string, {
60
+ quote_id: string;
61
+ expires_at: number;
62
+ quoted_amount: string;
63
+ exchange_rate?: string;
64
+ rate_provider_name?: string;
65
+ rate_provider_id?: string;
66
+ }>;
67
+ rateUnavailable?: boolean;
68
+ };
69
+ export interface UseCheckoutReturn {
70
+ isLoading: boolean;
71
+ error: string | null;
72
+ /** Structured error code: 'SESSION_EXPIRED' | 'EMPTY_LINE_ITEMS' | null */
73
+ errorCode: 'SESSION_EXPIRED' | 'EMPTY_LINE_ITEMS' | null;
74
+ refresh: () => Promise<void>;
75
+ vendorCount: number;
76
+ product: {
77
+ name: string;
78
+ description: string;
79
+ images: string[];
80
+ features: Array<{
81
+ name: string;
82
+ icon?: string;
83
+ }>;
84
+ billing: {
85
+ mode: 'payment' | 'subscription';
86
+ interval: 'month' | 'year' | 'week' | 'day' | null;
87
+ intervalCount: number;
88
+ displayInterval: string;
89
+ };
90
+ metadata: Record<string, string>;
91
+ } | null;
92
+ lineItems: {
93
+ items: Array<TLineItemExpanded & {
94
+ adjustable_quantity?: {
95
+ enabled: boolean;
96
+ minimum?: number;
97
+ maximum?: number;
98
+ };
99
+ }>;
100
+ updateQuantity: (itemId: string, qty: number) => Promise<void>;
101
+ upsell: (fromId: string, toId: string) => Promise<void>;
102
+ downsell: (priceId: string) => Promise<void>;
103
+ billingInterval: {
104
+ current: 'month' | 'year' | 'week' | 'day' | null;
105
+ available: Array<{
106
+ interval: 'month' | 'year' | 'week' | 'day';
107
+ priceId: string;
108
+ amount: string;
109
+ savings: string | null;
110
+ }>;
111
+ switch: (interval: 'month' | 'year' | 'week' | 'day') => Promise<void>;
112
+ } | null;
113
+ crossSellItem: TPrice | null;
114
+ crossSellRequired: boolean;
115
+ addCrossSell: () => Promise<void>;
116
+ removeCrossSell: () => Promise<void>;
117
+ };
118
+ paymentMethod: {
119
+ current: TPaymentMethodExpanded;
120
+ currency: TPaymentCurrency;
121
+ available: TPaymentMethodExpanded[];
122
+ currencies: TPaymentCurrency[];
123
+ isStripe: boolean;
124
+ isCrypto: boolean;
125
+ isCredit: boolean;
126
+ setType: (type: 'stripe' | 'crypto') => Promise<void>;
127
+ types: Array<{
128
+ type: 'stripe' | 'crypto';
129
+ label: string;
130
+ currencies: TPaymentCurrency[];
131
+ active: boolean;
132
+ }>;
133
+ setCurrency: (currencyId: string) => Promise<void>;
134
+ };
135
+ stripe: {
136
+ publishableKey: string | null;
137
+ clientSecret: string | null;
138
+ status: 'idle' | 'ready' | 'processing' | 'succeeded' | 'failed';
139
+ } | null;
140
+ pricing: {
141
+ subtotal: string;
142
+ discount: string | null;
143
+ tax: {
144
+ amount: string;
145
+ rate: number;
146
+ inclusive: boolean;
147
+ } | null;
148
+ staking: string | null;
149
+ total: string;
150
+ usdEquivalent: string | null;
151
+ hasDynamicPricing: boolean;
152
+ rate: {
153
+ value: string | null;
154
+ display: string | null;
155
+ provider: string | null;
156
+ providerDisplay: string | null;
157
+ fetchedAt: number | null;
158
+ status: 'loading' | 'available' | 'unavailable';
159
+ refresh: () => Promise<void>;
160
+ };
161
+ quote: {
162
+ locked: boolean;
163
+ lockedAt: number | null;
164
+ expiresAt: number | null;
165
+ expired: boolean;
166
+ baseCurrency: string | null;
167
+ };
168
+ slippage: {
169
+ percent: number;
170
+ set: (config: {
171
+ mode: string;
172
+ percent: number;
173
+ }) => Promise<void>;
174
+ };
175
+ promotion: {
176
+ applied: boolean;
177
+ code: string | null;
178
+ active: boolean;
179
+ inactiveReason: string | null;
180
+ apply: (code: string) => Promise<{
181
+ success: boolean;
182
+ error?: string;
183
+ }>;
184
+ remove: () => Promise<void>;
185
+ };
186
+ trial: {
187
+ active: boolean;
188
+ days: number;
189
+ afterTrialPrice: string | null;
190
+ afterTrialInterval: string | null;
191
+ };
192
+ };
193
+ form: {
194
+ fields: FieldConfig[];
195
+ values: CheckoutFormData;
196
+ onChange: (field: string, value: string | boolean | Record<string, string>) => void;
197
+ errors: Partial<Record<string, string>>;
198
+ touched: Record<string, boolean>;
199
+ validate: () => Promise<boolean>;
200
+ validateField: (field: string) => Promise<void>;
201
+ };
202
+ submit: {
203
+ status: SubmitStatus;
204
+ context: SubmitContext;
205
+ execute: () => Promise<void>;
206
+ confirm: () => Promise<void>;
207
+ cancel: () => void;
208
+ result: CheckoutResult | null;
209
+ retry: () => Promise<void>;
210
+ reset: () => void;
211
+ stripeConfirm: () => Promise<void>;
212
+ stripeCancel: () => Promise<void>;
213
+ vendorStatus: {
214
+ payment_status: string;
215
+ session_status: string;
216
+ vendors: Array<{
217
+ success: boolean;
218
+ status: 'delivered' | 'pending' | 'failed';
219
+ progress: number;
220
+ message: string;
221
+ appUrl?: string;
222
+ title?: string;
223
+ name?: string;
224
+ vendorType: string;
225
+ }>;
226
+ error: string | null;
227
+ isAllCompleted: boolean;
228
+ hasFailed: boolean;
229
+ } | null;
230
+ };
231
+ subscription: {
232
+ mode: 'payment' | 'subscription' | 'setup';
233
+ showStake: boolean;
234
+ confirmMessage: string;
235
+ } | null;
236
+ pageInfo: {
237
+ formPurposeDescription?: {
238
+ en: string;
239
+ zh: string;
240
+ };
241
+ showProductFeatures: boolean;
242
+ } | null;
243
+ canSubmit: boolean;
244
+ isCompleted: boolean;
245
+ isDonation: boolean;
246
+ setDonationAmount: (priceId: string, amount: string) => Promise<void>;
247
+ customer: {
248
+ name: string;
249
+ email: string;
250
+ phone: string;
251
+ address: {
252
+ country: string;
253
+ state: string;
254
+ city: string;
255
+ line1: string;
256
+ line2: string;
257
+ postal_code: string;
258
+ };
259
+ } | null;
260
+ livemode: boolean;
261
+ session: TCheckoutSessionExpanded | null;
262
+ }
@@ -0,0 +1 @@
1
+ "use strict";
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { type UseCheckoutReturn, type SubmitStatus, type SubmitContext, type FieldConfig, type CheckoutFormData, type CheckoutResult, type UseCheckoutSessionReturn, type SessionData, type UsePaymentMethodReturn, type UsePricingReturn, type UseCustomerFormReturn, type UseSubmitReturn, type UseProductReturn, type UseLineItemsReturn, type UseBillingIntervalReturn, type BillingIntervalData, type UseUpsellReturn, type UseCrossSellReturn, type UsePromotionReturn, type UseExchangeRateReturn, type UseSlippageReturn, type UseCheckoutStatusReturn, type UsePricingFeatureReturn, type CheckoutProviderProps, CheckoutProvider, useSessionContext, usePaymentMethodContext, useExchangeRateContext, useCustomerFormContext, useSubmitContext, useCheckout, useCheckoutSession, usePaymentMethod, usePricing, useCustomerForm, useSubmit, useProduct, useLineItems, useBillingInterval, useUpsell, useCrossSell, usePromotion, useExchangeRate, useSlippage, useCheckoutStatus, usePricingFeature, usePaymentMethodFeature, useCustomerFormFeature, useSubmitFeature, getPriceUnitAmountByCurrency, } from './checkout';
package/lib/index.js ADDED
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "CheckoutProvider", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _checkout.CheckoutProvider;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getPriceUnitAmountByCurrency", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _checkout.getPriceUnitAmountByCurrency;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "useBillingInterval", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _checkout.useBillingInterval;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useCheckout", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _checkout.useCheckout;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "useCheckoutSession", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _checkout.useCheckoutSession;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "useCheckoutStatus", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _checkout.useCheckoutStatus;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "useCrossSell", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _checkout.useCrossSell;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "useCustomerForm", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _checkout.useCustomerForm;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "useCustomerFormContext", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _checkout.useCustomerFormContext;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "useCustomerFormFeature", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _checkout.useCustomerFormFeature;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "useExchangeRate", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _checkout.useExchangeRate;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "useExchangeRateContext", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _checkout.useExchangeRateContext;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "useLineItems", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _checkout.useLineItems;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "usePaymentMethod", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _checkout.usePaymentMethod;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "usePaymentMethodContext", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _checkout.usePaymentMethodContext;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "usePaymentMethodFeature", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _checkout.usePaymentMethodFeature;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, "usePricing", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _checkout.usePricing;
106
+ }
107
+ });
108
+ Object.defineProperty(exports, "usePricingFeature", {
109
+ enumerable: true,
110
+ get: function () {
111
+ return _checkout.usePricingFeature;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, "useProduct", {
115
+ enumerable: true,
116
+ get: function () {
117
+ return _checkout.useProduct;
118
+ }
119
+ });
120
+ Object.defineProperty(exports, "usePromotion", {
121
+ enumerable: true,
122
+ get: function () {
123
+ return _checkout.usePromotion;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, "useSessionContext", {
127
+ enumerable: true,
128
+ get: function () {
129
+ return _checkout.useSessionContext;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, "useSlippage", {
133
+ enumerable: true,
134
+ get: function () {
135
+ return _checkout.useSlippage;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, "useSubmit", {
139
+ enumerable: true,
140
+ get: function () {
141
+ return _checkout.useSubmit;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "useSubmitContext", {
145
+ enumerable: true,
146
+ get: function () {
147
+ return _checkout.useSubmitContext;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, "useSubmitFeature", {
151
+ enumerable: true,
152
+ get: function () {
153
+ return _checkout.useSubmitFeature;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "useUpsell", {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _checkout.useUpsell;
160
+ }
161
+ });
162
+ var _checkout = require("./checkout");
@@ -0,0 +1,41 @@
1
+ declare global {
2
+ interface Window {
3
+ blocklet?: {
4
+ prefix?: string;
5
+ componentId?: string;
6
+ componentMountPoints?: Array<{
7
+ did: string;
8
+ mountPoint: string;
9
+ }>;
10
+ appName?: string;
11
+ languages?: string[];
12
+ };
13
+ __PAYMENT_KIT_AUTH_TOKEN?: string;
14
+ __PAYMENT_KIT_BASE_URL?: string;
15
+ }
16
+ }
17
+ export declare function getPrefix(): string;
18
+ export declare function getLocale(languages?: string[]): string;
19
+ declare const api: import("axios").AxiosInstance;
20
+ export default api;
21
+ export declare const API: {
22
+ readonly START_PAYMENT_LINK: (id: string) => string;
23
+ readonly RETRIEVE_SESSION: (id: string) => string;
24
+ readonly SWITCH_CURRENCY: (id: string) => string;
25
+ readonly SUBMIT: (id: string) => string;
26
+ readonly DONATE_SUBMIT: (id: string) => string;
27
+ readonly FAST_CHECKOUT_CONFIRM: (id: string) => string;
28
+ readonly EXCHANGE_RATE: (id: string) => string;
29
+ readonly ADJUST_QUANTITY: (id: string) => string;
30
+ readonly UPSELL: (id: string) => string;
31
+ readonly DOWNSELL: (id: string) => string;
32
+ readonly CROSS_SELL: (id: string) => string;
33
+ readonly CHANGE_AMOUNT: (id: string) => string;
34
+ readonly SLIPPAGE: (id: string) => string;
35
+ readonly ABORT_STRIPE: (id: string) => string;
36
+ readonly RECALCULATE_PROMOTION_SESSION: (id: string) => string;
37
+ readonly APPLY_PROMOTION: (id: string) => string;
38
+ readonly REMOVE_PROMOTION: (id: string) => string;
39
+ readonly CUSTOMER_ME: "/api/customers/me";
40
+ readonly VENDOR_ORDER_STATUS: (id: string) => string;
41
+ };