@commercelayer/react-components 4.5.0-beta.3 → 4.5.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (487) hide show
  1. package/lib/cjs/components/ExternalFunction.js +1 -0
  2. package/lib/cjs/components/MetadataInput.js +1 -0
  3. package/lib/cjs/components/SubmitButton.js +1 -0
  4. package/lib/cjs/components/addresses/Address.js +1 -0
  5. package/lib/cjs/components/addresses/AddressCountrySelector.js +1 -0
  6. package/lib/cjs/components/addresses/AddressField.js +1 -0
  7. package/lib/cjs/components/addresses/AddressInput.js +1 -0
  8. package/lib/cjs/components/addresses/AddressStateSelector.js +1 -0
  9. package/lib/cjs/components/addresses/AddressesContainer.js +1 -0
  10. package/lib/cjs/components/addresses/AddressesEmpty.js +1 -0
  11. package/lib/cjs/components/addresses/BillingAddressContainer.js +1 -0
  12. package/lib/cjs/components/addresses/BillingAddressForm.js +1 -0
  13. package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -0
  14. package/lib/cjs/components/addresses/ShippingAddressContainer.js +1 -0
  15. package/lib/cjs/components/addresses/ShippingAddressForm.js +1 -0
  16. package/lib/cjs/components/auth/CommerceLayer.js +1 -0
  17. package/lib/cjs/components/customers/CustomerAddressForm.js +1 -0
  18. package/lib/cjs/components/customers/CustomerContainer.js +1 -0
  19. package/lib/cjs/components/customers/CustomerField.js +1 -0
  20. package/lib/cjs/components/customers/CustomerInput.js +1 -0
  21. package/lib/cjs/components/customers/CustomerPaymentSource.js +1 -0
  22. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.js +1 -0
  23. package/lib/cjs/components/customers/MyAccountLink.js +1 -0
  24. package/lib/cjs/components/customers/MyIdentityLink.d.ts +35 -0
  25. package/lib/cjs/components/customers/MyIdentityLink.js +2 -0
  26. package/lib/cjs/components/customers/SaveCustomerButton.js +1 -0
  27. package/lib/cjs/components/errors/Errors.js +1 -0
  28. package/lib/cjs/components/gift_cards/GiftCard.js +1 -0
  29. package/lib/cjs/components/gift_cards/GiftCardContainer.js +1 -0
  30. package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.js +1 -0
  31. package/lib/cjs/components/gift_cards/GiftCardInput.js +1 -0
  32. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.js +1 -0
  33. package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.js +1 -0
  34. package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.js +1 -0
  35. package/lib/cjs/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -0
  36. package/lib/cjs/components/gift_cards/GiftCardOrCouponSubmit.js +1 -0
  37. package/lib/cjs/components/gift_cards/GiftCardRecipientInput.js +1 -0
  38. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.js +1 -0
  39. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.js +1 -0
  40. package/lib/cjs/components/line_items/LineItem.js +1 -0
  41. package/lib/cjs/components/line_items/LineItemAmount.js +1 -0
  42. package/lib/cjs/components/line_items/LineItemCode.js +1 -0
  43. package/lib/cjs/components/line_items/LineItemField.js +1 -0
  44. package/lib/cjs/components/line_items/LineItemImage.js +1 -0
  45. package/lib/cjs/components/line_items/LineItemName.js +1 -0
  46. package/lib/cjs/components/line_items/LineItemOption.js +1 -0
  47. package/lib/cjs/components/line_items/LineItemOptions.js +1 -0
  48. package/lib/cjs/components/line_items/LineItemQuantity.js +1 -0
  49. package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -0
  50. package/lib/cjs/components/line_items/LineItemsContainer.js +1 -0
  51. package/lib/cjs/components/line_items/LineItemsCount.js +1 -0
  52. package/lib/cjs/components/line_items/LineItemsEmpty.js +1 -0
  53. package/lib/cjs/components/orders/AddToCartButton.js +1 -0
  54. package/lib/cjs/components/orders/AdjustmentAmount.js +1 -0
  55. package/lib/cjs/components/orders/CartLink.d.ts +8 -0
  56. package/lib/cjs/components/orders/CartLink.js +2 -1
  57. package/lib/cjs/components/orders/CheckoutLink.js +1 -0
  58. package/lib/cjs/components/orders/DiscountAmount.js +1 -0
  59. package/lib/cjs/components/orders/GiftCardAmount.js +1 -0
  60. package/lib/cjs/components/orders/HostedCart.js +1 -0
  61. package/lib/cjs/components/orders/OrderContainer.js +1 -0
  62. package/lib/cjs/components/orders/OrderList.js +1 -0
  63. package/lib/cjs/components/orders/OrderListEmpty.js +1 -0
  64. package/lib/cjs/components/orders/OrderListPaginationButtons.js +1 -0
  65. package/lib/cjs/components/orders/OrderListPaginationInfo.js +1 -0
  66. package/lib/cjs/components/orders/OrderListRow.js +1 -0
  67. package/lib/cjs/components/orders/OrderNumber.js +1 -0
  68. package/lib/cjs/components/orders/OrderStorage.js +1 -0
  69. package/lib/cjs/components/orders/PaymentMethodAmount.js +1 -0
  70. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -0
  71. package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -0
  72. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.js +1 -0
  73. package/lib/cjs/components/orders/ShippingAmount.js +1 -0
  74. package/lib/cjs/components/orders/SubTotalAmount.js +1 -0
  75. package/lib/cjs/components/orders/TaxesAmount.js +1 -0
  76. package/lib/cjs/components/orders/TotalAmount.js +1 -0
  77. package/lib/cjs/components/parcels/ParcelField.js +1 -0
  78. package/lib/cjs/components/parcels/ParcelLineItem.js +1 -0
  79. package/lib/cjs/components/parcels/ParcelLineItemField.js +1 -0
  80. package/lib/cjs/components/parcels/ParcelLineItemsCount.js +1 -0
  81. package/lib/cjs/components/parcels/Parcels.js +1 -0
  82. package/lib/cjs/components/parcels/ParcelsCount.js +1 -0
  83. package/lib/cjs/components/payment_gateways/AdyenGateway.js +1 -0
  84. package/lib/cjs/components/payment_gateways/BraintreeGateway.js +1 -0
  85. package/lib/cjs/components/payment_gateways/CheckoutComGateway.js +1 -0
  86. package/lib/cjs/components/payment_gateways/ExternalGateway.js +1 -0
  87. package/lib/cjs/components/payment_gateways/KlarnaGateway.js +1 -0
  88. package/lib/cjs/components/payment_gateways/PaymentGateway.js +1 -0
  89. package/lib/cjs/components/payment_gateways/PaypalGateway.js +1 -0
  90. package/lib/cjs/components/payment_gateways/StripeGateway.js +1 -0
  91. package/lib/cjs/components/payment_gateways/WireTransferGateway.js +1 -0
  92. package/lib/cjs/components/payment_methods/PaymentMethod.js +1 -0
  93. package/lib/cjs/components/payment_methods/PaymentMethodName.js +1 -0
  94. package/lib/cjs/components/payment_methods/PaymentMethodPrice.js +1 -0
  95. package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.js +1 -0
  96. package/lib/cjs/components/payment_methods/PaymentMethodsContainer.js +1 -0
  97. package/lib/cjs/components/payment_source/AdyenPayment.js +1 -0
  98. package/lib/cjs/components/payment_source/BraintreePayment.js +1 -0
  99. package/lib/cjs/components/payment_source/CheckoutComPayment.js +1 -0
  100. package/lib/cjs/components/payment_source/ExternalPayment.js +1 -0
  101. package/lib/cjs/components/payment_source/KlarnaPayment.js +1 -0
  102. package/lib/cjs/components/payment_source/PaymentSource.js +1 -0
  103. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.js +1 -0
  104. package/lib/cjs/components/payment_source/PaymentSourceBrandName.js +1 -0
  105. package/lib/cjs/components/payment_source/PaymentSourceDetail.js +1 -0
  106. package/lib/cjs/components/payment_source/PaymentSourceEditButton.js +1 -0
  107. package/lib/cjs/components/payment_source/PaypalPayment.js +1 -0
  108. package/lib/cjs/components/payment_source/StripeExpressPayment.js +1 -0
  109. package/lib/cjs/components/payment_source/StripePayment.js +1 -0
  110. package/lib/cjs/components/payment_source/WireTransferPayment.js +1 -0
  111. package/lib/cjs/components/prices/Price.js +1 -0
  112. package/lib/cjs/components/prices/PricesContainer.js +1 -0
  113. package/lib/cjs/components/shipments/Shipment.js +1 -0
  114. package/lib/cjs/components/shipments/ShipmentField.js +1 -0
  115. package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -0
  116. package/lib/cjs/components/shipments/ShipmentsCount.js +1 -0
  117. package/lib/cjs/components/shipping_methods/ShippingMethod.js +1 -0
  118. package/lib/cjs/components/shipping_methods/ShippingMethodName.js +1 -0
  119. package/lib/cjs/components/shipping_methods/ShippingMethodPrice.js +1 -0
  120. package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.js +1 -0
  121. package/lib/cjs/components/skus/AvailabilityContainer.js +1 -0
  122. package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -0
  123. package/lib/cjs/components/skus/DeliveryLeadTime.js +1 -0
  124. package/lib/cjs/components/skus/SkuField.js +1 -0
  125. package/lib/cjs/components/skus/SkuList.js +1 -0
  126. package/lib/cjs/components/skus/SkuListsContainer.js +1 -0
  127. package/lib/cjs/components/skus/Skus.js +1 -0
  128. package/lib/cjs/components/skus/SkusContainer.js +1 -0
  129. package/lib/cjs/components/stock_transfers/StockTransfer.js +1 -0
  130. package/lib/cjs/components/stock_transfers/StockTransferField.js +1 -0
  131. package/lib/cjs/components/utils/AddressCardsTemplate.js +1 -0
  132. package/lib/cjs/components/utils/BaseField.js +1 -0
  133. package/lib/cjs/components/utils/BaseInput.js +1 -0
  134. package/lib/cjs/components/utils/BaseOrderPrice.js +1 -0
  135. package/lib/cjs/components/utils/BaseSelect.js +1 -0
  136. package/lib/cjs/components/utils/ErrorBoundary.js +1 -0
  137. package/lib/cjs/components/utils/GenericFieldComponent.js +1 -0
  138. package/lib/cjs/components/utils/Parent.js +1 -0
  139. package/lib/cjs/components/utils/PaymentCardsTemplate.js +1 -0
  140. package/lib/cjs/components/utils/PriceTemplate.js +1 -0
  141. package/lib/cjs/components/utils/getAllErrors.js +1 -0
  142. package/lib/cjs/config/currency.js +1 -0
  143. package/lib/cjs/context/AddressChildrenContext.js +1 -0
  144. package/lib/cjs/context/AddressContext.js +1 -0
  145. package/lib/cjs/context/AvailabilityContext.js +1 -0
  146. package/lib/cjs/context/BillingAddressContext.js +1 -0
  147. package/lib/cjs/context/BillingAddressFormContext.js +1 -0
  148. package/lib/cjs/context/CommerceLayerContext.js +1 -0
  149. package/lib/cjs/context/CouponAndGiftCardFormContext.js +1 -0
  150. package/lib/cjs/context/CustomerAddressFormContext.js +1 -0
  151. package/lib/cjs/context/CustomerContext.js +1 -0
  152. package/lib/cjs/context/CustomerPaymentSourceContext.js +1 -0
  153. package/lib/cjs/context/ExternalFunctionContext.js +1 -0
  154. package/lib/cjs/context/GiftCardContext.js +1 -0
  155. package/lib/cjs/context/InStockSubscriptionContext.js +1 -0
  156. package/lib/cjs/context/LineItemChildrenContext.js +1 -0
  157. package/lib/cjs/context/LineItemContext.js +1 -0
  158. package/lib/cjs/context/LineItemOptionChildrenContext.js +1 -0
  159. package/lib/cjs/context/OrderContext.js +1 -0
  160. package/lib/cjs/context/OrderListChildrenContext.js +1 -0
  161. package/lib/cjs/context/OrderListPaginationContext.js +1 -0
  162. package/lib/cjs/context/OrderStorageContext.js +1 -0
  163. package/lib/cjs/context/ParcelChildrenContext.js +1 -0
  164. package/lib/cjs/context/ParcelLineItemChildrenContext.js +1 -0
  165. package/lib/cjs/context/PaymentMethodChildrenContext.js +1 -0
  166. package/lib/cjs/context/PaymentMethodContext.js +1 -0
  167. package/lib/cjs/context/PaymentSourceContext.js +1 -0
  168. package/lib/cjs/context/PlaceOrderContext.js +1 -0
  169. package/lib/cjs/context/PricesContext.js +1 -0
  170. package/lib/cjs/context/ShipmentChildrenContext.js +1 -0
  171. package/lib/cjs/context/ShipmentContext.js +1 -0
  172. package/lib/cjs/context/ShippingAddressContext.js +1 -0
  173. package/lib/cjs/context/ShippingAddressFormContext.js +1 -0
  174. package/lib/cjs/context/ShippingMethodChildrenContext.js +1 -0
  175. package/lib/cjs/context/SkuChildrenContext.js +1 -0
  176. package/lib/cjs/context/SkuContext.js +1 -0
  177. package/lib/cjs/context/SkuListsContext.js +1 -0
  178. package/lib/cjs/context/StockTransferChildrenContext.js +1 -0
  179. package/lib/cjs/hooks/useCommerceLayer.js +1 -0
  180. package/lib/cjs/hooks/useOrderContainer.js +1 -0
  181. package/lib/cjs/index.js +1 -0
  182. package/lib/cjs/reducers/AddressReducer.js +1 -0
  183. package/lib/cjs/reducers/AvailabilityReducer.js +1 -0
  184. package/lib/cjs/reducers/BillingAddressReducer.js +1 -0
  185. package/lib/cjs/reducers/CustomerReducer.js +1 -0
  186. package/lib/cjs/reducers/GiftCardReducer.js +1 -0
  187. package/lib/cjs/reducers/InStockSubscriptionReducer.js +1 -0
  188. package/lib/cjs/reducers/LineItemReducer.js +1 -0
  189. package/lib/cjs/reducers/OrderReducer.js +1 -0
  190. package/lib/cjs/reducers/PaymentMethodReducer.js +1 -0
  191. package/lib/cjs/reducers/PlaceOrderReducer.js +2 -1
  192. package/lib/cjs/reducers/PriceReducer.js +1 -0
  193. package/lib/cjs/reducers/ShipmentReducer.js +1 -0
  194. package/lib/cjs/reducers/ShippingAddressReducer.js +1 -0
  195. package/lib/cjs/reducers/SkuListsReducer.js +1 -0
  196. package/lib/cjs/reducers/SkuReducer.js +1 -0
  197. package/lib/cjs/typings/errors.js +1 -0
  198. package/lib/cjs/typings/globals.js +1 -0
  199. package/lib/cjs/typings/index.js +1 -0
  200. package/lib/cjs/utils/PropsType.js +1 -0
  201. package/lib/cjs/utils/addressesManager.js +1 -0
  202. package/lib/cjs/utils/baseReducer.js +1 -0
  203. package/lib/cjs/utils/browserInfo.js +1 -0
  204. package/lib/cjs/utils/checkIncludeResource.js +1 -0
  205. package/lib/cjs/utils/compareObjAttribute.js +1 -0
  206. package/lib/cjs/utils/countryStateCity.js +1 -0
  207. package/lib/cjs/utils/customMessages.js +1 -0
  208. package/lib/cjs/utils/customerOrderOptions.js +1 -0
  209. package/lib/cjs/utils/events.js +1 -0
  210. package/lib/cjs/utils/expressPaymentHelper.js +1 -0
  211. package/lib/cjs/utils/filterChildren.js +1 -0
  212. package/lib/cjs/utils/getAmount.js +1 -0
  213. package/lib/cjs/utils/getApplicationLink.d.ts +22 -7
  214. package/lib/cjs/utils/getApplicationLink.js +2 -1
  215. package/lib/cjs/utils/getCardDetails.js +1 -0
  216. package/lib/cjs/utils/getDomain.js +1 -0
  217. package/lib/cjs/utils/getErrors.js +1 -0
  218. package/lib/cjs/utils/getLineItemsCount.js +1 -0
  219. package/lib/cjs/utils/getLoaderComponent.js +1 -0
  220. package/lib/cjs/utils/getPaymentAttributes.js +1 -0
  221. package/lib/cjs/utils/getPrices.js +1 -0
  222. package/lib/cjs/utils/getSdk.js +1 -0
  223. package/lib/cjs/utils/getSkus.js +1 -0
  224. package/lib/cjs/utils/hasSubscriptions.js +1 -0
  225. package/lib/cjs/utils/hooks/useCustomContext.js +1 -0
  226. package/lib/cjs/utils/hooks/useExternalScript.js +1 -0
  227. package/lib/cjs/utils/icons.js +1 -0
  228. package/lib/cjs/utils/isDate.js +1 -0
  229. package/lib/cjs/utils/isEmpty.js +1 -0
  230. package/lib/cjs/utils/isEmptyStates.js +1 -0
  231. package/lib/cjs/utils/isJSON.js +1 -0
  232. package/lib/cjs/utils/jwt.js +1 -0
  233. package/lib/cjs/utils/localStorage.js +1 -0
  234. package/lib/cjs/utils/omit.js +1 -0
  235. package/lib/cjs/utils/organization.js +1 -0
  236. package/lib/cjs/utils/pick.js +1 -0
  237. package/lib/cjs/utils/placeholderImages.js +1 -0
  238. package/lib/cjs/utils/promisify.js +1 -0
  239. package/lib/cjs/utils/replace.js +1 -0
  240. package/lib/cjs/utils/scrollbarWidth.js +1 -0
  241. package/lib/cjs/utils/shipments.js +1 -0
  242. package/lib/cjs/utils/snakeToCamelCase.js +1 -0
  243. package/lib/cjs/utils/validateFormFields.js +1 -0
  244. package/lib/esm/components/ExternalFunction.js +1 -0
  245. package/lib/esm/components/MetadataInput.js +1 -0
  246. package/lib/esm/components/SubmitButton.js +1 -0
  247. package/lib/esm/components/addresses/Address.js +1 -0
  248. package/lib/esm/components/addresses/AddressCountrySelector.js +1 -0
  249. package/lib/esm/components/addresses/AddressField.js +1 -0
  250. package/lib/esm/components/addresses/AddressInput.js +1 -0
  251. package/lib/esm/components/addresses/AddressStateSelector.js +1 -0
  252. package/lib/esm/components/addresses/AddressesContainer.js +1 -0
  253. package/lib/esm/components/addresses/AddressesEmpty.js +1 -0
  254. package/lib/esm/components/addresses/BillingAddressContainer.js +1 -0
  255. package/lib/esm/components/addresses/BillingAddressForm.js +1 -0
  256. package/lib/esm/components/addresses/SaveAddressesButton.js +1 -0
  257. package/lib/esm/components/addresses/ShippingAddressContainer.js +1 -0
  258. package/lib/esm/components/addresses/ShippingAddressForm.js +1 -0
  259. package/lib/esm/components/auth/CommerceLayer.js +1 -0
  260. package/lib/esm/components/customers/CustomerAddressForm.js +1 -0
  261. package/lib/esm/components/customers/CustomerContainer.js +1 -0
  262. package/lib/esm/components/customers/CustomerField.js +1 -0
  263. package/lib/esm/components/customers/CustomerInput.js +1 -0
  264. package/lib/esm/components/customers/CustomerPaymentSource.js +1 -0
  265. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.js +1 -0
  266. package/lib/esm/components/customers/MyAccountLink.js +1 -0
  267. package/lib/esm/components/customers/MyIdentityLink.d.ts +35 -0
  268. package/lib/esm/components/customers/MyIdentityLink.js +2 -0
  269. package/lib/esm/components/customers/SaveCustomerButton.js +1 -0
  270. package/lib/esm/components/errors/Errors.js +1 -0
  271. package/lib/esm/components/gift_cards/GiftCard.js +1 -0
  272. package/lib/esm/components/gift_cards/GiftCardContainer.js +1 -0
  273. package/lib/esm/components/gift_cards/GiftCardCurrencySelector.js +1 -0
  274. package/lib/esm/components/gift_cards/GiftCardInput.js +1 -0
  275. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.js +1 -0
  276. package/lib/esm/components/gift_cards/GiftCardOrCouponForm.js +1 -0
  277. package/lib/esm/components/gift_cards/GiftCardOrCouponInput.js +1 -0
  278. package/lib/esm/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -0
  279. package/lib/esm/components/gift_cards/GiftCardOrCouponSubmit.js +1 -0
  280. package/lib/esm/components/gift_cards/GiftCardRecipientInput.js +1 -0
  281. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.js +1 -0
  282. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.js +1 -0
  283. package/lib/esm/components/line_items/LineItem.js +1 -0
  284. package/lib/esm/components/line_items/LineItemAmount.js +1 -0
  285. package/lib/esm/components/line_items/LineItemCode.js +1 -0
  286. package/lib/esm/components/line_items/LineItemField.js +1 -0
  287. package/lib/esm/components/line_items/LineItemImage.js +1 -0
  288. package/lib/esm/components/line_items/LineItemName.js +1 -0
  289. package/lib/esm/components/line_items/LineItemOption.js +1 -0
  290. package/lib/esm/components/line_items/LineItemOptions.js +1 -0
  291. package/lib/esm/components/line_items/LineItemQuantity.js +1 -0
  292. package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -0
  293. package/lib/esm/components/line_items/LineItemsContainer.js +1 -0
  294. package/lib/esm/components/line_items/LineItemsCount.js +1 -0
  295. package/lib/esm/components/line_items/LineItemsEmpty.js +1 -0
  296. package/lib/esm/components/orders/AddToCartButton.js +1 -0
  297. package/lib/esm/components/orders/AdjustmentAmount.js +1 -0
  298. package/lib/esm/components/orders/CartLink.d.ts +8 -0
  299. package/lib/esm/components/orders/CartLink.js +2 -1
  300. package/lib/esm/components/orders/CheckoutLink.js +1 -0
  301. package/lib/esm/components/orders/DiscountAmount.js +1 -0
  302. package/lib/esm/components/orders/GiftCardAmount.js +1 -0
  303. package/lib/esm/components/orders/HostedCart.js +1 -0
  304. package/lib/esm/components/orders/OrderContainer.js +1 -0
  305. package/lib/esm/components/orders/OrderList.js +1 -0
  306. package/lib/esm/components/orders/OrderListEmpty.js +1 -0
  307. package/lib/esm/components/orders/OrderListPaginationButtons.js +1 -0
  308. package/lib/esm/components/orders/OrderListPaginationInfo.js +1 -0
  309. package/lib/esm/components/orders/OrderListRow.js +1 -0
  310. package/lib/esm/components/orders/OrderNumber.js +1 -0
  311. package/lib/esm/components/orders/OrderStorage.js +1 -0
  312. package/lib/esm/components/orders/PaymentMethodAmount.js +1 -0
  313. package/lib/esm/components/orders/PlaceOrderButton.js +1 -0
  314. package/lib/esm/components/orders/PlaceOrderContainer.js +1 -0
  315. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.js +1 -0
  316. package/lib/esm/components/orders/ShippingAmount.js +1 -0
  317. package/lib/esm/components/orders/SubTotalAmount.js +1 -0
  318. package/lib/esm/components/orders/TaxesAmount.js +1 -0
  319. package/lib/esm/components/orders/TotalAmount.js +1 -0
  320. package/lib/esm/components/parcels/ParcelField.js +1 -0
  321. package/lib/esm/components/parcels/ParcelLineItem.js +1 -0
  322. package/lib/esm/components/parcels/ParcelLineItemField.js +1 -0
  323. package/lib/esm/components/parcels/ParcelLineItemsCount.js +1 -0
  324. package/lib/esm/components/parcels/Parcels.js +1 -0
  325. package/lib/esm/components/parcels/ParcelsCount.js +1 -0
  326. package/lib/esm/components/payment_gateways/AdyenGateway.js +1 -0
  327. package/lib/esm/components/payment_gateways/BraintreeGateway.js +1 -0
  328. package/lib/esm/components/payment_gateways/CheckoutComGateway.js +1 -0
  329. package/lib/esm/components/payment_gateways/ExternalGateway.js +1 -0
  330. package/lib/esm/components/payment_gateways/KlarnaGateway.js +1 -0
  331. package/lib/esm/components/payment_gateways/PaymentGateway.js +1 -0
  332. package/lib/esm/components/payment_gateways/PaypalGateway.js +1 -0
  333. package/lib/esm/components/payment_gateways/StripeGateway.js +1 -0
  334. package/lib/esm/components/payment_gateways/WireTransferGateway.js +1 -0
  335. package/lib/esm/components/payment_methods/PaymentMethod.js +1 -0
  336. package/lib/esm/components/payment_methods/PaymentMethodName.js +1 -0
  337. package/lib/esm/components/payment_methods/PaymentMethodPrice.js +1 -0
  338. package/lib/esm/components/payment_methods/PaymentMethodRadioButton.js +1 -0
  339. package/lib/esm/components/payment_methods/PaymentMethodsContainer.js +1 -0
  340. package/lib/esm/components/payment_source/AdyenPayment.js +1 -0
  341. package/lib/esm/components/payment_source/BraintreePayment.js +1 -0
  342. package/lib/esm/components/payment_source/CheckoutComPayment.js +1 -0
  343. package/lib/esm/components/payment_source/ExternalPayment.js +1 -0
  344. package/lib/esm/components/payment_source/KlarnaPayment.js +1 -0
  345. package/lib/esm/components/payment_source/PaymentSource.js +1 -0
  346. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.js +1 -0
  347. package/lib/esm/components/payment_source/PaymentSourceBrandName.js +1 -0
  348. package/lib/esm/components/payment_source/PaymentSourceDetail.js +1 -0
  349. package/lib/esm/components/payment_source/PaymentSourceEditButton.js +1 -0
  350. package/lib/esm/components/payment_source/PaypalPayment.js +1 -0
  351. package/lib/esm/components/payment_source/StripeExpressPayment.js +1 -0
  352. package/lib/esm/components/payment_source/StripePayment.js +1 -0
  353. package/lib/esm/components/payment_source/WireTransferPayment.js +1 -0
  354. package/lib/esm/components/prices/Price.js +1 -0
  355. package/lib/esm/components/prices/PricesContainer.js +1 -0
  356. package/lib/esm/components/shipments/Shipment.js +1 -0
  357. package/lib/esm/components/shipments/ShipmentField.js +1 -0
  358. package/lib/esm/components/shipments/ShipmentsContainer.js +1 -0
  359. package/lib/esm/components/shipments/ShipmentsCount.js +1 -0
  360. package/lib/esm/components/shipping_methods/ShippingMethod.js +1 -0
  361. package/lib/esm/components/shipping_methods/ShippingMethodName.js +1 -0
  362. package/lib/esm/components/shipping_methods/ShippingMethodPrice.js +1 -0
  363. package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.js +1 -0
  364. package/lib/esm/components/skus/AvailabilityContainer.js +1 -0
  365. package/lib/esm/components/skus/AvailabilityTemplate.js +1 -0
  366. package/lib/esm/components/skus/DeliveryLeadTime.js +1 -0
  367. package/lib/esm/components/skus/SkuField.js +1 -0
  368. package/lib/esm/components/skus/SkuList.js +1 -0
  369. package/lib/esm/components/skus/SkuListsContainer.js +1 -0
  370. package/lib/esm/components/skus/Skus.js +1 -0
  371. package/lib/esm/components/skus/SkusContainer.js +1 -0
  372. package/lib/esm/components/stock_transfers/StockTransfer.js +1 -0
  373. package/lib/esm/components/stock_transfers/StockTransferField.js +1 -0
  374. package/lib/esm/components/utils/AddressCardsTemplate.js +1 -0
  375. package/lib/esm/components/utils/BaseField.js +1 -0
  376. package/lib/esm/components/utils/BaseInput.js +1 -0
  377. package/lib/esm/components/utils/BaseOrderPrice.js +1 -0
  378. package/lib/esm/components/utils/BaseSelect.js +1 -0
  379. package/lib/esm/components/utils/ErrorBoundary.js +1 -0
  380. package/lib/esm/components/utils/GenericFieldComponent.js +1 -0
  381. package/lib/esm/components/utils/Parent.js +1 -0
  382. package/lib/esm/components/utils/PaymentCardsTemplate.js +1 -0
  383. package/lib/esm/components/utils/PriceTemplate.js +1 -0
  384. package/lib/esm/components/utils/getAllErrors.js +1 -0
  385. package/lib/esm/config/currency.js +1 -0
  386. package/lib/esm/context/AddressChildrenContext.js +1 -0
  387. package/lib/esm/context/AddressContext.js +1 -0
  388. package/lib/esm/context/AvailabilityContext.js +1 -0
  389. package/lib/esm/context/BillingAddressContext.js +1 -0
  390. package/lib/esm/context/BillingAddressFormContext.js +1 -0
  391. package/lib/esm/context/CommerceLayerContext.js +1 -0
  392. package/lib/esm/context/CouponAndGiftCardFormContext.js +1 -0
  393. package/lib/esm/context/CustomerAddressFormContext.js +1 -0
  394. package/lib/esm/context/CustomerContext.js +1 -0
  395. package/lib/esm/context/CustomerPaymentSourceContext.js +1 -0
  396. package/lib/esm/context/ExternalFunctionContext.js +1 -0
  397. package/lib/esm/context/GiftCardContext.js +1 -0
  398. package/lib/esm/context/InStockSubscriptionContext.js +1 -0
  399. package/lib/esm/context/LineItemChildrenContext.js +1 -0
  400. package/lib/esm/context/LineItemContext.js +1 -0
  401. package/lib/esm/context/LineItemOptionChildrenContext.js +1 -0
  402. package/lib/esm/context/OrderContext.js +1 -0
  403. package/lib/esm/context/OrderListChildrenContext.js +1 -0
  404. package/lib/esm/context/OrderListPaginationContext.js +1 -0
  405. package/lib/esm/context/OrderStorageContext.js +1 -0
  406. package/lib/esm/context/ParcelChildrenContext.js +1 -0
  407. package/lib/esm/context/ParcelLineItemChildrenContext.js +1 -0
  408. package/lib/esm/context/PaymentMethodChildrenContext.js +1 -0
  409. package/lib/esm/context/PaymentMethodContext.js +1 -0
  410. package/lib/esm/context/PaymentSourceContext.js +1 -0
  411. package/lib/esm/context/PlaceOrderContext.js +1 -0
  412. package/lib/esm/context/PricesContext.js +1 -0
  413. package/lib/esm/context/ShipmentChildrenContext.js +1 -0
  414. package/lib/esm/context/ShipmentContext.js +1 -0
  415. package/lib/esm/context/ShippingAddressContext.js +1 -0
  416. package/lib/esm/context/ShippingAddressFormContext.js +1 -0
  417. package/lib/esm/context/ShippingMethodChildrenContext.js +1 -0
  418. package/lib/esm/context/SkuChildrenContext.js +1 -0
  419. package/lib/esm/context/SkuContext.js +1 -0
  420. package/lib/esm/context/SkuListsContext.js +1 -0
  421. package/lib/esm/context/StockTransferChildrenContext.js +1 -0
  422. package/lib/esm/hooks/useCommerceLayer.js +1 -0
  423. package/lib/esm/hooks/useOrderContainer.js +1 -0
  424. package/lib/esm/index.js +1 -0
  425. package/lib/esm/reducers/AddressReducer.js +1 -0
  426. package/lib/esm/reducers/AvailabilityReducer.js +1 -0
  427. package/lib/esm/reducers/BillingAddressReducer.js +1 -0
  428. package/lib/esm/reducers/CustomerReducer.js +1 -0
  429. package/lib/esm/reducers/GiftCardReducer.js +1 -0
  430. package/lib/esm/reducers/InStockSubscriptionReducer.js +1 -0
  431. package/lib/esm/reducers/LineItemReducer.js +1 -0
  432. package/lib/esm/reducers/OrderReducer.js +1 -0
  433. package/lib/esm/reducers/PaymentMethodReducer.js +1 -0
  434. package/lib/esm/reducers/PlaceOrderReducer.js +2 -1
  435. package/lib/esm/reducers/PriceReducer.js +1 -0
  436. package/lib/esm/reducers/ShipmentReducer.js +1 -0
  437. package/lib/esm/reducers/ShippingAddressReducer.js +1 -0
  438. package/lib/esm/reducers/SkuListsReducer.js +1 -0
  439. package/lib/esm/reducers/SkuReducer.js +1 -0
  440. package/lib/esm/typings/errors.js +1 -0
  441. package/lib/esm/typings/globals.js +1 -0
  442. package/lib/esm/typings/index.js +1 -0
  443. package/lib/esm/utils/PropsType.js +1 -0
  444. package/lib/esm/utils/addressesManager.js +1 -0
  445. package/lib/esm/utils/baseReducer.js +1 -0
  446. package/lib/esm/utils/browserInfo.js +1 -0
  447. package/lib/esm/utils/checkIncludeResource.js +1 -0
  448. package/lib/esm/utils/compareObjAttribute.js +1 -0
  449. package/lib/esm/utils/countryStateCity.js +1 -0
  450. package/lib/esm/utils/customMessages.js +1 -0
  451. package/lib/esm/utils/customerOrderOptions.js +1 -0
  452. package/lib/esm/utils/events.js +1 -0
  453. package/lib/esm/utils/expressPaymentHelper.js +1 -0
  454. package/lib/esm/utils/filterChildren.js +1 -0
  455. package/lib/esm/utils/getAmount.js +1 -0
  456. package/lib/esm/utils/getApplicationLink.d.ts +22 -7
  457. package/lib/esm/utils/getApplicationLink.js +2 -1
  458. package/lib/esm/utils/getCardDetails.js +1 -0
  459. package/lib/esm/utils/getDomain.js +1 -0
  460. package/lib/esm/utils/getErrors.js +1 -0
  461. package/lib/esm/utils/getLineItemsCount.js +1 -0
  462. package/lib/esm/utils/getLoaderComponent.js +1 -0
  463. package/lib/esm/utils/getPaymentAttributes.js +1 -0
  464. package/lib/esm/utils/getPrices.js +1 -0
  465. package/lib/esm/utils/getSdk.js +1 -0
  466. package/lib/esm/utils/getSkus.js +1 -0
  467. package/lib/esm/utils/hasSubscriptions.js +1 -0
  468. package/lib/esm/utils/hooks/useCustomContext.js +1 -0
  469. package/lib/esm/utils/hooks/useExternalScript.js +1 -0
  470. package/lib/esm/utils/icons.js +1 -0
  471. package/lib/esm/utils/isDate.js +1 -0
  472. package/lib/esm/utils/isEmpty.js +1 -0
  473. package/lib/esm/utils/isEmptyStates.js +1 -0
  474. package/lib/esm/utils/isJSON.js +1 -0
  475. package/lib/esm/utils/jwt.js +1 -0
  476. package/lib/esm/utils/localStorage.js +1 -0
  477. package/lib/esm/utils/omit.js +1 -0
  478. package/lib/esm/utils/organization.js +1 -0
  479. package/lib/esm/utils/pick.js +1 -0
  480. package/lib/esm/utils/placeholderImages.js +1 -0
  481. package/lib/esm/utils/promisify.js +1 -0
  482. package/lib/esm/utils/replace.js +1 -0
  483. package/lib/esm/utils/scrollbarWidth.js +1 -0
  484. package/lib/esm/utils/shipments.js +1 -0
  485. package/lib/esm/utils/snakeToCamelCase.js +1 -0
  486. package/lib/esm/utils/validateFormFields.js +1 -0
  487. package/package.json +23 -23
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useContext}from"react";import GiftCardContext from"../../context/GiftCardContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import giftCardReducer,{giftCardInitialState,addGiftCardRecipient,addGiftCard,addGiftCardError,addGiftCardLoading}from"../../reducers/GiftCardReducer";import OrderContext from"../../context/OrderContext";export function GiftCardContainer(props){const{children}=props,[state,dispatch]=useReducer(giftCardReducer,giftCardInitialState),config=useContext(CommerceLayerContext),{getOrder,createOrder,order}=useContext(OrderContext),giftCardValue={...state,addGiftCardRecipient:async values=>{await addGiftCardRecipient(values,config,dispatch)},addGiftCard:async values=>{await addGiftCard({...values},{config,dispatch,getOrder,createOrder,order})},addGiftCardError:errors=>{addGiftCardError(errors,dispatch)},addGiftCardLoading:loading=>{addGiftCardLoading(loading,dispatch)}};return _jsx(GiftCardContext.Provider,{value:giftCardValue,children})}export default GiftCardContainer;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseSelect from"../utils/BaseSelect";import currencyOptions from"../../config/currency";export function GiftCardCurrencySelector(props){return _jsx(BaseSelect,{options:currencyOptions,name:"currencyCode",...props})}export default GiftCardCurrencySelector;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseInput from"../utils/BaseInput";export function GiftCardInput(props){const{placeholder="",...p}=props;return _jsx(BaseInput,{placeholder,...p})}export default GiftCardInput;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function GiftCardOrCouponCode({children,type,...props}){const{order}=useContext(OrderContext);let codeType=type&&`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),parentProps={...props,code,hide,discountAmountCents:order?.discount_amount_cents,discountAmountFloat:order?.discount_amount_float,formattedDiscountAmount:order?.formatted_discount_amount};return children?_jsx(Parent,{...parentProps,children}):hide?null:_jsx("span",{...props,children:code})}export default GiftCardOrCouponCode;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef,useState}from"react";import CouponAndGiftCardFormContext from"../../context/CouponAndGiftCardFormContext";import OrderContext from"../../context/OrderContext";import isEmpty from"lodash/isEmpty";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import findIndex from"lodash/findIndex";export function GiftCardOrCouponForm(props){const{children,autoComplete="on",onSubmit,...p}=props,{validation,values,reset}=useRapidForm(),[codeType,setCodeType]=useState("gift_card_or_coupon_code"),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{if(values[inputName]?.value===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors(err),onSubmit&&onSubmit({value:values[inputName]?.value,success:!1})}values[inputName]?.value===""&&(setOrderErrors([]),onSubmit&&onSubmit({value:values[inputName]?.value,success:!1}))},[values]),useEffect(()=>{order?.gift_card_code&&!order?.coupon_code&&setCodeType("coupon_code"),!order?.gift_card_code&&order?.coupon_code&&setCodeType("gift_card_code"),!order?.gift_card_code&&!order?.coupon_code&&setCodeType("gift_card_or_coupon_code")},[order]);const handleSubmit=async e=>{e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code!=null&&setGiftCardOrCouponCode!=null){const{success,order:order2}=await setGiftCardOrCouponCode({code,codeType}),value=values[inputName]?.value;onSubmit&&onSubmit({success,value,order:order2}),success&&reset(e)}};return order?.gift_card_code&&order?.coupon_code||isEmpty(order)?null:_jsx(CouponAndGiftCardFormContext.Provider,{value:{validation,codeType},children:_jsx("form",{ref,autoComplete,onSubmit:e=>{handleSubmit(e)},...p,children})})}export default GiftCardOrCouponForm;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import BaseInput from"../utils/BaseInput";import CouponAndGiftCardFormContext from"../../context/CouponAndGiftCardFormContext";export function GiftCardOrCouponInput(props){const{placeholder="",required,value,placeholderTranslation,...p}=props,{validation,codeType}=useContext(CouponAndGiftCardFormContext);let placeholderLabel=placeholder;return placeholderTranslation&&codeType&&(placeholderLabel=placeholderTranslation(codeType)),_jsx(BaseInput,{type:"text",name:"gift_card_or_coupon_code",ref:validation,required:required!==void 0?required:!0,placeholder:placeholderLabel,defaultValue:value,...p})}export default GiftCardOrCouponInput;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";export function GiftCardOrCouponRemoveButton(props){const{children,label="Remove",onClick,type,...p}=props,{order,removeGiftCardOrCouponCode}=useContext(OrderContext);let codeType=type?`${type}_code`:void 0;!type&&order&&"coupon_code"in order&&order.coupon_code!=null?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=async()=>{if(codeType!=null&&removeGiftCardOrCouponCode!=null){const response=await removeGiftCardOrCouponCode({codeType});onClick!=null&&response!=null&&onClick(response)}},parentProps={...p,label,handleClick,codeType};return children?_jsx(Parent,{...parentProps,children}):hide?null:_jsx("button",{type:"button",onClick:()=>{handleClick()},...p,children:label})}export default GiftCardOrCouponRemoveButton;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";export function GiftCardOrCouponSubmit(props){const{children,label="Submit",...p}=props,parentProps={...p,label};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"submit",...p,children:label})}export default GiftCardOrCouponSubmit;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  "use strict";
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import InStockSubscriptionContext from"../../context/InStockSubscriptionContext";import useCustomContext from"../../utils/hooks/useCustomContext";import jwt from"../../utils/jwt";import{useContext,useState}from"react";export function InStockSubscriptionButton({skuCode,customerEmail,children,onClick,show=!1,label="Subscribe",loadingLabel="Loading...",...props}){const{setInStockSubscription}=useCustomContext({context:InStockSubscriptionContext,contextComponentName:"InStockSubscriptionsContainer",currentComponentName:"InStockSubscriptionButton",key:"setInStockSubscription"}),{accessToken}=useContext(CommerceLayerContext),[loading,setLoading]=useState(!1),handleClick=async()=>{if(accessToken!=null&&customerEmail==null&&jwt(accessToken)?.owner==null){console.error("Missing customerEmail");return}if(setInStockSubscription==null){console.error("Missing <InStockSubscriptionsContainer>");return}setLoading(!0);const res=await setInStockSubscription({customerEmail,skuCode});onClick?.(res),setLoading(!1)};if(children!=null){const parentProps={skuCode,customerEmail,onClick,show,label,loadingLabel,...props};return _jsx(Parent,{...parentProps,children})}return show?_jsx("button",{onClick:()=>{handleClick()},disabled:loading,...props,children:loading?loadingLabel:label}):null}export default InStockSubscriptionButton;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import InStockSubscriptionContext from"../../context/InStockSubscriptionContext";import inStockSubscriptionReducer,{inStockSubscriptionInitialState,setInStockSubscription}from"../../reducers/InStockSubscriptionReducer";import useCustomContext from"../../utils/hooks/useCustomContext";import{useReducer}from"react";export function InStockSubscriptionsContainer({children}){const config=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"InStockSubscriptionsContainer",key:"accessToken"}),[state,dispatch]=useReducer(inStockSubscriptionReducer,inStockSubscriptionInitialState),value={...state,setInStockSubscription:async({customerEmail,skuCode})=>await setInStockSubscription({customerEmail,skuCode,config,dispatch})};return _jsx(InStockSubscriptionContext.Provider,{value,children})}export default InStockSubscriptionsContainer;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemContext from"../../context/LineItemContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";export function LineItem(props){const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),components=(shipmentLineItems&&shipmentLineItems?.length>0?shipmentLineItems:lineItems)?.filter(l=>l?.item_type===type).map((lineItem,k,check)=>{if(lineItem?.item_type==="bundles"&&k>0&&check[k-1]?.bundle_code===lineItem.bundle_code||lineItem?.item_type==="gift_cards"&&lineItem?.total_amount_cents&&lineItem?.total_amount_cents<=0)return null;const lineProps={lineItem};return _jsx(LineItemChildrenContext.Provider,{value:lineProps,children},lineItem?.id)});return _jsx(_Fragment,{children:components})}export default LineItem;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../../utils/getAmount";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemAmount(props){const{format="formatted",type="total",...p}=props,{lineItem}=useContext(LineItemChildrenContext),[price,setPrice]=useState("");useEffect(()=>{if(lineItem){const p2=getAmount({base:"amount",type,format,obj:lineItem});setPrice(p2)}return()=>{setPrice("")}},[lineItem]);const parentProps={price,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:price})}export default LineItemAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemCode({type="sku_code",children,...p}){const{lineItem}=useContext(LineItemChildrenContext),labelName=lineItem?.[type],parentProps={lineItem,skuCode:labelName,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:labelName})}export default LineItemCode;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import GenericFieldComponent from"../utils/GenericFieldComponent";export function LineItemField(props){const{attribute,tagElement="span",children,...p}=props;return _jsx(GenericFieldComponent,{resource:"lineItem",attribute,tagElement,context:LineItemChildrenContext,...p,children})}export default LineItemField;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import{defaultGiftCardImgUrl,defaultImgUrl}from"../../utils/placeholderImages";import Parent from"../utils/Parent";export function LineItemImage(props){const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),itemType=lineItem?.item_type;let src=lineItem?.image_url;src||(placeholder?.[itemType]?src=placeholder?.[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps={lineItem,src,placeholder,...p};return children?_jsx(Parent,{...parenProps,children}):src?_jsx("img",{"data-testid":`line-item-image-${lineItem?.sku_code??""}`,alt:lineItem?.name??"",src,...p}):null}export default LineItemImage;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemName(props){const{lineItem}=useContext(LineItemChildrenContext),label=lineItem?.name,parentProps={label,lineItem,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("p",{"data-testid":`line-item-name-${lineItem?.sku_code??""}`,...props,children:label})}export default LineItemName;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import LineItemOptionChildrenContext from"../../context/LineItemOptionChildrenContext";import map from"lodash/map";import Parent from"../utils/Parent";import isJSON from"../../utils/isJSON";export function LineItemOption(props){const{name,children,valueClassName,key,tagElement="li",tagContainer="ul",...p}=props,{lineItemOption,showAll}=useContext(LineItemOptionChildrenContext),parentProps={...props,lineItemOption},TagElement=tagElement,TagContainer=tagContainer,label=name!=null?lineItemOption?.options?.[name]:"",components=showAll&&isJSON(JSON.stringify(lineItemOption?.options))?map(lineItemOption?.options,(value,key2)=>_jsxs(TagElement,{...p,children:[`${key2}:`,_jsx("span",{className:valueClassName,children:`${value}`})]},key2)):name!=null&&lineItemOption?.options!=null&&name in lineItemOption.options?_jsxs(TagElement,{...p,children:[`${name}:`,_jsx("span",{className:valueClassName,...p,children:label??""})]},key):null;return children?_jsx(Parent,{...parentProps,children:props.children}):_jsx(TagContainer,{children:components})}export default LineItemOption;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemOptionChildrenContext from"../../context/LineItemOptionChildrenContext";export function LineItemOptions(props){const{skuOptionId,title,children,showName=!0,showAll,className,titleTagElement="h6",titleClassName,...p}=props,{lineItem}=useContext(LineItemChildrenContext),lineItemOptions=lineItem!=null?lineItem?.line_item_options||[]:[],TitleTagElement=titleTagElement,options=lineItemOptions.filter(o=>showAll?!0:o.skuOption().id===skuOptionId).map((o,k)=>{const showTitle=showName?_jsx(TitleTagElement,{className:titleClassName,children:title||o.name}):null,valueProps={lineItemOption:o,showAll};return _jsxs("div",{className,...p,children:[showTitle,_jsx(LineItemOptionChildrenContext.Provider,{value:valueProps,children})]},k)});return _jsx(_Fragment,{children:options})}export default LineItemOptions;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";export function LineItemQuantity(props){const{max=50,readonly=!1,...p}=props,{lineItem}=useContext(LineItemChildrenContext),{updateLineItem}=useContext(LineItemContext),options=[];for(let i=1;i<=max;i++)options.push(_jsx("option",{value:`${i}`,children:i},i));const handleChange=e=>{const quantity2=Number(e.target.value);updateLineItem&&lineItem&&updateLineItem(lineItem.id,quantity2)},quantity=lineItem?.quantity,parentProps={handleChange,quantity,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):readonly?_jsx("span",{...p,children:quantity}):_jsx("select",{"data-testid":lineItem?.sku_code,title:lineItem?.name??"",value:quantity,onChange:handleChange,...p,children:options})}export default LineItemQuantity;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function LineItemRemoveLink(props){const{label="Remove",onClick}=props,{lineItem}=useCustomContext({context:LineItemChildrenContext,contextComponentName:"LineItem",currentComponentName:"LineItemRemoveLink",key:"lineItem"}),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem!=null&&lineItem!=null&&deleteLineItem(lineItem.id),onClick?.(e)},parentProps={handleRemove,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("a",{"data-testid":`line-item-remove-link-${lineItem?.sku_code??""}`,...props,href:"#",onClick:handleRemove,children:label})}export default LineItemRemoveLink;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext}from"react";import lineItemReducer,{lineItemInitialState,updateLineItem,deleteLineItem}from"../../reducers/LineItemReducer";import OrderContext from"../../context/OrderContext";import LineItemContext from"../../context/LineItemContext";import CommerceLayerContext from"../../context/CommerceLayerContext";export function LineItemsContainer(props){const{children,loader="Loading..."}=props,{order,addResourceToInclude,include,orderId,getOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(lineItemReducer,lineItemInitialState);useEffect(()=>{include?.includes("line_items.line_item_options.sku_option")?includeLoaded?.["line_items.line_item_options.sku_option"]||addResourceToInclude({newResourceLoaded:{"line_items.line_item_options.sku_option":!0}}):addResourceToInclude({newResource:["line_items.line_item_options.sku_option"]}),include?.includes("line_items.item")?includeLoaded?.["line_items.item"]||addResourceToInclude({newResourceLoaded:{"line_items.item":!0}}):addResourceToInclude({newResource:["line_items.item"]})},[include,includeLoaded]),useEffect(()=>{order?.line_items&&dispatch({type:"setLineItems",payload:{lineItems:order.line_items}})},[order?.line_items]);const lineItemValue={...state,loader,updateLineItem:async(lineItemId,quantity=1)=>{await updateLineItem({lineItemId,quantity,dispatch,config,getOrder,orderId,errors:state.errors})},deleteLineItem:async lineItemId=>{await deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})}};return _jsx(LineItemContext.Provider,{value:lineItemValue,children:state.loading?loader:children})}export default LineItemsContainer;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";export function LineItemsCount(props){const{children,typeAccepted,...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(0);useEffect(()=>{if(lineItems&&lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[],typeAccepted});setQuantity(qty)}return()=>{setQuantity(0)}},[lineItems,typeAccepted]);const parentProps={quantity,typeAccepted,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:quantity})}export default LineItemsCount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";export function LineItemsEmpty(props){const{children,text="Your shopping bag is empty",...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(),emptyText=quantity===0?_jsx("span",{...p,children:text}):null;useEffect(()=>{if(lineItems)if(lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[]});setQuantity(qty)}else setQuantity(0);return()=>{setQuantity(void 0)}},[lineItems]);const parentProps={quantity,text,...p};return children?_jsx(Parent,{...parentProps,children}):emptyText}export default LineItemsEmpty;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import{getApplicationLink}from"../../utils/getApplicationLink";import CommerceLayerContext from"../../context/CommerceLayerContext";import useCustomContext from"../../utils/hooks/useCustomContext";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,quantity,lineItemOption,...p}=props,{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AddToCartButton",key:"accessToken"}),{addToCart,orderId,getOrder,setOrderErrors}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"AddToCartButton",key:"addToCart"}),{url,callExternalFunction}=useContext(ExternalFunctionContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),sCode=sku?.code??skuCode,handleClick=async()=>{const qty=quantity!=null?parseInt(quantity):1;if(skuLists!=null&&skuListId&&url&&skuListId in skuLists){const lineItems=skuLists?.[skuListId]?.map(skuCode2=>({skuCode:skuCode2,quantity:qty,_update_quantity:1}));return await callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),publish("open-cart"),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}if(!url&&addToCart!=null){const res=await addToCart({bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart&&accessToken!=null&&endpoint!=null){const{slug,domain}=getDomain(endpoint),orderId2=res?.orderId;hostedCartUrl&&orderId2?location.href=`https://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getApplicationLink({orderId:orderId2,slug,accessToken,domain,applicationType:"cart"}))}return publish("open-cart"),res}else if(url)return await callExternalFunction({url,data:{bundleCode,skuCode:sCode,quantity:qty,lineItemOption,lineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),publish("open-cart"),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},parentProps={handleClick,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,onClick:()=>{handleClick()},children:label})}export default AddToCartButton;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function AdjustmentAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"adjustment",...props})}export default AdjustmentAmount;
@@ -11,6 +11,14 @@ interface ChildrenProps extends Omit<Props, 'children'> {
11
11
  * @returns Promise<void>
12
12
  */
13
13
  handleClick?: (e: MouseEvent<HTMLAnchorElement>) => Promise<void>;
14
+ /**
15
+ * The order id
16
+ */
17
+ orderId?: string;
18
+ /**
19
+ * The access token
20
+ */
21
+ accessToken?: string;
14
22
  }
15
23
  interface Props extends Omit<JSX.IntrinsicElements['a'], 'children'> {
16
24
  children?: ChildrenFunction<ChildrenProps>;
@@ -1 +1,2 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function CartLink(props){const{label,children,type,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");if(endpoint==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=slug&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,domain,applicationType:"cart"}):"",handleClick=async event=>{if(event.preventDefault(),type!=="mini")if(order?.id)location.href=href;else{const orderId=await createOrder();slug&&(location.href=getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart"}))}else publish("open-cart")},parentProps={handleClick,label,href,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,onClick:e=>{handleClick(e)},children:label}):null}export default CartLink;
1
+ "use client";
2
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function CartLink(props){const{label,children,type,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");if(endpoint==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=slug&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,domain,applicationType:"cart"}):"",handleClick=async event=>{if(event.preventDefault(),type!=="mini")if(order?.id)location.href=href;else{const orderId=await createOrder();slug&&(location.href=getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart"}))}else publish("open-cart")},parentProps={handleClick,label,href,orderId:order?.id,accessToken,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,onClick:e=>{handleClick(e)},children:label}):null}export default CartLink;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null||endpoint==null)throw new Error("Cannot use `CheckoutLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=hostedCheckout&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,applicationType:"checkout",domain}):order?.checkout_url??"",parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,children:label})}export default CheckoutLink;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function DiscountAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"discount",...props})}export default DiscountAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function GiftCardAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"gift_card",...props})}export default GiftCardAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import useCustomContext from"../../utils/hooks/useCustomContext";import{useContext,useEffect,useState,useRef}from"react";import{iframeResizer}from"iframe-resizer";import{subscribe,unsubscribe}from"../../utils/events";const defaultIframeStyle={width:"1px",minWidth:"100%",minHeight:"100%",border:"none"},defaultContainerStyle={position:"fixed",top:"0",right:"-25rem",height:"100%",width:"23rem",transition:"right 0.5s ease-in-out",zIndex:"0"},defaultBackgroundStyle={opacity:"0",position:"fixed",top:"0",left:"0",height:"100%",width:"100vw",transition:"opacity 0.5s ease-in-out",zIndex:"-10",backgroundColor:"black"},defaultStyle={cart:defaultIframeStyle,container:defaultContainerStyle,background:defaultBackgroundStyle};export function HostedCart({type,openAdd=!1,style=defaultStyle,open=!1,handleOpen,...props}){const[isOpen,setOpen]=useState(!1),ref=useRef(null),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"HostedCart",key:"accessToken"}),[src,setSrc]=useState();if(accessToken==null||endpoint==null)return null;const{order,createOrder}=useContext(OrderContext),{persistKey}=useContext(OrderStorageContext),{domain,slug}=getDomain(endpoint);async function setOrder(openCart){const orderId=localStorage.getItem(persistKey)??await createOrder();orderId!=null&&accessToken!=null&&(setSrc(getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart"})),openCart&&setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300))}function onMessage(data){switch(data.message.type){case"update":break;case"close":type==="mini"&&(handleOpen!=null?handleOpen():setOpen(!1));break;case"blur":type==="mini"&&isOpen&&ref.current?.focus();break}}return useEffect(()=>{const orderId=localStorage.getItem(persistKey);let ignore=!1;return open!=null&&open!==isOpen&&setOpen(open),openAdd&&type==="mini"&&subscribe("open-cart",()=>{console.log("open-cart by event",src,order?.id,orderId),src==null&&order?.id==null&&orderId==null?setOrder(!0):(src!=null&&ref.current!=null&&(ref.current.src=src),setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300))}),src==null&&order?.id==null&&orderId==null&&accessToken!=null&&!ignore&&isOpen?setOrder():src==null&&(order?.id!=null||orderId!=null)&&setSrc(getApplicationLink({slug,orderId:order?.id??orderId,accessToken,domain,applicationType:"cart"})),src!=null&&ref.current!=null&&(ref.current.src=src),()=>{ignore=!0,openAdd&&type==="mini"&&unsubscribe("open-cart",()=>{})}},[src,open,order?.id]),useEffect(()=>{ref.current!=null&&iframeResizer({checkOrigin:!1,bodyPadding:"20px",onMessage},ref.current)},[ref.current!=null]),src==null?null:type==="mini"?_jsxs(_Fragment,{children:[_jsx("div",{style:{...style.background,opacity:isOpen?"0.5":style.background?.opacity,zIndex:isOpen?"1":style.background?.zIndex},onClick:()=>{handleOpen!=null?handleOpen():setOpen(!1)}}),_jsx("div",{style:{...style.container,right:isOpen?"0":style.container?.right,zIndex:isOpen?"10":style.container?.zIndex},...props,children:_jsx("iframe",{title:"Cart",ref,style:style.cart,src,width:"100%",height:"100%"})})]}):_jsx("iframe",{title:"Cart",ref,style:style.cart,src,width:"100%",height:"100%"})}
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder,addToCart}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import compareObjAttribute from"../../utils/compareObjAttribute";import useCustomContext from"../../utils/hooks/useCustomContext";export function OrderContainer(props){const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"OrderContainer",key:"accessToken"}),{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext),localOrder=persistKey?getLocalOrder(persistKey):orderId,getOrder=async()=>{localOrder&&await getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state})};useEffect(()=>{state?.orderId&&(localOrder!=null&&state.orderId!==localOrder?getOrder():dispatch({type:"setOrderId",payload:{orderId:void 0,order:void 0}}))},[persistKey]),useEffect(()=>{state.withoutIncludes||dispatch({type:"setLoading",payload:{loading:!0}})},[state.withoutIncludes]),useEffect(()=>{if(attributes&&state?.order&&!lock){const updateAttributes=compareObjAttribute({attributes,object:state.order});Object.keys(updateAttributes).length>0&&(updateOrder({id:state.order.id,attributes:updateAttributes,dispatch,config,include:state.include,state}),setLock(!0))}return()=>{if(attributes&&state?.order){const updateAttributes=compareObjAttribute({attributes,object:state.order});state.order&&Object.keys(updateAttributes).length===0&&setLock(!1)}}},[attributes,state?.order,lock]),useEffect(()=>{const startRequest=Object.keys(state?.includeLoaded||{}).filter(key=>state?.includeLoaded?.[key]===!0);return config.accessToken&&state.loading===!1&&state?.order==null?(localOrder&&!state.order&&state.include?.length===startRequest.length&&!state.withoutIncludes&&!lockOrder||state.withoutIncludes&&!state.include?.length&&startRequest.length===0)&&getOrder():[config.accessToken,state.order==null,state.loading,state.withoutIncludes].every(Boolean)?dispatch({type:"setLoading",payload:{loading:!1}}):[config.accessToken,state.order==null,state.loading,state.withoutIncludes===!1].every(Boolean)&&dispatch({type:"setLoading",payload:{loading:!1}}),()=>{state.order==null&&state.loading&&state.withoutIncludes===!1&&(state.include?.length===0&&startRequest.length>0?dispatch({type:"setLoading",payload:{loading:!1}}):state.include&&state.include?.length>0&&(dispatch({type:"setIncludesResource",payload:{include:[]}}),setLockOrder(!1)))}},[config.accessToken,Object.keys(state.includeLoaded??{}).length,state.include?.length,orderId,Object.keys(state?.order??{}).length,state.loading,state.withoutIncludes,lockOrder]);const orderValue=useMemo(()=>(fetchOrder!=null&&state?.order!=null&&fetchOrder(state.order),{...state,setOrder:order=>{setOrder(order,dispatch)},getOrder:async id=>await getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:async()=>await createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:async params=>await addToCart({...params,persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder}),saveAddressToCustomerAddressBook:args=>{defaultOrderContext.saveAddressToCustomerAddressBook({...args,dispatch})},setGiftCardOrCouponCode:async({code,codeType})=>await defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:async({codeType})=>await defaultOrderContext.removeGiftCardOrCouponCode({codeType,dispatch,order:state.order,config,include:state.include,state}),addResourceToInclude:args=>{defaultOrderContext.addResourceToInclude({...args,dispatch,resourcesIncluded:state.include,resourceIncludedLoaded:state.includeLoaded})},updateOrder:async args=>await defaultOrderContext.updateOrder({...args,dispatch,config,include:state.include,state})}),[state,config.accessToken,persistKey]);return _jsx(OrderContext.Provider,{value:orderValue,children})}export default OrderContainer;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useMemo,useState,useEffect}from"react";import CustomerContext from"../../context/CustomerContext";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import OrderListPagination from"../../context/OrderListPaginationContext";import{useReactTable,getCoreRowModel,getPaginationRowModel,getSortedRowModel,flexRender}from"@tanstack/react-table";import{sortDescIcon,sortAscIcon}from"../../utils/icons";import filterChildren from"../../utils/filterChildren";const rowComponents=["OrderListRow","OrderListEmpty"],paginationComponents=["OrderListPaginationInfo","OrderListPaginationButtons"];export function OrderList({type="orders",children,columns,loadingElement,showActions=!1,showPagination=!1,sortBy=[{id:"number",desc:!0}],pageSize=10,paginationContainerClassName,actionsComponent,actionsContainerClassName,theadClassName,rowTrClassName,...p}){const[loading,setLoading]=useState(!0),[sorting,setSorting]=useState(sortBy),[{pageIndex,pageSize:currentPageSize},setPagination]=useState({pageIndex:0,pageSize}),{orders,subscriptions,getCustomerOrders,getCustomerSubscriptions}=useContext(CustomerContext);useEffect(()=>{type==="orders"&&getCustomerOrders!=null&&getCustomerOrders({pageNumber:pageIndex,pageSize:currentPageSize}),type==="subscriptions"&&getCustomerSubscriptions!=null&&getCustomerSubscriptions({pageNumber:pageIndex,pageSize:currentPageSize})},[pageIndex,currentPageSize]);const data=useMemo(()=>type==="subscriptions"?subscriptions??[]:orders??[],[orders,subscriptions]),cols=useMemo(()=>columns,[columns]),pagination=useMemo(()=>({pageIndex,pageSize:currentPageSize}),[pageIndex,currentPageSize]),pageCount=orders?.pageCount??subscriptions?.pageCount??-1,table=useReactTable({data,columns:cols,getSortedRowModel:getSortedRowModel(),getCoreRowModel:getCoreRowModel(),getPaginationRowModel:getPaginationRowModel(),manualPagination:!0,pageCount,state:{sorting,pagination},onSortingChange:setSorting,onPaginationChange:setPagination}),TableHtmlElement="table",TheadHtmlElement="thead",TbodyHtmlElement="tbody",ThHtmlElement="th",TrHtmlElement="tr";useEffect(()=>(type==="orders"&&orders!=null&&setLoading(!1),type==="subscriptions"&&subscriptions!=null&&setLoading(!1),()=>{setLoading(!0)}),[orders,subscriptions]);const LoadingComponent=loadingElement||_jsx("div",{children:"Loading..."}),headerComponent=table.getHeaderGroups().map(headerGroup=>{const columns2=headerGroup.headers.map((header,k)=>{const sortLabel=header.column.getIsSorted()!==!1?header.column.getIsSorted():"";return _jsx(ThHtmlElement,{"data-testid":`thead-${k}`,"data-sort":`${sortLabel||""}`,children:_jsxs("span",{className:header.column.getCanSort()?"cursor-pointer select-none":"",onClick:header.column.getToggleSortingHandler(),children:[flexRender(header.column.columnDef.header,header.getContext()),{asc:sortAscIcon,desc:sortDescIcon}[header.column.getIsSorted()]??null]})},header.id)});return _jsx(TrHtmlElement,{children:columns2},headerGroup.id)}),rowsComponents=filterChildren({children,filterBy:rowComponents,componentName:"OrderList"}),components=table.getRowModel().rows.map(row=>{const childProps={type,orders:type==="orders"?orders:subscriptions,order:row.original,row,showActions,actionsComponent,actionsContainerClassName};return _jsx(TrHtmlElement,{className:rowTrClassName,children:_jsx(OrderListChildrenContext.Provider,{value:childProps,children:rowsComponents})},row.id)}),pagComponents=filterChildren({children,filterBy:paginationComponents,componentName:"OrderList"}),totalRows=orders?.meta.recordCount??subscriptions?.meta.recordCount??0,Pagination=()=>showPagination?_jsx(OrderListPagination.Provider,{value:{canNextPage:table.getCanNextPage(),canPreviousPage:table.getCanPreviousPage(),gotoPage:table.setPageIndex,nextPage:table.nextPage,pageCount:table.getPageCount(),pageIndex:table.getState().pagination.pageIndex,pageOptions:table.getPageOptions(),pageSize:table.getState().pagination.pageSize,previousPage:table.previousPage,setPageSize:table.setPageSize,totalRows},children:pagComponents}):null;return loading&&(orders==null||subscriptions==null)?_jsx(_Fragment,{children:LoadingComponent}):orders?.length===0||subscriptions?.length===0?_jsxs(OrderListChildrenContext.Provider,{value:{orders:type==="orders"?orders:subscriptions},children:[rowsComponents,_jsx(Pagination,{})]}):_jsxs(_Fragment,{children:[_jsxs(TableHtmlElement,{...p,children:[_jsx(TheadHtmlElement,{className:theadClassName,children:headerComponent}),_jsx(TbodyHtmlElement,{children:components})]}),totalRows<=pageSize?null:_jsx("div",{className:paginationContainerClassName,children:_jsx(Pagination,{})})]})}export default OrderList;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import{useContext}from"react";export function OrderListEmpty(props){const{children,emptyText="No orders available",...p}=props,{orders}=useContext(OrderListChildrenContext),parentProps={emptyText,...p};return orders!=null&&orders.length>0?null:children!==void 0?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:emptyText})}OrderListEmpty.displayName="OrderListEmpty";export default OrderListEmpty;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import Parent from"../utils/Parent";import OrderListPaginationContext from"../../context/OrderListPaginationContext";import useCustomContext from"../../utils/hooks/useCustomContext";import omit from"../../utils/omit";export function OrderListPaginationButtons({previousPageButton,nextPageButton,navigationButtons,children,...props}){const{...prevButton}={show:!0,...previousPageButton},{...nextButton}={show:!0,...nextPageButton},{...navButton}={show:!0,...navigationButtons},ctx=useCustomContext({context:OrderListPaginationContext,contextComponentName:"OrderList",currentComponentName:"OrderListPaginationButtons",key:"totalRows"}),PrevButton=prevButton.show?prevButton.hideWhenDisabled===!0&&ctx?.canPreviousPage===!1?null:_jsx("button",{"data-testid":"prev-button",...omit(prevButton,["show","hideWhenDisabled"]),disabled:ctx?.canPreviousPage===!1,onClick:()=>ctx?.previousPage(),children:previousPageButton?.label??"<"}):null,NextButton=nextButton.show?nextButton.hideWhenDisabled===!0&&ctx?.canNextPage===!1?null:_jsx("button",{"data-testid":"next-button",...omit(nextButton,["show","hideWhenDisabled"]),disabled:ctx?.canNextPage===!1,onClick:()=>ctx?.nextPage(),children:nextButton?.label??">"}):null,pagesToShow=ctx?.canPreviousPage===!1?ctx?.pageOptions.slice(0,3).map(v=>v+1):ctx?.canNextPage===!1?ctx?.pageOptions.slice(ctx?.pageOptions.length-3,ctx?.pageOptions.length).map(v=>v+1):ctx?.pageOptions.slice(ctx?.pageIndex-1,ctx?.pageIndex+2).map(v=>v+1),NavButtons=navButton.show?pagesToShow?.map(v=>{const className=(ctx?.pageIndex!=null?ctx?.pageIndex+1:1)===v?`${navButton?.className??""} ${navButton?.activeClassName??""}`:navButton?.className;return _jsx("button",{"data-testid":`page-${v}`,...omit(navButton,["show","activeClassName","className"]),className,onClick:()=>ctx?.gotoPage(v-1),children:v},`page-${v}`)}):null,parentProps={navigationButtons,prevButton,nextButton,...ctx,...props};return children==null?ctx?.totalRows===0?null:_jsxs("div",{...props,children:[PrevButton,NavButtons,NextButton]}):_jsx(Parent,{...parentProps,children})}OrderListPaginationButtons.displayName="OrderListPaginationButtons";export default OrderListPaginationButtons;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import OrderListPaginationContext from"../../context/OrderListPaginationContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function OrderListPaginationInfo({as="span",children,...props}){const ctx=useCustomContext({context:OrderListPaginationContext,contextComponentName:"OrderList",currentComponentName:"OrderListPaginationInfo",key:"totalRows"}),TagElement=as,totRows=ctx?.totalRows??0,pageIndex=ctx?.pageIndex??0,pageSize=ctx?.pageSize??10;let firstRow=pageIndex===0?pageIndex+1:pageIndex,lastRow=firstRow*pageSize;ctx?.canPreviousPage===!0&&(firstRow=Math.floor(firstRow*pageSize)+1,lastRow=Math.floor(firstRow+pageSize-1)),ctx?.canNextPage===!1&&(lastRow=totRows);const parentProps={...props,as,firstRow,lastRow,totRows};return children==null?totRows===0?null:_jsx(TagElement,{...props,children:`${firstRow} - ${lastRow} of ${totRows}`}):_jsx(Parent,{...parentProps,children})}OrderListPaginationInfo.displayName="OrderListPaginationInfo";export default OrderListPaginationInfo;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{createElement as _createElement}from"react";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import isDate from"../../utils/isDate";import last from"lodash/last";import{flexRender}from"@tanstack/react-table";export function OrderListRow({field,children,...p}){const{order,row,showActions,actionsComponent,actionsContainerClassName}=useContext(OrderListChildrenContext),cell=row?.getVisibleCells().filter(cell2=>cell2.column.id===field),isLastRow=last(row?.getVisibleCells())?.column.id===field,As="td",ActionRow=()=>showActions&&isLastRow&&actionsComponent&&_jsx(As,{"data-testid":"action-cell",...p,className:actionsContainerClassName,children:_jsx(Parent,{...parentProps,children:actionsComponent})})||null,parentProps={...p,field,order,row,cell};return children?_jsxs(As,{children:[_jsx(Parent,{...parentProps,children}),_jsx(ActionRow,{})]}):_jsxs(_Fragment,{children:[cell?.map((cell2,k)=>{const cellValue=cell2.getValue(),value=isDate(cellValue)?new Date(Date.parse(cellValue)).toLocaleString():flexRender(cell2.column.columnDef.cell,cell2.getContext());return _createElement(As,{"data-testid":`cell-${k}`,...p,key:cell2.id},value)}),_jsx(ActionRow,{})]})}OrderListRow.displayName="OrderListRow";export default OrderListRow;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseField from"../utils/BaseField";export function OrderNumber(props){return _jsx(BaseField,{attribute:"number",...props})}export default OrderNumber;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import OrderStorageContext from"../../context/OrderStorageContext";import{getLocalOrder,setLocalOrder,deleteLocalOrder}from"../../utils/localStorage";export function OrderStorage(props){const{children,clearWhenPlaced=!0,...p}=props;return _jsx(OrderStorageContext.Provider,{value:{...p,setLocalOrder,getLocalOrder,deleteLocalOrder,clearWhenPlaced},children})}export default OrderStorage;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function PaymentMethodAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"payment_method",...props})}export default PaymentMethodAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import PlaceOrderContext from"../../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import getCardDetails from"../../utils/getCardDetails";export function PlaceOrderButton(props){const ref=useRef(null),{children,label="Place order",autoPlaceOrder=!0,disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{paymentType==="stripe_payments"&&options?.stripe?.redirectStatus==="succeeded"&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.stripe?.redirectStatus,paymentType]),useEffect(()=>{if(order?.status!=null&&["draft","pending"].includes(order?.status))if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&paymentSource!=null){const attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult}},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode,errorCode=res?.payment_response?.errorCode,message=res?.payment_response?.message;["Authorised","Pending","Received"].includes(resultCode)&&autoPlaceOrder?handleClick():errorCode!=null&&setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])})}else(paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&autoPlaceOrder||paymentType==="adyen_payments"&&order?.payment_source?.payment_response?.resultCode==="Authorised"&&ref?.current?.disabled===!1&&autoPlaceOrder)&&handleClick()},[options?.adyen,paymentType,order?.payment_source?.payment_response?.resultCode]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async e=>{e?.preventDefault(),e?.stopPropagation();let isValid=!0;setForceDisable(!0);const checkPaymentSource=await setPaymentSource({paymentResource:paymentType,paymentSourceId:paymentSource?.id}),card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:checkPaymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit(checkPaymentSource),!isValid&&checkPaymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(checkPaymentSource||isFree)&&await setPlaceOrder({paymentSource:checkPaymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps={...p,label,disabled:disabledButton,handleClick,ref};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:e=>{handleClick(e)},...p,children:isFunction(label)?label():label})}export default PlaceOrderButton;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import PlaceOrderContext from"../../context/PlaceOrderContext";import{useContext,useEffect,useReducer}from"react";import placeOrderReducer,{placeOrderInitialState,placeOrderPermitted,setButtonRef}from"../../reducers/PlaceOrderReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import{setPlaceOrder}from"../../reducers/PlaceOrderReducer";import useCustomContext from"../../utils/hooks/useCustomContext";export function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=useReducer(placeOrderReducer,placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&placeOrderPermitted({config,dispatch,order,options:{...options}})},[order,include,includeLoaded]);const contextValue={...state,setPlaceOrder:async({paymentSource})=>await setPlaceOrder({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>{placeOrderPermitted({config,dispatch,order,options:{...options}})},setButtonRef:ref=>{setButtonRef(ref,dispatch)}};return _jsx(PlaceOrderContext.Provider,{value:contextValue,children})}export default PlaceOrderContainer;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import PlaceOrderContext from"../../context/PlaceOrderContext";import{useContext,useEffect,useState}from"react";import BaseInput from"../utils/BaseInput";export function PrivacyAndTermsCheckbox(props){const{order}=useContext(OrderContext),{placeOrderPermitted}=useContext(PlaceOrderContext),[forceDisabled,setForceDisabled]=useState(!0),[checked,setChecked]=useState(!1),fieldName="privacy-terms",handleChange=e=>{const v=e.target?.checked;setChecked(v),localStorage.setItem(fieldName,v.toString()),placeOrderPermitted&&placeOrderPermitted()};return useEffect(()=>(order?.privacy_url&&order?.terms_url&&setForceDisabled(!1),checked||localStorage.setItem(fieldName,checked.toString()),()=>{setForceDisabled(!0),localStorage.removeItem(fieldName)}),[order?.privacy_url,order?.terms_url]),_jsx(BaseInput,{type:"checkbox",name:fieldName,disabled:forceDisabled,onChange:handleChange,checked,...props})}export default PrivacyAndTermsCheckbox;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function ShippingAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"shipping",...props})}export default ShippingAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function SubTotalAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"subtotal",...props})}export default SubTotalAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function TaxesAmount(props){return _jsx(BaseOrderPrice,{base:"amount",type:"total_tax",...props})}export default TaxesAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"../utils/BaseOrderPrice";export function TotalAmount(props){return _jsx(BaseOrderPrice,{base:"total_amount",type:"with_taxes",...props})}export default TotalAmount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import GenericFieldComponent from"../utils/GenericFieldComponent";import ParcelChildrenContext from"../../context/ParcelChildrenContext";export function ParcelField(props){const{attribute,tagElement="span",children,...p}=props;return _jsx(GenericFieldComponent,{resource:"parcel",attribute,tagElement,context:ParcelChildrenContext,...p,children})}export default ParcelField;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import ParcelChildrenContext from"../../context/ParcelChildrenContext";import ParcelLineItemChildrenContext from"../../context/ParcelLineItemChildrenContext";import{useContext}from"react";export function ParcelLineItem({children}){const{parcel}=useContext(ParcelChildrenContext),components=parcel?.parcel_line_items?.map((parcelLineItem,key)=>_jsx(ParcelLineItemChildrenContext.Provider,{value:{parcelLineItem},children},key));return _jsx(_Fragment,{children:components})}export default ParcelLineItem;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import GenericFieldComponent from"../utils/GenericFieldComponent";import ParcelLineItemChildrenContext from"../../context/ParcelLineItemChildrenContext";export function ParcelLineItemField(props){const{attribute,tagElement="span",children,...p}=props;return _jsx(GenericFieldComponent,{resource:"parcelLineItem",attribute,tagElement,context:ParcelLineItemChildrenContext,...p,children})}export default ParcelLineItemField;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import ParcelChildrenContext from"../../context/ParcelChildrenContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function ParcelLineItemsCount({children,...p}){const{parcel}=useCustomContext({context:ParcelChildrenContext,contextComponentName:"Parcels",currentComponentName:"ParcelLineItemsCount",key:"parcel"}),quantity=parcel?.parcel_line_items?.length??0,childrenProps={...p,quantity,parcel};return children?_jsx(Parent,{...childrenProps,children}):_jsx("span",{...p,children:quantity})}export default ParcelLineItemsCount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import ParcelChildrenContext from"../../context/ParcelChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import{useContext}from"react";export function Parcels({children,filterBy}){const{parcels}=useContext(ShipmentChildrenContext),components=parcels?.filter(parcel=>filterBy?.includes(parcel.id)??!0).map((parcel,key)=>_jsx(ParcelChildrenContext.Provider,{value:{parcel},children},key));return _jsx(_Fragment,{children:components})}export default Parcels;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function ParcelsCount({children,...p}){const{parcels}=useCustomContext({context:ShipmentChildrenContext,contextComponentName:"ShipmentsContainer",currentComponentName:"ParcelsCount",key:"parcels"}),quantity=parcels?.length??0,childrenProps={...p,quantity,parcels};return children?_jsx(Parent,{...childrenProps,children}):_jsx("span",{...p,children:quantity})}export default ParcelsCount;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import AdyenPayment from"../payment_source/AdyenPayment";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import jwt from"../../utils/jwt";import getCardDetails from"../../utils/getCardDetails";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";export function AdyenGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{accessToken}=useContext(CommerceLayerContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="adyen_payments",locale=order?.language_code,paymentMethods=paymentSource?.payment_methods;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientKey=paymentSource?.public_key,environment=accessToken&&jwt(accessToken).test?"test":"live",paymentConfig=getPaymentAttributes({resource:paymentResource,config:config??{},keys:["adyen_payments"]})?.adyenPayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="adyen_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?clientKey&&!loading&&paymentMethods?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(AdyenPayment,{templateCustomerSaveToWallet,clientKey,locale,environment,config:paymentConfig})]}):loaderComponent:clientKey&&!loading&&paymentMethods?_jsx(AdyenPayment,{clientKey,locale,config:paymentConfig,environment}):loaderComponent}export default AdyenGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import BraintreePayment from"../payment_source/BraintreePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import{useContext}from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";export function BraintreeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{payments,isGuest}=useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="braintree_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const authorization=paymentSource?.client_token,paymentConfig=getPaymentAttributes({resource:paymentResource,config:config??{},keys:["braintree_payments"]})?.braintreePayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type==="braintree_payments"):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?authorization&&!loading?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(BraintreePayment,{templateCustomerSaveToWallet,authorization,locale,config:paymentConfig})]}):loaderComponent:authorization&&!loading?_jsx(BraintreePayment,{locale,authorization,config:paymentConfig}):loaderComponent}export default BraintreeGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import CheckoutComPayment from"../payment_source/CheckoutComPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";import getCardDetails from"../../utils/getCardDetails";export function CheckoutComGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="checkout_com_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const publicKey=paymentSource?.public_key,paymentConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return card.brand?_jsx(PaymentSourceContext.Provider,{value,children}):null}return!isGuest&&templateCustomerCards?publicKey&&!loading?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(CheckoutComPayment,{show,templateCustomerSaveToWallet,publicKey,locale,...paymentConfig})]}):loaderComponent:publicKey&&!loading?_jsx(CheckoutComPayment,{show,publicKey,locale,...paymentConfig}):loaderComponent}export default CheckoutComGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import ExternalPayment from"../payment_source/ExternalPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function ExternalGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="external_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const paymentSourceToken=paymentSource?.payment_source_token,paymentSourceId=order?.payment_source?.id||paymentSource?.id,paymentConfig=(config?getPaymentConfig(paymentResource,config):{})?.externalPayment,customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(ExternalPayment,{show,templateCustomerSaveToWallet,paymentSourceToken,locale,...paymentConfig})]}):paymentSourceToken&&!loading&&paymentSourceId?_jsx(ExternalPayment,{show,paymentSourceToken,locale,...paymentConfig}):loaderComponent}export default ExternalGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import React from"react";import KlarnaPayment from"../payment_source/KlarnaPayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function KlarnaGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,loading,loaderComponent,...p}=props,{order}=React.useContext(OrderContext),{payment}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="klarna_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const clientToken=paymentSource?.client_token,klarnaConfig=config?getPaymentConfig(paymentResource,config):{},customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=paymentSource?.options?.card,value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(KlarnaPayment,{clientToken,locale,...klarnaConfig})]}):clientToken&&!loading?_jsx(KlarnaPayment,{clientToken,locale,...klarnaConfig}):loaderComponent}export default KlarnaGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../../utils/getLoaderComponent";import AdyenGateway from"./AdyenGateway";import StripeGateway from"./StripeGateway";import BraintreeGateway from"./BraintreeGateway";import PaypalGateway from"./PaypalGateway";import WireTransferGateway from"./WireTransferGateway";import CustomerContext from"../../context/CustomerContext";import CheckoutComGateway from"./CheckoutComGateway";import KlarnaGateway from"./KlarnaGateway";import{getExternalPaymentAttributes,getPaypalAttributes}from"../../utils/getPaymentAttributes";import ExternalGateway from"./ExternalGateway";export function PaymentGateway({readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading...",...p}){const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment,expressPayments}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment?.payment_source_type;useEffect(()=>{if(payment?.id===currentPaymentMethodId&&paymentResource&&order?.payment_method?.payment_source_type===paymentResource&&!expressPayments){let attributes={};config!=null&&paymentResource==="paypal_payments"&&(attributes=getPaypalAttributes(paymentResource,config)),config!=null&&paymentResource==="external_payments"&&(attributes=getExternalPaymentAttributes(paymentResource,config));const setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&getCustomerPaymentSources()};(!paymentSource&&order?.payment_method.id&&show&&!expressPayments||(!paymentSource&&!expressPayments||paymentSource?.type!==paymentResource)&&show)&&setPaymentSources(),paymentSource?.mismatched_amounts&&show&&setPaymentSources(),setLoading(!1)}return expressPayments&&setLoading(!1),()=>{setLoading(!0)}},[order?.payment_method?.id,show,paymentSource]);const gatewayConfig={readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet,...p};switch(paymentResource){case"adyen_payments":return _jsx(AdyenGateway,{...gatewayConfig,children});case"braintree_payments":return _jsx(BraintreeGateway,{...gatewayConfig,children});case"checkout_com_payments":return _jsx(CheckoutComGateway,{...gatewayConfig,children});case"external_payments":return _jsx(ExternalGateway,{...gatewayConfig,children});case"klarna_payments":return _jsx(KlarnaGateway,{...gatewayConfig,children});case"stripe_payments":return _jsx(StripeGateway,{...gatewayConfig,children});case"wire_transfers":return _jsx(WireTransferGateway,{...gatewayConfig,children});case"paypal_payments":return _jsx(PaypalGateway,{...gatewayConfig,children});default:return null}}export default PaymentGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import PaypalPayment from"../payment_source/PaypalPayment";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";import{getPaymentAttributes}from"../../utils/getPaymentAttributes";import isEmpty from"lodash/isEmpty";import{useContext}from"react";export function PaypalGateway(props){const{readonly,showCard,handleEditClick,children,...p}=props,{order}=useContext(OrderContext),{payment}=useContext(PaymentMethodChildrenContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="paypal_payments";if(!readonly&&payment?.id!==currentPaymentMethodId)return null;if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:order?.payment_source||paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}const infoMessage=getPaymentAttributes({resource:paymentResource,config:config??{},keys:["paypal_payments"]})?.paypalPayment?.infoMessage;return delete p.show,delete p.templateCustomerCards,delete p.templateCustomerSaveToWallet,delete p.loading,delete p.loaderComponent,delete p.onClickCustomerCards,_jsx(PaypalPayment,{...p,infoMessage})}export default PaypalGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import StripePayment from"../payment_source/StripePayment";import CustomerContext from"../../context/CustomerContext";import OrderContext from"../../context/OrderContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import getCardDetails from"../../utils/getCardDetails";import isEmpty from"lodash/isEmpty";import React from"react";import PaymentCardsTemplate from"../utils/PaymentCardsTemplate";export function StripeGateway(props){const{readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,loaderComponent,templateCustomerSaveToWallet,...p}=props,{order}=React.useContext(OrderContext),{payment,expressPayments}=React.useContext(PaymentMethodChildrenContext),{payments,isGuest}=React.useContext(CustomerContext),{currentPaymentMethodId,config,paymentSource}=React.useContext(PaymentMethodContext),paymentResource="stripe_payments",locale=order?.language_code;if(!readonly&&payment?.id!==currentPaymentMethodId)return null;const publishableKey=paymentSource?.publishable_key,clientSecret=paymentSource?.client_secret,paymentSourceId=order?.payment_source?.id||paymentSource?.id,stripeConfig=config?getPaymentConfig(paymentResource,config).stripePayment:{};console.log("stripeConfig",stripeConfig);const customerPayments=!isEmpty(payments)&&payments?payments.filter(customerPayment=>customerPayment.payment_source?.type===paymentResource):[];if(readonly||showCard){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType:paymentResource}),value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}return!isGuest&&templateCustomerCards?_jsxs(_Fragment,{children:[isEmpty(customerPayments)?null:_jsx("div",{className:p.className,children:_jsx(PaymentCardsTemplate,{paymentResource,customerPayments,children:templateCustomerCards})}),_jsx(StripePayment,{show,templateCustomerSaveToWallet,publishableKey,clientSecret,expressPayments,locale,...stripeConfig})]}):publishableKey&&!loading&&paymentSourceId?_jsx(StripePayment,{show,publishableKey,clientSecret,locale,expressPayments,...stripeConfig}):loaderComponent}export default StripeGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import WireTransferPayment from"../payment_source/WireTransferPayment";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentSourceContext from"../../context/PaymentSourceContext";import{getPaymentConfig}from"../../reducers/PaymentMethodReducer";import isEmpty from"lodash/isEmpty";import{useContext}from"react";export function WireTransferGateway(props){const{readonly,showCard,handleEditClick,children,...p}=props,{payment}=useContext(PaymentMethodChildrenContext),{currentPaymentMethodId,config,paymentSource}=useContext(PaymentMethodContext),paymentResource="wire_transfers";if(!readonly&&payment?.id!==currentPaymentMethodId)return null;if(readonly||showCard){const card=paymentSource?.options?.card||paymentSource?.metadata?.card,value={...card,showCard,handleEditClick,readonly};return isEmpty(card)?null:_jsx(PaymentSourceContext.Provider,{value,children})}const wireTransferConfig=config&&paymentResource?getPaymentConfig(paymentResource,config):{};return _jsx(WireTransferPayment,{...p,...wireTransferConfig?.wireTransfer})}export default WireTransferGateway;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import getLoaderComponent from"../../utils/getLoaderComponent";import useCustomContext from"../../utils/hooks/useCustomContext";import OrderContext from"../../context/OrderContext";import CustomerContext from"../../context/CustomerContext";import{getExternalPaymentAttributes,getPaypalAttributes}from"../../utils/getPaymentAttributes";import{isEmpty}from"../../utils/isEmpty";import{getAvailableExpressPayments}from"../../utils/expressPaymentHelper";export function PaymentMethod({children,className,activeClass,loader="Loading...",clickableContainer,autoSelectSinglePaymentMethod,expressPayments,hide,onClick,...p}){const[loading,setLoading]=useState(!0),[paymentSelected,setPaymentSelected]=useState(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder,paymentSource,setPaymentSource,config}=useCustomContext({context:PaymentMethodContext,contextComponentName:"PaymentMethodsContainer",currentComponentName:"PaymentMethod",key:"paymentMethods"}),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext);useEffect(()=>{if(paymentMethods!=null&&!isEmpty(paymentMethods)&&expressPayments){const[paymentMethod]=getAvailableExpressPayments(paymentMethods);!paymentSource&&paymentMethod!=null&&(async()=>{setLoadingPlaceOrder({loading:!0}),setPaymentSelected(paymentMethod.id);const paymentMethodId=paymentMethod?.id,paymentResource=paymentMethod?.payment_source_type;await setPaymentMethod({paymentResource,paymentMethodId}),await setPaymentSource({paymentResource,order})&&paymentMethod&&onClick!=null&&(onClick({payment:paymentMethod,order}),setTimeout(()=>{setLoading(!1)},200)),setLoadingPlaceOrder({loading:!1})})()}},[!isEmpty(paymentMethods),expressPayments]),useEffect(()=>{paymentMethods!=null&&autoSelectSinglePaymentMethod!=null&&!expressPayments&&(async()=>{if(paymentMethods.length===1){const[paymentMethod]=paymentMethods??[];if(paymentMethod&&!paymentSource){setLoadingPlaceOrder({loading:!0}),setPaymentSelected(paymentMethod.id);const paymentMethodId=paymentMethod?.id,paymentResource=paymentMethod?.payment_source_type;await setPaymentMethod({paymentResource,paymentMethodId});let attributes={};config!=null&&paymentResource==="paypal_payments"&&(attributes=getPaypalAttributes(paymentResource,config)),config!=null&&paymentResource==="external_payments"&&(attributes=getExternalPaymentAttributes(paymentResource,config)),await setPaymentSource({paymentResource,order,attributes})&&paymentMethod&&onClick!=null&&(onClick({payment:paymentMethod,order}),setTimeout(()=>{setLoading(!1)},200)),getCustomerPaymentSources&&getCustomerPaymentSources(),setLoadingPlaceOrder({loading:!1})}typeof autoSelectSinglePaymentMethod=="function"&&autoSelectSinglePaymentMethod()}else setTimeout(()=>{setLoading(!1)},200)})()},[paymentMethods,expressPayments]),useEffect(()=>(paymentMethods&&(paymentMethods.length===1&&autoSelectSinglePaymentMethod?paymentSource&&setTimeout(()=>{setLoading(!1)},200):setLoading(!1)),currentPaymentMethodId&&setPaymentSelected(currentPaymentMethodId),()=>{setLoading(!0)}),[paymentMethods,currentPaymentMethodId]);const components=paymentMethods?.filter(payment=>{if(Array.isArray(hide)){const source=payment?.payment_source_type;return!hide?.includes(source)}else if(typeof hide=="function")return hide(payment);return!0}).map((payment,k)=>{const isActive=currentPaymentMethodId===payment?.id,paymentMethodProps={payment,clickableContainer,paymentSelected,setPaymentSelected,expressPayments},paymentResource=payment?.payment_source_type,onClickable=clickableContainer?async e=>{e.stopPropagation(),setLoadingPlaceOrder({loading:!0}),setPaymentSelected(payment.id);const paymentMethodId=payment?.id,{order:order2}=await setPaymentMethod({paymentResource,paymentMethodId});onClick&&onClick({payment,order:order2}),setLoadingPlaceOrder({loading:!1})}:void 0;return _jsx("div",{"data-testid":paymentResource,className:`${className??""} ${isActive&&activeClass!=null?activeClass:""}`,onClick:onClickable,...p,children:_jsx(PaymentMethodChildrenContext.Provider,{value:paymentMethodProps,children})},k)});return loading?getLoaderComponent(loader):_jsx(_Fragment,{children:components})}export default PaymentMethod;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodName(props){const{payment}=useCustomContext({context:PaymentMethodChildrenContext,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodName",key:"payment"}),labelName=payment?.name,htmlFor=payment?.payment_source_type,paymentGateway=payment?.payment_gateway,parentProps={htmlFor,labelName,paymentGateway,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("label",{htmlFor,...props,children:labelName})}export default PaymentMethodName;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect}from"react";import getAmount from"../../utils/getAmount";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodPrice(props){const{format="formatted",type="amount",labelFree="Free",...p}=props,{payment}=useCustomContext({context:PaymentMethodChildrenContext,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodPrice",key:"payment"}),[price,setPrice]=useState(""),[priceCents,setPriceCents]=useState(0);useEffect(()=>{if(payment){const p2=getAmount({base:"price",type,format,obj:payment});setPrice(p2);const c=getAmount({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps={labelFree,price,priceCents,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:priceCents===0?labelFree:price})}export default PaymentMethodPrice;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import Parent from"../utils/Parent";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function PaymentMethodRadioButton(props){const{onChange,...p}=props,{payment,paymentSelected,setPaymentSelected,clickableContainer}=useCustomContext({context:PaymentMethodChildrenContext,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodRadioButton",key:"payment"}),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=payment?.id,name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=async e=>{if(e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer){const{order:order2}=await setPaymentMethod({paymentResource,paymentMethodId});onChange&&onChange({payment,order:order2})}setLoading({loading:!1})},id=payment?.payment_source_type,parentProps={handleOnChange,checked,id,name,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("input",{title:name,type:"radio",id,onChange:e=>{handleOnChange(e)},checked,...p})}export default PaymentMethodRadioButton;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig,setPaymentRef}from"../../reducers/PaymentMethodReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import useCustomContext from"../../utils/hooks/useCustomContext";import{isEmpty}from"../../utils/isEmpty";export function PaymentMethodsContainer(props){const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"PaymentMethodsContainer",key:"order"}),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{include?.includes("available_payment_methods")?includeLoaded?.available_payment_methods||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0,"line_items.line_item_options.sku_option":!0,"line_items.item":!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method","line_items.line_item_options.sku_option","line_items.item"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&!state.paymentMethods&&getPayMethods(),order?.payment_source&&dispatch({type:"setPaymentSource",payload:{paymentSource:order?.payment_source}}),order?.payment_source===null&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},[order,credentials,include?.length,Object.keys(includeLoaded??[]).length]);const contextValue=useMemo(()=>({...state,setLoading:({loading})=>{defaultPaymentMethodContext.setLoading({loading,dispatch})},setPaymentRef:({ref})=>{setPaymentRef({ref,dispatch})},setPaymentMethodErrors:errors=>{defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch)},setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod({...args,config:credentials,updateOrder,order,dispatch,setOrderErrors}),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource({...state,...args,config:credentials,dispatch,getOrder,updateOrder,order}),updatePaymentSource:async args=>{await defaultPaymentMethodContext.updatePaymentSource({...args,config:credentials,dispatch})},destroyPaymentSource:async args=>{await defaultPaymentMethodContext.destroyPaymentSource({...args,dispatch,config:credentials,updateOrder,orderId:order?.id})}}),[state]);return _jsx(PaymentMethodContext.Provider,{value:contextValue,children})}export default PaymentMethodsContainer;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import{setCustomerOrderParam}from"../../utils/localStorage";import Parent from"../utils/Parent";import getBrowserInfo,{cleanUrlBy}from"../../utils/browserInfo";import PlaceOrderContext from"../../context/PlaceOrderContext";import OrderContext from"../../context/OrderContext";import omit from"../../utils/omit";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};export function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState(),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{placeOrderButtonRef}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component?.submit&&component.submit(),!1},handleChange=async(state,_component)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=async()=>await handleSubmit(ref.current,checkout),setPaymentRef({ref}));const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}};paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,component)=>{const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=pSource?.payment_response?.action,resultCode=pSource?.payment_response?.resultCode;if(adyenAction&&component)return component.handleAction(adyenAction),!1;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current.click()),!0;if(["Cancelled","Refused"].includes(resultCode)){const message=pSource?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),component&&component.mount("#adyen-dropin")}return!1}catch(error){return console.error("Adyen additional details error:",error),!1}},onSubmit=async(state,component)=>{const browserInfo=getBrowserInfo(),saveCustomer=document.getElementById("save_payment_source_to_customer_wallet"),url=cleanUrlBy();let control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"});if(control?.payment_response?.resultCode==="Authorised")return!0;const paymentDataAvailable=Object.keys(control?.payment_request_data).length>0,paymentMethodSelected=control?.payment_request_data?.payment_method?.type,paymentMethod=saveCustomer?.checked?state.data.paymentMethod:omit(state.data.paymentMethod,["encryptedCardNumber","encryptedExpiryMonth","encryptedExpiryYear","encryptedSecurityCode"]);(!paymentDataAvailable||paymentMethodSelected!==state.data.paymentMethod.type)&&(control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes:{payment_request_data:{...state.data,payment_method:paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}}}));const attributes={payment_request_data:{...state.data,payment_method:paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}},_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=res?.payment_response?.action;if(component&&action)return component.handleAction(action),!1;const resultCode=res?.payment_response?.resultCode;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current.click()),!0;if(["Cancelled"].includes(resultCode)){const message=res?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}if(res?.payment_response?.errorType)if(res?.payment_response?.errorCode==="14_006")onSubmit(state,component);else{const message=res?.payment_response?.message;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}};return useEffect(()=>{const paymentMethodsResponse=paymentSource?.payment_methods?.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],[firstPaymentMethod]=paymentMethodsResponse,isOnlyCard=paymentMethodsResponse?.length===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse:{paymentMethods:paymentMethodsResponse},showPayButton:!1,paymentMethodsConfiguration:{threeDS2:threeDSConfiguration,paypal:{showPayButton:!0,style:styles?.paypal},card:{styles:styles?.card,holderNameRequired:!1}},onAdditionalDetails:(state,element)=>{handleOnAdditionalDetails(state,element)},onChange:(state,element)=>{handleChange(state,element)},onSubmit:(state,element)=>{onSubmit(state,element)}};return!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&import("@adyen/adyen-web").then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=async()=>await handleSubmit(ref.current,component2):ref.current.onsubmit=null,setPaymentRef({ref}))}}).mount("#adyen-dropin");component&&(setCheckout(component),setLoadAdyen(!0))})}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",{ref,onSubmit:e=>{handleSubmit(e,checkout)},children:[_jsx("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}export default AdyenPayment;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import{setCustomerOrderParam}from"../../utils/localStorage";import promisify from"../../utils/promisify";const defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"};export function BraintreePayment({authorization,config,templateCustomerSaveToWallet}){const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}={...defaultConfig,...config},[loadBraintree,setLoadBraintree]=useState(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),ref=useRef(null),handleSubmitForm=async({event,hostedFieldsInstance,threeDSInstance})=>{const savePaymentSourceToCustomerWallet=event?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=await promisify(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order?.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:order?.total_amount_with_taxes_float,email:order?.customer_email??"",billingAddress:{givenName:billingAddress?.first_name??"",surname:billingAddress?.last_name??"",phoneNumber:billingAddress?.phone,streetAddress:billingAddress?.line_1,countryCodeAlpha2:billingAddress?.country_code,postalCode:billingAddress?.zip_code??"",region:billingAddress?.state_code,locality:billingAddress?.city},onLookupComplete:(_data,next)=>{next()}},response=await threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}}),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1};return useEffect(()=>{if(!ref&&authorization&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!isEmpty(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,threeDSInstance)=>{threeDSecureErr&&(console.error("3DSecure error",threeDSecureErr),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:threeDSecureErr.message}])),ref.current&&(ref.current.onsubmit=async paymentSource2=>await handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:_jsx("div",{className:containerClassName,children:_jsxs("form",{ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName,children:[_jsxs("div",{className:fieldsContainerClassName,children:[_jsxs("div",{className:cardContainerClassName,children:[_jsx("label",{className:fieldLabelClassName,htmlFor:"card-number",children:fields?.number?.label}),_jsx("div",{className:inputWrapperClassName,id:"card-number"})]}),_jsxs("div",{className:cardDetailsContainerClassName,children:[_jsxs("div",{className:expDateContainerClassName,children:[_jsx("label",{className:fieldLabelClassName,htmlFor:"expiration-date",children:fields?.expirationDate?.label}),_jsx("div",{className:inputWrapperClassName,id:"expiration-date"})]}),_jsxs("div",{className:cvvContainerClassName,children:[_jsx("label",{className:fieldLabelClassName,htmlFor:"cvv",children:fields?.cvv?.label}),_jsx("div",{className:inputWrapperClassName,id:"cvv"})]})]})]}),_jsx("div",{className:fieldsContainerClassName,children:templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})})]})})}export default BraintreePayment;
@@ -1 +1,2 @@
1
+ "use client";
1
2
  import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useRef}from"react";import useExternalScript from"../../utils/hooks/useExternalScript";import PaymentMethodContext from"../../context/PaymentMethodContext";import{Frames,CardNumber,ExpiryDate,Cvv}from"frames-react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import{setCustomerOrderParam}from"../../utils/localStorage";const scriptUrl="https://cdn.checkout.com/js/framesv2.min.js",systemLanguages=["DE-DE","EN-GB","ES-ES","FR-FR","IT-IT","KR-KR","NL-NL"],defaultOptions={style:{base:{color:"black",fontSize:"18px"},autofill:{backgroundColor:"yellow"},hover:{color:"blue"},focus:{color:"blue"},valid:{color:"green"},invalid:{color:"red"},placeholder:{base:{color:"gray"},focus:{border:"solid 1px blue"}}}};export function CheckoutComPayment({publicKey,options=defaultOptions,locale="EN-GB",...p}){const ref=useRef(null),loaded=useExternalScript(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{containerClassName,templateCustomerSaveToWallet,successUrl=window.location.href,failureUrl=window.location.href,show,...divProps}=p,handleSubmit=async()=>{const savePaymentSourceToCustomerWallet=ref?.current?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:order?.billing_address?.full_name,billingAddress:{addressLine1:order?.billing_address?.line_1,addressLine2:order?.billing_address?.line_2??"",zip:order?.billing_address?.zip_code??"",city:order?.billing_address?.city,state:order?.billing_address?.state_code,country:order?.billing_address?.country_code},phone:order?.billing_address?.phone};try{const data=await window.Frames.submitCard();if(data.token&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{token:data.token,payment_type:"token",success_url:successUrl,failure_url:failureUrl,_authorize:!0}});ps?.redirect_uri&&(window.location.href=ps.redirect_uri)}}catch(error){console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error?.message}])}}return!1},lang=`${locale.toUpperCase()}-${locale.toUpperCase()}`,localization=systemLanguages.includes(lang)?lang:"EN-GB";return loaded&&show?_jsxs("form",{ref,children:[_jsx("div",{className:containerClassName,...divProps,children:_jsxs(Frames,{config:{debug:!0,publicKey,localization,...options},cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=async()=>await handleSubmit(),setPaymentRef({ref}))},cardTokenized:data=>data,children:[_jsx(CardNumber,{}),_jsx(ExpiryDate,{}),_jsx(Cvv,{})]})}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]}):null}export default CheckoutComPayment;