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