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way/./resources/js/frontend/acima-credit-checkout.js","webpack://acima-leasing-payment-gateway/./resources/js/frontend/block-checkout.js","webpack://acima-leasing-payment-gateway/./node_modules/react/cjs/react-jsx-runtime.production.min.js","webpack://acima-leasing-payment-gateway/./node_modules/react/jsx-runtime.js","webpack://acima-leasing-payment-gateway/external window \"React\"","webpack://acima-leasing-payment-gateway/external window [\"wc\",\"wcSettings\"]","webpack://acima-leasing-payment-gateway/webpack/bootstrap","webpack://acima-leasing-payment-gateway/webpack/runtime/compat get default export","webpack://acima-leasing-payment-gateway/webpack/runtime/define property getters","webpack://acima-leasing-payment-gateway/webpack/runtime/hasOwnProperty shorthand","webpack://acima-leasing-payment-gateway/external window [\"wp\",\"i18n\"]","webpack://acima-leasing-payment-gateway/external window [\"wc\",\"wcBlocksRegistry\"]","webpack://acima-leasing-payment-gateway/external window [\"wp\",\"htmlEntities\"]","webpack://acima-leasing-payment-gateway/external window [\"wp\",\"element\"]","webpack://acima-leasing-payment-gateway/./resources/js/frontend/index.js"],"sourcesContent":["export class AcimaCreditCheckout {\n constructor(settings, customerData, transactionData, thankYouPage, orderId, nonce) {\n this.settings = settings ;\n this.client = null;\n this.customer = customerData;\n this.transaction = transactionData;\n this.thankYouPage = thankYouPage;\n this.orderId = orderId;\n this.nonce = nonce;\n console.log('AcimaCreditCheckout constructor called with settings:', settings);\n }\n\n redirectToThankYouPage() {\n if (this.thankYouPage) {\n // Prevent back navigation using replace\n window.location.replace(this.thankYouPage);\n } else {\n console.error('Thank you page URL is not set');\n }\n }\n\n async initCheckout() {\n try {\n console.log('Initiating checkout with client:', window.AcimaCredit.client);\n return window.AcimaCredit.client.checkout({\n customer: this.customer,\n transaction: this.transaction,\n isSuccessCallbackMode: true,\n onSuccess: (response) => this.success(response),\n onError: (error) => this.handleError(error),\n onEventNotification: (result) => this.onEventNotification(result)\n }).then(async (response) => {\n console.log(\"Checkout response:\", JSON.stringify(response));\n await this.closeOrder(response);\n response.createOrderComplete();\n this.redirectToThankYouPage();\n return response;\n }).catch((error) => {\n if (error.code === 'CheckoutInterrupted') {\n console.log(error.message);\n } else {\n console.error(\"Unhandled error:\", error);\n }\n throw error;\n });\n } catch (error) {\n console.error('Error during checkout initialization:', error);\n throw error;\n }\n }\n\n handleError(error) {\n console.error(\"Checkout error:\", error);\n }\n\n onEventNotification(result) {\n console.log(\"onCheckoutSuccessful:\", result);\n const leaseId = result.leaseId || result.applicationId;\n if (leaseId) {\n this.saveLeaseInfo(result);\n }\n }\n\n async closeOrder(result) {\n console.log('this.nonce:', this.nonce);\n const data = {\n action: 'acima_leasing_checkout_successful',\n order: this.orderId,\n nonce: window.acimaBlockCheckout.nonce,\n lease_id: result.leaseId || result.applicationId,\n checkout_token: result.checkoutToken,\n is_acima_credit: true,\n is_block_checkout: true\n };\n\n console.log('Closing order with data:', data);\n\n try {\n const ajaxUrl = window.acimaCredit?.ajax_url ||\n (window.woocommerce_params && window.woocommerce_params.ajax_url);\n\n const response = await fetch(ajaxUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: new URLSearchParams(data).toString()\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n const responseData = await response.json();\n console.log('Order closing response:', responseData);\n\n if (responseData.success) {\n console.log('Order closed successfully');\n return { isAcimaCredit: true, ...responseData };\n } else {\n console.error('Error closing order:', responseData);\n throw new Error('Failed to close order');\n }\n } catch (error) {\n console.error('Error in closeOrder:', error);\n throw error;\n }\n }\n\n saveLeaseInfo(result) {\n const data = JSON.stringify({\n leaseId: result.leaseId || result.applicationId,\n leaseNumber: result.leaseNumber,\n orderId: this.orderId\n });\n\n fetch('/?rest_route=/acima/v1/cancel-checkout', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-WP-Nonce': acimaCredit.rest_nonce\n },\n body: data,\n })\n .then(response => response.json())\n .then(data => console.log('Lease saved successfully:', data))\n .catch(error => console.error('Error saving lease:', error));\n }\n}","import { AcimaCreditCheckout } from './acima-credit-checkout';\nimport { getSetting } from '@woocommerce/settings';\n\nconst settings = getSetting('acima_credit_data', {});\n\nconst processAcimaPayment = async (paymentData) => {\n try {\n const response = await fetch('/wp-json/wc-acima-credit/v1/process-payment', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-WP-Nonce': window.acimaBlockCheckout.nonce || '',\n },\n body: JSON.stringify({\n payment_method: window.acimaCredit.payment_method,\n order_id: paymentData.transactionData.orderId,\n }),\n });\n\n const data = await response.json();\n\n if (data.success) {\n const checkout = new AcimaCreditCheckout(\n settings,\n data.customer_data,\n data.transaction_data,\n data.thank_you_page,\n paymentData.transactionData.orderId,\n paymentData.orderNonce,\n paymentData.storeApiNonce\n );\n const result = await checkout.initCheckout();\n return {\n success: data.success,\n isAcimaCredit: true,\n ...result\n };\n } else {\n throw new Error(data.message || 'Payment processing failed.');\n }\n } catch (error) {\n console.error('Error during Acima payment processing:', error);\n throw error;\n }\n};\n\nexport { processAcimaPayment };","/**\n * @license React\n * react-jsx-runtime.production.min.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';var f=require(\"react\"),k=Symbol.for(\"react.element\"),l=Symbol.for(\"react.fragment\"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};\nfunction q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=\"\"+g);void 0!==a.key&&(e=\"\"+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}exports.Fragment=l;exports.jsx=q;exports.jsxs=q;\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.min.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n","module.exports = window[\"React\"];","module.exports = window[\"wc\"][\"wcSettings\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"wp\"][\"i18n\"];","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"wc\"][\"wcBlocksRegistry\"];","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"wp\"][\"htmlEntities\"];","const __WEBPACK_NAMESPACE_OBJECT__ = window[\"wp\"][\"element\"];","import { sprintf, __ } from '@wordpress/i18n';\nimport { registerPaymentMethod } from '@woocommerce/blocks-registry';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { getSetting } from '@woocommerce/settings';\nimport { useEffect, useState } from '@wordpress/element';\nimport { processAcimaPayment } from './block-checkout';\n\nconst settings = getSetting('acima_credit_data', {});\nconst defaultLabel = __('Acima Leasing', 'acima_credit');\nconst label = decodeEntities(settings.title) || defaultLabel;\n\nconst Content = (props) => {\n const { eventRegistration, emitResponse } = props;\n const { onPaymentProcessing, onCheckoutAfterProcessingWithError, onCheckoutValidation,onCheckoutSuccess } = eventRegistration;\n const [checkoutData, setCheckoutData] = useState(null);\n const [orderNonce, setOrderNonce] = useState(null);\n\n useEffect(() => {\n const fetchCheckoutData = async () => {\n console.log(`storeApiNonce: ${settings.storeApiNonce}`);\n console.log(`restApiNonce: ${settings.restApiNonce}`);\n\n try {\n // First request - fetch checkout data\n const response = await fetch('/wp-json/wc/store/v1/checkout', {\n method: 'GET',\n headers: {\n 'Nonce': settings.storeApiNonce,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch checkout data: ${response.status}`);\n }\n\n const data = await response.json();\n setCheckoutData(data);\n console.log('Checkout data fetched:', data);\n\n // Second request - generate order nonce\n const nonceResponse = await fetch('/wp-json/wc-acima-credit/v1/generate-order-nonce', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-WP-Nonce': settings.restApiNonce, // Add REST API nonce\n },\n body: JSON.stringify({ order_id: data.order_id })\n });\n\n if (!nonceResponse.ok) {\n throw new Error(`Failed to generate nonce: ${nonceResponse.status}`);\n }\n\n const nonceData = await nonceResponse.json();\n console.log('Received nonce from server:', nonceData.nonce);\n setOrderNonce(nonceData.nonce);\n } catch (error) {\n console.error('Acima Credit: Error fetching checkout data:', error);\n }\n };\n\n fetchCheckoutData();\n }, []);\n\n useEffect(() => {\n const unsubscribeValidation = onCheckoutValidation(() => {\n console.log('Acima Credit: onCheckoutValidation called');\n return true;\n });\n\n const unsubscribePaymentProcessing = onPaymentProcessing(async () => {\n if (!checkoutData || !orderNonce) {\n console.log('Acima Credit: Checkout data or order nonce not available');\n return {\n type: emitResponse.responseTypes.ERROR,\n message: 'Checkout data or order nonce not available',\n };\n }\n\n try {\n console.log('Acima Credit: Payment setup initiated');\n\n const success = await processAcimaPayment({\n customerData: {\n billingAddress: checkoutData.billing_address,\n shippingAddress: checkoutData.shipping_address,\n },\n transactionData: {\n orderId: checkoutData.order_id,\n orderKey: checkoutData.order_key,\n },\n orderNonce: orderNonce,\n storeApiNonce: settings.storeApiNonce\n });\n\n if (success) {\n return { type: emitResponse.responseTypes.SUCCESS };\n } else {\n throw new Error('Acima Credit checkout failed');\n }\n } catch (error) {\n console.error('Acima Credit: Error processing payment:', error);\n return {\n type: emitResponse.responseTypes.ERROR,\n message: error.message || 'An error occurred while processing your payment.',\n };\n }\n });\n\n const unsubscribeSuccess = onCheckoutSuccess((checkoutSuccessData) => {\n if (checkoutSuccessData.paymentResult.paymentDetails.isAcimaCredit) {\n // Prevent further processing and redirect\n window.location.replace(checkoutSuccessData.redirectUrl);\n return false; // Stops further processing\n }\n return true;\n });\n\n const unsubscribeError = onCheckoutAfterProcessingWithError(() => {\n console.log('Acima Credit: Error occurred after processing');\n return { type: emitResponse.responseTypes.ERROR };\n });\n\n return () => {\n unsubscribeValidation();\n unsubscribePaymentProcessing ();\n unsubscribeError();\n unsubscribeSuccess();\n };\n }, [\n onCheckoutValidation,\n checkoutData,\n orderNonce,\n onPaymentProcessing,\n onCheckoutAfterProcessingWithError,\n onCheckoutSuccess,\n emitResponse.responseTypes\n ]);\n\n return (\n
\n );\n};\n\nconst Label = (props) => {\n const { PaymentMethodLabel } = props.components;\n return ;\n};\n\nconst Acima = {\n name: 'acima_credit',\n label: