@commercelayer/react-components 4.15.5-beta.0 → 4.15.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/lib/cjs/components/MetadataInput.d.ts +1 -0
  2. package/lib/cjs/components/addresses/Address.d.ts +1 -0
  3. package/lib/cjs/components/addresses/AddressCountrySelector.d.ts +1 -0
  4. package/lib/cjs/components/addresses/AddressInput.d.ts +1 -0
  5. package/lib/cjs/components/addresses/AddressInputSelect.d.ts +1 -0
  6. package/lib/cjs/components/addresses/AddressStateSelector.d.ts +1 -0
  7. package/lib/cjs/components/addresses/AddressesEmpty.d.ts +1 -0
  8. package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
  9. package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +1 -0
  10. package/lib/cjs/components/auth/CommerceLayer.d.ts +1 -0
  11. package/lib/cjs/components/customers/CustomerContainer.d.ts +1 -0
  12. package/lib/cjs/components/customers/CustomerField.d.ts +1 -0
  13. package/lib/cjs/components/customers/CustomerInput.d.ts +1 -0
  14. package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +1 -0
  15. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
  16. package/lib/cjs/components/customers/MyAccountLink.d.ts +1 -0
  17. package/lib/cjs/components/customers/MyIdentityLink.d.ts +1 -0
  18. package/lib/cjs/components/errors/Errors.d.ts +1 -0
  19. package/lib/cjs/components/gift_cards/GiftCard.d.ts +1 -0
  20. package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
  21. package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +1 -0
  22. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
  23. package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
  24. package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
  25. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
  26. package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
  27. package/lib/cjs/components/line_items/LineItem.d.ts +1 -0
  28. package/lib/cjs/components/line_items/LineItemAmount.d.ts +1 -0
  29. package/lib/cjs/components/line_items/LineItemCode.d.ts +1 -0
  30. package/lib/cjs/components/line_items/LineItemField.d.ts +1 -0
  31. package/lib/cjs/components/line_items/LineItemImage.d.ts +1 -0
  32. package/lib/cjs/components/line_items/LineItemName.d.ts +1 -0
  33. package/lib/cjs/components/line_items/LineItemsContainer.d.ts +1 -0
  34. package/lib/cjs/components/line_items/LineItemsCount.d.ts +1 -0
  35. package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +1 -0
  36. package/lib/cjs/components/orders/AdjustmentAmount.d.ts +1 -0
  37. package/lib/cjs/components/orders/CheckoutLink.d.ts +1 -0
  38. package/lib/cjs/components/orders/DiscountAmount.d.ts +1 -0
  39. package/lib/cjs/components/orders/GiftCardAmount.d.ts +1 -0
  40. package/lib/cjs/components/orders/OrderContainer.d.ts +1 -0
  41. package/lib/cjs/components/orders/OrderList.d.ts +1 -0
  42. package/lib/cjs/components/orders/OrderListEmpty.d.ts +1 -0
  43. package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +1 -0
  44. package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +1 -0
  45. package/lib/cjs/components/orders/OrderListRow.d.ts +1 -0
  46. package/lib/cjs/components/orders/OrderNumber.d.ts +1 -0
  47. package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +1 -0
  48. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
  49. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
  50. package/lib/cjs/components/orders/ShippingAmount.d.ts +1 -0
  51. package/lib/cjs/components/orders/SubTotalAmount.d.ts +1 -0
  52. package/lib/cjs/components/orders/TaxesAmount.d.ts +1 -0
  53. package/lib/cjs/components/orders/TotalAmount.d.ts +1 -0
  54. package/lib/cjs/components/parcels/ParcelField.d.ts +1 -0
  55. package/lib/cjs/components/parcels/ParcelLineItem.d.ts +1 -0
  56. package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +1 -0
  57. package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +1 -0
  58. package/lib/cjs/components/parcels/Parcels.d.ts +1 -0
  59. package/lib/cjs/components/parcels/ParcelsCount.d.ts +1 -0
  60. package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +1 -0
  61. package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +1 -0
  62. package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
  63. package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +1 -0
  64. package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +1 -0
  65. package/lib/cjs/components/payment_gateways/PaymentGateway.d.ts +1 -0
  66. package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +1 -0
  67. package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +1 -0
  68. package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +1 -0
  69. package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +1 -0
  70. package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +1 -0
  71. package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
  72. package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
  73. package/lib/cjs/components/payment_source/BraintreePayment.d.ts +1 -0
  74. package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +1 -0
  75. package/lib/cjs/components/payment_source/ExternalPayment.d.ts +1 -0
  76. package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +1 -0
  77. package/lib/cjs/components/payment_source/PaymentSource.d.ts +1 -0
  78. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
  79. package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
  80. package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +1 -0
  81. package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +1 -0
  82. package/lib/cjs/components/payment_source/StripePayment.d.ts +1 -0
  83. package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +1 -0
  84. package/lib/cjs/components/prices/Price.d.ts +1 -0
  85. package/lib/cjs/components/prices/PricesContainer.d.ts +1 -0
  86. package/lib/cjs/components/shipments/ShipmentField.d.ts +1 -0
  87. package/lib/cjs/components/shipments/ShipmentsCount.d.ts +1 -0
  88. package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +1 -0
  89. package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
  90. package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
  91. package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +1 -0
  92. package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +1 -0
  93. package/lib/cjs/components/skus/SkuField.d.ts +1 -0
  94. package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +1 -0
  95. package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +1 -0
  96. package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +1 -0
  97. package/lib/cjs/components/utils/BaseOrderPrice.d.ts +1 -0
  98. package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +1 -0
  99. package/lib/cjs/components/utils/PriceTemplate.d.ts +1 -0
  100. package/lib/cjs/components/utils/getAllErrors.d.ts +1 -0
  101. package/lib/cjs/typings/globals.d.ts +1 -0
  102. package/lib/cjs/utils/filterChildren.d.ts +1 -0
  103. package/lib/cjs/utils/getLoaderComponent.d.ts +1 -0
  104. package/lib/cjs/utils/getPrices.d.ts +1 -0
  105. package/lib/esm/components/MetadataInput.d.ts +1 -0
  106. package/lib/esm/components/addresses/Address.d.ts +1 -0
  107. package/lib/esm/components/addresses/AddressCountrySelector.d.ts +1 -0
  108. package/lib/esm/components/addresses/AddressInput.d.ts +1 -0
  109. package/lib/esm/components/addresses/AddressInputSelect.d.ts +1 -0
  110. package/lib/esm/components/addresses/AddressStateSelector.d.ts +1 -0
  111. package/lib/esm/components/addresses/AddressesEmpty.d.ts +1 -0
  112. package/lib/esm/components/addresses/SaveAddressesButton.js +1 -1
  113. package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +1 -0
  114. package/lib/esm/components/auth/CommerceLayer.d.ts +1 -0
  115. package/lib/esm/components/customers/CustomerContainer.d.ts +1 -0
  116. package/lib/esm/components/customers/CustomerField.d.ts +1 -0
  117. package/lib/esm/components/customers/CustomerInput.d.ts +1 -0
  118. package/lib/esm/components/customers/CustomerPaymentSource.d.ts +1 -0
  119. package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
  120. package/lib/esm/components/customers/MyAccountLink.d.ts +1 -0
  121. package/lib/esm/components/customers/MyIdentityLink.d.ts +1 -0
  122. package/lib/esm/components/errors/Errors.d.ts +1 -0
  123. package/lib/esm/components/gift_cards/GiftCard.d.ts +1 -0
  124. package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
  125. package/lib/esm/components/gift_cards/GiftCardInput.d.ts +1 -0
  126. package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
  127. package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
  128. package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
  129. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
  130. package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
  131. package/lib/esm/components/line_items/LineItem.d.ts +1 -0
  132. package/lib/esm/components/line_items/LineItemAmount.d.ts +1 -0
  133. package/lib/esm/components/line_items/LineItemCode.d.ts +1 -0
  134. package/lib/esm/components/line_items/LineItemField.d.ts +1 -0
  135. package/lib/esm/components/line_items/LineItemImage.d.ts +1 -0
  136. package/lib/esm/components/line_items/LineItemName.d.ts +1 -0
  137. package/lib/esm/components/line_items/LineItemsContainer.d.ts +1 -0
  138. package/lib/esm/components/line_items/LineItemsCount.d.ts +1 -0
  139. package/lib/esm/components/line_items/LineItemsEmpty.d.ts +1 -0
  140. package/lib/esm/components/orders/AdjustmentAmount.d.ts +1 -0
  141. package/lib/esm/components/orders/CheckoutLink.d.ts +1 -0
  142. package/lib/esm/components/orders/DiscountAmount.d.ts +1 -0
  143. package/lib/esm/components/orders/GiftCardAmount.d.ts +1 -0
  144. package/lib/esm/components/orders/OrderContainer.d.ts +1 -0
  145. package/lib/esm/components/orders/OrderList.d.ts +1 -0
  146. package/lib/esm/components/orders/OrderListEmpty.d.ts +1 -0
  147. package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +1 -0
  148. package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +1 -0
  149. package/lib/esm/components/orders/OrderListRow.d.ts +1 -0
  150. package/lib/esm/components/orders/OrderNumber.d.ts +1 -0
  151. package/lib/esm/components/orders/PaymentMethodAmount.d.ts +1 -0
  152. package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
  153. package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
  154. package/lib/esm/components/orders/ShippingAmount.d.ts +1 -0
  155. package/lib/esm/components/orders/SubTotalAmount.d.ts +1 -0
  156. package/lib/esm/components/orders/TaxesAmount.d.ts +1 -0
  157. package/lib/esm/components/orders/TotalAmount.d.ts +1 -0
  158. package/lib/esm/components/parcels/ParcelField.d.ts +1 -0
  159. package/lib/esm/components/parcels/ParcelLineItem.d.ts +1 -0
  160. package/lib/esm/components/parcels/ParcelLineItemField.d.ts +1 -0
  161. package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +1 -0
  162. package/lib/esm/components/parcels/Parcels.d.ts +1 -0
  163. package/lib/esm/components/parcels/ParcelsCount.d.ts +1 -0
  164. package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +1 -0
  165. package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +1 -0
  166. package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
  167. package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +1 -0
  168. package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +1 -0
  169. package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +1 -0
  170. package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +1 -0
  171. package/lib/esm/components/payment_gateways/StripeGateway.d.ts +1 -0
  172. package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +1 -0
  173. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -0
  174. package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +1 -0
  175. package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
  176. package/lib/esm/components/payment_source/AdyenPayment.js +1 -1
  177. package/lib/esm/components/payment_source/BraintreePayment.d.ts +1 -0
  178. package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +1 -0
  179. package/lib/esm/components/payment_source/ExternalPayment.d.ts +1 -0
  180. package/lib/esm/components/payment_source/KlarnaPayment.d.ts +1 -0
  181. package/lib/esm/components/payment_source/PaymentSource.d.ts +1 -0
  182. package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
  183. package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
  184. package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +1 -0
  185. package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +1 -0
  186. package/lib/esm/components/payment_source/StripePayment.d.ts +1 -0
  187. package/lib/esm/components/payment_source/WireTransferPayment.d.ts +1 -0
  188. package/lib/esm/components/prices/Price.d.ts +1 -0
  189. package/lib/esm/components/prices/PricesContainer.d.ts +1 -0
  190. package/lib/esm/components/shipments/ShipmentField.d.ts +1 -0
  191. package/lib/esm/components/shipments/ShipmentsCount.d.ts +1 -0
  192. package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +1 -0
  193. package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
  194. package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
  195. package/lib/esm/components/skus/AvailabilityTemplate.d.ts +1 -0
  196. package/lib/esm/components/skus/DeliveryLeadTime.d.ts +1 -0
  197. package/lib/esm/components/skus/SkuField.d.ts +1 -0
  198. package/lib/esm/components/stock_transfers/StockTransfer.d.ts +1 -0
  199. package/lib/esm/components/stock_transfers/StockTransferField.d.ts +1 -0
  200. package/lib/esm/components/utils/AddressCardsTemplate.d.ts +1 -0
  201. package/lib/esm/components/utils/BaseOrderPrice.d.ts +1 -0
  202. package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +1 -0
  203. package/lib/esm/components/utils/PriceTemplate.d.ts +1 -0
  204. package/lib/esm/components/utils/getAllErrors.d.ts +1 -0
  205. package/lib/esm/typings/globals.d.ts +1 -0
  206. package/lib/esm/utils/filterChildren.d.ts +1 -0
  207. package/lib/esm/utils/getLoaderComponent.d.ts +1 -0
  208. package/lib/esm/utils/getPrices.d.ts +1 -0
  209. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps } from '../typings/index';
