@shipengine/elements 2.27.0 → 2.29.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 (199) hide show
  1. package/dist/cjs/components/field/rate-select/rate-card/rate-card.cjs +1 -0
  2. package/dist/cjs/components/forms/edit-billing-form/edit-billing-form.cjs +87 -12
  3. package/dist/cjs/components/forms/edit-billing-form/edit-billing-form.styles.cjs +15 -0
  4. package/dist/cjs/components/forms/wallet-form/index.cjs +0 -2
  5. package/dist/cjs/components/forms/wallet-form/wallet-form.cjs +153 -23
  6. package/dist/cjs/components/forms/wallet-form/wallet-form.styles.cjs +15 -0
  7. package/dist/cjs/components/forms/wallet-form/wallet-schema.cjs +8 -43
  8. package/dist/cjs/components/forms/warehouse-form/warehouse-form.cjs +10 -1
  9. package/dist/cjs/components/payment/payment-method-selector/index.cjs +7 -0
  10. package/dist/cjs/components/payment/payment-method-selector/payment-method-selector.cjs +55 -0
  11. package/dist/cjs/components/payment/payment-method-selector/payment-method-selector.styles.cjs +58 -0
  12. package/dist/cjs/components/service-card/service-card.cjs +3 -2
  13. package/dist/cjs/components/service-card/service-card.styles.cjs +4 -2
  14. package/dist/cjs/contexts/auctane-pay-session-context.cjs +158 -0
  15. package/dist/cjs/contexts/index.cjs +8 -0
  16. package/dist/cjs/elements/labels-grid/hooks/use-labels-grid.cjs +2 -2
  17. package/dist/cjs/elements/labels-grid/labels-grid.cjs +29 -9
  18. package/dist/cjs/elements/labels-grid/labels-grid.styles.cjs +5 -0
  19. package/dist/cjs/elements/purchase-label/components/rate-form/rate-view.cjs +3 -5
  20. package/dist/cjs/elements/purchase-label/components/shipment-form/shipment-form.cjs +3 -1
  21. package/dist/cjs/elements/purchase-label/hooks/use-filter-visible-rate-options/use-filter-visible-rate-options.cjs +5 -5
  22. package/dist/cjs/elements/shipments-grid/hooks/use-shipments-grid.cjs +2 -2
  23. package/dist/cjs/elements/shipments-grid/shipments-grid.cjs +20 -6
  24. package/dist/cjs/elements/shipments-grid/shipments-grid.styles.cjs +5 -0
  25. package/dist/cjs/features/manage-warehouses/manage-warehouses.cjs +9 -5
  26. package/dist/cjs/features/payment-method-settings/payment-method-settings.cjs +4 -3
  27. package/dist/cjs/hooks/financial-services/financial-service.cjs +464 -0
  28. package/dist/cjs/hooks/financial-services/index.cjs +9 -0
  29. package/dist/cjs/hooks/financial-services/use-financial-service.cjs +188 -0
  30. package/dist/cjs/hooks/use-configure-shipment.cjs +8 -0
  31. package/dist/cjs/hooks/use-get-service-data.cjs +60 -0
  32. package/dist/cjs/locales/en/list-labels.json.cjs +2 -1
  33. package/dist/cjs/locales/en/list-shipments.json.cjs +1 -1
  34. package/dist/cjs/locales/en/manage-warehouses.json.cjs +2 -0
  35. package/dist/cjs/locales/en/register-wallet.json.cjs +5 -0
  36. package/dist/cjs/package.json.cjs +1 -1
  37. package/dist/cjs/utilities/feature-flags/feature-flags.cjs +2 -1
  38. package/dist/cjs/workflows/onboarding/components/confirmation-and-submission-step/confirmation-and-submission-step.cjs +16 -5
  39. package/dist/cjs/workflows/onboarding/components/confirmation-and-submission-step/use-confirmation-and-submission-step.cjs +6 -6
  40. package/dist/cjs/workflows/onboarding/components/funding-step/funding-step.cjs +7 -3
  41. package/dist/cjs/workflows/onboarding/components/ship-from-address-step/ship-from-address-step.cjs +1 -1
  42. package/dist/cjs/workflows/onboarding/onboarding.cjs +8 -5
  43. package/dist/esm/components/field/rate-select/rate-card/rate-card.js +1 -0
  44. package/dist/esm/components/forms/edit-billing-form/edit-billing-form.js +88 -13
  45. package/dist/esm/components/forms/edit-billing-form/edit-billing-form.styles.js +15 -0
  46. package/dist/esm/components/forms/wallet-form/index.js +0 -1
  47. package/dist/esm/components/forms/wallet-form/wallet-form.js +155 -25
  48. package/dist/esm/components/forms/wallet-form/wallet-form.styles.js +15 -0
  49. package/dist/esm/components/forms/wallet-form/wallet-schema.js +1 -36
  50. package/dist/esm/components/forms/warehouse-form/warehouse-form.js +10 -1
  51. package/dist/esm/components/payment/payment-method-selector/index.js +1 -0
  52. package/dist/esm/components/payment/payment-method-selector/payment-method-selector.js +53 -0
  53. package/dist/esm/components/payment/payment-method-selector/payment-method-selector.styles.js +56 -0
  54. package/dist/esm/components/service-card/service-card.js +3 -2
  55. package/dist/esm/components/service-card/service-card.styles.js +4 -2
  56. package/dist/esm/contexts/auctane-pay-session-context.js +155 -0
  57. package/dist/esm/contexts/index.js +1 -0
  58. package/dist/esm/elements/labels-grid/hooks/use-labels-grid.js +2 -2
  59. package/dist/esm/elements/labels-grid/labels-grid.js +30 -10
  60. package/dist/esm/elements/labels-grid/labels-grid.styles.js +5 -0
  61. package/dist/esm/elements/purchase-label/components/rate-form/rate-view.js +3 -5
  62. package/dist/esm/elements/purchase-label/components/shipment-form/shipment-form.js +3 -1
  63. package/dist/esm/elements/purchase-label/hooks/use-filter-visible-rate-options/use-filter-visible-rate-options.js +5 -5
  64. package/dist/esm/elements/shipments-grid/hooks/use-shipments-grid.js +2 -2
  65. package/dist/esm/elements/shipments-grid/shipments-grid.js +21 -7
  66. package/dist/esm/elements/shipments-grid/shipments-grid.styles.js +5 -0
  67. package/dist/esm/features/manage-warehouses/manage-warehouses.js +9 -5
  68. package/dist/esm/features/payment-method-settings/payment-method-settings.js +5 -4
  69. package/dist/esm/hooks/financial-services/financial-service.js +462 -0
  70. package/dist/esm/hooks/financial-services/index.js +2 -0
  71. package/dist/esm/hooks/financial-services/use-financial-service.js +186 -0
  72. package/dist/esm/hooks/use-configure-shipment.js +8 -0
  73. package/dist/esm/hooks/use-get-service-data.js +58 -0
  74. package/dist/esm/locales/en/list-labels.json.js +2 -1
  75. package/dist/esm/locales/en/list-shipments.json.js +1 -1
  76. package/dist/esm/locales/en/manage-warehouses.json.js +2 -0
  77. package/dist/esm/locales/en/register-wallet.json.js +5 -0
  78. package/dist/esm/package.json.js +1 -1
  79. package/dist/esm/utilities/feature-flags/feature-flags.js +2 -1
  80. package/dist/esm/workflows/onboarding/components/confirmation-and-submission-step/confirmation-and-submission-step.js +16 -5
  81. package/dist/esm/workflows/onboarding/components/confirmation-and-submission-step/use-confirmation-and-submission-step.js +6 -6
  82. package/dist/esm/workflows/onboarding/components/funding-step/funding-step.js +7 -3
  83. package/dist/esm/workflows/onboarding/components/ship-from-address-step/ship-from-address-step.js +1 -1
  84. package/dist/esm/workflows/onboarding/onboarding.js +8 -5
  85. package/dist/types/components/address-preference-context/address-preference-context.d.ts +0 -1
  86. package/dist/types/components/address-preference-context/address-preference-context.d.ts.map +1 -1
  87. package/dist/types/components/field/rate-select/rate-card/rate-card.d.ts.map +1 -1
  88. package/dist/types/components/forms/edit-billing-form/edit-billing-form.d.ts +2 -2
  89. package/dist/types/components/forms/edit-billing-form/edit-billing-form.d.ts.map +1 -1
  90. package/dist/types/components/forms/edit-billing-form/edit-billing-form.styles.d.ts +14 -0
  91. package/dist/types/components/forms/edit-billing-form/edit-billing-form.styles.d.ts.map +1 -1
  92. package/dist/types/components/forms/wallet-form/index.d.ts +0 -1
  93. package/dist/types/components/forms/wallet-form/index.d.ts.map +1 -1
  94. package/dist/types/components/forms/wallet-form/wallet-form.d.ts +4 -1
  95. package/dist/types/components/forms/wallet-form/wallet-form.d.ts.map +1 -1
  96. package/dist/types/components/forms/wallet-form/wallet-form.styles.d.ts +14 -0
  97. package/dist/types/components/forms/wallet-form/wallet-form.styles.d.ts.map +1 -1
  98. package/dist/types/components/forms/wallet-form/wallet-schema.d.ts +3 -43
  99. package/dist/types/components/forms/wallet-form/wallet-schema.d.ts.map +1 -1
  100. package/dist/types/components/forms/warehouse-form/warehouse-form.d.ts.map +1 -1
  101. package/dist/types/components/payment/payment-method-selector/index.d.ts +2 -0
  102. package/dist/types/components/payment/payment-method-selector/index.d.ts.map +1 -0
  103. package/dist/types/components/payment/payment-method-selector/payment-method-selector.d.ts +11 -0
  104. package/dist/types/components/payment/payment-method-selector/payment-method-selector.d.ts.map +1 -0
  105. package/dist/types/components/payment/payment-method-selector/payment-method-selector.styles.d.ts +52 -0
  106. package/dist/types/components/payment/payment-method-selector/payment-method-selector.styles.d.ts.map +1 -0
  107. package/dist/types/components/service-card/service-card.d.ts +2 -1
  108. package/dist/types/components/service-card/service-card.d.ts.map +1 -1
  109. package/dist/types/components/service-card/service-card.styles.d.ts +2 -1
  110. package/dist/types/components/service-card/service-card.styles.d.ts.map +1 -1
  111. package/dist/types/contexts/auctane-pay-session-context.d.ts +54 -0
  112. package/dist/types/contexts/auctane-pay-session-context.d.ts.map +1 -0
  113. package/dist/types/contexts/index.d.ts +3 -0
  114. package/dist/types/contexts/index.d.ts.map +1 -0
  115. package/dist/types/elements/customs-form/customs-form-element.d.ts +10 -2
  116. package/dist/types/elements/customs-form/customs-form-element.d.ts.map +1 -1
  117. package/dist/types/elements/labels-grid/labels-grid.d.ts +10 -2
  118. package/dist/types/elements/labels-grid/labels-grid.d.ts.map +1 -1
  119. package/dist/types/elements/labels-grid/labels-grid.styles.d.ts +5 -0
  120. package/dist/types/elements/labels-grid/labels-grid.styles.d.ts.map +1 -1
  121. package/dist/types/elements/manage-carriers/manage-carriers.d.ts +10 -2
  122. package/dist/types/elements/manage-carriers/manage-carriers.d.ts.map +1 -1
  123. package/dist/types/elements/manage-external-carriers/manage-external-carriers.d.ts +10 -2
  124. package/dist/types/elements/manage-external-carriers/manage-external-carriers.d.ts.map +1 -1
  125. package/dist/types/elements/manage-funding/manage-funding-element.d.ts +10 -2
  126. package/dist/types/elements/manage-funding/manage-funding-element.d.ts.map +1 -1
  127. package/dist/types/elements/manage-warehouses/manage-warehouses.d.ts +10 -2
  128. package/dist/types/elements/manage-warehouses/manage-warehouses.d.ts.map +1 -1
  129. package/dist/types/elements/payment-method-settings/payment-method-settings-element.d.ts +10 -2
  130. package/dist/types/elements/payment-method-settings/payment-method-settings-element.d.ts.map +1 -1
  131. package/dist/types/elements/purchase-label/components/rate-form/rate-view.d.ts +1 -1
  132. package/dist/types/elements/purchase-label/components/rate-form/rate-view.d.ts.map +1 -1
  133. package/dist/types/elements/purchase-label/components/shipment-form/shipment-form.d.ts.map +1 -1
  134. package/dist/types/elements/purchase-label/hooks/use-filter-visible-rate-options/use-filter-visible-rate-options.d.ts +2 -1
  135. package/dist/types/elements/purchase-label/hooks/use-filter-visible-rate-options/use-filter-visible-rate-options.d.ts.map +1 -1
  136. package/dist/types/elements/purchase-label/purchase-label.d.ts +10 -2
  137. package/dist/types/elements/purchase-label/purchase-label.d.ts.map +1 -1
  138. package/dist/types/elements/select-label-layout/select-label-layout-element.d.ts +10 -2
  139. package/dist/types/elements/select-label-layout/select-label-layout-element.d.ts.map +1 -1
  140. package/dist/types/elements/shipment-summary/shipment-summary.d.ts +10 -2
  141. package/dist/types/elements/shipment-summary/shipment-summary.d.ts.map +1 -1
  142. package/dist/types/elements/shipments-grid/shipments-grid.d.ts +10 -2
  143. package/dist/types/elements/shipments-grid/shipments-grid.d.ts.map +1 -1
  144. package/dist/types/elements/shipments-grid/shipments-grid.styles.d.ts +5 -0
  145. package/dist/types/elements/shipments-grid/shipments-grid.styles.d.ts.map +1 -1
  146. package/dist/types/elements/theme-creator/theme-creator.d.ts +10 -2
  147. package/dist/types/elements/theme-creator/theme-creator.d.ts.map +1 -1
  148. package/dist/types/elements/transaction-history/transaction-history-element.d.ts +10 -2
  149. package/dist/types/elements/transaction-history/transaction-history-element.d.ts.map +1 -1
  150. package/dist/types/elements/unit-settings/unit-settings-element.d.ts +10 -2
  151. package/dist/types/elements/unit-settings/unit-settings-element.d.ts.map +1 -1
  152. package/dist/types/elements/vat-settings/vat-settings-element.d.ts +10 -2
  153. package/dist/types/elements/vat-settings/vat-settings-element.d.ts.map +1 -1
  154. package/dist/types/elements/void-label/void-label.d.ts +10 -2
  155. package/dist/types/elements/void-label/void-label.d.ts.map +1 -1
  156. package/dist/types/elements-provider/elements-provider.d.ts.map +1 -1
  157. package/dist/types/features/manage-warehouses/manage-warehouses.d.ts.map +1 -1
  158. package/dist/types/features/payment-method-settings/payment-method-settings.d.ts.map +1 -1
  159. package/dist/types/hooks/financial-services/financial-service.d.ts +279 -0
  160. package/dist/types/hooks/financial-services/financial-service.d.ts.map +1 -0
  161. package/dist/types/hooks/financial-services/index.d.ts +5 -0
  162. package/dist/types/hooks/financial-services/index.d.ts.map +1 -0
  163. package/dist/types/hooks/financial-services/use-financial-service.d.ts +40 -0
  164. package/dist/types/hooks/financial-services/use-financial-service.d.ts.map +1 -0
  165. package/dist/types/hooks/use-configure-shipment.d.ts.map +1 -1
  166. package/dist/types/hooks/use-get-service-data.d.ts +14 -0
  167. package/dist/types/hooks/use-get-service-data.d.ts.map +1 -0
  168. package/dist/types/locales/en/index.d.ts +10 -2
  169. package/dist/types/locales/en/index.d.ts.map +1 -1
  170. package/dist/types/types/financial-services.d.ts +34 -0
  171. package/dist/types/types/financial-services.d.ts.map +1 -0
  172. package/dist/types/types/index.d.ts +1 -1
  173. package/dist/types/types/index.d.ts.map +1 -1
  174. package/dist/types/utilities/feature-flags/feature-flags.d.ts.map +1 -1
  175. package/dist/types/utilities/feature-flags/types.d.ts +4 -0
  176. package/dist/types/utilities/feature-flags/types.d.ts.map +1 -1
  177. package/dist/types/workflows/account-settings/account-settings.d.ts +10 -2
  178. package/dist/types/workflows/account-settings/account-settings.d.ts.map +1 -1
  179. package/dist/types/workflows/carrier-services/carrier-services.d.ts +10 -2
  180. package/dist/types/workflows/carrier-services/carrier-services.d.ts.map +1 -1
  181. package/dist/types/workflows/connect-external-carrier/connect-external-carrier.d.ts +10 -2
  182. package/dist/types/workflows/connect-external-carrier/connect-external-carrier.d.ts.map +1 -1
  183. package/dist/types/workflows/label-workflow/label-workflow.d.ts +10 -2
  184. package/dist/types/workflows/label-workflow/label-workflow.d.ts.map +1 -1
  185. package/dist/types/workflows/onboarding/components/confirmation-and-submission-step/confirmation-and-submission-step.d.ts.map +1 -1
  186. package/dist/types/workflows/onboarding/components/confirmation-and-submission-step/use-confirmation-and-submission-step.d.ts.map +1 -1
  187. package/dist/types/workflows/onboarding/components/funding-step/funding-step.d.ts.map +1 -1
  188. package/dist/types/workflows/onboarding/components/ship-from-address-step/ship-from-address-step.d.ts.map +1 -1
  189. package/dist/types/workflows/onboarding/onboarding.d.ts +10 -2
  190. package/dist/types/workflows/onboarding/onboarding.d.ts.map +1 -1
  191. package/package.json +5 -5
  192. package/dist/cjs/components/forms/wallet-form/billing-fields.cjs +0 -71
  193. package/dist/cjs/hooks/use-get-service-name.cjs +0 -22
  194. package/dist/esm/components/forms/wallet-form/billing-fields.js +0 -69
  195. package/dist/esm/hooks/use-get-service-name.js +0 -20
  196. package/dist/types/components/forms/wallet-form/billing-fields.d.ts +0 -7
  197. package/dist/types/components/forms/wallet-form/billing-fields.d.ts.map +0 -1
  198. package/dist/types/hooks/use-get-service-name.d.ts +0 -5
  199. package/dist/types/hooks/use-get-service-name.d.ts.map +0 -1
@@ -0,0 +1,462 @@
1
+ import { __awaiter, __rest } from '../../_virtual/_tslib.js';
2
+ import { AdyenCheckout, Card, PayByBankUS } from '@adyen/adyen-web';
3
+
4
+ /**
5
+ * ShipstationFinancialService - This class provides a simple, unified interface for initializing and managing Adyen payment flows,
6
+ * including credit card payments, bank transfers, and handling 3D Secure redirects.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // 1. Create service instance with session data callback
11
+ * const financialService = new ShipstationFinancialService({
12
+ * getAdyenSessionData: async () => {
13
+ * // Fetch Adyen session data from Auctane Pay
14
+ * const response = await fetch('/api/adyen/session', {
15
+ * method: 'POST',
16
+ * headers: { 'Authorization': `Bearer ${token}` },
17
+ * body: JSON.stringify({ amount: 1000, currency: 'USD' })
18
+ * });
19
+ * return response.json();
20
+ * }
21
+ * });
22
+ *
23
+ * // 2. Initialize the service
24
+ * await financialService.init();
25
+ *
26
+ * // 3. Create a credit card checkout component
27
+ * await financialService.createCheckout('credit_card', {
28
+ * locale: 'en-US',
29
+ * onPaymentCompleted: (result) => {
30
+ * if (result.resultCode === 'Authorised') {
31
+ * console.log('Payment successful!');
32
+ * }
33
+ * },
34
+ * onError: (error) => {
35
+ * console.error('Payment error:', error);
36
+ * },
37
+ * creditCardOptions: {
38
+ * hasHolderName: true,
39
+ * placeholders: {
40
+ * cardNumber: '1234 5678 9012 3456',
41
+ * expiryDate: 'MM/YY',
42
+ * securityCodeThreeDigits: '123'
43
+ * }
44
+ * }
45
+ * });
46
+ *
47
+ * // 4. Mount the component to a DOM element
48
+ * financialService.mount('#payment-container');
49
+ *
50
+ * // 5. Submit payment when user clicks pay button
51
+ * document.getElementById('pay-button').addEventListener('click', () => {
52
+ * financialService.submit();
53
+ * });
54
+ * ```
55
+ */
56
+ class FinancialService {
57
+ /**
58
+ * A flag that indicates whether the current instance of the financial services class has been initialized.
59
+ *
60
+ * @example
61
+ * if (financialService.isReady()) {
62
+ * financialService.mount("#service-container");
63
+ * }
64
+ */
65
+ isReady() {
66
+ return !!this.getCurrentSessionData();
67
+ }
68
+ constructor(config) {
69
+ this.paymentConfig = config;
70
+ }
71
+ /**
72
+ * Initializes the service by fetching Adyen session data.
73
+ * Must be called before creating any payment components.
74
+ *
75
+ * @throws Error If session data cannot be retrieved
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * try {
80
+ * await new ShipstationFinancialService({ getAdyenSessionData }).init()
81
+ * console.log('Service initialized successfully');
82
+ * } catch (error) {
83
+ * console.error('Failed to initialize:', error);
84
+ * }
85
+ * ```
86
+ */
87
+ init() {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const {
90
+ getAdyenSessionData
91
+ } = this.paymentConfig;
92
+ try {
93
+ this.adyenCheckoutData = yield getAdyenSessionData();
94
+ if (!this.adyenCheckoutData) {
95
+ throw new Error("Failed to retrieve Adyen session data");
96
+ }
97
+ } catch (error) {
98
+ throw new Error(`Failed to initialize: ${error instanceof Error ? error.message : "Unknown error"}`);
99
+ }
100
+ });
101
+ }
102
+ /**
103
+ * Creates a payment checkout component for the specified payment method.
104
+ *
105
+ * @returns The created Adyen component (Card or PayByBankUS)
106
+ * @throws {Error} If init() hasn't been called or if payment method is unsupported
107
+ *
108
+ * @example Credit card with custom styling
109
+ * ```typescript
110
+ * const cardComponent = await financialService.createCheckout('credit_card', {
111
+ * locale: 'en-US',
112
+ * creditCardOptions: {
113
+ * hasHolderName: true,
114
+ * holderNameRequired: true,
115
+ * showBrandIcon: true,
116
+ * placeholders: {
117
+ * cardNumber: 'Card number',
118
+ * expiryDate: 'MM/YY',
119
+ * securityCodeThreeDigits: 'CVV'
120
+ * }
121
+ * },
122
+ * onChange: (state) => {
123
+ * // Update UI based on validation state
124
+ * submitButton.disabled = !state.isValid;
125
+ * }
126
+ * });
127
+ * ```
128
+ */
129
+ createCheckout(type_1) {
130
+ return __awaiter(this, arguments, void 0, function* (type, options = {}) {
131
+ if (!this.isReady()) {
132
+ throw new Error("No session data. Please call init() first.");
133
+ }
134
+ const coreConfig = this.getCoreConfig(options);
135
+ try {
136
+ this.checkout = yield AdyenCheckout(coreConfig);
137
+ // Create the specific component based on payment method type
138
+ if (type === "credit_card") {
139
+ this.activeComponent = this.createCreditCardComponent(options.creditCardOptions);
140
+ } else if (type === "pay_by_bank_us") {
141
+ this.activeComponent = this.createPayByBankComponent();
142
+ } else {
143
+ throw new Error(`Unsupported payment method type: ${type}`);
144
+ }
145
+ if (!this.activeComponent) {
146
+ throw new Error("Failed to create payment component");
147
+ }
148
+ return this.activeComponent;
149
+ } catch (error) {
150
+ throw new Error(`Failed to create checkout: ${error instanceof Error ? error.message : "Unknown error"}`);
151
+ }
152
+ });
153
+ }
154
+ /**
155
+ * Mounts the active payment component to a DOM element.
156
+ *
157
+ * @param element - DOM element or CSS selector where the component should be mounted
158
+ * @throws Error If no active component exists (createCheckout must be called first)
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Mount to element by ID
163
+ * financialService.mount('#payment-form');
164
+ *
165
+ * // Mount to DOM element
166
+ * const container = document.getElementById('payment-container');
167
+ * financialService.mount(container);
168
+ * ```
169
+ */
170
+ mount(element) {
171
+ if (!this.activeComponent) {
172
+ throw new Error("No active component. Please call createCheckout() first.");
173
+ }
174
+ this.activeComponent.mount(element);
175
+ }
176
+ /**
177
+ * Submits the payment using the active component.
178
+ * Triggers validation and payment processing.
179
+ *
180
+ * @throws Error If no active component exists
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * // In a form submit handler
185
+ * form.addEventListener('submit', (e) => {
186
+ * e.preventDefault();
187
+ * financialService.submit();
188
+ * });
189
+ * ```
190
+ */
191
+ submit() {
192
+ if (!this.activeComponent) {
193
+ throw new Error("No active component. Please call createCheckout() first.");
194
+ }
195
+ this.activeComponent.submit();
196
+ }
197
+ /**
198
+ * Submits the payment and returns a Promise that resolves with the payment result.
199
+ * This method should be used when you need to wait for payment completion.
200
+ *
201
+ * @returns Promise that resolves with PaymentResult
202
+ * @throws Error If no active component exists
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * try {
207
+ * const result = await financialService.submitPayment();
208
+ * if (result.success) {
209
+ * console.log('Payment successful!', result.resultCode);
210
+ * } else {
211
+ * console.error('Payment failed:', result.error);
212
+ * }
213
+ * } catch (error) {
214
+ * console.error('Payment error:', error);
215
+ * }
216
+ * ```
217
+ */
218
+ submitPromise() {
219
+ return __awaiter(this, void 0, void 0, function* () {
220
+ if (!this.activeComponent) {
221
+ throw new Error("No active component. Please call createCheckout() first.");
222
+ }
223
+ return new Promise((resolve, reject) => {
224
+ this.paymentPromise = {
225
+ resolve,
226
+ reject
227
+ };
228
+ this.activeComponent.submit();
229
+ });
230
+ });
231
+ }
232
+ /**
233
+ * Unmounts and cleans up the active payment component.
234
+ * Should be called when the component is no longer needed.
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * // Clean up on component unmount (React example)
239
+ * useEffect(() => {
240
+ * return () => {
241
+ * financialService.unmount();
242
+ * };
243
+ * }, []);
244
+ * ```
245
+ */
246
+ unmount() {
247
+ if (this.activeComponent && "unmount" in this.activeComponent) {
248
+ this.activeComponent.unmount();
249
+ }
250
+ this.activeComponent = undefined;
251
+ }
252
+ /**
253
+ * Resets the payment component to ready state, allowing user to edit fields and retry.
254
+ * This is useful after a failed payment to unlock the form fields.
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // After a failed payment
259
+ * const result = await financialService.submitPromise();
260
+ * if (!result.success) {
261
+ * // Reset the component to allow retry
262
+ * financialService.resetComponent();
263
+ * // Show error message to user
264
+ * }
265
+ * ```
266
+ */
267
+ resetComponent() {
268
+ if (this.activeComponent && "setStatus" in this.activeComponent) {
269
+ this.activeComponent.setStatus("ready");
270
+ }
271
+ }
272
+ /**
273
+ * Returns the current Adyen session data if available.
274
+ * Useful for accessing session metadata or debugging.
275
+ *
276
+ * @returns The current session data or undefined if not initialized
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const sessionData = financialService.getCurrentSessionData();
281
+ * if (sessionData) {
282
+ * console.log('Session ID:', sessionData.metadata.adyenSessionId);
283
+ * console.log('Expires:', sessionData.metadata.adyenExpiration);
284
+ * }
285
+ * ```
286
+ */
287
+ getCurrentSessionData() {
288
+ return this.adyenCheckoutData;
289
+ }
290
+ /**
291
+ * Handles the return flow from payment redirects (3D Secure, bank authentication, etc.).
292
+ * Should be called on your return URL page with the redirect parameters.
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // On your return URL page
297
+ * const urlParams = new URLSearchParams(window.location.search);
298
+ *
299
+ * await financialService.handleRedirect({
300
+ * sessionId: urlParams.get('sessionId'),
301
+ * redirectResult: urlParams.get('redirectResult'),
302
+ * onPaymentCompleted: (result) => {
303
+ * switch (result.resultCode) {
304
+ * case 'Authorised':
305
+ * ...
306
+ * break;
307
+ * case 'Pending':
308
+ * ...
309
+ * break;
310
+ * default:
311
+ * ...
312
+ * }
313
+ * },
314
+ * onError: (error) => {
315
+ * console.error('Redirect handling failed:', error);
316
+ * showErrorMessage('Payment verification failed');
317
+ * }
318
+ * });
319
+ * ```
320
+ */
321
+ handleRedirect(options) {
322
+ return __awaiter(this, void 0, void 0, function* () {
323
+ const {
324
+ sessionId,
325
+ redirectResult,
326
+ clientKey,
327
+ locale = "en-US",
328
+ countryCode = "US"
329
+ } = options,
330
+ rest = __rest(options, ["sessionId", "redirectResult", "clientKey", "locale", "countryCode"]);
331
+ if (!sessionId || !redirectResult) {
332
+ throw new Error("Missing sessionId or redirectResult, unable to complete checkout");
333
+ }
334
+ // Determine client key - use provided one or try to get from existing session data
335
+ let finalClientKey = clientKey;
336
+ if (!finalClientKey && this.adyenCheckoutData) {
337
+ finalClientKey = this.adyenCheckoutData.metadata.adyenClientKey;
338
+ }
339
+ if (!finalClientKey) {
340
+ throw new Error("Client key not found, unable to complete checkout");
341
+ }
342
+ const environment = this.parseEnvironment(finalClientKey);
343
+ try {
344
+ // Create a new checkout instance specifically for handling the redirect
345
+ const redirectCheckout = yield AdyenCheckout(Object.assign({
346
+ environment,
347
+ clientKey: finalClientKey,
348
+ session: {
349
+ id: sessionId
350
+ },
351
+ locale,
352
+ countryCode
353
+ }, rest));
354
+ // Submit the redirect details to complete the payment
355
+ redirectCheckout.submitDetails({
356
+ details: {
357
+ redirectResult
358
+ }
359
+ });
360
+ } catch (error) {
361
+ throw new Error(`Failed to handle redirect: ${error instanceof Error ? error.message : "Unknown error"}`);
362
+ }
363
+ });
364
+ }
365
+ getCoreConfig(options) {
366
+ if (!this.adyenCheckoutData) {
367
+ throw new Error("No session data available");
368
+ }
369
+ const {
370
+ metadata: {
371
+ adyenClientKey,
372
+ adyenSessionId,
373
+ adyenSessionData
374
+ }
375
+ } = this.adyenCheckoutData;
376
+ // Determine environment from client key
377
+ const environment = options.environment || this.parseEnvironment(adyenClientKey);
378
+ // Exclude creditCardOptions from the core config as it's component-specific
379
+ const coreOptions = __rest(options, ["creditCardOptions"]);
380
+ const config = Object.assign(Object.assign({
381
+ environment,
382
+ clientKey: adyenClientKey,
383
+ session: {
384
+ id: adyenSessionId,
385
+ sessionData: adyenSessionData
386
+ },
387
+ locale: options.locale || "en-US",
388
+ countryCode: options.countryCode || "US"
389
+ }, coreOptions), {
390
+ // Override callbacks to handle Promise resolution while preserving original callbacks
391
+ onPaymentCompleted: result => {
392
+ // Call original callback if provided
393
+ var _a;
394
+ (_a = options.onPaymentCompleted) === null || _a === void 0 ? void 0 : _a.call(options, result);
395
+ // Resolve Promise if waiting
396
+ if (this.paymentPromise) {
397
+ const paymentResult = {
398
+ success: result.resultCode === "Authorised" || result.resultCode === "Received",
399
+ resultCode: result.resultCode,
400
+ data: result
401
+ };
402
+ this.paymentPromise.resolve(paymentResult);
403
+ this.paymentPromise = undefined;
404
+ }
405
+ },
406
+ onPaymentFailed: result => {
407
+ // Call original callback if provided
408
+ var _a;
409
+ (_a = options.onPaymentFailed) === null || _a === void 0 ? void 0 : _a.call(options, result);
410
+ // Reset component to unlock form fields for retry
411
+ this.resetComponent();
412
+ // Resolve Promise with failure if waiting
413
+ if (this.paymentPromise) {
414
+ const paymentResult = {
415
+ success: false,
416
+ resultCode: result === null || result === void 0 ? void 0 : result.resultCode,
417
+ error: (result === null || result === void 0 ? void 0 : result.resultCode) ? `Payment failed: ${result.resultCode}` : "Payment failed",
418
+ data: result
419
+ };
420
+ this.paymentPromise.resolve(paymentResult);
421
+ this.paymentPromise = undefined;
422
+ }
423
+ },
424
+ onError: error => {
425
+ // Call original callback if provided
426
+ var _a;
427
+ (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
428
+ // Reset component to unlock form fields for retry
429
+ this.resetComponent();
430
+ // Reject Promise if waiting
431
+ if (this.paymentPromise) {
432
+ this.paymentPromise.reject(new Error(error.message || "Payment processing error"));
433
+ this.paymentPromise = undefined;
434
+ }
435
+ }
436
+ });
437
+ if (options.beforeSubmit) {
438
+ config.beforeSubmit = options.beforeSubmit;
439
+ }
440
+ if (options.onChange) {
441
+ config.onChange = options.onChange;
442
+ }
443
+ return config;
444
+ }
445
+ createCreditCardComponent(creditCardOptions) {
446
+ if (!this.checkout) {
447
+ throw new Error("Checkout not initialized");
448
+ }
449
+ return new Card(this.checkout, creditCardOptions);
450
+ }
451
+ createPayByBankComponent() {
452
+ if (!this.checkout) {
453
+ throw new Error("Checkout not initialized");
454
+ }
455
+ return new PayByBankUS(this.checkout);
456
+ }
457
+ parseEnvironment(clientKey) {
458
+ return clientKey.startsWith("test_") ? "test" : "live";
459
+ }
460
+ }
461
+
462
+ export { FinancialService };
@@ -0,0 +1,2 @@
1
+ export { FinancialService } from './financial-service.js';
2
+ export { useFinancialService } from './use-financial-service.js';
@@ -0,0 +1,186 @@
1
+ import { __awaiter } from '../../_virtual/_tslib.js';
2
+ import { useState, useRef, useCallback, useEffect } from 'react';
3
+ import { FinancialService } from './financial-service.js';
4
+ import { useElements } from '../../elements-provider/elements-context-provider.js';
5
+
6
+ /**
7
+ * React hook for managing Adyen payment components lifecycle
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const { adyenRef, adyenSubmit, isLoading, error } = useFinancialService({
12
+ * serviceParams: { getAdyenSessionData: fetchSession },
13
+ * paymentMethod: "credit_card",
14
+ * options: { locale: 'en-US' }
15
+ * });
16
+ *
17
+ * return (
18
+ * <div>
19
+ * {isLoading && <Spinner />}
20
+ * {error && <ErrorMessage>{error.message}</ErrorMessage>}
21
+ * <div ref={adyenRef} />
22
+ * <button onClick={adyenSubmit}>Pay</button>
23
+ * </div>
24
+ * );
25
+ * ```
26
+ */
27
+ const useFinancialService = ({
28
+ getAdyenSessionData,
29
+ paymentMethod,
30
+ options
31
+ }) => {
32
+ const {
33
+ emotionCacheShadowRootContainer
34
+ } = useElements();
35
+ const [isLoading, setIsLoading] = useState(true);
36
+ const [error, setError] = useState(null);
37
+ const [isMounted, setIsMounted] = useState(false);
38
+ const adyenRef = useRef(null);
39
+ const currentPaymentMethodRef = useRef(null);
40
+ const service = useRef(new FinancialService({
41
+ getAdyenSessionData
42
+ })).current;
43
+ /**
44
+ * Indicates if the current page is a redirect return (i.e., Coming back from bank account authorization).
45
+ */
46
+ const isRedirectReturn = !!new URLSearchParams(window.location.search).get("redirectResult");
47
+ const handleRedirect = useCallback(options => __awaiter(void 0, void 0, void 0, function* () {
48
+ const params = new URLSearchParams(window.location.search);
49
+ const sessionId = params.get("sessionId");
50
+ const redirectResult = params.get("redirectResult");
51
+ if (!redirectResult || !sessionId) {
52
+ console.error("No redirectResult or sessionId param found in redirect URL");
53
+ return;
54
+ }
55
+ setIsLoading(true);
56
+ try {
57
+ yield service.handleRedirect(Object.assign({
58
+ redirectResult,
59
+ sessionId
60
+ }, options));
61
+ } catch (err) {
62
+ console.warn("Redirect handling failed:", err);
63
+ throw err;
64
+ } finally {
65
+ setIsLoading(false);
66
+ }
67
+ }), [service]);
68
+ const submit = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
69
+ if (!isMounted) {
70
+ throw new Error("Adyen component is not mounted. Cannot submit payment.");
71
+ }
72
+ return service.submitPromise();
73
+ }), [isMounted, service]);
74
+ const createCheckout = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
75
+ if (service.isReady()) {
76
+ yield service.createCheckout(paymentMethod, options);
77
+ } else {
78
+ throw new Error("Financial Services is not ready");
79
+ }
80
+ }), [options, paymentMethod, service]);
81
+ const init = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
82
+ if (!service.isReady()) {
83
+ yield service.init();
84
+ } else {
85
+ throw new Error("Financial Service already initialized");
86
+ }
87
+ }), [service]);
88
+ const mount = useCallback(() => {
89
+ if (!service.isReady()) {
90
+ throw new Error("Financial Services is not ready");
91
+ } else {
92
+ if (adyenRef.current) {
93
+ // Mount Adyen styles
94
+ const adyenStyles = document.createElement("link");
95
+ adyenStyles.rel = "stylesheet";
96
+ adyenStyles.href = "https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/6.19.0/adyen.css";
97
+ adyenStyles.id = "adyen-styles";
98
+ emotionCacheShadowRootContainer === null || emotionCacheShadowRootContainer === void 0 ? void 0 : emotionCacheShadowRootContainer.appendChild(adyenStyles);
99
+ // Mount Adyen component
100
+ service.mount(adyenRef.current);
101
+ setIsMounted(true);
102
+ } else {
103
+ throw new Error("Failed to mount Adyen component");
104
+ }
105
+ }
106
+ }, [service, emotionCacheShadowRootContainer]);
107
+ useEffect(() => {
108
+ if (service.isReady()) {
109
+ setIsLoading(false);
110
+ return;
111
+ }
112
+ const initCheckout = () => __awaiter(void 0, void 0, void 0, function* () {
113
+ setIsLoading(true);
114
+ setError(null);
115
+ try {
116
+ yield init();
117
+ yield createCheckout();
118
+ mount();
119
+ // Set the initial payment method
120
+ currentPaymentMethodRef.current = paymentMethod;
121
+ } catch (e) {
122
+ if (e instanceof Error) {
123
+ console.error("Financial Services Lifecycle Error: failed to initialize.", e);
124
+ setError(e);
125
+ }
126
+ } finally {
127
+ setIsLoading(false);
128
+ }
129
+ });
130
+ void initCheckout();
131
+ return () => {
132
+ var _a;
133
+ service.unmount();
134
+ (_a = document.getElementById("adyen-styles")) === null || _a === void 0 ? void 0 : _a.remove();
135
+ };
136
+ }, []); // Only run once on mount
137
+ // Handle payment method changes - recreate component when payment method changes
138
+ useEffect(() => {
139
+ if (!service.isReady() || currentPaymentMethodRef.current === paymentMethod) {
140
+ return;
141
+ }
142
+ const recreateComponent = () => __awaiter(void 0, void 0, void 0, function* () {
143
+ setIsLoading(true);
144
+ setError(null);
145
+ setIsMounted(false);
146
+ try {
147
+ // Unmount the existing component
148
+ service.unmount();
149
+ if (service.isReady()) {
150
+ yield service.createCheckout(paymentMethod, options);
151
+ } else {
152
+ throw new Error("Financial Services is not ready");
153
+ }
154
+ // Mount the new component
155
+ if (adyenRef.current) {
156
+ service.mount(adyenRef.current);
157
+ setIsMounted(true);
158
+ } else {
159
+ throw new Error("Failed to mount Adyen component");
160
+ }
161
+ // Update the ref to track current payment method
162
+ currentPaymentMethodRef.current = paymentMethod;
163
+ } catch (e) {
164
+ if (e instanceof Error) {
165
+ console.error("Financial Services Error: failed to recreate component for payment method change.", e);
166
+ setError(e);
167
+ }
168
+ } finally {
169
+ setIsLoading(false);
170
+ }
171
+ });
172
+ void recreateComponent();
173
+ }, [paymentMethod, options, service]);
174
+ return {
175
+ adyenRef,
176
+ submit,
177
+ handleRedirect,
178
+ isRedirectReturn,
179
+ isLoading,
180
+ error,
181
+ isMounted,
182
+ getSessionData: () => service.getCurrentSessionData()
183
+ };
184
+ };
185
+
186
+ export { useFinancialService };
@@ -112,6 +112,14 @@ const useConfigureShipment = ({
112
112
  isSuccess: salesOrderShipmentCreated
113
113
  } = useCreateSalesOrderShipment();
114
114
  const pendingSalesOrderShipment = getShipmentByStatus("pending", salesOrderShipments);
115
+ if (pendingSalesOrderShipment) {
116
+ // ensure state code is uppercase for form hydration. SE API may return mixed case state codes.
117
+ pendingSalesOrderShipment.shipFrom.stateProvince = pendingSalesOrderShipment.shipFrom.stateProvince.toUpperCase();
118
+ pendingSalesOrderShipment.shipTo.stateProvince = pendingSalesOrderShipment.shipTo.stateProvince.toUpperCase();
119
+ if (pendingSalesOrderShipment.returnTo) {
120
+ pendingSalesOrderShipment.returnTo.stateProvince = pendingSalesOrderShipment.returnTo.stateProvince.toUpperCase();
121
+ }
122
+ }
115
123
  const labelPurchasedSalesOrderShipment = getShipmentByStatus("label_purchased", salesOrderShipments);
116
124
  const cancelledShipment = getShipmentByStatus("cancelled", salesOrderShipments);
117
125
  const defaultWarehouse = getDefaultWarehouse(warehouses);