@commercelayer/react-components 4.4.0-beta.2 → 4.4.0-beta.4

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 (195) hide show
  1. package/lib/cjs/components/ExternalFunction.js +1 -1
  2. package/lib/cjs/components/MetadataInput.js +1 -1
  3. package/lib/cjs/components/SubmitButton.js +1 -1
  4. package/lib/cjs/components/addresses/Address.js +1 -1
  5. package/lib/cjs/components/addresses/AddressCountrySelector.js +1 -1
  6. package/lib/cjs/components/addresses/AddressField.js +1 -1
  7. package/lib/cjs/components/addresses/AddressInput.js +1 -1
  8. package/lib/cjs/components/addresses/AddressStateSelector.js +1 -1
  9. package/lib/cjs/components/addresses/AddressesContainer.js +1 -1
  10. package/lib/cjs/components/addresses/AddressesEmpty.js +1 -1
  11. package/lib/cjs/components/addresses/BillingAddressContainer.js +1 -1
  12. package/lib/cjs/components/addresses/BillingAddressForm.js +1 -1
  13. package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
  14. package/lib/cjs/components/addresses/ShippingAddressContainer.js +1 -1
  15. package/lib/cjs/components/addresses/ShippingAddressForm.js +1 -1
  16. package/lib/cjs/components/auth/CommerceLayer.js +1 -1
  17. package/lib/cjs/components/customers/CustomerAddressForm.js +1 -1
  18. package/lib/cjs/components/customers/CustomerContainer.js +1 -1
  19. package/lib/cjs/components/customers/CustomerField.js +1 -1
  20. package/lib/cjs/components/customers/CustomerInput.js +1 -1
  21. package/lib/cjs/components/customers/CustomerPaymentSource.js +1 -1
  22. package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.js +1 -1
  23. package/lib/cjs/components/customers/SaveCustomerButton.js +1 -1
  24. package/lib/cjs/components/errors/Errors.js +1 -1
  25. package/lib/cjs/components/gift_cards/GiftCard.js +1 -1
  26. package/lib/cjs/components/gift_cards/GiftCardContainer.js +1 -1
  27. package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.js +1 -1
  28. package/lib/cjs/components/gift_cards/GiftCardInput.js +1 -1
  29. package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.js +1 -1
  30. package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.js +1 -1
  31. package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.js +1 -1
  32. package/lib/cjs/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -1
  33. package/lib/cjs/components/gift_cards/GiftCardOrCouponSubmit.js +1 -1
  34. package/lib/cjs/components/line_items/LineItem.js +1 -1
  35. package/lib/cjs/components/line_items/LineItemAmount.js +1 -1
  36. package/lib/cjs/components/line_items/LineItemCode.js +1 -1
  37. package/lib/cjs/components/line_items/LineItemField.js +1 -1
  38. package/lib/cjs/components/line_items/LineItemImage.js +1 -1
  39. package/lib/cjs/components/line_items/LineItemName.js +1 -1
  40. package/lib/cjs/components/line_items/LineItemOption.js +1 -1
  41. package/lib/cjs/components/line_items/LineItemOptions.js +1 -1
  42. package/lib/cjs/components/line_items/LineItemQuantity.js +1 -1
  43. package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
  44. package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
  45. package/lib/cjs/components/line_items/LineItemsCount.js +1 -1
  46. package/lib/cjs/components/line_items/LineItemsEmpty.js +1 -1
  47. package/lib/cjs/components/orders/AddToCartButton.js +1 -1
  48. package/lib/cjs/components/orders/AdjustmentAmount.js +1 -1
  49. package/lib/cjs/components/orders/CartLink.js +1 -1
  50. package/lib/cjs/components/orders/CheckoutLink.js +1 -1
  51. package/lib/cjs/components/orders/DiscountAmount.js +1 -1
  52. package/lib/cjs/components/orders/GiftCardAmount.js +1 -1
  53. package/lib/cjs/components/orders/OrderContainer.js +1 -1
  54. package/lib/cjs/components/orders/OrderList.js +1 -1
  55. package/lib/cjs/components/orders/OrderListEmpty.js +1 -1
  56. package/lib/cjs/components/orders/OrderListPaginationButtons.js +1 -1
  57. package/lib/cjs/components/orders/OrderListPaginationInfo.js +1 -1
  58. package/lib/cjs/components/orders/OrderListRow.js +1 -1
  59. package/lib/cjs/components/orders/OrderNumber.js +1 -1
  60. package/lib/cjs/components/orders/OrderStorage.js +1 -1
  61. package/lib/cjs/components/orders/PaymentMethodAmount.js +1 -1
  62. package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
  63. package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
  64. package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.js +1 -1
  65. package/lib/cjs/components/orders/ShippingAmount.js +1 -1
  66. package/lib/cjs/components/orders/SubTotalAmount.js +1 -1
  67. package/lib/cjs/components/orders/TaxesAmount.js +1 -1
  68. package/lib/cjs/components/orders/TotalAmount.js +1 -1
  69. package/lib/cjs/components/parcels/ParcelField.js +1 -1
  70. package/lib/cjs/components/parcels/ParcelLineItem.js +1 -1
  71. package/lib/cjs/components/parcels/ParcelLineItemField.js +1 -1
  72. package/lib/cjs/components/parcels/ParcelLineItemsCount.js +1 -1
  73. package/lib/cjs/components/parcels/Parcels.js +1 -1
  74. package/lib/cjs/components/parcels/ParcelsCount.js +1 -1
  75. package/lib/cjs/components/payment_gateways/AdyenGateway.js +1 -1
  76. package/lib/cjs/components/payment_gateways/BraintreeGateway.js +1 -1
  77. package/lib/cjs/components/payment_gateways/CheckoutComGateway.js +1 -1
  78. package/lib/cjs/components/payment_gateways/ExternalGateway.js +1 -1
  79. package/lib/cjs/components/payment_gateways/KlarnaGateway.js +1 -1
  80. package/lib/cjs/components/payment_gateways/PaymentGateway.js +1 -1
  81. package/lib/cjs/components/payment_gateways/PaypalGateway.js +1 -1
  82. package/lib/cjs/components/payment_gateways/StripeGateway.js +1 -1
  83. package/lib/cjs/components/payment_gateways/WireTransferGateway.js +1 -1
  84. package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +14 -1
  85. package/lib/cjs/components/payment_methods/PaymentMethod.js +1 -1
  86. package/lib/cjs/components/payment_methods/PaymentMethodName.js +1 -1
  87. package/lib/cjs/components/payment_methods/PaymentMethodPrice.js +1 -1
  88. package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.js +1 -1
  89. package/lib/cjs/components/payment_methods/PaymentMethodsContainer.js +1 -1
  90. package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
  91. package/lib/cjs/components/payment_source/BraintreePayment.js +1 -1
  92. package/lib/cjs/components/payment_source/CheckoutComPayment.js +1 -1
  93. package/lib/cjs/components/payment_source/ExternalPayment.js +1 -1
  94. package/lib/cjs/components/payment_source/KlarnaPayment.js +1 -1
  95. package/lib/cjs/components/payment_source/PaymentSource.js +1 -1
  96. package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.js +1 -1
  97. package/lib/cjs/components/payment_source/PaymentSourceBrandName.js +1 -1
  98. package/lib/cjs/components/payment_source/PaymentSourceDetail.js +1 -1
  99. package/lib/cjs/components/payment_source/PaymentSourceEditButton.js +1 -1
  100. package/lib/cjs/components/payment_source/PaypalPayment.js +1 -1
  101. package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +5 -0
  102. package/lib/cjs/components/payment_source/StripeExpressPayment.js +1 -0
  103. package/lib/cjs/components/payment_source/StripePayment.d.ts +2 -1
  104. package/lib/cjs/components/payment_source/StripePayment.js +1 -1
  105. package/lib/cjs/components/payment_source/WireTransferPayment.js +1 -1
  106. package/lib/cjs/components/prices/Price.js +1 -1
  107. package/lib/cjs/components/prices/PricesContainer.js +1 -1
  108. package/lib/cjs/components/shipments/Shipment.js +1 -1
  109. package/lib/cjs/components/shipments/ShipmentField.js +1 -1
  110. package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -1
  111. package/lib/cjs/components/shipments/ShipmentsCount.js +1 -1
  112. package/lib/cjs/components/shipping_methods/ShippingMethod.js +1 -1
  113. package/lib/cjs/components/shipping_methods/ShippingMethodName.js +1 -1
  114. package/lib/cjs/components/shipping_methods/ShippingMethodPrice.js +1 -1
  115. package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.js +1 -1
  116. package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
  117. package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
  118. package/lib/cjs/components/skus/DeliveryLeadTime.js +1 -1
  119. package/lib/cjs/components/skus/SkuField.js +1 -1
  120. package/lib/cjs/components/skus/SkuListsContainer.js +1 -1
  121. package/lib/cjs/components/skus/Skus.js +1 -1
  122. package/lib/cjs/components/skus/SkusContainer.js +1 -1
  123. package/lib/cjs/components/stock_transfers/StockTransfer.js +1 -1
  124. package/lib/cjs/components/stock_transfers/StockTransferField.js +1 -1
  125. package/lib/cjs/components/utils/AddressCardsTemplate.js +1 -1
  126. package/lib/cjs/components/utils/BaseField.js +1 -1
  127. package/lib/cjs/components/utils/BaseInput.js +1 -1
  128. package/lib/cjs/components/utils/BaseOrderPrice.js +1 -1
  129. package/lib/cjs/components/utils/BaseSelect.js +1 -1
  130. package/lib/cjs/components/utils/ErrorBoundary.js +1 -1
  131. package/lib/cjs/components/utils/GenericFieldComponent.js +1 -1
  132. package/lib/cjs/components/utils/Parent.js +1 -1
  133. package/lib/cjs/components/utils/PaymentCardsTemplate.js +1 -1
  134. package/lib/cjs/components/utils/PriceTemplate.js +1 -1
  135. package/lib/cjs/components/utils/getAllErrors.js +1 -1
  136. package/lib/cjs/context/ExternalFunctionContext.js +1 -1
  137. package/lib/cjs/context/OrderContext.js +1 -1
  138. package/lib/cjs/context/PaymentMethodChildrenContext.d.ts +1 -0
  139. package/lib/cjs/hooks/useOrderContainer.js +1 -1
  140. package/lib/cjs/reducers/AddressReducer.js +1 -1
  141. package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
  142. package/lib/cjs/reducers/BillingAddressReducer.js +1 -1
  143. package/lib/cjs/reducers/CustomerReducer.js +1 -1
  144. package/lib/cjs/reducers/GiftCardReducer.js +1 -1
  145. package/lib/cjs/reducers/LineItemReducer.js +1 -1
  146. package/lib/cjs/reducers/OrderReducer.js +1 -1
  147. package/lib/cjs/reducers/PaymentMethodReducer.js +1 -1
  148. package/lib/cjs/reducers/PlaceOrderReducer.js +1 -1
  149. package/lib/cjs/reducers/PriceReducer.js +1 -1
  150. package/lib/cjs/reducers/ShipmentReducer.js +1 -1
  151. package/lib/cjs/reducers/ShippingAddressReducer.js +1 -1
  152. package/lib/cjs/reducers/SkuListsReducer.js +1 -1
  153. package/lib/cjs/reducers/SkuReducer.js +1 -1
  154. package/lib/cjs/typings/index.d.ts +2 -2
  155. package/lib/cjs/typings/index.js +1 -1
  156. package/lib/cjs/utils/baseReducer.js +1 -1
  157. package/lib/cjs/utils/expressPaymentHelper.d.ts +83 -0
  158. package/lib/cjs/utils/expressPaymentHelper.js +1 -0
  159. package/lib/cjs/utils/getCardDetails.js +1 -1
  160. package/lib/cjs/utils/getErrors.js +1 -1
  161. package/lib/cjs/utils/getPrices.js +1 -1
  162. package/lib/cjs/utils/getSdk.js +1 -1
  163. package/lib/cjs/utils/icons.js +1 -1
  164. package/lib/cjs/utils/isEmpty.d.ts +1 -0
  165. package/lib/cjs/utils/isEmpty.js +1 -0
  166. package/lib/cjs/utils/promisify.js +1 -1
  167. package/lib/cjs/utils/shipments.js +1 -1
  168. package/lib/cjs/utils/snakeToCamelCase.js +1 -1
  169. package/lib/cjs/utils/validateFormFields.js +1 -1
  170. package/lib/esm/components/customers/CustomerField.js +1 -1
  171. package/lib/esm/components/line_items/LineItemField.js +1 -1
  172. package/lib/esm/components/parcels/ParcelField.js +1 -1
  173. package/lib/esm/components/parcels/ParcelLineItemField.js +1 -1
  174. package/lib/esm/components/payment_gateways/PaymentGateway.js +1 -1
  175. package/lib/esm/components/payment_gateways/StripeGateway.js +1 -1
  176. package/lib/esm/components/payment_methods/PaymentMethod.d.ts +14 -1
  177. package/lib/esm/components/payment_methods/PaymentMethod.js +1 -1
  178. package/lib/esm/components/payment_methods/PaymentMethodsContainer.js +1 -1
  179. package/lib/esm/components/payment_source/PaymentSource.js +1 -1
  180. package/lib/esm/components/payment_source/PaymentSourceBrandName.js +1 -1
  181. package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +5 -0
  182. package/lib/esm/components/payment_source/StripeExpressPayment.js +1 -0
  183. package/lib/esm/components/payment_source/StripePayment.d.ts +2 -1
  184. package/lib/esm/components/payment_source/StripePayment.js +1 -1
  185. package/lib/esm/components/skus/SkuField.js +1 -1
  186. package/lib/esm/components/stock_transfers/StockTransferField.js +1 -1
  187. package/lib/esm/context/PaymentMethodChildrenContext.d.ts +1 -0
  188. package/lib/esm/typings/index.d.ts +2 -2
  189. package/lib/esm/utils/expressPaymentHelper.d.ts +83 -0
  190. package/lib/esm/utils/expressPaymentHelper.js +1 -0
  191. package/lib/esm/utils/isEmpty.d.ts +1 -0
  192. package/lib/esm/utils/isEmpty.js +1 -0
  193. package/package.json +16 -16
  194. package/lib/tsconfig.prod.esm.tsbuildinfo +0 -1
  195. package/lib/tsconfig.prod.tsbuildinfo +0 -1
@@ -12,9 +12,22 @@ type Props = {
12
12
  */
13
13
  hide?: PaymentResource[] | ((payment: PaymentMethodType) => boolean);
14
14
  children: DefaultChildrenType;
15
+ /**
16
+ * Set CSS classes when the payment method is selected
17
+ */
15
18
  activeClass?: string;
19
+ /**
20
+ * Customize the loader component
21
+ */
16
22
  loader?: LoaderType;
23
+ /**
24
+ * Auto select the payment method when there is only one available
25
+ */
17
26
  autoSelectSinglePaymentMethod?: boolean | (() => void);
27
+ /**
28
+ * Enable express payment. Other payment methods will be disabled.
29
+ */
30
+ expressPayments?: boolean;
18
31
  } & Omit<JSX.IntrinsicElements['div'], 'onClick' | 'children'> & ({
19
32
  clickableContainer: true;
20
33
  onClick?: (params?: TOnClickParams) => void;
@@ -22,5 +35,5 @@ type Props = {
22
35
  clickableContainer?: never;
23
36
  onClick?: never;
24
37
  });
25
- export declare function PaymentMethod({ children, className, activeClass, loader, clickableContainer, autoSelectSinglePaymentMethod, hide, onClick, ...p }: Props): JSX.Element;
38
+ export declare function PaymentMethod({ children, className, activeClass, loader, clickableContainer, autoSelectSinglePaymentMethod, expressPayments, hide, onClick, ...p }: Props): JSX.Element;
26
39
  export default PaymentMethod;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethod=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")),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),getPaymentAttributes_1=require("../../utils/getPaymentAttributes");function PaymentMethod({children,className,activeClass,loader="Loading...",clickableContainer,autoSelectSinglePaymentMethod,hide,onClick,...p}){const[loading,setLoading]=(0,react_1.useState)(!0),[paymentSelected,setPaymentSelected]=(0,react_1.useState)(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder,paymentSource,setPaymentSource,config}=(0,useCustomContext_1.default)({context:PaymentMethodContext_1.default,contextComponentName:"PaymentMethodsContainer",currentComponentName:"PaymentMethod",key:"paymentMethods"}),{order}=(0,react_1.useContext)(OrderContext_1.default),{getCustomerPaymentSources}=(0,react_1.useContext)(CustomerContext_1.default);(0,react_1.useEffect)(()=>{paymentMethods!=null&&autoSelectSinglePaymentMethod!=null&&(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=(0,getPaymentAttributes_1.getPaypalAttributes)(paymentResource,config)),config!=null&&paymentResource==="external_payments"&&(attributes=(0,getPaymentAttributes_1.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]),(0,react_1.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},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(0,jsx_runtime_1.jsx)("div",{"data-testid":paymentResource,className:`${className??""} ${isActive&&activeClass!=null?activeClass:""}`,onClick:onClickable,...p,children:(0,jsx_runtime_1.jsx)(PaymentMethodChildrenContext_1.default.Provider,{value:paymentMethodProps,children})},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.PaymentMethod=PaymentMethod,exports.default=PaymentMethod;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethod=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")),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),getPaymentAttributes_1=require("../../utils/getPaymentAttributes"),isEmpty_1=require("../../utils/isEmpty"),expressPaymentHelper_1=require("../../utils/expressPaymentHelper");function PaymentMethod(_a){var{children,className,activeClass,loader="Loading...",clickableContainer,autoSelectSinglePaymentMethod,expressPayments,hide,onClick}=_a,p=tslib_1.__rest(_a,["children","className","activeClass","loader","clickableContainer","autoSelectSinglePaymentMethod","expressPayments","hide","onClick"]);const[loading,setLoading]=(0,react_1.useState)(!0),[paymentSelected,setPaymentSelected]=(0,react_1.useState)(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder,paymentSource,setPaymentSource,config}=(0,useCustomContext_1.default)({context:PaymentMethodContext_1.default,contextComponentName:"PaymentMethodsContainer",currentComponentName:"PaymentMethod",key:"paymentMethods"}),{order}=(0,react_1.useContext)(OrderContext_1.default),{getCustomerPaymentSources}=(0,react_1.useContext)(CustomerContext_1.default);(0,react_1.useEffect)(()=>{if(paymentMethods!=null&&!(0,isEmpty_1.isEmpty)(paymentMethods)&&expressPayments){const[paymentMethod]=(0,expressPaymentHelper_1.getAvailableExpressPayments)(paymentMethods);!paymentSource&&paymentMethod!=null&&tslib_1.__awaiter(this,void 0,void 0,function*(){setLoadingPlaceOrder({loading:!0}),setPaymentSelected(paymentMethod.id);const paymentMethodId=paymentMethod?.id,paymentResource=paymentMethod?.payment_source_type;yield setPaymentMethod({paymentResource,paymentMethodId}),(yield setPaymentSource({paymentResource,order}))&&paymentMethod&&onClick!=null&&(onClick({payment:paymentMethod,order}),setTimeout(()=>{setLoading(!1)},200)),setLoadingPlaceOrder({loading:!1})})}},[!(0,isEmpty_1.isEmpty)(paymentMethods),expressPayments]),(0,react_1.useEffect)(()=>{paymentMethods!=null&&autoSelectSinglePaymentMethod!=null&&!expressPayments&&tslib_1.__awaiter(this,void 0,void 0,function*(){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;yield setPaymentMethod({paymentResource,paymentMethodId});let attributes={};config!=null&&paymentResource==="paypal_payments"&&(attributes=(0,getPaymentAttributes_1.getPaypalAttributes)(paymentResource,config)),config!=null&&paymentResource==="external_payments"&&(attributes=(0,getPaymentAttributes_1.getExternalPaymentAttributes)(paymentResource,config)),(yield 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]),(0,react_1.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?e=>tslib_1.__awaiter(this,void 0,void 0,function*(){e.stopPropagation(),setLoadingPlaceOrder({loading:!0}),setPaymentSelected(payment.id);const paymentMethodId=payment?.id,{order:order2}=yield setPaymentMethod({paymentResource,paymentMethodId});onClick&&onClick({payment,order:order2}),setLoadingPlaceOrder({loading:!1})}):void 0;return(0,jsx_runtime_1.jsx)("div",Object.assign({"data-testid":paymentResource,className:`${className??""} ${isActive&&activeClass!=null?activeClass:""}`,onClick:onClickable},p,{children:(0,jsx_runtime_1.jsx)(PaymentMethodChildrenContext_1.default.Provider,Object.assign({value:paymentMethodProps},{children}))}),k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.PaymentMethod=PaymentMethod,exports.default=PaymentMethod;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodName(props){const{payment}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,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?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("label",{htmlFor,...props,children:labelName})}exports.PaymentMethodName=PaymentMethodName,exports.default=PaymentMethodName;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodName(props){const{payment}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodName",key:"payment"}),labelName=payment?.name,htmlFor=payment?.payment_source_type,paymentGateway=payment?.payment_gateway,parentProps=Object.assign({htmlFor,labelName,paymentGateway},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("label",Object.assign({htmlFor},props,{children:labelName}))}exports.PaymentMethodName=PaymentMethodName,exports.default=PaymentMethodName;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodPrice=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),getAmount_1=tslib_1.__importDefault(require("../../utils/getAmount")),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodPrice(props){const{format="formatted",type="amount",labelFree="Free",...p}=props,{payment}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodPrice",key:"payment"}),[price,setPrice]=(0,react_1.useState)(""),[priceCents,setPriceCents]=(0,react_1.useState)(0);(0,react_1.useEffect)(()=>{if(payment){const p2=(0,getAmount_1.default)({base:"price",type,format,obj:payment});setPrice(p2);const c=(0,getAmount_1.default)({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps={labelFree,price,priceCents,...p};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("span",{...p,children:priceCents===0?labelFree:price})}exports.PaymentMethodPrice=PaymentMethodPrice,exports.default=PaymentMethodPrice;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodPrice=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),getAmount_1=tslib_1.__importDefault(require("../../utils/getAmount")),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodPrice(props){const{format="formatted",type="amount",labelFree="Free"}=props,p=tslib_1.__rest(props,["format","type","labelFree"]),{payment}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodPrice",key:"payment"}),[price,setPrice]=(0,react_1.useState)(""),[priceCents,setPriceCents]=(0,react_1.useState)(0);(0,react_1.useEffect)(()=>{if(payment){const p2=(0,getAmount_1.default)({base:"price",type,format,obj:payment});setPrice(p2);const c=(0,getAmount_1.default)({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps=Object.assign({labelFree,price,priceCents},p);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},p,{children:priceCents===0?labelFree:price}))}exports.PaymentMethodPrice=PaymentMethodPrice,exports.default=PaymentMethodPrice;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodRadioButton(props){const{onChange,...p}=props,{payment,paymentSelected,setPaymentSelected,clickableContainer}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodRadioButton",key:"payment"}),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPaymentMethod,setLoading}=(0,react_1.useContext)(PaymentMethodContext_1.default),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?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("input",{title:name,type:"radio",id,onChange:e=>{handleOnChange(e)},checked,...p})}exports.PaymentMethodRadioButton=PaymentMethodRadioButton,exports.default=PaymentMethodRadioButton;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodRadioButton(props){const{onChange}=props,p=tslib_1.__rest(props,["onChange"]),{payment,paymentSelected,setPaymentSelected,clickableContainer}=(0,useCustomContext_1.default)({context:PaymentMethodChildrenContext_1.default,contextComponentName:"PaymentMethod",currentComponentName:"PaymentMethodRadioButton",key:"payment"}),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPaymentMethod,setLoading}=(0,react_1.useContext)(PaymentMethodContext_1.default),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=payment?.id,name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer){const{order:order2}=yield setPaymentMethod({paymentResource,paymentMethodId});onChange&&onChange({payment,order:order2})}setLoading({loading:!1})}),id=payment?.payment_source_type,parentProps=Object.assign({handleOnChange,checked,id,name},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("input",Object.assign({title:name,type:"radio",id,onChange:e=>{handleOnChange(e)},checked},p))}exports.PaymentMethodRadioButton=PaymentMethodRadioButton,exports.default=PaymentMethodRadioButton;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importStar(require("../../context/PaymentMethodContext")),react_1=require("react"),PaymentMethodReducer_1=tslib_1.__importStar(require("../../reducers/PaymentMethodReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PaymentMethodsContainer(props){const{children,config}=props,[state,dispatch]=(0,react_1.useReducer)(PaymentMethodReducer_1.default,PaymentMethodReducer_1.paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=(0,useCustomContext_1.default)({context:OrderContext_1.default,contextComponentName:"OrderContainer",currentComponentName:"PaymentMethodsContainer",key:"order"}),credentials=(0,react_1.useContext)(CommerceLayerContext_1.default);async function getPayMethods(){order&&await(0,PaymentMethodReducer_1.getPaymentMethods)({order,dispatch})}(0,react_1.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&&(0,isEmpty_1.default)(state.config)&&(0,PaymentMethodReducer_1.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=(0,react_1.useMemo)(()=>({...state,setLoading:({loading})=>{PaymentMethodContext_1.defaultPaymentMethodContext.setLoading({loading,dispatch})},setPaymentRef:({ref})=>{(0,PaymentMethodReducer_1.setPaymentRef)({ref,dispatch})},setPaymentMethodErrors:errors=>{PaymentMethodContext_1.defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch)},setPaymentMethod:async args=>await PaymentMethodContext_1.defaultPaymentMethodContext.setPaymentMethod({...args,config:credentials,updateOrder,order,dispatch,setOrderErrors}),setPaymentSource:async args=>await PaymentMethodContext_1.defaultPaymentMethodContext.setPaymentSource({...state,...args,config:credentials,dispatch,getOrder,updateOrder,order}),updatePaymentSource:async args=>{await PaymentMethodContext_1.defaultPaymentMethodContext.updatePaymentSource({...args,config:credentials,dispatch})},destroyPaymentSource:async args=>{await PaymentMethodContext_1.defaultPaymentMethodContext.destroyPaymentSource({...args,dispatch,config:credentials,updateOrder,orderId:order?.id})}}),[state]);return(0,jsx_runtime_1.jsx)(PaymentMethodContext_1.default.Provider,{value:contextValue,children})}exports.PaymentMethodsContainer=PaymentMethodsContainer,exports.default=PaymentMethodsContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentMethodsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importStar(require("../../context/PaymentMethodContext")),react_1=require("react"),PaymentMethodReducer_1=tslib_1.__importStar(require("../../reducers/PaymentMethodReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext")),isEmpty_1=require("../../utils/isEmpty");function PaymentMethodsContainer(props){const{children,config}=props,[state,dispatch]=(0,react_1.useReducer)(PaymentMethodReducer_1.default,PaymentMethodReducer_1.paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=(0,useCustomContext_1.default)({context:OrderContext_1.default,contextComponentName:"OrderContainer",currentComponentName:"PaymentMethodsContainer",key:"order"}),credentials=(0,react_1.useContext)(CommerceLayerContext_1.default);function getPayMethods(){return tslib_1.__awaiter(this,void 0,void 0,function*(){order&&(yield(0,PaymentMethodReducer_1.getPaymentMethods)({order,dispatch}))})}(0,react_1.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&&(0,isEmpty_1.isEmpty)(state.config)&&(0,PaymentMethodReducer_1.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=(0,react_1.useMemo)(()=>Object.assign(Object.assign({},state),{setLoading:({loading})=>{PaymentMethodContext_1.defaultPaymentMethodContext.setLoading({loading,dispatch})},setPaymentRef:({ref})=>{(0,PaymentMethodReducer_1.setPaymentRef)({ref,dispatch})},setPaymentMethodErrors:errors=>{PaymentMethodContext_1.defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch)},setPaymentMethod:args=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield PaymentMethodContext_1.defaultPaymentMethodContext.setPaymentMethod(Object.assign(Object.assign({},args),{config:credentials,updateOrder,order,dispatch,setOrderErrors}))}),setPaymentSource:args=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield PaymentMethodContext_1.defaultPaymentMethodContext.setPaymentSource(Object.assign(Object.assign(Object.assign({},state),args),{config:credentials,dispatch,getOrder,updateOrder,order}))}),updatePaymentSource:args=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield PaymentMethodContext_1.defaultPaymentMethodContext.updatePaymentSource(Object.assign(Object.assign({},args),{config:credentials,dispatch}))}),destroyPaymentSource:args=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield PaymentMethodContext_1.defaultPaymentMethodContext.destroyPaymentSource(Object.assign(Object.assign({},args),{dispatch,config:credentials,updateOrder,orderId:order?.id}))})}),[state]);return(0,jsx_runtime_1.jsx)(PaymentMethodContext_1.default.Provider,Object.assign({value:contextValue},{children}))}exports.PaymentMethodsContainer=PaymentMethodsContainer,exports.default=PaymentMethodsContainer;
@@ -1 +1 @@
1
- "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")),threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=(0,react_1.useState)(!1),[checkout,setCheckout]=(0,react_1.useState)(null),{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=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component?.submit&&component.submit(),!1},handleChange=async(state,checkout2)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=async()=>await handleSubmit(ref.current,checkout2),setPaymentRef({ref}));const browserInfo=(0,browserInfo_1.default)(),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=(0,browserInfo_1.default)(),saveCustomer=document.getElementById("save_payment_source_to_customer_wallet"),url=(0,browserInfo_1.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:(0,omit_1.default)(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(0,react_1.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:handleOnAdditionalDetails,onChange:handleChange,onSubmit};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,{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:(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
+ "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")),threeDSConfiguration={challengeWindowSize:"05"},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)(null),{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,checkout2)=>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,checkout2)}),setPaymentRef({ref}));const browserInfo=(0,browserInfo_1.default)(),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: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 browserInfo=(0,browserInfo_1.default)(),saveCustomer=document.getElementById("save_payment_source_to_customer_wallet"),url=(0,browserInfo_1.cleanUrlBy)();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","encryptedSecurityCode"]);(!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",browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)})}}));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",browser_info:Object.assign({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=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"].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}])}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;const paymentMethodsResponse=!((_a=paymentSource?.payment_methods)===null||_a===void 0)&&_a.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:handleOnAdditionalDetails,onChange:handleChange,onSubmit};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,{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]),!clientKey&&!loadAdyen&&!checkout?null:(0,jsx_runtime_1.jsxs)("form",Object.assign({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,Object.assign({},{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 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BraintreePayment=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")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),promisify_1=tslib_1.__importDefault(require("../../utils/promisify")),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"};function BraintreePayment({authorization,config,templateCustomerSaveToWallet}){const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}={...defaultConfig,...config},[loadBraintree,setLoadBraintree]=(0,react_1.useState)(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),ref=(0,react_1.useRef)(null),handleSubmitForm=async({event,hostedFieldsInstance,threeDSInstance})=>{const savePaymentSourceToCustomerWallet=event?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=await(0,promisify_1.default)(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(0,react_1.useEffect)(()=>{if(!ref&&authorization&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!(0,isEmpty_1.default)(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:(0,jsx_runtime_1.jsx)("div",{className:containerClassName,children:(0,jsx_runtime_1.jsxs)("form",{ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:fieldsContainerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:cardContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"card-number",children:fields?.number?.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"card-number"})]}),(0,jsx_runtime_1.jsxs)("div",{className:cardDetailsContainerClassName,children:[(0,jsx_runtime_1.jsxs)("div",{className:expDateContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"expiration-date",children:fields?.expirationDate?.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"expiration-date"})]}),(0,jsx_runtime_1.jsxs)("div",{className:cvvContainerClassName,children:[(0,jsx_runtime_1.jsx)("label",{className:fieldLabelClassName,htmlFor:"cvv",children:fields?.cvv?.label}),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"cvv"})]})]})]}),(0,jsx_runtime_1.jsx)("div",{className:fieldsContainerClassName,children:templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})})]})})}exports.BraintreePayment=BraintreePayment,exports.default=BraintreePayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BraintreePayment=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")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),promisify_1=tslib_1.__importDefault(require("../../utils/promisify")),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"};function BraintreePayment({authorization,config,templateCustomerSaveToWallet}){var _a,_b,_c;const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}=Object.assign(Object.assign({},defaultConfig),config),[loadBraintree,setLoadBraintree]=(0,react_1.useState)(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),ref=(0,react_1.useRef)(null),handleSubmitForm=({event,hostedFieldsInstance,threeDSInstance})=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _d,_e;const savePaymentSourceToCustomerWallet=(_e=(_d=event?.elements)===null||_d===void 0?void 0:_d.save_payment_source_to_customer_wallet)===null||_e===void 0?void 0:_e.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=yield(0,promisify_1.default)(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=yield threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&(yield 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(0,react_1.useEffect)(()=>{if(!ref&&authorization&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!(0,isEmpty_1.default)(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=paymentSource2=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2})}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},{children:(0,jsx_runtime_1.jsxs)("form",Object.assign({ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName},{children:[(0,jsx_runtime_1.jsxs)("div",Object.assign({className:fieldsContainerClassName},{children:[(0,jsx_runtime_1.jsxs)("div",Object.assign({className:cardContainerClassName},{children:[(0,jsx_runtime_1.jsx)("label",Object.assign({className:fieldLabelClassName,htmlFor:"card-number"},{children:(_a=fields?.number)===null||_a===void 0?void 0:_a.label})),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"card-number"})]})),(0,jsx_runtime_1.jsxs)("div",Object.assign({className:cardDetailsContainerClassName},{children:[(0,jsx_runtime_1.jsxs)("div",Object.assign({className:expDateContainerClassName},{children:[(0,jsx_runtime_1.jsx)("label",Object.assign({className:fieldLabelClassName,htmlFor:"expiration-date"},{children:(_b=fields?.expirationDate)===null||_b===void 0?void 0:_b.label})),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"expiration-date"})]})),(0,jsx_runtime_1.jsxs)("div",Object.assign({className:cvvContainerClassName},{children:[(0,jsx_runtime_1.jsx)("label",Object.assign({className:fieldLabelClassName,htmlFor:"cvv"},{children:(_c=fields?.cvv)===null||_c===void 0?void 0:_c.label})),(0,jsx_runtime_1.jsx)("div",{className:inputWrapperClassName,id:"cvv"})]}))]}))]})),(0,jsx_runtime_1.jsx)("div",Object.assign({className:fieldsContainerClassName},{children:templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))}))]}))}))}exports.BraintreePayment=BraintreePayment,exports.default=BraintreePayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutComPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),frames_react_1=require("frames-react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),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"}}}};function CheckoutComPayment({publicKey,options=defaultOptions,locale="EN-GB",...p}){const ref=(0,react_1.useRef)(null),loaded=(0,useExternalScript_1.default)(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{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&&(0,localStorage_1.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?(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsxs)(frames_react_1.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:[(0,jsx_runtime_1.jsx)(frames_react_1.CardNumber,{}),(0,jsx_runtime_1.jsx)(frames_react_1.ExpiryDate,{}),(0,jsx_runtime_1.jsx)(frames_react_1.Cvv,{})]})}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]}):null}exports.CheckoutComPayment=CheckoutComPayment,exports.default=CheckoutComPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CheckoutComPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),frames_react_1=require("frames-react"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),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"}}}};function CheckoutComPayment(_a){var{publicKey,options=defaultOptions,locale="EN-GB"}=_a,p=tslib_1.__rest(_a,["publicKey","options","locale"]);const ref=(0,react_1.useRef)(null),loaded=(0,useExternalScript_1.default)(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{containerClassName,templateCustomerSaveToWallet,successUrl=window.location.href,failureUrl=window.location.href,show}=p,divProps=tslib_1.__rest(p,["containerClassName","templateCustomerSaveToWallet","successUrl","failureUrl","show"]),handleSubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m;const savePaymentSourceToCustomerWallet=(_d=(_c=(_b=ref?.current)===null||_b===void 0?void 0:_b.elements)===null||_c===void 0?void 0:_c.save_payment_source_to_customer_wallet)===null||_d===void 0?void 0:_d.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:(_e=order?.billing_address)===null||_e===void 0?void 0:_e.full_name,billingAddress:{addressLine1:(_f=order?.billing_address)===null||_f===void 0?void 0:_f.line_1,addressLine2:(_g=order?.billing_address)===null||_g===void 0?void 0:_g.line_2,zip:(_h=order?.billing_address)===null||_h===void 0?void 0:_h.zip_code,city:(_j=order?.billing_address)===null||_j===void 0?void 0:_j.city,state:(_k=order?.billing_address)===null||_k===void 0?void 0:_k.state_code,country:(_l=order?.billing_address)===null||_l===void 0?void 0:_l.country_code},phone:(_m=order?.billing_address)===null||_m===void 0?void 0:_m.phone};try{const data=yield window.Frames.submitCard();if(data.token&&paymentSource&&currentPaymentMethodType){const ps=yield 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?(0,jsx_runtime_1.jsxs)("form",Object.assign({ref},{children:[(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsxs)(frames_react_1.Frames,Object.assign({config:Object.assign({debug:!0,publicKey,localization},options),cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleSubmit()}),setPaymentRef({ref}))},cardTokenized:data=>data},{children:[(0,jsx_runtime_1.jsx)(frames_react_1.CardNumber,{}),(0,jsx_runtime_1.jsx)(frames_react_1.ExpiryDate,{}),(0,jsx_runtime_1.jsx)(frames_react_1.Cvv,{})]}))})),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))]})):null}exports.CheckoutComPayment=CheckoutComPayment,exports.default=CheckoutComPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExternalPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),react_1=require("react");function ExternalPayment(props){const{setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),ref=(0,react_1.useRef)(null);return(0,react_1.useEffect)(()=>{ref!==null&&(ref.current.onsubmit=async()=>!0,setPaymentRef({ref}))},[ref]),props?.customComponent!=null&&props.show?(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)(Parent_1.default,{children:props.customComponent}),props?.templateCustomerSaveToWallet!=null&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:props.templateCustomerSaveToWallet})]}):null}exports.ExternalPayment=ExternalPayment,exports.default=ExternalPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExternalPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),react_1=require("react");function ExternalPayment(props){const{setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),ref=(0,react_1.useRef)(null);return(0,react_1.useEffect)(()=>{ref!==null&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return!0}),setPaymentRef({ref}))},[ref]),props?.customComponent!=null&&props.show?(0,jsx_runtime_1.jsxs)("form",Object.assign({ref},{children:[(0,jsx_runtime_1.jsx)(Parent_1.default,{children:props.customComponent}),props?.templateCustomerSaveToWallet!=null&&(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:props.templateCustomerSaveToWallet}))]})):null}exports.ExternalPayment=ExternalPayment,exports.default=ExternalPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!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")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext"));function typeOfLine(lineItemType){switch(lineItemType){case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical";case"payment_methods":default:return null}}function klarnaOrderLines(lineItems){return lineItems?lineItems.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{name:item.name,quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}function KlarnaPayment({clientToken,placeOrderCallback,locale="EN",...p}){const ref=(0,react_1.useRef)(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPlaceOrder}=(0,react_1.useContext)(PlaceOrderContext_1.default),loaded=(0,useExternalScript_1.default)("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=(0,react_1.useState)(),{containerClassName,...divProps}=p;(0,react_1.useEffect)(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=async()=>{await handleClick(klarna)},setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=async kl=>{const[first]=paymentSource?.payment_methods||void 0,paymentMethodCategory=first?.identifier,billingAddress={given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:null,organization_name:null,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shippingAddress={given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,email:order?.customer_email,street_address:order?.shipping_address?.line_1,street_address2:null,postal_code:order?.shipping_address?.zip_code,organization_name:null,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address:shippingAddress,billing_address:billingAddress,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category:paymentMethodCategory},{billing_address:billingAddress,shipping_address:shippingAddress},async function({show_form}){if(show_form)try{await kl.Payments.authorize({payment_method_category:paymentMethodCategory},klarnaData,async function(res){if(res.approved&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}}),{placed}=setPlaceOrder&&ps&&await setPlaceOrder({paymentSource:ps})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})}catch(e){console.error("Load Klarna libray",e)}};if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier},{billing_address:{given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:order?.billing_address?.line_2,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shipping_address:{given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,street_address:order?.shipping_address?.line_1,street_address2:order?.shipping_address?.line_2,postal_code:order?.shipping_address?.zip_code,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code}})}return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsx)("div",{id:"klarna-payments-container"})})})}exports.default=KlarnaPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!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")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),useExternalScript_1=tslib_1.__importDefault(require("../../utils/hooks/useExternalScript")),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext"));function typeOfLine(lineItemType){switch(lineItemType){case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical";case"payment_methods":default:return null}}function klarnaOrderLines(lineItems){return lineItems?lineItems.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{name:item.name,quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}function KlarnaPayment(_a){var _b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,{clientToken,placeOrderCallback,locale="EN"}=_a,p=tslib_1.__rest(_a,["clientToken","placeOrderCallback","locale"]);const ref=(0,react_1.useRef)(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource,setPaymentMethodErrors}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{setPlaceOrder}=(0,react_1.useContext)(PlaceOrderContext_1.default),loaded=(0,useExternalScript_1.default)("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=(0,react_1.useState)(),{containerClassName}=p,divProps=tslib_1.__rest(p,["containerClassName"]);(0,react_1.useEffect)(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){yield handleClick(klarna)}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=kl=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _v,_w,_x,_y,_z,_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10;const[first]=paymentSource?.payment_methods||void 0,paymentMethodCategory=first?.identifier,billingAddress={given_name:(_v=order?.billing_address)===null||_v===void 0?void 0:_v.first_name,family_name:(_w=order?.billing_address)===null||_w===void 0?void 0:_w.last_name,email:order?.customer_email,street_address:(_x=order?.billing_address)===null||_x===void 0?void 0:_x.line_1,street_address2:null,organization_name:null,postal_code:(_y=order?.billing_address)===null||_y===void 0?void 0:_y.zip_code,city:(_z=order?.billing_address)===null||_z===void 0?void 0:_z.city,region:(_0=order?.billing_address)===null||_0===void 0?void 0:_0.state_code,phone:(_1=order?.billing_address)===null||_1===void 0?void 0:_1.phone,country:(_2=order?.billing_address)===null||_2===void 0?void 0:_2.country_code},shippingAddress={given_name:(_3=order?.shipping_address)===null||_3===void 0?void 0:_3.first_name,family_name:(_4=order?.shipping_address)===null||_4===void 0?void 0:_4.last_name,email:order?.customer_email,street_address:(_5=order?.shipping_address)===null||_5===void 0?void 0:_5.line_1,street_address2:null,postal_code:(_6=order?.shipping_address)===null||_6===void 0?void 0:_6.zip_code,organization_name:null,city:(_7=order?.shipping_address)===null||_7===void 0?void 0:_7.city,region:(_8=order?.shipping_address)===null||_8===void 0?void 0:_8.state_code,phone:(_9=order?.shipping_address)===null||_9===void 0?void 0:_9.phone,country:(_10=order?.shipping_address)===null||_10===void 0?void 0:_10.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address:shippingAddress,billing_address:billingAddress,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category:paymentMethodCategory},{billing_address:billingAddress,shipping_address:shippingAddress},function({show_form}){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(show_form)try{yield kl.Payments.authorize({payment_method_category:paymentMethodCategory},klarnaData,function(res){return tslib_1.__awaiter(this,void 0,void 0,function*(){if(res.approved&&paymentSource&&currentPaymentMethodType){const ps=yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}}),{placed}=setPlaceOrder&&ps&&(yield setPlaceOrder({paymentSource:ps}))||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}})})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})})}catch(e){console.error("Load Klarna libray",e)}});if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier},{billing_address:{given_name:(_b=order?.billing_address)===null||_b===void 0?void 0:_b.first_name,family_name:(_c=order?.billing_address)===null||_c===void 0?void 0:_c.last_name,email:order?.customer_email,street_address:(_d=order?.billing_address)===null||_d===void 0?void 0:_d.line_1,street_address2:(_e=order?.billing_address)===null||_e===void 0?void 0:_e.line_2,postal_code:(_f=order?.billing_address)===null||_f===void 0?void 0:_f.zip_code,city:(_g=order?.billing_address)===null||_g===void 0?void 0:_g.city,region:(_h=order?.billing_address)===null||_h===void 0?void 0:_h.state_code,phone:(_j=order?.billing_address)===null||_j===void 0?void 0:_j.phone,country:(_k=order?.billing_address)===null||_k===void 0?void 0:_k.country_code},shipping_address:{given_name:(_l=order?.shipping_address)===null||_l===void 0?void 0:_l.first_name,family_name:(_m=order?.shipping_address)===null||_m===void 0?void 0:_m.last_name,street_address:(_o=order?.shipping_address)===null||_o===void 0?void 0:_o.line_1,street_address2:(_p=order?.shipping_address)===null||_p===void 0?void 0:_p.line_2,postal_code:(_q=order?.shipping_address)===null||_q===void 0?void 0:_q.zip_code,city:(_r=order?.shipping_address)===null||_r===void 0?void 0:_r.city,region:(_s=order?.shipping_address)===null||_s===void 0?void 0:_s.state_code,phone:(_t=order?.shipping_address)===null||_t===void 0?void 0:_t.phone,country:(_u=order?.shipping_address)===null||_u===void 0?void 0:_u.country_code}})}return(0,jsx_runtime_1.jsx)("form",Object.assign({ref},{children:(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsx)("div",{id:"klarna-payments-container"})}))}))}exports.default=KlarnaPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSource=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),PaymentGateway_1=tslib_1.__importDefault(require("../payment_gateways/PaymentGateway")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function PaymentSource(props){const{readonly}=props,{payment}=(0,react_1.useContext)(PaymentMethodChildrenContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{payments}=(0,react_1.useContext)(CustomerContext_1.default),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=(0,react_1.useContext)(PaymentMethodContext_1.default),[show,setShow]=(0,react_1.useState)(!1),[showCard,setShowCard]=(0,react_1.useState)(!1);(0,react_1.useEffect)(()=>(readonly?(setShow(!0),setShowCard(!0)):payment?.id===currentPaymentMethodId?(setShow(!0),(0,getCardDetails_1.default)({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!1),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const gatewayProps={...props,show,showCard,handleEditClick:async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)},readonly};return(0,jsx_runtime_1.jsx)(PaymentGateway_1.default,{...gatewayProps})}exports.PaymentSource=PaymentSource,exports.default=PaymentSource;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSource=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),PaymentMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodChildrenContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),PaymentGateway_1=tslib_1.__importDefault(require("../payment_gateways/PaymentGateway")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function PaymentSource(props){const{readonly}=props,{payment,expressPayments}=(0,react_1.useContext)(PaymentMethodChildrenContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{payments}=(0,react_1.useContext)(CustomerContext_1.default),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=(0,react_1.useContext)(PaymentMethodContext_1.default),[show,setShow]=(0,react_1.useState)(!1),[showCard,setShowCard]=(0,react_1.useState)(!1);(0,react_1.useEffect)(()=>(readonly?(setShow(!0),setShowCard(!0)):payment?.id===currentPaymentMethodId?(setShow(!0),(0,getCardDetails_1.default)({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!!expressPayments),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const handleEditClick=e=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;yield destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)}),gatewayProps=Object.assign(Object.assign({},props),{show,showCard,handleEditClick,readonly});return(0,jsx_runtime_1.jsx)(PaymentGateway_1.default,Object.assign({},gatewayProps))}exports.PaymentSource=PaymentSource,exports.default=PaymentSource;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${cardBrand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand:cardBrand,defaultSrc,url,width,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("img",{ref,src:url,onError:handleError,width,...p})}exports.PaymentSourceBrandIcon=PaymentSourceBrandIcon,exports.default=PaymentSourceBrandIcon;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandIcon(_a){var{src,width=32,children}=_a,p=tslib_1.__rest(_a,["src","width","children"]);const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${cardBrand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps=Object.assign({brand:cardBrand,defaultSrc,url,width},p);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("img",Object.assign({ref,src:url,onError:handleError,width},p))}exports.PaymentSourceBrandIcon=PaymentSourceBrandIcon,exports.default=PaymentSourceBrandIcon;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),capitalize_1=tslib_1.__importDefault(require("lodash/capitalize")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandName({children,label,...props}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,brandName=cardBrand&&(0,capitalize_1.default)(cardBrand.replaceAll(/_|-/gm," ")),parentProps={brand:brandName,label,...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...props,children:label||(0,capitalize_1.default)(brandName)})}exports.PaymentSourceBrandName=PaymentSourceBrandName,exports.default=PaymentSourceBrandName;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),capitalize_1=tslib_1.__importDefault(require("lodash/capitalize")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandName(_a){var{children,label}=_a,props=tslib_1.__rest(_a,["children","label"]);const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,brandName=cardBrand&&(0,capitalize_1.default)(cardBrand.replace(/_|-/gm," ")),parentProps=Object.assign({brand:brandName,label},props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},props,{children:label||(0,capitalize_1.default)(brandName)}))}exports.PaymentSourceBrandName=PaymentSourceBrandName,exports.default=PaymentSourceBrandName;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceDetail=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceDetail({type,children,...p}){const card=(0,react_1.useContext)(PaymentSourceContext_1.default),customerCard=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardObj=Object.keys(card).length>0?card:customerCard,text=type in cardObj?cardObj[type]:type==="last4"?"****":"**",parentProps={type,text,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:text})}exports.PaymentSourceDetail=PaymentSourceDetail,exports.default=PaymentSourceDetail;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceDetail=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceDetail(_a){var{type,children}=_a,p=tslib_1.__rest(_a,["type","children"]);const card=(0,react_1.useContext)(PaymentSourceContext_1.default),customerCard=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardObj=Object.keys(card).length>0?card:customerCard,text=type in cardObj?cardObj[type]:type==="last4"?"****":"**",parentProps=Object.assign({type,text},p);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},p,{children:text}))}exports.PaymentSourceDetail=PaymentSourceDetail,exports.default=PaymentSourceDetail;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceEditButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function PaymentSourceEditButton({children,label="Edit",...props}){const{showCard,handleEditClick,readonly}=(0,react_1.useContext)(PaymentSourceContext_1.default),parentProps={showCard,label,handleEditClick,...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):readonly?null:(0,jsx_runtime_1.jsx)("button",{...props,onClick:handleEditClick,children:label})}exports.PaymentSourceEditButton=PaymentSourceEditButton,exports.default=PaymentSourceEditButton;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceEditButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function PaymentSourceEditButton(_a){var{children,label="Edit"}=_a,props=tslib_1.__rest(_a,["children","label"]);const{showCard,handleEditClick,readonly}=(0,react_1.useContext)(PaymentSourceContext_1.default),parentProps=Object.assign({showCard,label,handleEditClick},props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):readonly?null:(0,jsx_runtime_1.jsx)("button",Object.assign({},props,{onClick:handleEditClick},{children:label}))}exports.PaymentSourceEditButton=PaymentSourceEditButton,exports.default=PaymentSourceEditButton;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaypalPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),react_1=require("react"),defaultMessage="by placing the order, you will be redirected to the PayPal website to sign in and authorize the payment";function PaypalPayment({infoMessage,...p}){const ref=(0,react_1.useRef)(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default);(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&paymentSource?.approval_url&&(ref.current.onsubmit=async()=>await handleClick(),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=async()=>{if(paymentSource&&currentPaymentMethodType)try{return await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"paypal",last4:""}}}}),!0}catch{return!1}return!1};return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{...p,children:(0,jsx_runtime_1.jsx)("span",{className:infoMessage?.className,children:(0,isFunction_1.default)(infoMessage?.text)?infoMessage?.text():infoMessage?.text||defaultMessage})})})}exports.PaypalPayment=PaypalPayment,exports.default=PaypalPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaypalPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),isFunction_1=tslib_1.__importDefault(require("lodash/isFunction")),react_1=require("react"),defaultMessage="by placing the order, you will be redirected to the PayPal website to sign in and authorize the payment";function PaypalPayment(_a){var{infoMessage}=_a,p=tslib_1.__rest(_a,["infoMessage"]);const ref=(0,react_1.useRef)(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default);(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&paymentSource?.approval_url&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleClick()}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(paymentSource&&currentPaymentMethodType)try{return yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"paypal",last4:""}}}}),!0}catch{return!1}return!1});return(0,jsx_runtime_1.jsx)("form",Object.assign({ref},{children:(0,jsx_runtime_1.jsx)("div",Object.assign({},p,{children:(0,jsx_runtime_1.jsx)("span",Object.assign({className:infoMessage?.className},{children:(0,isFunction_1.default)(infoMessage?.text)?infoMessage?.text():infoMessage?.text||defaultMessage}))}))}))}exports.PaypalPayment=PaypalPayment,exports.default=PaypalPayment;
@@ -0,0 +1,5 @@
1
+ interface Props {
2
+ clientSecret: string;
3
+ }
4
+ export declare function StripeExpressPayment({ clientSecret }: Props): JSX.Element | null;
5
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripeExpressPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),expressPaymentHelper_1=require("../../utils/expressPaymentHelper"),isEmpty_1=require("../../utils/isEmpty"),react_stripe_js_1=require("@stripe/react-stripe-js"),react_1=require("react");function StripeExpressPayment({clientSecret}){const stripe=(0,react_stripe_js_1.useStripe)(),[paymentRequest,setPaymentRequest]=(0,react_1.useState)(null),{accessToken,endpoint}=(0,react_1.useContext)(CommerceLayerContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),{paymentMethods,paymentSource}=(0,react_1.useContext)(PaymentMethodContext_1.default);return(0,react_1.useEffect)(()=>{var _a,_b,_c,_d,_e;if(stripe==null||order==null)return;const pr=stripe.paymentRequest({country:(_a=order.country_code)!==null&&_a!==void 0?_a:"",currency:(_c=(_b=order?.currency_code)===null||_b===void 0?void 0:_b.toLowerCase())!==null&&_c!==void 0?_c:"",total:{label:`#${(_d=order?.number)!==null&&_d!==void 0?_d:""}`,amount:(_e=order?.total_amount_with_taxes_cents)!==null&&_e!==void 0?_e:0},requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:!0,requestShipping:!0});pr.canMakePayment().then(result=>{console.log("available payment:",result),result&&setPaymentRequest(pr)}).catch(err=>{console.error("Can make payment:",err)})},[(0,isEmpty_1.isEmpty)(stripe),(0,isEmpty_1.isEmpty)(order)]),paymentRequest!=null&&stripe!=null?(paymentRequest.on("shippingaddresschange",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b,_c,_d,_e,_f,_g;if(order!=null&&accessToken!=null&&endpoint!=null){const requiresBillingInfo=(_a=order?.requires_billing_info)!==null&&_a!==void 0?_a:!1,orderWithShipments=yield(0,expressPaymentHelper_1.setExpressFakeAddress)({orderId:order.id,config:{accessToken,endpoint},address:{first_name:"Fake name",last_name:"Fake lastname",country_code:(_b=ev.shippingAddress.country)!==null&&_b!==void 0?_b:"",line_1:"Fake street 123",city:(_c=ev.shippingAddress.city)!==null&&_c!==void 0?_c:"Fake city",zip_code:(_d=ev.shippingAddress.postalCode)!==null&&_d!==void 0?_d:"12345",state_code:(_e=ev.shippingAddress.region)!==null&&_e!==void 0?_e:"Fake state",phone:"1234567890",billing_info:requiresBillingInfo?"Fake billing info":void 0}}),shippingOptions=(0,expressPaymentHelper_1.getExpressShippingMethods)(orderWithShipments);shippingOptions!=null&&!(0,isEmpty_1.isEmpty)(shippingOptions)?ev.updateWith({status:"success",shippingOptions,total:{label:`#${(_f=orderWithShipments?.number)!==null&&_f!==void 0?_f:""}`,amount:(_g=orderWithShipments?.total_amount_with_taxes_cents)!==null&&_g!==void 0?_g:0}}):ev.updateWith({status:"invalid_shipping_address"})}else ev.updateWith({status:"fail"})})),paymentRequest.on("shippingoptionchange",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _h,_j;if(order!=null&&accessToken!=null&&endpoint!=null){const updatedOrder=yield(0,expressPaymentHelper_1.setExpressShippingMethod)({orderId:order.id,config:{accessToken,endpoint},selectFirst:!1,selectedShippingMethodId:ev.shippingOption.id,params:{include:["shipments.available_shipping_methods"]}});ev.updateWith({status:"success",total:{label:`#${(_h=updatedOrder?.number)!==null&&_h!==void 0?_h:""}`,amount:(_j=updatedOrder?.total_amount_with_taxes_cents)!==null&&_j!==void 0?_j:0}})}else ev.updateWith({status:"fail"})})),paymentRequest.on("paymentmethod",ev=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _k,_l,_m,_o,_p,_q,_r,_s,_t,_u,_v,_w,_x,_y,_z;if(console.log("ev",ev),order?.id==null)throw new Error("Order is null");if(paymentMethods==null)throw new Error("Payment methods are null");const[paymentMethod]=(0,expressPaymentHelper_1.getAvailableExpressPayments)(paymentMethods);if(paymentMethod==null)throw new Error("Payment method is null");if(paymentSource==null)throw new Error("Payment source is null");const requiresBillingInfo=(_k=order?.requires_billing_info)!==null&&_k!==void 0?_k:!1,paymentResource=paymentMethod?.payment_source_type;if(accessToken!=null&&endpoint!=null){const[firstName,lastName]=(_m=(_l=ev.payerName)===null||_l===void 0?void 0:_l.split(" "))!==null&&_m!==void 0?_m:[],[line]=(_p=(_o=ev.shippingAddress)===null||_o===void 0?void 0:_o.addressLine)!==null&&_p!==void 0?_p:"";yield(0,expressPaymentHelper_1.setExpressFakeAddress)({orderId:order.id,config:{accessToken,endpoint},address:{first_name:firstName??"Fake name",last_name:lastName??"Fake lastname",country_code:(_r=(_q=ev?.shippingAddress)===null||_q===void 0?void 0:_q.country)!==null&&_r!==void 0?_r:"",line_1:line??"Fake street 123",city:(_t=(_s=ev?.shippingAddress)===null||_s===void 0?void 0:_s.city)!==null&&_t!==void 0?_t:"Fake city",zip_code:(_v=(_u=ev?.shippingAddress)===null||_u===void 0?void 0:_u.postalCode)!==null&&_v!==void 0?_v:"12345",state_code:(_x=(_w=ev?.shippingAddress)===null||_w===void 0?void 0:_w.region)!==null&&_x!==void 0?_x:"Fake state",phone:(_y=ev?.payerPhone)!==null&&_y!==void 0?_y:"1234567890",billing_info:requiresBillingInfo?"Fake billing info":void 0}}),yield(0,expressPaymentHelper_1.setExpressShippingMethod)({orderId:order.id,config:{accessToken,endpoint},selectFirst:!1,selectedShippingMethodId:(_z=ev?.shippingOption)===null||_z===void 0?void 0:_z.id,params:{include:["shipments.available_shipping_methods"]}});const{paymentIntent,error:confirmError}=yield stripe.confirmCardPayment(clientSecret,{payment_method:ev.paymentMethod.id},{handleActions:!1});if(confirmError)ev.complete("fail"),console.error("Confirm card payment:",confirmError);else if(ev.complete("success"),paymentIntent.status==="requires_action"){const{error}=yield stripe.confirmCardPayment(clientSecret);if(error)console.error("Confirm card payment:",error);else{const placeOrderParams={config:{accessToken,endpoint},orderId:order?.id,paymentResource,paymentSourceId:paymentSource?.id};try{const order2=yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams);ev.complete("success"),(0,expressPaymentHelper_1.expressRedirectUrl)({order:order2,config:{accessToken,endpoint}})}catch(err){console.error("Place order:",err),ev.complete("fail")}}}else{const placeOrderParams={config:{accessToken,endpoint},orderId:order?.id,paymentResource,paymentSourceId:paymentSource?.id};try{const order2=yield(0,expressPaymentHelper_1.setExpressPlaceOrder)(placeOrderParams);ev.complete("success"),(0,expressPaymentHelper_1.expressRedirectUrl)({order:order2,config:{accessToken,endpoint}})}catch(err){console.error("Place order:",err),ev.complete("fail")}}}})),(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentRequestButtonElement,{className:"",options:{paymentRequest}})):null}exports.StripeExpressPayment=StripeExpressPayment;
@@ -14,6 +14,7 @@ type Props = PaymentMethodConfig['stripePayment'] & JSX.IntrinsicElements['div']
14
14
  publishableKey: string;