2
3
  type Props = BaseInputComponentProps & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
3
4
  export declare function MetadataInput(props: Props): JSX.Element;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type Address as AddressType } from '@commercelayer/sdk';
2
3
  import { type AddressCardsTemplateChildren } from '../utils/AddressCardsTemplate';
3
4
  import type { DefaultChildrenType } from '../../typings/globals';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseSelectComponentProps } from '../../typings/index';
2
3
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
3
4
  import { type Country } from '../../utils/countryStateCity';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps, type AddressInputName } from '../../typings/index';
2
3
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
3
4
  type Props = {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseSelectComponentProps } from '../../typings/index';
2
3
  import { type AddressValuesKeys } from '../../context/BillingAddressFormContext';
3
4
  type SelectFieldName = `billing_address_${`metadata_${string}`}` | `shipping_address_${`metadata_${string}`}`;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type AddressStateSelectName, type BaseSelectComponentProps } from '../../typings/index';
2
3
  import { type States } from '../../utils/countryStateCity';
3
4
  type Props = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
3
4
  /**
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SaveAddressesButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),AddressContext_1=tslib_1.__importDefault(require("../../context/AddressContext")),addressesManager_1=require("../../utils/addressesManager"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),validateFormFields_1=require("../../utils/validateFormFields");function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,requiredMetadataFields,onClick}=props,p=tslib_1.__rest(props,["children","label","resource","disabled","addressId","requiredMetadataFields","onClick"]),{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId,invertAddresses}=(0,react_1.useContext)(AddressContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{customerEmail:email,addresses,isGuest,createCustomerAddress}=(0,react_1.useContext)(CustomerContext_1.default),[forceDisable,setForceDisable]=(0,react_1.useState)(disabled);let customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email;if(email!=null&&email!==""){const isValidEmail=(0,validateFormFields_1.validateValue)(email,"customer_email","email","orders");customerEmail=Object.keys(isValidEmail).length>0}const shippingAddressCleaned=Object.keys(shippingAddress??{}).reduce((acc,key)=>Object.assign(Object.assign({},acc),{[key.replace("shipping_address_","")]:shippingAddress[key].value}),{}),{billingDisable,shippingDisable}=(0,addressesManager_1.addressesController)({invertAddresses,requiresBillingInfo:order?.requires_billing_info,billing_address:billingAddress,shipping_address:shippingAddressCleaned,shipToDifferentAddress,shippingAddressId,billingAddressId,errors,requiredMetadataFields}),countryLockDisable=(0,addressesManager_1.countryLockController)({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId,lineItems:order?.line_items}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(errors&&Object.keys(errors).length===0&&!disable){let response={success:!1};if(setForceDisable(!0),order&&saveAddresses!=null)response=yield saveAddresses(email);else if(createCustomerAddress){const address=invertAddresses?Object.assign({},shippingAddress):Object.assign({},billingAddress);addressId&&(address.id=addressId),createCustomerAddress(address),response={success:!0}}setForceDisable(!1),onClick&&response.success&&onClick(response)}}),parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("button",Object.assign({type:"button",disabled:disable||forceDisable,onClick:()=>{handleClick()}},p,{children:(0,isFunction_1.default)(label)?label():label}))}exports.SaveAddressesButton=SaveAddressesButton,exports.default=SaveAddressesButton;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SaveAddressesButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),AddressContext_1=tslib_1.__importDefault(require("../../context/AddressContext")),addressesManager_1=require("../../utils/addressesManager"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),validateFormFields_1=require("../../utils/validateFormFields");function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,requiredMetadataFields,onClick}=props,p=tslib_1.__rest(props,["children","label","resource","disabled","addressId","requiredMetadataFields","onClick"]),{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId,invertAddresses}=(0,react_1.useContext)(AddressContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{customerEmail:email,addresses,isGuest,createCustomerAddress}=(0,react_1.useContext)(CustomerContext_1.default),[forceDisable,setForceDisable]=(0,react_1.useState)(disabled);let customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email;if(email!=null&&email!==""){const isValidEmail=(0,validateFormFields_1.validateValue)(email,"customer_email","email","orders");customerEmail=Object.keys(isValidEmail).length>0}const shippingAddressCleaned=Object.keys(shippingAddress??{}).reduce((acc,key)=>Object.assign(Object.assign({},acc),{[key.replace("shipping_address_","")]:shippingAddress[key].value}),{}),{billingDisable,shippingDisable}=(0,addressesManager_1.addressesController)({invertAddresses,requiresBillingInfo:order?.requires_billing_info,billing_address:billingAddress,shipping_address:shippingAddressCleaned,shipToDifferentAddress,shippingAddressId,billingAddressId,errors,requiredMetadataFields}),countryLockDisable=(0,addressesManager_1.countryLockController)({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId,lineItems:order?.line_items}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(errors&&Object.keys(errors).length===0&&!disable){let response={success:!1};if(setForceDisable(!0),order&&saveAddresses!=null)response=yield saveAddresses(email);else if(createCustomerAddress&&billingAddress){const address=Object.assign({},billingAddress);addressId&&(address.id=addressId),createCustomerAddress(address),response={success:!0}}setForceDisable(!1),onClick&&response.success&&onClick(response)}}),parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("button",Object.assign({type:"button",disabled:disable||forceDisable,onClick:()=>{handleClick()}},p,{children:(0,isFunction_1.default)(label)?label():label}))}exports.SaveAddressesButton=SaveAddressesButton,exports.default=SaveAddressesButton;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type StockTransferFieldChildrenProps = TGenericChildrenProps<TResources['Customer']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps } from '../../typings/index';
2
3
  type Props = {
3
4
  name?: 'customer_email' | string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children?: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { CodeErrorType } from '../../typings/errors';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  export type TResourceError = 'addresses' | 'billing_address' | 'gift_cards' | 'gift_card_or_coupon_code' | 'line_items' | 'orders' | 'payment_methods' | 'prices' | 'shipments' | 'shipping_address' | 'customer_address' | 'sku_options' | 'variant' | 'in_stock_subscriptions';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseState } from '../../typings/index';
2
3
  import type { DefaultChildrenType } from '../../typings/globals';
3
4
  interface Props extends Omit<JSX.IntrinsicElements['form'], 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseSelectComponentProps } from '../../typings/index';
2
3
  type Props = Omit<BaseSelectComponentProps, 'options' | 'name'> & {
3
4
  required?: boolean;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps, type GiftCardInputName } from '../../typings/index';
2
3
  type Props = {
3
4
  name: GiftCardInputName;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { CodeType } from '../../reducers/OrderReducer';
3
4
  interface ChildrenProps extends Omit<Props, 'children' | 'type'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { OrderCodeType } from '../../reducers/OrderReducer';
2
3
  import type { Order } from '@commercelayer/sdk';
3
4
  import type { DefaultChildrenType } from '../../typings/globals';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputComponentProps } from '../../typings/index';
2
3
  import { type OrderCodeType } from '../../reducers/OrderReducer';
3
4
  type FieldName = 'gift_card_code' | 'coupon_code';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['button'], 'children' | 'onClick'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export type TLineItem = 'gift_cards' | 'payment_methods' | 'promotions' | 'shipments' | 'skus' | 'bundles' | 'adjustments';
2
3
  interface Props {
3
4
  children: JSX.Element | JSX.Element[];
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent, type BasePriceType } from '../../typings/index';
2
3
  type Props = BaseAmountComponent & {
3
4
  type?: BasePriceType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LineItem } from '@commercelayer/sdk';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  export interface TLineItemCode extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type LineItemFieldChildrenProps = TGenericChildrenProps<TResources['LineItem']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LineItem } from '@commercelayer/sdk';
2
3
  import type { ChildrenFunction } from '../../typings/index';
3
4
  import { type TLineItem } from './LineItem';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { LineItem } from '@commercelayer/sdk';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  export interface TLineItemName extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type TypeAccepted } from '../../utils/getLineItemsCount';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  quantity: number;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function AdjustmentAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default AdjustmentAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  checkoutUrl: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function DiscountAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default DiscountAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function GiftCardAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default GiftCardAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseMetadataObject } from '../../typings/index';
2
3
  import type { OrderCreate, Order } from '@commercelayer/sdk';
3
4
  import type { DefaultChildrenType } from '../../typings/globals';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type TOrderList, type InitialOrderListContext, type OrderListContent } from '../../context/OrderListChildrenContext';
2
3
  import { type ColumnDef, type SortingState } from '@tanstack/react-table';
3
4
  import type { DefaultChildrenType, TRange } from '../../typings/globals';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type OrderListPaginationContext as TOrderListPaginationContext } from '../../context/OrderListPaginationContext';
2
3
  import { type ChildrenFunction } from '../../typings/index';
3
4
  interface PaginationButton extends Omit<JSX.IntrinsicElements['button'], 'children' | 'disabled'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  type TAsComponent = keyof Pick<JSX.IntrinsicElements, 'p' | 'span' | 'div'>;
3
4
  type ChildrenProps<A extends TAsComponent> = Omit<Props<A>, 'children'> & {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type TOrderList, type OrderListContent, type TableAccessor } from '../../context/OrderListChildrenContext';
2
3
  import { type Row } from '@tanstack/react-table';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseFieldProps } from '../utils/BaseField';
2
3
  type Props = Omit<BaseFieldProps, 'attribute'>;
3
4
  export declare function OrderNumber(props: Props): JSX.Element;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function PaymentMethodAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default PaymentMethodAmount;
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlaceOrderButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails"));function PlaceOrderButton(props){var _a,_b,_c,_d;const ref=(0,react_1.useRef)(null),{children,label="Place order",loadingLabel="Placing...",autoPlaceOrder=!0,disabled,onClick}=props,p=tslib_1.__rest(props,["children","label","loadingLabel","autoPlaceOrder","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType,setButtonRef,setPlaceOrderStatus}=(0,react_1.useContext)(PlaceOrderContext_1.default),[notPermitted,setNotPermitted]=(0,react_1.useState)(!0),[forceDisable,setForceDisable]=(0,react_1.useState)(disabled),[isLoading,setIsLoading]=(0,react_1.useState)(!1),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors,currentCustomerPaymentSourceId}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),isFree=order?.total_amount_with_taxes_cents===0;(0,react_1.useEffect)(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=(0,getCardDetails_1.default)({customerPayment:{payment_source:paymentSource},paymentType});currentCustomerPaymentSourceId!=null&&paymentSource?.id===currentCustomerPaymentSourceId&&card.brand===""&&(card.brand="credit-card"),(isFree&&isPermitted||!((_a2=currentPaymentMethodRef?.current)===null||_a2===void 0)&&_a2.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,(_a=currentPaymentMethodRef?.current)===null||_a===void 0?void 0:_a.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),(0,react_1.useEffect)(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.paypalPayerId,paymentType]),(0,react_1.useEffect)(()=>{var _a2,_b2;paymentType==="stripe_payments"&&["succeeded","pending"].includes((_b2=(_a2=options?.stripe)===null||_a2===void 0?void 0:_a2.redirectStatus)!==null&&_b2!==void 0?_b2:"")&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[(_b=options?.stripe)===null||_b===void 0?void 0:_b.redirectStatus,paymentType]),(0,react_1.useEffect)(()=>{var _a2,_b2,_c2,_d2,_e,_f,_g,_h,_j,_k,_l,_m;if(order?.status!=null&&["draft","pending"].includes(order?.status)){const resultCode=((_b2=(_a2=order?.payment_source)===null||_a2===void 0?void 0:_a2.payment_response)===null||_b2===void 0?void 0:_b2.resultCode)==="Authorised",paymentDetails=((_d2=(_c2=order?.payment_source)===null||_c2===void 0?void 0:_c2.payment_request_details)===null||_d2===void 0?void 0:_d2.details)!=null;if(paymentType==="adyen_payments"&&(!((_e=options?.adyen)===null||_e===void 0)&&_e.redirectResult)&&!paymentDetails){const attributes={payment_request_details:{details:{redirectResult:(_f=options?.adyen)===null||_f===void 0?void 0:_f.redirectResult}},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{var _a3,_b3,_c3;const resultCode2=(_a3=res?.payment_response)===null||_a3===void 0?void 0:_a3.resultCode,errorCode=(_b3=res?.payment_response)===null||_b3===void 0?void 0:_b3.errorCode,message=(_c3=res?.payment_response)===null||_c3===void 0?void 0:_c3.message;["Authorised","Pending","Received"].includes(resultCode2)&&autoPlaceOrder?handleClick():errorCode!=null&&setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])})}else(paymentType==="adyen_payments"&&(!((_g=options?.adyen)===null||_g===void 0)&&_g.MD)&&(!((_h=options?.adyen)===null||_h===void 0)&&_h.PaRes)&&autoPlaceOrder||paymentType==="adyen_payments"&&resultCode&&((_j=ref?.current)===null||_j===void 0?void 0:_j.disabled)===!1&&currentCustomerPaymentSourceId==null&&autoPlaceOrder&&!((_m=(_l=(_k=order?.payment_source)===null||_k===void 0?void 0:_k.payment_response)===null||_l===void 0?void 0:_l.merchantReference)===null||_m===void 0)&&_m.includes(order?.number))&&handleClick()}},[options?.adyen,paymentType,(_d=(_c=order?.payment_source)===null||_c===void 0?void 0:_c.payment_response)===null||_d===void 0?void 0:_d.resultCode]),(0,react_1.useEffect)(()=>{var _a2;paymentType==="checkout_com_payments"&&(!((_a2=options?.checkoutCom)===null||_a2===void 0)&&_a2.session_id)&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.checkoutCom,paymentType]),(0,react_1.useEffect)(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _e,_f,_g,_h,_j;e?.preventDefault(),e?.stopPropagation(),setIsLoading(!0);let isValid=!0;setForceDisable(!0);const checkPaymentSource=yield setPaymentSource({paymentResource:paymentType,paymentSourceId:paymentSource?.id}),card=paymentType&&(0,getCardDetails_1.default)({paymentType,customerPayment:{payment_source:checkPaymentSource}});!((_e=currentPaymentMethodRef?.current)===null||_e===void 0)&&_e.onsubmit&&[!options?.paypalPayerId,!(!((_f=options?.adyen)===null||_f===void 0)&&_f.MD),!(!((_g=options?.checkoutCom)===null||_g===void 0)&&_g.session_id)].every(Boolean)?(isValid=yield(_h=currentPaymentMethodRef.current)===null||_h===void 0?void 0:_h.onsubmit({paymentSource:checkPaymentSource,setPlaceOrder,onclickCallback:onClick}),!isValid&&((_j=checkPaymentSource.payment_response)===null||_j===void 0?void 0:_j.resultCode)==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0),isValid&&setPlaceOrderStatus!=null&&setPlaceOrderStatus({status:"placing"});const placed=isValid&&setPlaceOrder&&(checkPaymentSource||isFree)&&(yield setPlaceOrder({paymentSource:checkPaymentSource,currentCustomerPaymentSourceId}));setForceDisable(!1),onClick&&placed&&onClick(placed),setIsLoading(!1),setPlaceOrderStatus?.({status:"standby"})}),disabledButton=disabled!==void 0?disabled:notPermitted,labelButton=isLoading?loadingLabel:(0,isFunction_1.default)(label)?label():label,parentProps=Object.assign(Object.assign({},p),{label,disabled:disabledButton,handleClick,parentRef:ref,isLoading});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("button",Object.assign({ref,type:"button",disabled:disabledButton||forceDisable,onClick:e=>{handleClick(e)}},p,{children:labelButton}))}exports.PlaceOrderButton=PlaceOrderButton,exports.default=PlaceOrderButton;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlaceOrderButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails"));function PlaceOrderButton(props){var _a,_b,_c,_d;const ref=(0,react_1.useRef)(null),{children,label="Place order",loadingLabel="Placing...",autoPlaceOrder=!0,disabled,onClick}=props,p=tslib_1.__rest(props,["children","label","loadingLabel","autoPlaceOrder","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType,setButtonRef,setPlaceOrderStatus}=(0,react_1.useContext)(PlaceOrderContext_1.default),[notPermitted,setNotPermitted]=(0,react_1.useState)(!0),[forceDisable,setForceDisable]=(0,react_1.useState)(disabled),[isLoading,setIsLoading]=(0,react_1.useState)(!1),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors,currentCustomerPaymentSourceId}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),isFree=order?.total_amount_with_taxes_cents===0;(0,react_1.useEffect)(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=(0,getCardDetails_1.default)({customerPayment:{payment_source:paymentSource},paymentType});currentCustomerPaymentSourceId!=null&&paymentSource?.id===currentCustomerPaymentSourceId&&card.brand===""&&(card.brand="credit-card"),(isFree&&isPermitted||!((_a2=currentPaymentMethodRef?.current)===null||_a2===void 0)&&_a2.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,(_a=currentPaymentMethodRef?.current)===null||_a===void 0?void 0:_a.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),(0,react_1.useEffect)(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.paypalPayerId,paymentType]),(0,react_1.useEffect)(()=>{var _a2,_b2;paymentType==="stripe_payments"&&["succeeded","pending"].includes((_b2=(_a2=options?.stripe)===null||_a2===void 0?void 0:_a2.redirectStatus)!==null&&_b2!==void 0?_b2:"")&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[(_b=options?.stripe)===null||_b===void 0?void 0:_b.redirectStatus,paymentType]),(0,react_1.useEffect)(()=>{var _a2,_b2,_c2,_d2,_e,_f,_g,_h,_j,_k,_l,_m;if(order?.status!=null&&["draft","pending"].includes(order?.status)){const resultCode=((_b2=(_a2=order?.payment_source)===null||_a2===void 0?void 0:_a2.payment_response)===null||_b2===void 0?void 0:_b2.resultCode)==="Authorised",paymentDetails=((_d2=(_c2=order?.payment_source)===null||_c2===void 0?void 0:_c2.payment_request_details)===null||_d2===void 0?void 0:_d2.details)!=null;if(paymentType==="adyen_payments"&&(!((_e=options?.adyen)===null||_e===void 0)&&_e.redirectResult)&&!paymentDetails){const attributes={payment_request_details:{details:{redirectResult:(_f=options?.adyen)===null||_f===void 0?void 0:_f.redirectResult}},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{var _a3,_b3,_c3;const resultCode2=(_a3=res?.payment_response)===null||_a3===void 0?void 0:_a3.resultCode,errorCode=(_b3=res?.payment_response)===null||_b3===void 0?void 0:_b3.errorCode,message=(_c3=res?.payment_response)===null||_c3===void 0?void 0:_c3.message;["Authorised","Pending","Received"].includes(resultCode2)&&autoPlaceOrder?handleClick():errorCode!=null&&setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])})}else(paymentType==="adyen_payments"&&(!((_g=options?.adyen)===null||_g===void 0)&&_g.MD)&&(!((_h=options?.adyen)===null||_h===void 0)&&_h.PaRes)&&autoPlaceOrder||paymentType==="adyen_payments"&&resultCode&&((_j=ref?.current)===null||_j===void 0?void 0:_j.disabled)===!1&&currentCustomerPaymentSourceId==null&&autoPlaceOrder&&!((_m=(_l=(_k=order?.payment_source)===null||_k===void 0?void 0:_k.payment_response)===null||_l===void 0?void 0:_l.merchantReference)===null||_m===void 0)&&_m.includes(order?.number))&&handleClick()}},[options?.adyen,paymentType,(_d=(_c=order?.payment_source)===null||_c===void 0?void 0:_c.payment_response)===null||_d===void 0?void 0:_d.resultCode]),(0,react_1.useEffect)(()=>{var _a2;paymentType==="checkout_com_payments"&&(!((_a2=options?.checkoutCom)===null||_a2===void 0)&&_a2.session_id)&&order?.status&&["draft","pending"].includes(order?.status)&&autoPlaceOrder&&handleClick()},[options?.checkoutCom,paymentType]),(0,react_1.useEffect)(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _e,_f,_g,_h,_j;e?.preventDefault(),e?.stopPropagation(),setIsLoading(!0);let isValid=!0;setForceDisable(!0);const checkPaymentSource=yield setPaymentSource({paymentResource:paymentType,paymentSourceId:paymentSource?.id}),card=paymentType&&(0,getCardDetails_1.default)({paymentType,customerPayment:{payment_source:checkPaymentSource}});!((_e=currentPaymentMethodRef?.current)===null||_e===void 0)&&_e.onsubmit&&[!options?.paypalPayerId,!(!((_f=options?.adyen)===null||_f===void 0)&&_f.MD),!(!((_g=options?.checkoutCom)===null||_g===void 0)&&_g.session_id)].every(Boolean)?(isValid=yield(_h=currentPaymentMethodRef.current)===null||_h===void 0?void 0:_h.onsubmit({paymentSource:checkPaymentSource,setPlaceOrder,onclickCallback:onClick}),!isValid&&((_j=checkPaymentSource.payment_response)===null||_j===void 0?void 0:_j.resultCode)==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0),isValid&&setPlaceOrderStatus!=null&&setPlaceOrderStatus({status:"placing"});const placed=isValid&&setPlaceOrder&&(checkPaymentSource||isFree)&&(yield setPlaceOrder({paymentSource:checkPaymentSource,currentCustomerPaymentSourceId}));setForceDisable(!1),onClick&&placed&&onClick(placed),setPlaceOrderStatus?.({status:"standby"}),placed&&setIsLoading(!1)}),disabledButton=disabled!==void 0?disabled:notPermitted,labelButton=isLoading?loadingLabel:(0,isFunction_1.default)(label)?label():label,parentProps=Object.assign(Object.assign({},p),{label,disabled:disabledButton,handleClick,parentRef:ref,isLoading});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("button",Object.assign({ref,type:"button",disabled:isLoading||disabledButton||forceDisable,onClick:e=>{handleClick(e)}},p,{children:labelButton}))}exports.PlaceOrderButton=PlaceOrderButton,exports.default=PlaceOrderButton;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseInputProps } from '../utils/BaseInput';
2
3
  export declare function PrivacyAndTermsCheckbox(props: Partial<BaseInputProps>): JSX.Element;
3
4
  export default PrivacyAndTermsCheckbox;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function ShippingAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default ShippingAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function SubTotalAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default SubTotalAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function TaxesAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default TaxesAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  export declare function TotalAmount(props: BaseAmountComponent): JSX.Element;
3
4
  export default TotalAmount;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type ParcelFieldChildrenProps = TGenericChildrenProps<TResources['Parcel']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { DefaultChildrenType } from '../../typings/globals';
2
3
  interface Props {
3
4
  children: DefaultChildrenType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ConditionalElement } from '../../typings/index';
2
3
  import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
3
4
  type ParcelLineItemFieldChildrenProps = TGenericChildrenProps<TResources['ParcelLineItem']>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { Parcel } from '@commercelayer/sdk';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  interface Props {
2
3
  children: JSX.Element | JSX.Element[];
3
4
  filterBy?: string[];
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { Parcel } from '@commercelayer/sdk';
3
4
  interface ChildrenProps extends Omit<Props, 'children'> {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function AdyenGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function BraintreeGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function CheckoutComGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function ExternalGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function KlarnaGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LoaderType } from '../../typings/index';
2
3
  import { type PaymentSourceProps } from '../payment_source/PaymentSource';
3
4
  export type GatewayBaseType = Props & {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = Partial<GatewayBaseType>;
3
4
  export declare function PaypalGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function StripeGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type GatewayBaseType } from '../payment_gateways/PaymentGateway';
2
3
  type Props = GatewayBaseType;
3
4
  export declare function WireTransferGateway(props: Props): JSX.Element | null;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { LoaderType } from '../../typings/index';
2
3
  import type { Order, PaymentMethod as PaymentMethodType } from '@commercelayer/sdk';
3
4
  import type { PaymentResource } from '../../reducers/PaymentMethodReducer';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  interface ChildrenProps extends Omit<Props, 'children'> {
3
4
  labelName: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type BaseAmountComponent } from '../../typings/index';
2
3
  interface Props extends BaseAmountComponent {
3
4
  type?: 'amount';
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AdyenPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),localStorage_1=require("../../utils/localStorage"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),browserInfo_1=tslib_1.__importStar(require("../../utils/browserInfo")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),omit_1=tslib_1.__importDefault(require("../../utils/omit")),getPublicIp_1=require("../../utils/getPublicIp"),defaultConfig={};function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=(0,react_1.useState)(!1),[checkout,setCheckout]=(0,react_1.useState)(),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{placeOrderButtonRef}=(0,react_1.useContext)(PlaceOrderContext_1.default),ref=(0,react_1.useRef)(null),handleSubmit=(e,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b;const savePaymentSourceToCustomerWallet=(_b=(_a=e?.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;return savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component?.submit&&component.submit(),!1}),handleChange=(state,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(state.isValid){ref.current&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleSubmit(ref.current,component)}),setPaymentRef({ref}));const browserInfo=(0,browserInfo_1.default)(),shopperIp=yield(0,getPublicIp_1.getPublicIP)(),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",shopper_ip:shopperIp,browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)}};paymentSource&&(yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}))}}),handleOnAdditionalDetails=(state,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _c,_d,_e;const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&(yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})),adyenAction=(_c=pSource?.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource?.payment_response)===null||_d===void 0?void 0:_d.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=(_e=pSource?.payment_response)===null||_e===void 0?void 0:_e.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=(state,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _f,_g,_h,_j,_k,_l,_m,_o,_p;const saveCustomer=document.getElementById("save_payment_source_to_customer_wallet"),url=(0,browserInfo_1.cleanUrlBy)(),shopperIp=yield(0,getPublicIp_1.getPublicIP)();let control=yield setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"});if(((_f=control?.payment_response)===null||_f===void 0?void 0:_f.resultCode)==="Authorised")return!0;const paymentDataAvailable=Object.keys(control?.payment_request_data).length>0,paymentMethodSelected=(_h=(_g=control?.payment_request_data)===null||_g===void 0?void 0:_g.payment_method)===null||_h===void 0?void 0:_h.type,paymentMethod=saveCustomer?.checked?state.data.paymentMethod:(0,omit_1.default)(state.data.paymentMethod,["encryptedCardNumber","encryptedExpiryMonth","encryptedExpiryYear"]);(!paymentDataAvailable||paymentMethodSelected!==state.data.paymentMethod.type)&&(control=yield setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes:{payment_request_data:Object.assign(Object.assign({},state.data),{payment_method:paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",shopper_id:shopperIp})}}));const attributes={payment_request_data:Object.assign(Object.assign({},state.data),{payment_method:paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",shopper_id:shopperIp}),_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=yield setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=(_j=res?.payment_response)===null||_j===void 0?void 0:_j.action;if(component&&action)return component.handleAction(action),!1;const resultCode=(_k=res?.payment_response)===null||_k===void 0?void 0:_k.resultCode;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=(_l=res?.payment_response)===null||_l===void 0?void 0:_l.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),component&&component.mount("#adyen-dropin")}if((_m=res?.payment_response)===null||_m===void 0?void 0:_m.errorType)if(((_o=res?.payment_response)===null||_o===void 0?void 0:_o.errorCode)==="14_006")onSubmit(state,component);else{const message=(_p=res?.payment_response)===null||_p===void 0?void 0:_p.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(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e,_f;const paymentMethodsResponse={paymentMethods:!((_a=paymentSource?.payment_methods)===null||_a===void 0)&&_a.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],storedPaymentMethods:!((_b=paymentSource?.payment_methods)===null||_b===void 0)&&_b.storedPaymentMethods?paymentSource?.payment_methods.storedPaymentMethods:[]},[firstPaymentMethod]=paymentMethodsResponse.paymentMethods,isOnlyCard=((_c=paymentMethodsResponse.paymentMethods)===null||_c===void 0?void 0:_c.length)===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.paymentMethods.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const showStoredPaymentMethods=(_e=((_d=paymentSource?.payment_methods)===null||_d===void 0?void 0:_d.storedPaymentMethods)!=null)!==null&&_e!==void 0?_e:!1,options={locale:(_f=order?.language_code)!==null&&_f!==void 0?_f:locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse,showPayButton:!1,paymentMethodsConfiguration:{showStoredPaymentMethods,paypal:{showPayButton:!0,style:styles?.paypal},card:{enableStoreDetails:showStoredPaymentMethods,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&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&Promise.resolve().then(()=>tslib_1.__importStar(require("@adyen/adyen-web"))).then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{showRemovePaymentMethodButton:showStoredPaymentMethods,onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield 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!=null]),!clientKey&&!loadAdyen&&!checkout?null:(0,jsx_runtime_1.jsxs)("form",{ref,onSubmit:e=>{handleSubmit(e,checkout)},children:[(0,jsx_runtime_1.jsx)("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),(0,jsx_runtime_1.jsx)("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}exports.AdyenPayment=AdyenPayment,exports.default=AdyenPayment;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AdyenPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),localStorage_1=require("../../utils/localStorage"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),browserInfo_1=tslib_1.__importStar(require("../../utils/browserInfo")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),omit_1=tslib_1.__importDefault(require("../../utils/omit")),getPublicIp_1=require("../../utils/getPublicIp"),defaultConfig={};function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=(0,react_1.useState)(!1),[checkout,setCheckout]=(0,react_1.useState)(),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{placeOrderButtonRef}=(0,react_1.useContext)(PlaceOrderContext_1.default),ref=(0,react_1.useRef)(null),handleSubmit=(e,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b;const savePaymentSourceToCustomerWallet=(_b=(_a=e?.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;return savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component?.submit&&component.submit(),!1}),handleChange=(state,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(state.isValid){ref.current&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleSubmit(ref.current,component)}),setPaymentRef({ref}));const browserInfo=(0,browserInfo_1.default)(),shopperIp=yield(0,getPublicIp_1.getPublicIP)(),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",shopper_ip:shopperIp,browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)}};paymentSource&&(yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}))}}),handleOnAdditionalDetails=(state,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _c,_d,_e;const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&(yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})),adyenAction=(_c=pSource?.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource?.payment_response)===null||_d===void 0?void 0:_d.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=(_e=pSource?.payment_response)===null||_e===void 0?void 0:_e.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=(state,component)=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _f,_g,_h,_j,_k,_l,_m,_o,_p;const saveCustomer=document.getElementById("save_payment_source_to_customer_wallet"),url=(0,browserInfo_1.cleanUrlBy)(),shopperIp=yield(0,getPublicIp_1.getPublicIP)();let control=yield setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"});if(((_f=control?.payment_response)===null||_f===void 0?void 0:_f.resultCode)==="Authorised")return!0;const paymentDataAvailable=Object.keys(control?.payment_request_data).length>0,paymentMethodSelected=(_h=(_g=control?.payment_request_data)===null||_g===void 0?void 0:_g.payment_method)===null||_h===void 0?void 0:_h.type,paymentMethod=saveCustomer?.checked?state.data.paymentMethod:(0,omit_1.default)(state.data.paymentMethod,["encryptedCardNumber","encryptedExpiryMonth","encryptedExpiryYear"]);(!paymentDataAvailable||paymentMethodSelected!==state.data.paymentMethod.type)&&(control=yield setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes:{payment_request_data:Object.assign(Object.assign({},state.data),{payment_method:paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",shopper_ip:shopperIp})}}));const attributes={payment_request_data:Object.assign(Object.assign({},state.data),{payment_method:paymentMethod,return_url:url,origin:window.location.origin,redirect_from_issuer_method:"GET",shopper_ip:shopperIp}),_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=yield setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=(_j=res?.payment_response)===null||_j===void 0?void 0:_j.action;if(component&&action)return component.handleAction(action),!1;const resultCode=(_k=res?.payment_response)===null||_k===void 0?void 0:_k.resultCode;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=(_l=res?.payment_response)===null||_l===void 0?void 0:_l.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),component&&component.mount("#adyen-dropin")}if((_m=res?.payment_response)===null||_m===void 0?void 0:_m.errorType)if(((_o=res?.payment_response)===null||_o===void 0?void 0:_o.errorCode)==="14_006")onSubmit(state,component);else{const message=(_p=res?.payment_response)===null||_p===void 0?void 0:_p.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(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e,_f;const paymentMethodsResponse={paymentMethods:!((_a=paymentSource?.payment_methods)===null||_a===void 0)&&_a.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],storedPaymentMethods:!((_b=paymentSource?.payment_methods)===null||_b===void 0)&&_b.storedPaymentMethods?paymentSource?.payment_methods.storedPaymentMethods:[]},[firstPaymentMethod]=paymentMethodsResponse.paymentMethods,isOnlyCard=((_c=paymentMethodsResponse.paymentMethods)===null||_c===void 0?void 0:_c.length)===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.paymentMethods.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const showStoredPaymentMethods=(_e=((_d=paymentSource?.payment_methods)===null||_d===void 0?void 0:_d.storedPaymentMethods)!=null)!==null&&_e!==void 0?_e:!1,options={locale:(_f=order?.language_code)!==null&&_f!==void 0?_f:locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse,showPayButton:!1,paymentMethodsConfiguration:{showStoredPaymentMethods,paypal:{showPayButton:!0,style:styles?.paypal},card:{enableStoreDetails:showStoredPaymentMethods,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&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&Promise.resolve().then(()=>tslib_1.__importStar(require("@adyen/adyen-web"))).then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{showRemovePaymentMethodButton:showStoredPaymentMethods,onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield 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!=null]),!clientKey&&!loadAdyen&&!checkout?null:(0,jsx_runtime_1.jsxs)("form",{ref,onSubmit:e=>{handleSubmit(e,checkout)},children:[(0,jsx_runtime_1.jsx)("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),(0,jsx_runtime_1.jsx)("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}exports.AdyenPayment=AdyenPayment,exports.default=AdyenPayment;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PaymentSourceProps } from './PaymentSource';
2
3
  import { type HostedFieldFieldOptions } from 'braintree-web';
3
4
  type BraintreeHostedFields<Type> = {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
2
3
  import { type PaymentSourceProps } from './PaymentSource';
3
4
  import { type FramesStyle } from 'frames-react';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type ChildrenFunction } from '../../typings/index';
2
3
  import type { StripeElementLocale } from '@stripe/stripe-js';
3
4
  import { type PaymentSourceProps } from './PaymentSource';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type PaymentMethodConfig } from '../../reducers/PaymentMethodReducer';
2
3
  import { type PaymentSourceProps } from './PaymentSource';
3
4
  type KlarnaPaymentProps = PaymentMethodConfig['klarnaPayment'] & JSX.IntrinsicElements['div'] & Partial<PaymentSourceProps['templateCustomerSaveToWallet']> & {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { type LoaderType } from '../../typings/index';
2
3
  import { type CustomerCardsTemplateChildren } from '../utils/PaymentCardsTemplate';
3
4
  export interface CustomerCardsProps {