{"version":3,"file":"payment-method-actions-2T7_kew9.js","sources":["../../src/components/cart/terms-consent.jsx","../../src/components/checkout/payment-form.jsx","../../src/features/payment-methods/payment-method-actions.js"],"sourcesContent":["import React from 'react';\nimport { Link } from 'react-router';\n\nimport { helpCenterRoute, termsRoute } from '~/routes';\n\nconst linkStyles = {\n color: 'var(--secondary-dark-color)',\n textDecoration: 'underline',\n};\n\nconst TermsConsent = ({ textBlocks, buttonText = 'submit order' }) => {\n return (\n
\n By clicking \"{buttonText}\" you agree to our{' '}\n \n Terms of Use\n {' '}\n and Privacy Policy.{' '}\n {textBlocks?.filter(Boolean)?.join(' ')} \n \n Cancel anytime\n \n .\n
\n );\n};\n\nexport default TermsConsent;\n","import React from 'react';\nimport { useElements, useStripe } from '@stripe/react-stripe-js';\n\nimport { PaymentMethodSelection } from '~/components/checkout/checkout-form';\nimport { Form } from '~/components/form';\nimport { useFlashMessage } from '~/features/flash-messages/flash-message-actions';\nimport {\n confirmPayment,\n confirmSetup,\n handleValidation,\n} from '~/features/stripe';\nimport { captureException } from '~/utils/exception-tracking';\n\nconst PaymentForm = ({\n children,\n initialValues,\n onSubmit,\n savedPaymentMethod,\n paymentIntent,\n cartUuid,\n redirectUrl,\n}) => {\n // Get a reference to Stripe and Elements using hooks.\n // 'elements' handles form input values directly\n const stripe = useStripe();\n const elements = useElements();\n const { showFlashMessage } = useFlashMessage();\n\n const handleSubmit = async (formValues) => {\n if (elements === null) {\n return;\n }\n\n // try {\n // await api.cart.paymentValidation(\n // cartUuid,\n // paymentIntent.provider_charge_id\n // );\n\n if (formValues.paymentMethod === PaymentMethodSelection.EXISTING) {\n let res = {};\n if (paymentIntent.intent_type === 'setup') {\n // this is if a cart total is $0, we need to still accept\n // a card to keep on file and store card as part of SetupIntent\n await handleValidation(elements, showFlashMessage);\n res = await confirmSetup(\n stripe,\n elements,\n paymentIntent.client_secret,\n {\n payment_method: savedPaymentMethod.id,\n return_url: redirectUrl,\n }\n );\n } else {\n res = await confirmPayment(\n stripe,\n elements,\n paymentIntent.client_secret,\n {\n payment_method: savedPaymentMethod.id,\n return_url: redirectUrl,\n }\n );\n }\n\n const paymentMethod =\n res.paymentIntent?.payment_method || res.setupIntent?.payment_method;\n\n if (res.error) {\n // since the parseStripeTokenError only responds with error messaging for input fields\n // with a user using a saved payment method, this fails silently, so we are displaying\n // a message if there is an error for saved payment methods when we can't connect to stripe.\n if (res.error.type === 'api_connection_error') {\n captureException(new Error('Error connecting to Stripe.'), {\n extras: {\n error: res.error,\n },\n });\n showFlashMessage(\n 'Sorry, something went wrong. We are unable to complete your order at this time. Please try again later.',\n 'error'\n );\n return;\n } else {\n captureException(new Error('Error connecting to Stripe.'), {\n extras: {\n error: res.error.message,\n },\n });\n\n return showFlashMessage(res.error.message, 'error');\n }\n } else {\n return onSubmit(paymentMethod);\n }\n }\n\n let res = {};\n if (paymentIntent.intent_type === 'setup') {\n // this is if a cart total is $0, we need to still accept\n // a card to keep on file and store card as part of SetupIntent\n await handleValidation(elements, showFlashMessage);\n res = await confirmSetup(stripe, elements, paymentIntent.client_secret, {\n payment_method_data: {\n billing_details: {\n address: {\n country: 'US',\n },\n },\n },\n return_url: redirectUrl,\n });\n } else {\n await handleValidation(elements, showFlashMessage);\n res = await confirmPayment(\n stripe,\n elements,\n paymentIntent.client_secret,\n {\n payment_method_data: {\n billing_details: {\n address: {\n country: 'US',\n },\n },\n },\n return_url: redirectUrl,\n }\n );\n }\n\n const paymentMethod =\n res.paymentIntent?.payment_method || res.setupIntent?.payment_method;\n\n if (res.error) {\n return showFlashMessage(res.error.message, 'error');\n } else {\n return onSubmit(paymentMethod);\n }\n // } catch (err) {\n // captureException(\n // new Error('Cart and PaymentIntent totals do not match.'),\n // {\n // extras: {\n // error: JSON.stringify(err.error),\n // },\n // }\n // );\n // await queryClient.invalidateQueries(['cart']);\n // showFlashMessage(\n // 'Uh oh! It looks like your cart contents may have changed. Please review and try again.'\n // );\n // navigate(cartRoute());\n // }\n };\n\n return (\n \n );\n};\n\nexport default PaymentForm;\n","import { useQuery, useQueryClient } from 'react-query';\n\nimport { api } from '~/api';\nimport { captureException } from '~/utils/exception-tracking';\n\nexport const useUpdatePaymentMethod = () => {\n const queryClient = useQueryClient();\n\n const updatePaymentMethod = async (paymentMethodId) => {\n await api.paymentMethods.add(paymentMethodId);\n await Promise.all([\n queryClient.refetchQueries(['cart']),\n queryClient.refetchQueries(['card']),\n ]);\n };\n\n return { updatePaymentMethod };\n};\n\n/**\n * Fetch PaymentIntents for client_secret to complete stripe payment\n */\nexport const usePaymentIntents = (\n cartUuid,\n restrictedSkus,\n isLoadingCartValidation\n) => {\n const enabledApiCall =\n Boolean(cartUuid) &&\n Boolean(!restrictedSkus?.length) &&\n Boolean(!isLoadingCartValidation);\n const {\n data: paymentIntent,\n isLoading,\n isError,\n ...rest\n } = useQuery(\n ['paymentIntents', cartUuid],\n () => api.paymentMethods.createPaymentIntent(cartUuid),\n {\n enabled: enabledApiCall,\n cacheTime: 0,\n onError: (error) =>\n captureException(new Error('PaymentIntent API error'), {\n extras: { error: error.message },\n }),\n retry: 3,\n }\n );\n\n return { paymentIntent, isLoading, isError, ...rest };\n};\n\n/**\n * Fetch payment data with a paymentMethodId\n */\nexport const usePaymentMethod = (paymentMethodId) => {\n const { data: paymentMethodData, isLoading } = useQuery(\n ['paymentMethod', paymentMethodId],\n () => api.paymentMethods.find(paymentMethodId),\n { enabled: Boolean(paymentMethodId) }\n );\n\n return { paymentMethodData, isLoading };\n};\n"],"names":["linkStyles","TermsConsent","textBlocks","buttonText","Link","termsRoute","_a","jsx","helpCenterRoute","PaymentForm","children","initialValues","onSubmit","savedPaymentMethod","paymentIntent","cartUuid","redirectUrl","stripe","useStripe","elements","useElements","showFlashMessage","useFlashMessage","handleSubmit","formValues","PaymentMethodSelection","res","handleValidation","confirmSetup","confirmPayment","paymentMethod","captureException","_c","_d","Form","useUpdatePaymentMethod","queryClient","useQueryClient","paymentMethodId","api","usePaymentIntents","restrictedSkus","isLoadingCartValidation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