15
15
  locale?: StripeElementLocale;
16
16
  clientSecret: string;
17
+ expressPayments?: boolean;
17
18
  };
18
- export declare function StripePayment({ publishableKey, show, options, clientSecret, locale, ...p }: Props): JSX.Element | null;
19
+ export declare function StripePayment({ publishableKey, show, options, clientSecret, locale, expressPayments, ...p }: Props): JSX.Element | null;
19
20
  export default StripePayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripePayment=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")),react_stripe_js_1=require("@stripe/react-stripe-js"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),defaultOptions={layout:{type:"accordion",defaultCollapsed:!1,radios:!0,spacedAccordionItems:!1},fields:{billingDetails:"never"}},defaultAppearance={theme:"stripe",variables:{colorText:"#32325d",fontFamily:'"Helvetica Neue", Helvetica, sans-serif'}};function StripePaymentForm({options=defaultOptions,templateCustomerSaveToWallet}){const ref=(0,react_1.useRef)(null),{currentPaymentMethodType,setPaymentMethodErrors,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),stripe=(0,react_stripe_js_1.useStripe)(),elements=(0,react_stripe_js_1.useElements)();(0,react_1.useEffect)(()=>(ref.current&&stripe&&elements&&(ref.current.onsubmit=async()=>await onSubmit({event:ref.current,stripe,elements}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,stripe,elements]);const onSubmit=async({event,stripe:stripe2,elements:elements2})=>{if(!stripe2)return!1;const savePaymentSourceToCustomerWallet=event?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),elements2!=null){const billingInfo=order?.billing_address,email=order?.customer_email,billingDetails={name:billingInfo?.full_name,email,phone:billingInfo?.phone,address:{city:billingInfo?.city,country:billingInfo?.country_code,line1:billingInfo?.line_1,line2:billingInfo?.line_2,postal_code:billingInfo?.zip_code,state:billingInfo?.state_code}},{error}=await stripe2.confirmPayment({elements:elements2,confirmParams:{return_url:window.location.href,payment_method_data:{billing_details:billingDetails}}});return error?(console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1):!0}return!1};return(0,jsx_runtime_1.jsxs)("form",{ref,children:[(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement,{id:"payment-element",options:{...defaultOptions,...options}}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]})}function StripePayment({publishableKey,show,options,clientSecret,locale="auto",...p}){const[isLoaded,setIsLoaded]=(0,react_1.useState)(!1),[stripe,setStripe]=(0,react_1.useState)(null),{containerClassName,templateCustomerSaveToWallet,fonts=[],appearance,...divProps}=p;(0,react_1.useEffect)(()=>(show&&publishableKey&&Promise.resolve().then(()=>tslib_1.__importStar(require("@stripe/stripe-js"))).then(({loadStripe})=>{(async()=>{const res=await loadStripe(publishableKey,{locale});res!=null&&(setStripe(res),setIsLoaded(!0))})()}),()=>{setIsLoaded(!1)}),[show,publishableKey]);const elementsOptions={clientSecret,appearance:{...defaultAppearance,...appearance},fonts};return isLoaded&&stripe!=null&&clientSecret!=null?(0,jsx_runtime_1.jsx)("div",{className:containerClassName,...divProps,children:(0,jsx_runtime_1.jsx)(react_stripe_js_1.Elements,{stripe,options:elementsOptions,children:(0,jsx_runtime_1.jsx)(StripePaymentForm,{options,templateCustomerSaveToWallet})})}):null}exports.StripePayment=StripePayment,exports.default=StripePayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StripePayment=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")),react_stripe_js_1=require("@stripe/react-stripe-js"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),localStorage_1=require("../../utils/localStorage"),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),StripeExpressPayment_1=require("./StripeExpressPayment"),defaultOptions={layout:{type:"accordion",defaultCollapsed:!1,radios:!0,spacedAccordionItems:!1},fields:{billingDetails:"never"}},defaultAppearance={theme:"stripe",variables:{colorText:"#32325d",fontFamily:'"Helvetica Neue", Helvetica, sans-serif'}};function StripePaymentForm({options=defaultOptions,templateCustomerSaveToWallet}){const ref=(0,react_1.useRef)(null),{currentPaymentMethodType,setPaymentMethodErrors,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default),stripe=(0,react_stripe_js_1.useStripe)(),elements=(0,react_stripe_js_1.useElements)();(0,react_1.useEffect)(()=>(ref.current&&stripe&&elements&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield onSubmit({event:ref.current,stripe,elements})}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,stripe,elements]);const onSubmit=({event,stripe:stripe2,elements:elements2})=>tslib_1.__awaiter(this,void 0,void 0,function*(){var _a,_b;if(!stripe2)return!1;const savePaymentSourceToCustomerWallet=(_b=(_a=event?.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;if(savePaymentSourceToCustomerWallet&&(0,localStorage_1.setCustomerOrderParam)("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),elements2!=null){const billingInfo=order?.billing_address,email=order?.customer_email,billingDetails={name:billingInfo?.full_name,email,phone:billingInfo?.phone,address:{city:billingInfo?.city,country:billingInfo?.country_code,line1:billingInfo?.line_1,line2:billingInfo?.line_2,postal_code:billingInfo?.zip_code,state:billingInfo?.state_code}},{error}=yield stripe2.confirmPayment({elements:elements2,confirmParams:{return_url:window.location.href,payment_method_data:{billing_details:billingDetails}}});return error?(console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1):!0}return!1});return(0,jsx_runtime_1.jsxs)("form",Object.assign({ref},{children:[(0,jsx_runtime_1.jsx)(react_stripe_js_1.PaymentElement,{id:"payment-element",options:Object.assign(Object.assign({},defaultOptions),options)}),templateCustomerSaveToWallet&&(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))]}))}function StripePayment(_a){var{publishableKey,show,options,clientSecret,locale="auto",expressPayments=!1}=_a,p=tslib_1.__rest(_a,["publishableKey","show","options","clientSecret","locale","expressPayments"]);const[isLoaded,setIsLoaded]=(0,react_1.useState)(!1),[stripe,setStripe]=(0,react_1.useState)(null),{containerClassName,templateCustomerSaveToWallet,fonts=[],appearance}=p,divProps=tslib_1.__rest(p,["containerClassName","templateCustomerSaveToWallet","fonts","appearance"]);(0,react_1.useEffect)(()=>(show&&publishableKey&&Promise.resolve().then(()=>tslib_1.__importStar(require("@stripe/stripe-js"))).then(({loadStripe})=>{(()=>tslib_1.__awaiter(this,void 0,void 0,function*(){const res=yield loadStripe(publishableKey,{locale});res!=null&&(setStripe(res),setIsLoaded(!0))}))()}),()=>{setIsLoaded(!1)}),[show,publishableKey]);const elementsOptions={clientSecret,appearance:Object.assign(Object.assign({},defaultAppearance),appearance),fonts};return isLoaded&&stripe!=null&&clientSecret!=null?(0,jsx_runtime_1.jsx)("div",Object.assign({className:containerClassName},divProps,{children:(0,jsx_runtime_1.jsx)(react_stripe_js_1.Elements,Object.assign({stripe,options:elementsOptions},{children:expressPayments?(0,jsx_runtime_1.jsx)(StripeExpressPayment_1.StripeExpressPayment,{clientSecret}):(0,jsx_runtime_1.jsx)(StripePaymentForm,{options,templateCustomerSaveToWallet})}))})):null}exports.StripePayment=StripePayment,exports.default=StripePayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WireTransferPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),react_1=require("react"),defaultMessage="after placing the order, you will need to manually complete the payment with your bank";function WireTransferPayment({infoMessage,...p}){const{className,"data-testid":dataTestId}=p,ref=(0,react_1.useRef)(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default);(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&(ref.current.onsubmit=async()=>await handleClick(),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=async()=>{if(paymentSource&&currentPaymentMethodType)try{return await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"wire-transfer",last4:""}}}}),!0}catch{return!1}return!1};return(0,jsx_runtime_1.jsx)("form",{ref,children:(0,jsx_runtime_1.jsx)("div",{className,"data-testid":dataTestId,children:(0,jsx_runtime_1.jsx)("span",{className:infoMessage?.className,children:infoMessage?.text||defaultMessage})})})}exports.WireTransferPayment=WireTransferPayment,exports.default=WireTransferPayment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WireTransferPayment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentMethodContext_1=tslib_1.__importDefault(require("../../context/PaymentMethodContext")),react_1=require("react"),defaultMessage="after placing the order, you will need to manually complete the payment with your bank";function WireTransferPayment(_a){var{infoMessage}=_a,p=tslib_1.__rest(_a,["infoMessage"]);const{className,"data-testid":dataTestId}=p,ref=(0,react_1.useRef)(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=(0,react_1.useContext)(PaymentMethodContext_1.default);(0,react_1.useEffect)(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&(ref.current.onsubmit=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield handleClick()}),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(paymentSource&&currentPaymentMethodType)try{return yield setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"wire-transfer",last4:""}}}}),!0}catch{return!1}return!1});return(0,jsx_runtime_1.jsx)("form",Object.assign({ref},{children:(0,jsx_runtime_1.jsx)("div",Object.assign({className,"data-testid":dataTestId},{children:(0,jsx_runtime_1.jsx)("span",Object.assign({className:infoMessage?.className},{children:infoMessage?.text||defaultMessage}))}))}))}exports.WireTransferPayment=WireTransferPayment,exports.default=WireTransferPayment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Price=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PricesContext_1=tslib_1.__importDefault(require("../../context/PricesContext")),react_1=require("react"),getPrices_1=require("../../utils/getPrices"),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext"));function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=(0,react_1.useContext)(PricesContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),[skuPrices,setSkuPrices]=(0,react_1.useState)([]),sCode=pricesSkuCode||skuCode||sku?.code;(0,react_1.useEffect)(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps={loading,loader,prices:skuPrices,...props},pricesComponent=prices==null||skuPrices==null?null:(0,getPrices_1.getPricesComponent)(skuPrices,props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}exports.Price=Price,exports.default=Price;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Price=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),PricesContext_1=tslib_1.__importDefault(require("../../context/PricesContext")),react_1=require("react"),getPrices_1=require("../../utils/getPrices"),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext"));function Price(props){const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=(0,react_1.useContext)(PricesContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),[skuPrices,setSkuPrices]=(0,react_1.useState)([]),sCode=pricesSkuCode||skuCode||sku?.code;(0,react_1.useEffect)(()=>(prices!=null&&`${sCode}`in prices?setSkuPrices(prices[sCode]):sCode&&!skuCodes.includes(sCode)&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes({skuCodes})),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps=Object.assign({loading,loader,prices:skuPrices},props),pricesComponent=prices==null||skuPrices==null?null:(0,getPrices_1.getPricesComponent)(skuPrices,props);return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children})):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loading||pricesComponent==null?loader:pricesComponent})}exports.Price=Price,exports.default=Price;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PricesContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),PriceReducer_1=tslib_1.__importStar(require("../../reducers/PriceReducer")),PricesContext_1=tslib_1.__importDefault(require("../../context/PricesContext")),SkuContext_1=tslib_1.__importDefault(require("../../context/SkuContext"));function PricesContainer(props){const{children,skuCode="",loader="Loading...",perPage=10,filters={}}=props,[state,dispatch]=(0,react_1.useReducer)(PriceReducer_1.default,PriceReducer_1.priceInitialState),config=(0,react_1.useContext)(CommerceLayerContext_1.default),{skuCodes}=(0,react_1.useContext)(SkuContext_1.default);!state.skuCodes.includes(skuCode)&&skuCode&&state.skuCodes.push(skuCode);const sCode=skuCodes&&skuCodes?.length>0?"":skuCode??"";(0,react_1.useEffect)(()=>{state.skuCodes.length===0&&skuCodes!=null&&skuCodes.length>0&&state.setSkuCodes!=null&&state.setSkuCodes({skuCodes,dispatch}),config.accessToken&&(state.skuCodes.length>0||sCode)&&(0,PriceReducer_1.getSkusPrice)(sCode&&[sCode]||state.skuCodes,{config,dispatch,perPage,filters})},[config.accessToken,sCode,state.skuCodes.length]);const priceValue={...state,skuCode:sCode,loader,setSkuCodes:params=>{(0,PriceReducer_1.setSkuCodes)({...params,dispatch})}};return(0,jsx_runtime_1.jsx)(PricesContext_1.default.Provider,{value:priceValue,children})}exports.PricesContainer=PricesContainer,exports.default=PricesContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PricesContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),PriceReducer_1=tslib_1.__importStar(require("../../reducers/PriceReducer")),PricesContext_1=tslib_1.__importDefault(require("../../context/PricesContext")),SkuContext_1=tslib_1.__importDefault(require("../../context/SkuContext"));function PricesContainer(props){const{children,skuCode="",loader="Loading...",perPage=10,filters={}}=props,[state,dispatch]=(0,react_1.useReducer)(PriceReducer_1.default,PriceReducer_1.priceInitialState),config=(0,react_1.useContext)(CommerceLayerContext_1.default),{skuCodes}=(0,react_1.useContext)(SkuContext_1.default);!state.skuCodes.includes(skuCode)&&skuCode&&state.skuCodes.push(skuCode);const sCode=skuCodes&&skuCodes?.length>0?"":skuCode??"";(0,react_1.useEffect)(()=>{state.skuCodes.length===0&&skuCodes!=null&&skuCodes.length>0&&state.setSkuCodes!=null&&state.setSkuCodes({skuCodes,dispatch}),config.accessToken&&(state.skuCodes.length>0||sCode)&&(0,PriceReducer_1.getSkusPrice)(sCode&&[sCode]||state.skuCodes,{config,dispatch,perPage,filters})},[config.accessToken,sCode,state.skuCodes.length]);const priceValue=Object.assign(Object.assign({},state),{skuCode:sCode,loader,setSkuCodes:params=>{(0,PriceReducer_1.setSkuCodes)(Object.assign(Object.assign({},params),{dispatch}))}});return(0,jsx_runtime_1.jsx)(PricesContext_1.default.Provider,Object.assign({value:priceValue},{children}))}exports.PricesContainer=PricesContainer,exports.default=PricesContainer;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.stock_line_items?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0]?.id:shipment.shipping_method?.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>time.stock_location?.id===shipment.stock_location?.id),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,{value:shipmentProps,children},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?tslib_1.__awaiter(this,void 0,void 0,function*(){var _a;for(const shipment of shipments){const isSingle=((_a=shipment?.available_shipping_methods)===null||_a===void 0?void 0:_a.length)===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=yield setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}}):setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{var _a,_b;const shipmentLineItems=shipment.stock_line_items,lineItems=shipmentLineItems?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?(_a=shippingMethods[0])===null||_a===void 0?void 0:_a.id:(_b=shipment.shipping_method)===null||_b===void 0?void 0:_b.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>{var _a2,_b2;return((_a2=time.stock_location)===null||_a2===void 0?void 0:_a2.id)===((_b2=shipment.stock_location)===null||_b2===void 0?void 0:_b2.id)}),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,Object.assign({value:shipmentProps},{children}),k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentField=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")),get_1=tslib_1.__importDefault(require("lodash/get")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext"));function ShipmentField(props){const{name}=props,{shipment,keyNumber}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),key=name,text=key!=="key_number"?(0,get_1.default)(shipment,key):keyNumber,parentProps={shipment,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("span",{...props,children:text})}exports.ShipmentField=ShipmentField,exports.default=ShipmentField;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentField=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")),get_1=tslib_1.__importDefault(require("lodash/get")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext"));function ShipmentField(props){const{name}=props,{shipment,keyNumber}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),key=name,text=key!=="key_number"?(0,get_1.default)(shipment,key):keyNumber,parentProps=Object.assign({shipment},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},props,{children:text}))}exports.ShipmentField=ShipmentField,exports.default=ShipmentField;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.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,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order!=null,order?.shipments?.length]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>!!(lineItem.item?.do_not_ship||lineItem.item?.do_not_track||lineItem.item?.inventory?.quantity>=lineItem?.quantity)).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>({...state,setShipmentErrors:errors=>{ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch)},setShippingMethod:async(shipmentId,shippingMethodId)=>await(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,{value:contextValue,children})}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){var _a;const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.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,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order!=null,(_a=order?.shipments)===null||_a===void 0?void 0:_a.length]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>{var _a2,_b,_c,_d;return!!(((_a2=lineItem.item)===null||_a2===void 0?void 0:_a2.do_not_ship)||((_b=lineItem.item)===null||_b===void 0?void 0:_b.do_not_track)||((_d=(_c=lineItem.item)===null||_c===void 0?void 0:_c.inventory)===null||_d===void 0?void 0:_d.quantity)>=lineItem?.quantity)}).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>Object.assign(Object.assign({},state),{setShipmentErrors:errors=>{ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch)},setShippingMethod:(shipmentId,shippingMethodId)=>tslib_1.__awaiter(this,void 0,void 0,function*(){return yield(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,Object.assign({value:contextValue},{children}))}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsCount=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function ShipmentsCount({children,...p}){const{shipments}=(0,useCustomContext_1.default)({context:ShipmentContext_1.default,contextComponentName:"ShipmentsContainer",currentComponentName:"ShipmentsCount",key:"shipments"}),quantity=shipments?.length??0,childrenProps={...p,quantity,shipments};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...childrenProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:quantity})}exports.ShipmentsCount=ShipmentsCount,exports.default=ShipmentsCount;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsCount=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function ShipmentsCount(_a){var _b,{children}=_a,p=tslib_1.__rest(_a,["children"]);const{shipments}=(0,useCustomContext_1.default)({context:ShipmentContext_1.default,contextComponentName:"ShipmentsContainer",currentComponentName:"ShipmentsCount",key:"shipments"}),quantity=(_b=shipments?.length)!==null&&_b!==void 0?_b:0,childrenProps=Object.assign(Object.assign({},p),{quantity,shipments});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},childrenProps,{children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},p,{children:quantity}))}exports.ShipmentsCount=ShipmentsCount,exports.default=ShipmentsCount;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethod=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),[items,setItems]=(0,react_1.useState)([]);(0,react_1.useEffect)(()=>{const methods=shippingMethods?.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{const deliveryShippingMethodId=delivery.shipping_method?.id;return shippingMethod.id===deliveryShippingMethodId}),shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return(0,jsx_runtime_1.jsx)(ShippingMethodChildrenContext_1.default.Provider,{value:shippingProps,children},k)});methods&&setItems(methods)},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components=!(0,isEmpty_1.default)(items)&&items||emptyText;return(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.ShippingMethod=ShippingMethod,exports.default=ShippingMethod;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethod=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShippingMethod(props){const{children,readonly,emptyText="There are not any shipping method available"}=props,{shippingMethods,currentShippingMethodId,deliveryLeadTimes,shipment}=(0,react_1.useContext)(ShipmentChildrenContext_1.default),[items,setItems]=(0,react_1.useState)([]);(0,react_1.useEffect)(()=>{const methods=shippingMethods?.filter(s=>readonly?s.id===currentShippingMethodId:!0).map((shippingMethod,k)=>{const[deliveryLeadTimeForShipment]=deliveryLeadTimes?.filter(delivery=>{var _a;const deliveryShippingMethodId=(_a=delivery.shipping_method)===null||_a===void 0?void 0:_a.id;return shippingMethod.id===deliveryShippingMethodId}),shippingProps={shipmentId:shipment?.id,shippingMethod,currentShippingMethodId,deliveryLeadTimeForShipment};return(0,jsx_runtime_1.jsx)(ShippingMethodChildrenContext_1.default.Provider,Object.assign({value:shippingProps},{children}),k)});methods&&setItems(methods)},[currentShippingMethodId,deliveryLeadTimes,shippingMethods]);const components=!(0,isEmpty_1.default)(items)&&items||emptyText;return(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.ShippingMethod=ShippingMethod,exports.default=ShippingMethod;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function ShippingMethodName(props){const{shippingMethod,deliveryLeadTimeForShipment,shipmentId}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),htmlFor=`shipment-${shipmentId??""}-${shippingMethod?.id??""}`||"",labelName=shippingMethod?.name,parentProps={shippingMethod,deliveryLeadTimeForShipment,label:labelName,htmlFor,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("label",{htmlFor,...props,children:labelName})}exports.ShippingMethodName=ShippingMethodName,exports.default=ShippingMethodName;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function ShippingMethodName(props){var _a;const{shippingMethod,deliveryLeadTimeForShipment,shipmentId}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),htmlFor=`shipment-${shipmentId??""}-${(_a=shippingMethod?.id)!==null&&_a!==void 0?_a:""}`||"",labelName=shippingMethod?.name,parentProps=Object.assign({shippingMethod,deliveryLeadTimeForShipment,label:labelName,htmlFor},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("label",Object.assign({htmlFor},props,{children:labelName}))}exports.ShippingMethodName=ShippingMethodName,exports.default=ShippingMethodName;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodPrice=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),getAmount_1=tslib_1.__importDefault(require("../../utils/getAmount")),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function ShippingMethodPrice(props){const{base="price_amount",type="for_shipment",format="formatted",labelFreeOver="Free",...p}=props,{shippingMethod}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),[price,setPrice]=(0,react_1.useState)(""),[priceCents,setPriceCents]=(0,react_1.useState)(0);(0,react_1.useEffect)(()=>{if(shippingMethod){const p2=(0,getAmount_1.default)({base,type,format,obj:shippingMethod});setPrice(p2);const pCents=(0,getAmount_1.default)({base:"price_amount",type:"for_shipment",format:"cents",obj:shippingMethod});setPriceCents(pCents)}return()=>{setPrice(""),setPriceCents(0)}},[shippingMethod]);const parentProps={price,...p},finalPrice=priceCents===0?labelFreeOver:price;return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("span",{...p,children:finalPrice})}exports.ShippingMethodPrice=ShippingMethodPrice,exports.default=ShippingMethodPrice;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodPrice=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),getAmount_1=tslib_1.__importDefault(require("../../utils/getAmount")),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function ShippingMethodPrice(props){const{base="price_amount",type="for_shipment",format="formatted",labelFreeOver="Free"}=props,p=tslib_1.__rest(props,["base","type","format","labelFreeOver"]),{shippingMethod}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),[price,setPrice]=(0,react_1.useState)(""),[priceCents,setPriceCents]=(0,react_1.useState)(0);(0,react_1.useEffect)(()=>{if(shippingMethod){const p2=(0,getAmount_1.default)({base,type,format,obj:shippingMethod});setPrice(p2);const pCents=(0,getAmount_1.default)({base:"price_amount",type:"for_shipment",format:"cents",obj:shippingMethod});setPriceCents(pCents)}return()=>{setPrice(""),setPriceCents(0)}},[shippingMethod]);const parentProps=Object.assign({price},p),finalPrice=priceCents===0?labelFreeOver:price;return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("span",Object.assign({},p,{children:finalPrice}))}exports.ShippingMethodPrice=ShippingMethodPrice,exports.default=ShippingMethodPrice;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext"));function ShippingMethodRadioButton(props){const{onChange,...p}=props,[checked,setChecked]=(0,react_1.useState)(!1),{shippingMethod,currentShippingMethodId,shipmentId}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),{setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),shippingMethodId=shippingMethod?.id,name=`shipment-${shipmentId??""}`,id=`${name}-${shippingMethodId??""}`;(0,react_1.useEffect)(()=>(setChecked(shippingMethodId===currentShippingMethodId),()=>{setChecked(!1)}),[currentShippingMethodId]);const handleOnChange=async()=>{if(shipmentId&&shippingMethodId&&setShippingMethod!=null){setChecked(!0);const{order}=await setShippingMethod(shipmentId,shippingMethodId);shippingMethod&&onChange!=null&&onChange({shippingMethod,shipmentId,order})}},parentProps={shippingMethod,shipmentId,handleOnChange,name,id,...props};return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children:props.children}):(0,jsx_runtime_1.jsx)("input",{type:"radio",name,id,onChange:()=>{handleOnChange()},checked,...p})}exports.ShippingMethodRadioButton=ShippingMethodRadioButton,exports.default=ShippingMethodRadioButton;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShippingMethodRadioButton=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShippingMethodChildrenContext_1=tslib_1.__importDefault(require("../../context/ShippingMethodChildrenContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext"));function ShippingMethodRadioButton(props){const{onChange}=props,p=tslib_1.__rest(props,["onChange"]),[checked,setChecked]=(0,react_1.useState)(!1),{shippingMethod,currentShippingMethodId,shipmentId}=(0,react_1.useContext)(ShippingMethodChildrenContext_1.default),{setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),shippingMethodId=shippingMethod?.id,name=`shipment-${shipmentId??""}`,id=`${name}-${shippingMethodId??""}`;(0,react_1.useEffect)(()=>(setChecked(shippingMethodId===currentShippingMethodId),()=>{setChecked(!1)}),[currentShippingMethodId]);const handleOnChange=()=>tslib_1.__awaiter(this,void 0,void 0,function*(){if(shipmentId&&shippingMethodId&&setShippingMethod!=null){setChecked(!0);const{order}=yield setShippingMethod(shipmentId,shippingMethodId);shippingMethod&&onChange!=null&&onChange({shippingMethod,shipmentId,order})}}),parentProps=Object.assign({shippingMethod,shipmentId,handleOnChange,name,id},props);return props.children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children:props.children})):(0,jsx_runtime_1.jsx)("input",Object.assign({type:"radio",name,id,onChange:()=>{handleOnChange()},checked},p))}exports.ShippingMethodRadioButton=ShippingMethodRadioButton,exports.default=ShippingMethodRadioButton;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),AvailabilityReducer_1=tslib_1.__importStar(require("../../reducers/AvailabilityReducer")),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),{accessToken,endpoint}=(0,useCustomContext_1.default)({context:CommerceLayerContext_1.default,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=(0,react_1.useReducer)(AvailabilityReducer_1.default,AvailabilityReducer_1.availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;(0,react_1.useEffect)(()=>{if(accessToken!=null&&accessToken!==""){const config={accessToken,endpoint};sCode&&(0,AvailabilityReducer_1.getAvailability)({skuCode:sCode,config,dispatch})}return()=>{dispatch({type:"setAvailability",payload:{}})}},[accessToken,sCode]),(0,react_1.useEffect)(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]);const memoized=(0,react_1.useMemo)(()=>({...state,parent:!0}),[state]);return(0,jsx_runtime_1.jsx)(AvailabilityContext_1.default.Provider,{value:memoized,children})}exports.AvailabilityContainer=AvailabilityContainer,exports.default=AvailabilityContainer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),AvailabilityReducer_1=tslib_1.__importStar(require("../../reducers/AvailabilityReducer")),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),{accessToken,endpoint}=(0,useCustomContext_1.default)({context:CommerceLayerContext_1.default,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=(0,react_1.useReducer)(AvailabilityReducer_1.default,AvailabilityReducer_1.availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;(0,react_1.useEffect)(()=>{if(accessToken!=null&&accessToken!==""){const config={accessToken,endpoint};sCode&&(0,AvailabilityReducer_1.getAvailability)({skuCode:sCode,config,dispatch})}return()=>{dispatch({type:"setAvailability",payload:{}})}},[accessToken,sCode]),(0,react_1.useEffect)(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]);const memoized=(0,react_1.useMemo)(()=>Object.assign(Object.assign({},state),{parent:!0}),[state]);return(0,jsx_runtime_1.jsx)(AvailabilityContext_1.default.Provider,Object.assign({value:memoized},{children}))}exports.AvailabilityContainer=AvailabilityContainer,exports.default=AvailabilityContainer;