diff --git a/src/Controller/StoreApi/ExpressCheckout/ExpressCheckoutController.php b/src/Controller/StoreApi/ExpressCheckout/ExpressCheckoutController.php index e5cfd129..b0c296f2 100755 --- a/src/Controller/StoreApi/ExpressCheckout/ExpressCheckoutController.php +++ b/src/Controller/StoreApi/ExpressCheckout/ExpressCheckoutController.php @@ -24,6 +24,8 @@ namespace Adyen\Shopware\Controller\StoreApi\ExpressCheckout; +use Adyen\Shopware\Exception\ResolveCountryException; +use Adyen\Shopware\Exception\ResolveShippingMethodException; use Adyen\Shopware\Service\ExpressCheckoutService; use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Component\HttpFoundation\JsonResponse; @@ -81,13 +83,41 @@ public function getExpressCheckoutConfig( $newShipping = []; } - return new JsonResponse($this->expressCheckoutService->getExpressCheckoutConfigOnProductPage( - $productId, - $quantity, - $salesChannelContext, - $newAddress, - $newShipping - )); + try { + $config = $this->expressCheckoutService->getExpressCheckoutConfigOnProductPage( + $productId, + $quantity, + $salesChannelContext, + $newAddress, + $newShipping + ); + + return new JsonResponse($config); + } catch (ResolveCountryException $e) { + return new JsonResponse([ + 'error' => [ + 'reason' => 'SHIPPING_ADDRESS_INVALID', + 'message' => $e->getMessage(), + 'intent' => 'SHIPPING_ADDRESS', + ] + ], 400); + } catch (ResolveShippingMethodException $e) { + return new JsonResponse([ + 'error' => [ + 'reason' => 'SHIPPING_OPTION_INVALID', + 'message' => $e->getMessage(), + 'intent' => 'SHIPPING_OPTION', + ] + ], 400); + } catch (\Exception $e) { + // Fallback for unexpected errors + return new JsonResponse([ + 'error' => [ + 'reason' => 'OTHER_ERROR', + 'message' => $e->getMessage(), + ] + ], 500); + } } /** diff --git a/src/Exception/ResolveCountryException.php b/src/Exception/ResolveCountryException.php new file mode 100644 index 00000000..8e0cf8a3 --- /dev/null +++ b/src/Exception/ResolveCountryException.php @@ -0,0 +1,30 @@ + + */ + +namespace Adyen\Shopware\Exception; + +class ResolveCountryException extends \Exception +{ + +} diff --git a/src/Exception/ResolveShippingMethodException.php b/src/Exception/ResolveShippingMethodException.php new file mode 100644 index 00000000..9f0ebfd9 --- /dev/null +++ b/src/Exception/ResolveShippingMethodException.php @@ -0,0 +1,30 @@ + + */ + +namespace Adyen\Shopware\Exception; + +class ResolveShippingMethodException extends \Exception +{ + +} diff --git a/src/Resources/app/storefront/build/storefront/js/adyen-payment-shopware64.js.dist b/src/Resources/app/storefront/build/storefront/js/adyen-payment-shopware64.js.dist index 98d358a4..3b13e2c3 100644 --- a/src/Resources/app/storefront/build/storefront/js/adyen-payment-shopware64.js.dist +++ b/src/Resources/app/storefront/build/storefront/js/adyen-payment-shopware64.js.dist @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([["adyen-payment-shopware6"],{YcTq:function(e,t,n){"use strict";t.a={updatablePaymentMethods:["scheme","ideal","sepadirectdebit","oneclick","bcmc","bcmc_mobile","blik","klarna_b2b","eps","facilypay_3x","facilypay_4x","facilypay_6x","facilypay_10x","facilypay_12x","afterpay_default","ratepay","ratepay_directdebit","giftcard","paybright","affirm","multibanco","mbway","vipps","mobilepay","wechatpayQR","wechatpayWeb","paybybank"],componentsWithPayButton:{applepay:{extra:{},onClick:function(e,t,n){return n.confirmOrderForm.checkValidity()?(e(),!0):(t(),!1)}},googlepay:{extra:{buttonSizeMode:"fill"},onClick:function(e,t,n){return n.confirmOrderForm.checkValidity()?(e(),!0):(t(),!1)},onError:function(e,t,n){"CANCELED"!==e.statusCode&&("statusMessage"in e?console.log(e.statusMessage):console.log(e.statusCode))}},paypal:{extra:{},onClick:function(e,t,n){return n.confirmOrderForm.checkValidity()},onError:function(e,t,n){t.setStatus("ready"),window.location.href=n.errorUrl.toString()},onCancel:function(e,t,n){t.setStatus("ready"),window.location.href=n.errorUrl.toString()},responseHandler:function(e,t){try{(t=JSON.parse(t)).isFinal&&(location.href=e.returnUrl),this.handleAction(t.action)}catch(e){console.error(e)}}},amazonpay:{extra:{productType:"PayAndShip",checkoutMode:"ProcessOrder",returnUrl:location.href},prePayRedirect:!0,sessionKey:"amazonCheckoutSessionId",onClick:function(e,t,n){return n.confirmOrderForm.checkValidity()?(e(),!0):(t(),!1)},onError:function(e,t){console.log(e),t.setStatus("ready")}}},paymentMethodTypeHandlers:{scheme:"handler_adyen_cardspaymentmethodhandler",ideal:"handler_adyen_idealpaymentmethodhandler",klarna:"handler_adyen_klarnapaylaterpaaymentmethodhandler",klarna_account:"handler_adyen_klarnaaccountpaymentmethodhandler",klarna_paynow:"handler_adyen_klarnapaynowpaymentmethodhandler",ratepay:"handler_adyen_ratepaypaymentmethodhandler",ratepay_directdebit:"handler_adyen_ratepaydirectdebitpaymentmethodhandler",sepadirectdebit:"handler_adyen_sepapaymentmethodhandler",directEbanking:"handler_adyen_klarnadebitriskpaymentmethodhandler",paypal:"handler_adyen_paypalpaymentmethodhandler",oneclick:"handler_adyen_oneclickpaymentmethodhandler",giropay:"handler_adyen_giropaypaymentmethodhandler",applepay:"handler_adyen_applepaypaymentmethodhandler",googlepay:"handler_adyen_googlepaypaymentmethodhandler",bcmc:"handler_adyen_bancontactcardpaymentmethodhandler",bcmc_mobile:"handler_adyen_bancontactmobilepaymentmethodhandler",amazonpay:"handler_adyen_amazonpaypaymentmethodhandler",twint:"handler_adyen_twintpaymentmethodhandler",eps:"handler_adyen_epspaymentmethodhandler",swish:"handler_adyen_swishpaymentmethodhandler",alipay:"handler_adyen_alipaypaymentmethodhandler",alipay_hk:"handler_adyen_alipayhkpaymentmethodhandler",blik:"handler_adyen_blikpaymentmethodhandler",clearpay:"handler_adyen_clearpaypaymentmethodhandler",facilypay_3x:"handler_adyen_facilypay3xpaymentmethodhandler",facilypay_4x:"handler_adyen_facilypay4xpaymentmethodhandler",facilypay_6x:"handler_adyen_facilypay6xpaymentmethodhandler",facilypay_10x:"handler_adyen_facilypay10xpaymentmethodhandler",facilypay_12x:"handler_adyen_facilypay12xpaymentmethodhandler",afterpay_default:"handler_adyen_afterpaydefaultpaymentmethodhandler",trustly:"handler_adyen_trustlypaymentmethodhandler",paysafecard:"handler_adyen_paysafecardpaymentmethodhandler",giftcard:"handler_adyen_giftcardpaymentmethodhandler",mbway:"handler_adyen_mbwaypaymentmethodhandler",multibanco:"handler_adyen_multibancopaymentmethodhandler",wechatpayQR:"handler_adyen_wechatpayqrpaymentmethodhandler",wechatpayWeb:"handler_adyen_wechatpaywebpaymentmethodhandler",mobilepay:"handler_adyen_mobilepaypaymentmethodhandler",vipps:"handler_adyen_vippspaymentmethodhandler",affirm:"handler_adyen_affirmpaymentmethodhandler",paybright:"handler_adyen_paybrightpaymentmethodhandler",paybybank:"handler_adyen_openbankingpaymentmethodhandler",klarna_b2b:"handler_adyen_billiepaymentmethodhandler",ebanking_FI:"handler_adyen_onlinebankingfinlandpaymentmethodhandler",onlineBanking_PL:"handler_adyen_onlinebankingpolandpaymentmethodhandler"}}},j5lx:function(e,t,n){"use strict";(function(e,o){n.d(t,"a",(function(){return b}));var r=n("FGIj"),a=n("gHbT"),i=n("k8s9"),c=n("2Y4b"),s=n("u0Tz"),d=n("YcTq");function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(){return(y=Object.assign||function(e){for(var t=1;t0?parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.appendGiftcardSummary():this.appendGiftcardSummary()}},{key:"initializeCheckoutComponent",value:(C=regeneratorRuntime.mark((function e(){var t,n,o,r,a,i,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=adyenCheckoutConfiguration,n=t.locale,o=t.clientKey,r=t.environment,a=t.merchantAccount,i=adyenCheckoutOptions.paymentMethodsResponse,c={locale:n,clientKey:o,environment:r,showPayButton:this.selectedAdyenPaymentMethod in d.a.componentsWithPayButton,hasHolderName:!0,paymentMethodsResponse:JSON.parse(i),onAdditionalDetails:this.handleOnAdditionalDetails.bind(this),countryCode:activeShippingAddress.country,paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,clickToPayConfiguration:{merchantDisplayName:a,shopperEmail:shopperDetails.shopperEmail}}}},e.next=5,AdyenCheckout(c);case 5:this.adyenCheckout=e.sent;case 6:case"end":return e.stop()}}),e,this)})),k=function(){var e=this,t=arguments;return new Promise((function(n,o){var r=C.apply(e,t);function a(e){h(r,n,o,a,i,"next",e)}function i(e){h(r,n,o,a,i,"throw",e)}a(void 0)}))},function(){return k.apply(this,arguments)})},{key:"handleOnAdditionalDetails",value:function(e){this._client.post("".concat(adyenCheckoutOptions.paymentDetailsUrl),JSON.stringify({orderId:this.orderId,stateData:JSON.stringify(e.data)}),function(e){200===this._client._request.status?this.responseHandler(e):location.href=this.errorUrl.toString()}.bind(this))}},{key:"onConfirmOrderSubmit",value:function(e){var t=a.a.querySelector(document,"#confirmOrderForm");if(t.checkValidity()){if("klarna_b2b"===this.selectedAdyenPaymentMethod){var n=a.a.querySelector(document,"#adyen-company-name"),o=a.a.querySelector(document,"#adyen-registration-number"),r=n?n.value.trim():"",i=o?o.value.trim():"",d=a.a.querySelector(document,"#adyen-company-name-error"),u=a.a.querySelector(document,"#adyen-registration-number-error");d.style.display="none",u.style.display="none";var l=!1;if(r||(d.style.display="block",l=!0),i||(u.style.display="block",l=!0),l)return void e.preventDefault()}e.preventDefault(),s.a.create(document.body);var y=c.a.serialize(t);this.confirmOrder(y)}}},{key:"renderPaymentComponent",value:function(e){if("oneclick"!==e){if("giftcard"!==e){var t=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e}));if(0!==t.length){var n=t[0];this.mountPaymentComponent(n,!1)}else"test"===this.adyenCheckout.options.environment&&console.error("Payment method configuration not found. ",e)}}else this.renderStoredPaymentMethodComponents()}},{key:"renderStoredPaymentMethodComponents",value:function(){var e=this;this.adyenCheckout.paymentMethodsResponse.storedPaymentMethods.forEach((function(t){var n='[data-adyen-stored-payment-method-id="'.concat(t.id,'"]');e.mountPaymentComponent(t,!0,n)})),this.hideStorePaymentMethodComponents();var t=null;a.a.querySelectorAll(document,"[name=adyenStoredPaymentMethodId]").forEach((function(n){t||(t=n.value),n.addEventListener("change",e.showSelectedStoredPaymentMethod.bind(e))})),this.showSelectedStoredPaymentMethod(null,t)}},{key:"showSelectedStoredPaymentMethod",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.hideStorePaymentMethodComponents(),t=e?e.target.value:t;var n='[data-adyen-stored-payment-method-id="'.concat(t,'"]'),o=a.a.querySelector(document,n);o.style.display="block"}},{key:"hideStorePaymentMethodComponents",value:function(){a.a.querySelectorAll(document,".stored-payment-component").forEach((function(e){e.style.display="none"}))}},{key:"confirmOrder",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=adyenCheckoutOptions.orderId;e.set("affiliateCode",adyenCheckoutOptions.affiliateCode),e.set("campaignCode",adyenCheckoutOptions.campaignCode),n?this.updatePayment(e,n,t):this.createOrder(e,t)}},{key:"updatePayment",value:function(e,t,n){e.set("orderId",t),this._client.post(adyenCheckoutOptions.updatePaymentUrl,e,this.afterSetPayment.bind(this,n))}},{key:"createOrder",value:function(e,t){this._client.post(adyenCheckoutOptions.checkoutOrderUrl,e,this.afterCreateOrder.bind(this,t))}},{key:"afterCreateOrder",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;try{e=JSON.parse(n)}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",n)}if(e.url)location.href=e.url;else{if(this.orderId=e.id,this.finishUrl=new URL(location.origin+adyenCheckoutOptions.paymentFinishUrl),this.finishUrl.searchParams.set("orderId",e.id),this.errorUrl=new URL(location.origin+adyenCheckoutOptions.paymentErrorUrl),this.errorUrl.searchParams.set("orderId",e.id),"handler_adyen_billiepaymentmethodhandler"===adyenCheckoutOptions.selectedPaymentMethodHandler){var o=a.a.querySelector(document,"#adyen-company-name"),r=o?o.value:"",i=a.a.querySelector(document,"#adyen-registration-number"),c=i?i.value:"";t.companyName=r,t.registrationNumber=c}var d={orderId:this.orderId,finishUrl:this.finishUrl.toString(),errorUrl:this.errorUrl.toString()};for(var u in t)d[u]=t[u];this._client.post(adyenCheckoutOptions.paymentHandleUrl,JSON.stringify(d),this.afterPayOrder.bind(this,this.orderId))}}},{key:"afterSetPayment",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;try{var n=JSON.parse(t);n.success&&this.afterCreateOrder(e,JSON.stringify({id:adyenCheckoutOptions.orderId}))}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}}},{key:"afterPayOrder",value:function(e,t){try{t=JSON.parse(t),this.returnUrl=t.redirectUrl}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}this.returnUrl===this.errorUrl.toString()&&(location.href=this.returnUrl);try{this._client.post("".concat(adyenCheckoutOptions.paymentStatusUrl),JSON.stringify({orderId:e}),this.responseHandler.bind(this))}catch(e){console.log(e)}}},{key:"handlePaymentAction",value:function(t){try{var n=JSON.parse(t);if((n.isFinal||"voucher"===n.action.type)&&(location.href=this.returnUrl),n.action){var r={};"threeDS2"===n.action.type&&(r.challengeWindowSize="05"),this.adyenCheckout.createFromAction(n.action,r).mount("[data-adyen-payment-action-container]"),["threeDS2","qrCode"].includes(n.action.type)&&(e?o("[data-adyen-payment-action-modal]").modal({show:!0}):new bootstrap.Modal(document.getElementById("adyen-payment-action-modal"),{keyboard:!1}).show())}}catch(e){console.log(e)}}},{key:"initializeCustomPayButton",value:function(){var e=this,t=d.a.componentsWithPayButton[this.selectedAdyenPaymentMethod];this.completePendingPayment(this.selectedAdyenPaymentMethod,t);var n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e.selectedAdyenPaymentMethod}));if(n.length<1&&"googlepay"===this.selectedAdyenPaymentMethod&&(n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(e){return"paywithgoogle"===e.type}))),!(n.length<1)){var o=n[0];if(adyenCheckoutOptions.amount)if(t.prePayRedirect)this.renderPrePaymentButton(t,o);else{var r=y(t.extra,o,{amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onClick:function(n,o){if(!t.onClick(n,o,e))return!1;s.a.create(document.body)},onSubmit:function(e,n){if(e.isValid){var o={stateData:JSON.stringify(e.data)},r=c.a.serialize(this.confirmOrderForm);"responseHandler"in t&&(this.responseHandler=t.responseHandler.bind(n,this)),this.confirmOrder(r,o)}else n.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",e)}.bind(this),onCancel:function(n,o){s.a.remove(document.body),t.onCancel(n,o,e)},onError:function(n,o){"PayPal"===o.props.name&&"CANCEL"===n.name&&e._client.post("".concat(adyenCheckoutOptions.cancelOrderTransactionUrl),JSON.stringify({orderId:e.orderId})),s.a.remove(document.body),t.onError(n,o,e),console.log(n)}}),a=this.adyenCheckout.create(o.type,r);try{"isAvailable"in a?a.isAvailable().then(function(){this.mountCustomPayButton(a)}.bind(this)).catch((function(e){console.log(o.type+" is not available",e)})):this.mountCustomPayButton(a)}catch(e){console.log(e)}}else console.error("Failed to fetch Cart/Order total amount.")}}},{key:"renderPrePaymentButton",value:function(e,t){var n=this;"amazonpay"===t.type&&(e.extra=this.setAddressDetails(e.extra));var o=y(e.extra,t,{configuration:t.configuration,amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},onClick:function(t,o){if(!e.onClick(t,o,n))return!1;s.a.create(document.body)},onError:function(t,o){s.a.remove(document.body),e.onError(t,o,n),console.log(t)}}),r=this.adyenCheckout.create(t.type,o);this.mountCustomPayButton(r)}},{key:"completePendingPayment",value:function(e,t){var n=new URL(location.href);if(n.searchParams.has(t.sessionKey)){var o;s.a.create(document.body);var r=this.adyenCheckout.create(e,(l(o={},t.sessionKey,n.searchParams.get(t.sessionKey)),l(o,"showOrderButton",!1),l(o,"onSubmit",function(e,t){if(e.isValid){var n={stateData:JSON.stringify(e.data)},o=c.a.serialize(this.confirmOrderForm);this.confirmOrder(o,n)}}.bind(this)),o));this.mountCustomPayButton(r),r.submit()}}},{key:"getSelectedPaymentMethodKey",value:function(){return Object.keys(d.a.paymentMethodTypeHandlers).find((function(e){return d.a.paymentMethodTypeHandlers[e]===adyenCheckoutOptions.selectedPaymentMethodHandler}))}},{key:"mountCustomPayButton",value:function(e){var t=document.querySelector("#confirmOrderForm");if(t){var n=t.querySelector("button[type=submit]");if(n&&!n.disabled){var o=document.createElement("div");o.id="adyen-confirm-button",o.setAttribute("data-adyen-confirm-button",""),t.appendChild(o),e.mount(o),n.remove()}}}},{key:"mountPaymentComponent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=y({},e,{data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onSubmit:function(n,o){if(n.isValid){t&&void 0!==e.holderName&&(n.data.paymentMethod.holderName=e.holderName);var r={stateData:JSON.stringify(n.data)},a=c.a.serialize(this.confirmOrderForm);s.a.create(document.body),this.confirmOrder(a,r)}else o.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",n)}.bind(this)});!t&&"scheme"===e.type&&adyenCheckoutOptions.displaySaveCreditCardOption&&(o.enableStoreDetails=!0);var r=t?n:"#"+this.el.id;try{var i=this.adyenCheckout.create(e.type,o);i.mount(r),this.confirmFormSubmit.addEventListener("click",function(e){a.a.querySelector(document,"#confirmOrderForm").checkValidity()&&(e.preventDefault(),this.el.parentNode.scrollIntoView({behavior:"smooth",block:"start"}),i.submit())}.bind(this))}catch(t){return console.error(e.type,t),!1}}},{key:"appendGiftcardSummary",value:function(){if(parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.shoppingCartSummaryBlock.length){var e=parseFloat(this.giftcardDiscount).toFixed(2),t=parseFloat(this.remainingAmount).toFixed(2),n='
'+adyenCheckoutOptions.translationAdyenGiftcardDiscount+'
'+adyenCheckoutOptions.currencySymbol+e+'
'+adyenCheckoutOptions.translationAdyenGiftcardRemainingAmount+'
'+adyenCheckoutOptions.currencySymbol+t+"
";this.shoppingCartSummaryBlock[0].innerHTML+=n}}},{key:"setAddressDetails",value:function(e){return""!==activeShippingAddress.phoneNumber?e.addressDetails={name:shopperDetails.firstName+" "+shopperDetails.lastName,addressLine1:activeShippingAddress.street,city:activeShippingAddress.city,postalCode:activeShippingAddress.postalCode,countryCode:activeShippingAddress.country,phoneNumber:activeShippingAddress.phoneNumber}:e.productType="PayOnly",e}}])&&m(r.prototype,u),b&&m(r,b),n}(r.a)}).call(this,n("UoTJ"),n("UoTJ"))},jC4o:function(e,t,n){"use strict";n.r(t);var o=n("FGIj"),r=n("gHbT"),a=n("k8s9"),i=n("u0Tz");function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(){return(s=Object.assign||function(e){for(var t=1;t".concat(e.title,""),r.appendChild(i),r.innerHTML+='

'.concat(o,"


"),t.appendChild(r)})),this.remainingAmount=e.redeemedGiftcards.remainingAmount,this.giftcardDiscount=e.redeemedGiftcards.totalDiscount,this.paymentMethodInstance&&this.paymentMethodInstance.unmount(),this.giftcardComponentClose.style.display="none",this.giftcardItem.innerHTML="",this.giftcardHeader.innerHTML=" ",this.appendGiftcardSummary(),this.remainingAmount>0?n.style.display="block":(this.adyenGiftcardDropDown.length>0&&(this.adyenGiftcardDropDown[0].style.display="none"),n.style.display="none"),document.getElementById("giftcardsContainer")}.bind(this))}},{key:"saveGiftcardStateData",value:function(e){e=JSON.stringify(e),this._client.post(adyenGiftcardsConfiguration.setGiftcardUrl,JSON.stringify({stateData:e}),function(e){"token"in(e=JSON.parse(e))&&(this.fetchRedeemedGiftcards(),i.a.remove(document.body))}.bind(this))}},{key:"removeGiftcard",value:function(e){var t=this;i.a.create(document.body),this._client.post(adyenGiftcardsConfiguration.removeGiftcardUrl,JSON.stringify({stateDataId:e}),(function(e){"token"in(e=JSON.parse(e))&&(t.fetchRedeemedGiftcards(),i.a.remove(document.body))}))}},{key:"appendGiftcardSummary",value:function(){if(this.shoppingCartSummaryBlock.length)for(var e=this.shoppingCartSummaryBlock[0].querySelectorAll(".adyen-giftcard-summary"),t=0;t
'+adyenGiftcardsConfiguration.currencySymbol+n+'
'+adyenGiftcardsConfiguration.translationAdyenGiftcardRemainingAmount+'
'+adyenGiftcardsConfiguration.currencySymbol+o+"
";this.shoppingCartSummaryBlock[0].innerHTML+=r}}}])&&l(n.prototype,o),c&&l(n,c),t}(o.a),f=n("j5lx");function g(e){return(g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function v(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function b(e){for(var t=1;t1&&void 0!==i[1]?i[1]:{},o=document.querySelector('meta[itemprop="productID"]'),r=o?o.content:"-1",e.abrupt("return",new Promise((function(e,o){a._client.post(t,JSON.stringify(b({quantity:a.quantityInput?a.quantityInput.value:-1,productId:r},n)),(function(t){try{var n=JSON.parse(t);console.log("Controller Response:",n),e(n)}catch(e){console.error("Failed to parse response:",e),o(e)}}))})));case 4:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"mountExpressCheckoutComponents",value:function(e){var t=this;if(document.getElementById("adyen-express-checkout")){var n=document.getElementsByClassName("adyen-express-checkout-element");if(0!==n.length)for(var o=function(o){var r=n[o].getElementsByClassName("adyen-type")[0].value;t.initializeCheckoutComponent(e).then(function(e){this.mountElement(r,e,n[o])}.bind(t))},r=0;r0?parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.appendGiftcardSummary():this.appendGiftcardSummary()}},{key:"initializeCheckoutComponent",value:(C=regeneratorRuntime.mark((function e(){var t,n,o,r,a,i,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=adyenCheckoutConfiguration,n=t.locale,o=t.clientKey,r=t.environment,a=t.merchantAccount,i=adyenCheckoutOptions.paymentMethodsResponse,c={locale:n,clientKey:o,environment:r,showPayButton:this.selectedAdyenPaymentMethod in d.a.componentsWithPayButton,hasHolderName:!0,paymentMethodsResponse:JSON.parse(i),onAdditionalDetails:this.handleOnAdditionalDetails.bind(this),countryCode:activeShippingAddress.country,paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,clickToPayConfiguration:{merchantDisplayName:a,shopperEmail:shopperDetails.shopperEmail}}}},e.next=5,AdyenCheckout(c);case 5:this.adyenCheckout=e.sent;case 6:case"end":return e.stop()}}),e,this)})),k=function(){var e=this,t=arguments;return new Promise((function(n,o){var r=C.apply(e,t);function a(e){h(r,n,o,a,i,"next",e)}function i(e){h(r,n,o,a,i,"throw",e)}a(void 0)}))},function(){return k.apply(this,arguments)})},{key:"handleOnAdditionalDetails",value:function(e){this._client.post("".concat(adyenCheckoutOptions.paymentDetailsUrl),JSON.stringify({orderId:this.orderId,stateData:JSON.stringify(e.data)}),function(e){200===this._client._request.status?this.responseHandler(e):location.href=this.errorUrl.toString()}.bind(this))}},{key:"onConfirmOrderSubmit",value:function(e){var t=a.a.querySelector(document,"#confirmOrderForm");if(t.checkValidity()){if("klarna_b2b"===this.selectedAdyenPaymentMethod){var n=a.a.querySelector(document,"#adyen-company-name"),o=a.a.querySelector(document,"#adyen-registration-number"),r=n?n.value.trim():"",i=o?o.value.trim():"",d=a.a.querySelector(document,"#adyen-company-name-error"),u=a.a.querySelector(document,"#adyen-registration-number-error");d.style.display="none",u.style.display="none";var l=!1;if(r||(d.style.display="block",l=!0),i||(u.style.display="block",l=!0),l)return void e.preventDefault()}e.preventDefault(),s.a.create(document.body);var y=c.a.serialize(t);this.confirmOrder(y)}}},{key:"renderPaymentComponent",value:function(e){if("oneclick"!==e){if("giftcard"!==e){var t=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e}));if(0!==t.length){var n=t[0];this.mountPaymentComponent(n,!1)}else"test"===this.adyenCheckout.options.environment&&console.error("Payment method configuration not found. ",e)}}else this.renderStoredPaymentMethodComponents()}},{key:"renderStoredPaymentMethodComponents",value:function(){var e=this;this.adyenCheckout.paymentMethodsResponse.storedPaymentMethods.forEach((function(t){var n='[data-adyen-stored-payment-method-id="'.concat(t.id,'"]');e.mountPaymentComponent(t,!0,n)})),this.hideStorePaymentMethodComponents();var t=null;a.a.querySelectorAll(document,"[name=adyenStoredPaymentMethodId]").forEach((function(n){t||(t=n.value),n.addEventListener("change",e.showSelectedStoredPaymentMethod.bind(e))})),this.showSelectedStoredPaymentMethod(null,t)}},{key:"showSelectedStoredPaymentMethod",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.hideStorePaymentMethodComponents(),t=e?e.target.value:t;var n='[data-adyen-stored-payment-method-id="'.concat(t,'"]'),o=a.a.querySelector(document,n);o.style.display="block"}},{key:"hideStorePaymentMethodComponents",value:function(){a.a.querySelectorAll(document,".stored-payment-component").forEach((function(e){e.style.display="none"}))}},{key:"confirmOrder",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=adyenCheckoutOptions.orderId;e.set("affiliateCode",adyenCheckoutOptions.affiliateCode),e.set("campaignCode",adyenCheckoutOptions.campaignCode),n?this.updatePayment(e,n,t):this.createOrder(e,t)}},{key:"updatePayment",value:function(e,t,n){e.set("orderId",t),this._client.post(adyenCheckoutOptions.updatePaymentUrl,e,this.afterSetPayment.bind(this,n))}},{key:"createOrder",value:function(e,t){this._client.post(adyenCheckoutOptions.checkoutOrderUrl,e,this.afterCreateOrder.bind(this,t))}},{key:"afterCreateOrder",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;try{e=JSON.parse(n)}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",n)}if(e.url)location.href=e.url;else{if(this.orderId=e.id,this.finishUrl=new URL(location.origin+adyenCheckoutOptions.paymentFinishUrl),this.finishUrl.searchParams.set("orderId",e.id),this.errorUrl=new URL(location.origin+adyenCheckoutOptions.paymentErrorUrl),this.errorUrl.searchParams.set("orderId",e.id),"handler_adyen_billiepaymentmethodhandler"===adyenCheckoutOptions.selectedPaymentMethodHandler){var o=a.a.querySelector(document,"#adyen-company-name"),r=o?o.value:"",i=a.a.querySelector(document,"#adyen-registration-number"),c=i?i.value:"";t.companyName=r,t.registrationNumber=c}var d={orderId:this.orderId,finishUrl:this.finishUrl.toString(),errorUrl:this.errorUrl.toString()};for(var u in t)d[u]=t[u];this._client.post(adyenCheckoutOptions.paymentHandleUrl,JSON.stringify(d),this.afterPayOrder.bind(this,this.orderId))}}},{key:"afterSetPayment",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;try{var n=JSON.parse(t);n.success&&this.afterCreateOrder(e,JSON.stringify({id:adyenCheckoutOptions.orderId}))}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}}},{key:"afterPayOrder",value:function(e,t){try{t=JSON.parse(t),this.returnUrl=t.redirectUrl}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}this.returnUrl===this.errorUrl.toString()&&(location.href=this.returnUrl);try{this._client.post("".concat(adyenCheckoutOptions.paymentStatusUrl),JSON.stringify({orderId:e}),this.responseHandler.bind(this))}catch(e){console.log(e)}}},{key:"handlePaymentAction",value:function(t){try{var n=JSON.parse(t);if((n.isFinal||"voucher"===n.action.type)&&(location.href=this.returnUrl),n.action){var r={};"threeDS2"===n.action.type&&(r.challengeWindowSize="05"),this.adyenCheckout.createFromAction(n.action,r).mount("[data-adyen-payment-action-container]"),["threeDS2","qrCode"].includes(n.action.type)&&(e?o("[data-adyen-payment-action-modal]").modal({show:!0}):new bootstrap.Modal(document.getElementById("adyen-payment-action-modal"),{keyboard:!1}).show())}}catch(e){console.log(e)}}},{key:"initializeCustomPayButton",value:function(){var e=this,t=d.a.componentsWithPayButton[this.selectedAdyenPaymentMethod];this.completePendingPayment(this.selectedAdyenPaymentMethod,t);var n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e.selectedAdyenPaymentMethod}));if(n.length<1&&"googlepay"===this.selectedAdyenPaymentMethod&&(n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(e){return"paywithgoogle"===e.type}))),!(n.length<1)){var o=n[0];if(adyenCheckoutOptions.amount)if(t.prePayRedirect)this.renderPrePaymentButton(t,o);else{var r=y(t.extra,o,{amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onClick:function(n,o){if(!t.onClick(n,o,e))return!1;s.a.create(document.body)},onSubmit:function(e,n){if(e.isValid){var o={stateData:JSON.stringify(e.data)},r=c.a.serialize(this.confirmOrderForm);"responseHandler"in t&&(this.responseHandler=t.responseHandler.bind(n,this)),this.confirmOrder(r,o)}else n.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",e)}.bind(this),onCancel:function(n,o){s.a.remove(document.body),t.onCancel(n,o,e)},onError:function(n,o){"PayPal"===o.props.name&&"CANCEL"===n.name&&e._client.post("".concat(adyenCheckoutOptions.cancelOrderTransactionUrl),JSON.stringify({orderId:e.orderId})),s.a.remove(document.body),t.onError(n,o,e),console.log(n)}}),a=this.adyenCheckout.create(o.type,r);try{"isAvailable"in a?a.isAvailable().then(function(){this.mountCustomPayButton(a)}.bind(this)).catch((function(e){console.log(o.type+" is not available",e)})):this.mountCustomPayButton(a)}catch(e){console.log(e)}}else console.error("Failed to fetch Cart/Order total amount.")}}},{key:"renderPrePaymentButton",value:function(e,t){var n=this;"amazonpay"===t.type&&(e.extra=this.setAddressDetails(e.extra));var o=y(e.extra,t,{configuration:t.configuration,amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},onClick:function(t,o){if(!e.onClick(t,o,n))return!1;s.a.create(document.body)},onError:function(t,o){s.a.remove(document.body),e.onError(t,o,n),console.log(t)}}),r=this.adyenCheckout.create(t.type,o);this.mountCustomPayButton(r)}},{key:"completePendingPayment",value:function(e,t){var n=new URL(location.href);if(n.searchParams.has(t.sessionKey)){var o;s.a.create(document.body);var r=this.adyenCheckout.create(e,(l(o={},t.sessionKey,n.searchParams.get(t.sessionKey)),l(o,"showOrderButton",!1),l(o,"onSubmit",function(e,t){if(e.isValid){var n={stateData:JSON.stringify(e.data)},o=c.a.serialize(this.confirmOrderForm);this.confirmOrder(o,n)}}.bind(this)),o));this.mountCustomPayButton(r),r.submit()}}},{key:"getSelectedPaymentMethodKey",value:function(){return Object.keys(d.a.paymentMethodTypeHandlers).find((function(e){return d.a.paymentMethodTypeHandlers[e]===adyenCheckoutOptions.selectedPaymentMethodHandler}))}},{key:"mountCustomPayButton",value:function(e){var t=document.querySelector("#confirmOrderForm");if(t){var n=t.querySelector("button[type=submit]");if(n&&!n.disabled){var o=document.createElement("div");o.id="adyen-confirm-button",o.setAttribute("data-adyen-confirm-button",""),t.appendChild(o),e.mount(o),n.remove()}}}},{key:"mountPaymentComponent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=y({},e,{data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onSubmit:function(n,o){if(n.isValid){t&&void 0!==e.holderName&&(n.data.paymentMethod.holderName=e.holderName);var r={stateData:JSON.stringify(n.data)},a=c.a.serialize(this.confirmOrderForm);s.a.create(document.body),this.confirmOrder(a,r)}else o.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",n)}.bind(this)});!t&&"scheme"===e.type&&adyenCheckoutOptions.displaySaveCreditCardOption&&(o.enableStoreDetails=!0);var r=t?n:"#"+this.el.id;try{var i=this.adyenCheckout.create(e.type,o);i.mount(r),this.confirmFormSubmit.addEventListener("click",function(e){a.a.querySelector(document,"#confirmOrderForm").checkValidity()&&(e.preventDefault(),this.el.parentNode.scrollIntoView({behavior:"smooth",block:"start"}),i.submit())}.bind(this))}catch(t){return console.error(e.type,t),!1}}},{key:"appendGiftcardSummary",value:function(){if(parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.shoppingCartSummaryBlock.length){var e=parseFloat(this.giftcardDiscount).toFixed(2),t=parseFloat(this.remainingAmount).toFixed(2),n='
'+adyenCheckoutOptions.translationAdyenGiftcardDiscount+'
'+adyenCheckoutOptions.currencySymbol+e+'
'+adyenCheckoutOptions.translationAdyenGiftcardRemainingAmount+'
'+adyenCheckoutOptions.currencySymbol+t+"
";this.shoppingCartSummaryBlock[0].innerHTML+=n}}},{key:"setAddressDetails",value:function(e){return""!==activeShippingAddress.phoneNumber?e.addressDetails={name:shopperDetails.firstName+" "+shopperDetails.lastName,addressLine1:activeShippingAddress.street,city:activeShippingAddress.city,postalCode:activeShippingAddress.postalCode,countryCode:activeShippingAddress.country,phoneNumber:activeShippingAddress.phoneNumber}:e.productType="PayOnly",e}}])&&m(r.prototype,u),b&&m(r,b),n}(r.a)}).call(this,n("UoTJ"),n("UoTJ"))},jC4o:function(e,t,n){"use strict";n.r(t);var o=n("FGIj"),r=n("gHbT"),a=n("k8s9"),i=n("u0Tz");function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(){return(s=Object.assign||function(e){for(var t=1;t".concat(e.title,""),r.appendChild(i),r.innerHTML+='

'.concat(o,"


"),t.appendChild(r)})),this.remainingAmount=e.redeemedGiftcards.remainingAmount,this.giftcardDiscount=e.redeemedGiftcards.totalDiscount,this.paymentMethodInstance&&this.paymentMethodInstance.unmount(),this.giftcardComponentClose.style.display="none",this.giftcardItem.innerHTML="",this.giftcardHeader.innerHTML=" ",this.appendGiftcardSummary(),this.remainingAmount>0?n.style.display="block":(this.adyenGiftcardDropDown.length>0&&(this.adyenGiftcardDropDown[0].style.display="none"),n.style.display="none"),document.getElementById("giftcardsContainer")}.bind(this))}},{key:"saveGiftcardStateData",value:function(e){e=JSON.stringify(e),this._client.post(adyenGiftcardsConfiguration.setGiftcardUrl,JSON.stringify({stateData:e}),function(e){"token"in(e=JSON.parse(e))&&(this.fetchRedeemedGiftcards(),i.a.remove(document.body))}.bind(this))}},{key:"removeGiftcard",value:function(e){var t=this;i.a.create(document.body),this._client.post(adyenGiftcardsConfiguration.removeGiftcardUrl,JSON.stringify({stateDataId:e}),(function(e){"token"in(e=JSON.parse(e))&&(t.fetchRedeemedGiftcards(),i.a.remove(document.body))}))}},{key:"appendGiftcardSummary",value:function(){if(this.shoppingCartSummaryBlock.length)for(var e=this.shoppingCartSummaryBlock[0].querySelectorAll(".adyen-giftcard-summary"),t=0;t
'+adyenGiftcardsConfiguration.currencySymbol+n+'
'+adyenGiftcardsConfiguration.translationAdyenGiftcardRemainingAmount+'
'+adyenGiftcardsConfiguration.currencySymbol+o+"
";this.shoppingCartSummaryBlock[0].innerHTML+=r}}}])&&l(n.prototype,o),c&&l(n,c),t}(o.a),f=n("j5lx");function g(e){return(g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function v(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function b(e){for(var t=1;t1&&void 0!==i[1]?i[1]:{},o=document.querySelector('meta[itemprop="productID"]'),r=o?o.content:"-1",e.abrupt("return",new Promise((function(e,o){a._client.post(t,JSON.stringify(b({quantity:a.quantityInput?a.quantityInput.value:-1,productId:r},n)),(function(t){try{var n=JSON.parse(t);if(console.log("odgovor "),console.log(n),console.log("status "),console.log(a._client._request.status),a._client._request.status>=400)return void o({error:n.error});e(n)}catch(e){o({status:500,message:"Failed to parse server response."})}}))})));case 4:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"mountExpressCheckoutComponents",value:function(e){var t=this;if(document.getElementById("adyen-express-checkout")){var n=document.getElementsByClassName("adyen-express-checkout-element");if(0!==n.length)for(var o=function(o){var r=n[o].getElementsByClassName("adyen-type")[0].value;t.initializeCheckoutComponent(e).then(function(e){this.mountElement(r,e,n[o])}.bind(t))},r=0;r0?parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.appendGiftcardSummary():this.appendGiftcardSummary()}},{key:"initializeCheckoutComponent",value:(C=regeneratorRuntime.mark((function e(){var t,n,o,r,a,i,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=adyenCheckoutConfiguration,n=t.locale,o=t.clientKey,r=t.environment,a=t.merchantAccount,i=adyenCheckoutOptions.paymentMethodsResponse,c={locale:n,clientKey:o,environment:r,showPayButton:this.selectedAdyenPaymentMethod in d.a.componentsWithPayButton,hasHolderName:!0,paymentMethodsResponse:JSON.parse(i),onAdditionalDetails:this.handleOnAdditionalDetails.bind(this),countryCode:activeShippingAddress.country,paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,clickToPayConfiguration:{merchantDisplayName:a,shopperEmail:shopperDetails.shopperEmail}}}},e.next=5,AdyenCheckout(c);case 5:this.adyenCheckout=e.sent;case 6:case"end":return e.stop()}}),e,this)})),k=function(){var e=this,t=arguments;return new Promise((function(n,o){var r=C.apply(e,t);function a(e){h(r,n,o,a,i,"next",e)}function i(e){h(r,n,o,a,i,"throw",e)}a(void 0)}))},function(){return k.apply(this,arguments)})},{key:"handleOnAdditionalDetails",value:function(e){this._client.post("".concat(adyenCheckoutOptions.paymentDetailsUrl),JSON.stringify({orderId:this.orderId,stateData:JSON.stringify(e.data)}),function(e){200===this._client._request.status?this.responseHandler(e):location.href=this.errorUrl.toString()}.bind(this))}},{key:"onConfirmOrderSubmit",value:function(e){var t=a.a.querySelector(document,"#confirmOrderForm");if(t.checkValidity()){if("klarna_b2b"===this.selectedAdyenPaymentMethod){var n=a.a.querySelector(document,"#adyen-company-name"),o=a.a.querySelector(document,"#adyen-registration-number"),r=n?n.value.trim():"",i=o?o.value.trim():"",d=a.a.querySelector(document,"#adyen-company-name-error"),u=a.a.querySelector(document,"#adyen-registration-number-error");d.style.display="none",u.style.display="none";var l=!1;if(r||(d.style.display="block",l=!0),i||(u.style.display="block",l=!0),l)return void e.preventDefault()}e.preventDefault(),s.a.create(document.body);var y=c.a.serialize(t);this.confirmOrder(y)}}},{key:"renderPaymentComponent",value:function(e){if("oneclick"!==e){if("giftcard"!==e){var t=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e}));if(0!==t.length){var n=t[0];this.mountPaymentComponent(n,!1)}else"test"===this.adyenCheckout.options.environment&&console.error("Payment method configuration not found. ",e)}}else this.renderStoredPaymentMethodComponents()}},{key:"renderStoredPaymentMethodComponents",value:function(){var e=this;this.adyenCheckout.paymentMethodsResponse.storedPaymentMethods.forEach((function(t){var n='[data-adyen-stored-payment-method-id="'.concat(t.id,'"]');e.mountPaymentComponent(t,!0,n)})),this.hideStorePaymentMethodComponents();var t=null;a.a.querySelectorAll(document,"[name=adyenStoredPaymentMethodId]").forEach((function(n){t||(t=n.value),n.addEventListener("change",e.showSelectedStoredPaymentMethod.bind(e))})),this.showSelectedStoredPaymentMethod(null,t)}},{key:"showSelectedStoredPaymentMethod",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.hideStorePaymentMethodComponents(),t=e?e.target.value:t;var n='[data-adyen-stored-payment-method-id="'.concat(t,'"]'),o=a.a.querySelector(document,n);o.style.display="block"}},{key:"hideStorePaymentMethodComponents",value:function(){a.a.querySelectorAll(document,".stored-payment-component").forEach((function(e){e.style.display="none"}))}},{key:"confirmOrder",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=adyenCheckoutOptions.orderId;e.set("affiliateCode",adyenCheckoutOptions.affiliateCode),e.set("campaignCode",adyenCheckoutOptions.campaignCode),n?this.updatePayment(e,n,t):this.createOrder(e,t)}},{key:"updatePayment",value:function(e,t,n){e.set("orderId",t),this._client.post(adyenCheckoutOptions.updatePaymentUrl,e,this.afterSetPayment.bind(this,n))}},{key:"createOrder",value:function(e,t){this._client.post(adyenCheckoutOptions.checkoutOrderUrl,e,this.afterCreateOrder.bind(this,t))}},{key:"afterCreateOrder",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;try{e=JSON.parse(n)}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",n)}if(e.url)location.href=e.url;else{if(this.orderId=e.id,this.finishUrl=new URL(location.origin+adyenCheckoutOptions.paymentFinishUrl),this.finishUrl.searchParams.set("orderId",e.id),this.errorUrl=new URL(location.origin+adyenCheckoutOptions.paymentErrorUrl),this.errorUrl.searchParams.set("orderId",e.id),"handler_adyen_billiepaymentmethodhandler"===adyenCheckoutOptions.selectedPaymentMethodHandler){var o=a.a.querySelector(document,"#adyen-company-name"),r=o?o.value:"",i=a.a.querySelector(document,"#adyen-registration-number"),c=i?i.value:"";t.companyName=r,t.registrationNumber=c}var d={orderId:this.orderId,finishUrl:this.finishUrl.toString(),errorUrl:this.errorUrl.toString()};for(var u in t)d[u]=t[u];this._client.post(adyenCheckoutOptions.paymentHandleUrl,JSON.stringify(d),this.afterPayOrder.bind(this,this.orderId))}}},{key:"afterSetPayment",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;try{var n=JSON.parse(t);n.success&&this.afterCreateOrder(e,JSON.stringify({id:adyenCheckoutOptions.orderId}))}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}}},{key:"afterPayOrder",value:function(e,t){try{t=JSON.parse(t),this.returnUrl=t.redirectUrl}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}this.returnUrl===this.errorUrl.toString()&&(location.href=this.returnUrl);try{this._client.post("".concat(adyenCheckoutOptions.paymentStatusUrl),JSON.stringify({orderId:e}),this.responseHandler.bind(this))}catch(e){console.log(e)}}},{key:"handlePaymentAction",value:function(t){try{var n=JSON.parse(t);if((n.isFinal||"voucher"===n.action.type)&&(location.href=this.returnUrl),n.action){var r={};"threeDS2"===n.action.type&&(r.challengeWindowSize="05"),this.adyenCheckout.createFromAction(n.action,r).mount("[data-adyen-payment-action-container]"),["threeDS2","qrCode"].includes(n.action.type)&&(e?o("[data-adyen-payment-action-modal]").modal({show:!0}):new bootstrap.Modal(document.getElementById("adyen-payment-action-modal"),{keyboard:!1}).show())}}catch(e){console.log(e)}}},{key:"initializeCustomPayButton",value:function(){var e=this,t=d.a.componentsWithPayButton[this.selectedAdyenPaymentMethod];this.completePendingPayment(this.selectedAdyenPaymentMethod,t);var n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e.selectedAdyenPaymentMethod}));if(n.length<1&&"googlepay"===this.selectedAdyenPaymentMethod&&(n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(e){return"paywithgoogle"===e.type}))),!(n.length<1)){var o=n[0];if(adyenCheckoutOptions.amount)if(t.prePayRedirect)this.renderPrePaymentButton(t,o);else{var r=y(t.extra,o,{amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onClick:function(n,o){if(!t.onClick(n,o,e))return!1;s.a.create(document.body)},onSubmit:function(e,n){if(e.isValid){var o={stateData:JSON.stringify(e.data)},r=c.a.serialize(this.confirmOrderForm);"responseHandler"in t&&(this.responseHandler=t.responseHandler.bind(n,this)),this.confirmOrder(r,o)}else n.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",e)}.bind(this),onCancel:function(n,o){s.a.remove(document.body),t.onCancel(n,o,e)},onError:function(n,o){"PayPal"===o.props.name&&"CANCEL"===n.name&&e._client.post("".concat(adyenCheckoutOptions.cancelOrderTransactionUrl),JSON.stringify({orderId:e.orderId})),s.a.remove(document.body),t.onError(n,o,e),console.log(n)}}),a=this.adyenCheckout.create(o.type,r);try{"isAvailable"in a?a.isAvailable().then(function(){this.mountCustomPayButton(a)}.bind(this)).catch((function(e){console.log(o.type+" is not available",e)})):this.mountCustomPayButton(a)}catch(e){console.log(e)}}else console.error("Failed to fetch Cart/Order total amount.")}}},{key:"renderPrePaymentButton",value:function(e,t){var n=this;"amazonpay"===t.type&&(e.extra=this.setAddressDetails(e.extra));var o=y(e.extra,t,{configuration:t.configuration,amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},onClick:function(t,o){if(!e.onClick(t,o,n))return!1;s.a.create(document.body)},onError:function(t,o){s.a.remove(document.body),e.onError(t,o,n),console.log(t)}}),r=this.adyenCheckout.create(t.type,o);this.mountCustomPayButton(r)}},{key:"completePendingPayment",value:function(e,t){var n=new URL(location.href);if(n.searchParams.has(t.sessionKey)){var o;s.a.create(document.body);var r=this.adyenCheckout.create(e,(l(o={},t.sessionKey,n.searchParams.get(t.sessionKey)),l(o,"showOrderButton",!1),l(o,"onSubmit",function(e,t){if(e.isValid){var n={stateData:JSON.stringify(e.data)},o=c.a.serialize(this.confirmOrderForm);this.confirmOrder(o,n)}}.bind(this)),o));this.mountCustomPayButton(r),r.submit()}}},{key:"getSelectedPaymentMethodKey",value:function(){return Object.keys(d.a.paymentMethodTypeHandlers).find((function(e){return d.a.paymentMethodTypeHandlers[e]===adyenCheckoutOptions.selectedPaymentMethodHandler}))}},{key:"mountCustomPayButton",value:function(e){var t=document.querySelector("#confirmOrderForm");if(t){var n=t.querySelector("button[type=submit]");if(n&&!n.disabled){var o=document.createElement("div");o.id="adyen-confirm-button",o.setAttribute("data-adyen-confirm-button",""),t.appendChild(o),e.mount(o),n.remove()}}}},{key:"mountPaymentComponent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=y({},e,{data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onSubmit:function(n,o){if(n.isValid){t&&void 0!==e.holderName&&(n.data.paymentMethod.holderName=e.holderName);var r={stateData:JSON.stringify(n.data)},a=c.a.serialize(this.confirmOrderForm);s.a.create(document.body),this.confirmOrder(a,r)}else o.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",n)}.bind(this)});!t&&"scheme"===e.type&&adyenCheckoutOptions.displaySaveCreditCardOption&&(o.enableStoreDetails=!0);var r=t?n:"#"+this.el.id;try{var i=this.adyenCheckout.create(e.type,o);i.mount(r),this.confirmFormSubmit.addEventListener("click",function(e){a.a.querySelector(document,"#confirmOrderForm").checkValidity()&&(e.preventDefault(),this.el.parentNode.scrollIntoView({behavior:"smooth",block:"start"}),i.submit())}.bind(this))}catch(t){return console.error(e.type,t),!1}}},{key:"appendGiftcardSummary",value:function(){if(parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.shoppingCartSummaryBlock.length){var e=parseFloat(this.giftcardDiscount).toFixed(2),t=parseFloat(this.remainingAmount).toFixed(2),n='
'+adyenCheckoutOptions.translationAdyenGiftcardDiscount+'
'+adyenCheckoutOptions.currencySymbol+e+'
'+adyenCheckoutOptions.translationAdyenGiftcardRemainingAmount+'
'+adyenCheckoutOptions.currencySymbol+t+"
";this.shoppingCartSummaryBlock[0].innerHTML+=n}}},{key:"setAddressDetails",value:function(e){return""!==activeShippingAddress.phoneNumber?e.addressDetails={name:shopperDetails.firstName+" "+shopperDetails.lastName,addressLine1:activeShippingAddress.street,city:activeShippingAddress.city,postalCode:activeShippingAddress.postalCode,countryCode:activeShippingAddress.country,phoneNumber:activeShippingAddress.phoneNumber}:e.productType="PayOnly",e}}])&&m(r.prototype,u),b&&m(r,b),n}(r.a)}).call(this,n("UoTJ"),n("UoTJ"))},jC4o:function(e,t,n){"use strict";n.r(t);var o=n("FGIj"),r=n("gHbT"),a=n("k8s9"),i=n("u0Tz");function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(){return(s=Object.assign||function(e){for(var t=1;t".concat(e.title,""),r.appendChild(i),r.innerHTML+='

'.concat(o,"


"),t.appendChild(r)})),this.remainingAmount=e.redeemedGiftcards.remainingAmount,this.giftcardDiscount=e.redeemedGiftcards.totalDiscount,this.paymentMethodInstance&&this.paymentMethodInstance.unmount(),this.giftcardComponentClose.style.display="none",this.giftcardItem.innerHTML="",this.giftcardHeader.innerHTML=" ",this.appendGiftcardSummary(),this.remainingAmount>0?n.style.display="block":(this.adyenGiftcardDropDown.length>0&&(this.adyenGiftcardDropDown[0].style.display="none"),n.style.display="none"),document.getElementById("giftcardsContainer")}.bind(this))}},{key:"saveGiftcardStateData",value:function(e){e=JSON.stringify(e),this._client.post(adyenGiftcardsConfiguration.setGiftcardUrl,JSON.stringify({stateData:e}),function(e){"token"in(e=JSON.parse(e))&&(this.fetchRedeemedGiftcards(),i.a.remove(document.body))}.bind(this))}},{key:"removeGiftcard",value:function(e){var t=this;i.a.create(document.body),this._client.post(adyenGiftcardsConfiguration.removeGiftcardUrl,JSON.stringify({stateDataId:e}),(function(e){"token"in(e=JSON.parse(e))&&(t.fetchRedeemedGiftcards(),i.a.remove(document.body))}))}},{key:"appendGiftcardSummary",value:function(){if(this.shoppingCartSummaryBlock.length)for(var e=this.shoppingCartSummaryBlock[0].querySelectorAll(".adyen-giftcard-summary"),t=0;t
'+adyenGiftcardsConfiguration.currencySymbol+n+'
'+adyenGiftcardsConfiguration.translationAdyenGiftcardRemainingAmount+'
'+adyenGiftcardsConfiguration.currencySymbol+o+"
";this.shoppingCartSummaryBlock[0].innerHTML+=r}}}])&&l(n.prototype,o),c&&l(n,c),t}(o.a),f=n("j5lx");function g(e){return(g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function v(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function b(e){for(var t=1;t1&&void 0!==i[1]?i[1]:{},o=document.querySelector('meta[itemprop="productID"]'),r=o?o.content:"-1",e.abrupt("return",new Promise((function(e,o){a._client.post(t,JSON.stringify(b({quantity:a.quantityInput?a.quantityInput.value:-1,productId:r},n)),(function(t){try{var n=JSON.parse(t);console.log("Controller Response:",n),e(n)}catch(e){console.error("Failed to parse response:",e),o(e)}}))})));case 4:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"mountExpressCheckoutComponents",value:function(e){var t=this;if(document.getElementById("adyen-express-checkout")){var n=document.getElementsByClassName("adyen-express-checkout-element");if(0!==n.length)for(var o=function(o){var r=n[o].getElementsByClassName("adyen-type")[0].value;t.initializeCheckoutComponent(e).then(function(e){this.mountElement(r,e,n[o])}.bind(t))},r=0;r0?parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.appendGiftcardSummary():this.appendGiftcardSummary()}},{key:"initializeCheckoutComponent",value:(C=regeneratorRuntime.mark((function e(){var t,n,o,r,a,i,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=adyenCheckoutConfiguration,n=t.locale,o=t.clientKey,r=t.environment,a=t.merchantAccount,i=adyenCheckoutOptions.paymentMethodsResponse,c={locale:n,clientKey:o,environment:r,showPayButton:this.selectedAdyenPaymentMethod in d.a.componentsWithPayButton,hasHolderName:!0,paymentMethodsResponse:JSON.parse(i),onAdditionalDetails:this.handleOnAdditionalDetails.bind(this),countryCode:activeShippingAddress.country,paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,clickToPayConfiguration:{merchantDisplayName:a,shopperEmail:shopperDetails.shopperEmail}}}},e.next=5,AdyenCheckout(c);case 5:this.adyenCheckout=e.sent;case 6:case"end":return e.stop()}}),e,this)})),k=function(){var e=this,t=arguments;return new Promise((function(n,o){var r=C.apply(e,t);function a(e){h(r,n,o,a,i,"next",e)}function i(e){h(r,n,o,a,i,"throw",e)}a(void 0)}))},function(){return k.apply(this,arguments)})},{key:"handleOnAdditionalDetails",value:function(e){this._client.post("".concat(adyenCheckoutOptions.paymentDetailsUrl),JSON.stringify({orderId:this.orderId,stateData:JSON.stringify(e.data)}),function(e){200===this._client._request.status?this.responseHandler(e):location.href=this.errorUrl.toString()}.bind(this))}},{key:"onConfirmOrderSubmit",value:function(e){var t=a.a.querySelector(document,"#confirmOrderForm");if(t.checkValidity()){if("klarna_b2b"===this.selectedAdyenPaymentMethod){var n=a.a.querySelector(document,"#adyen-company-name"),o=a.a.querySelector(document,"#adyen-registration-number"),r=n?n.value.trim():"",i=o?o.value.trim():"",d=a.a.querySelector(document,"#adyen-company-name-error"),u=a.a.querySelector(document,"#adyen-registration-number-error");d.style.display="none",u.style.display="none";var l=!1;if(r||(d.style.display="block",l=!0),i||(u.style.display="block",l=!0),l)return void e.preventDefault()}e.preventDefault(),s.a.create(document.body);var y=c.a.serialize(t);this.confirmOrder(y)}}},{key:"renderPaymentComponent",value:function(e){if("oneclick"!==e){if("giftcard"!==e){var t=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e}));if(0!==t.length){var n=t[0];this.mountPaymentComponent(n,!1)}else"test"===this.adyenCheckout.options.environment&&console.error("Payment method configuration not found. ",e)}}else this.renderStoredPaymentMethodComponents()}},{key:"renderStoredPaymentMethodComponents",value:function(){var e=this;this.adyenCheckout.paymentMethodsResponse.storedPaymentMethods.forEach((function(t){var n='[data-adyen-stored-payment-method-id="'.concat(t.id,'"]');e.mountPaymentComponent(t,!0,n)})),this.hideStorePaymentMethodComponents();var t=null;a.a.querySelectorAll(document,"[name=adyenStoredPaymentMethodId]").forEach((function(n){t||(t=n.value),n.addEventListener("change",e.showSelectedStoredPaymentMethod.bind(e))})),this.showSelectedStoredPaymentMethod(null,t)}},{key:"showSelectedStoredPaymentMethod",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.hideStorePaymentMethodComponents(),t=e?e.target.value:t;var n='[data-adyen-stored-payment-method-id="'.concat(t,'"]'),o=a.a.querySelector(document,n);o.style.display="block"}},{key:"hideStorePaymentMethodComponents",value:function(){a.a.querySelectorAll(document,".stored-payment-component").forEach((function(e){e.style.display="none"}))}},{key:"confirmOrder",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=adyenCheckoutOptions.orderId;e.set("affiliateCode",adyenCheckoutOptions.affiliateCode),e.set("campaignCode",adyenCheckoutOptions.campaignCode),n?this.updatePayment(e,n,t):this.createOrder(e,t)}},{key:"updatePayment",value:function(e,t,n){e.set("orderId",t),this._client.post(adyenCheckoutOptions.updatePaymentUrl,e,this.afterSetPayment.bind(this,n))}},{key:"createOrder",value:function(e,t){this._client.post(adyenCheckoutOptions.checkoutOrderUrl,e,this.afterCreateOrder.bind(this,t))}},{key:"afterCreateOrder",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;try{e=JSON.parse(n)}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",n)}if(e.url)location.href=e.url;else{if(this.orderId=e.id,this.finishUrl=new URL(location.origin+adyenCheckoutOptions.paymentFinishUrl),this.finishUrl.searchParams.set("orderId",e.id),this.errorUrl=new URL(location.origin+adyenCheckoutOptions.paymentErrorUrl),this.errorUrl.searchParams.set("orderId",e.id),"handler_adyen_billiepaymentmethodhandler"===adyenCheckoutOptions.selectedPaymentMethodHandler){var o=a.a.querySelector(document,"#adyen-company-name"),r=o?o.value:"",i=a.a.querySelector(document,"#adyen-registration-number"),c=i?i.value:"";t.companyName=r,t.registrationNumber=c}var d={orderId:this.orderId,finishUrl:this.finishUrl.toString(),errorUrl:this.errorUrl.toString()};for(var u in t)d[u]=t[u];this._client.post(adyenCheckoutOptions.paymentHandleUrl,JSON.stringify(d),this.afterPayOrder.bind(this,this.orderId))}}},{key:"afterSetPayment",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;try{var n=JSON.parse(t);n.success&&this.afterCreateOrder(e,JSON.stringify({id:adyenCheckoutOptions.orderId}))}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}}},{key:"afterPayOrder",value:function(e,t){try{t=JSON.parse(t),this.returnUrl=t.redirectUrl}catch(e){return s.a.remove(document.body),void console.log("Error: invalid response from Shopware API",t)}this.returnUrl===this.errorUrl.toString()&&(location.href=this.returnUrl);try{this._client.post("".concat(adyenCheckoutOptions.paymentStatusUrl),JSON.stringify({orderId:e}),this.responseHandler.bind(this))}catch(e){console.log(e)}}},{key:"handlePaymentAction",value:function(t){try{var n=JSON.parse(t);if((n.isFinal||"voucher"===n.action.type)&&(location.href=this.returnUrl),n.action){var r={};"threeDS2"===n.action.type&&(r.challengeWindowSize="05"),this.adyenCheckout.createFromAction(n.action,r).mount("[data-adyen-payment-action-container]"),["threeDS2","qrCode"].includes(n.action.type)&&(e?o("[data-adyen-payment-action-modal]").modal({show:!0}):new bootstrap.Modal(document.getElementById("adyen-payment-action-modal"),{keyboard:!1}).show())}}catch(e){console.log(e)}}},{key:"initializeCustomPayButton",value:function(){var e=this,t=d.a.componentsWithPayButton[this.selectedAdyenPaymentMethod];this.completePendingPayment(this.selectedAdyenPaymentMethod,t);var n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(t){return t.type===e.selectedAdyenPaymentMethod}));if(n.length<1&&"googlepay"===this.selectedAdyenPaymentMethod&&(n=this.adyenCheckout.paymentMethodsResponse.paymentMethods.filter((function(e){return"paywithgoogle"===e.type}))),!(n.length<1)){var o=n[0];if(adyenCheckoutOptions.amount)if(t.prePayRedirect)this.renderPrePaymentButton(t,o);else{var r=y(t.extra,o,{amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onClick:function(n,o){if(!t.onClick(n,o,e))return!1;s.a.create(document.body)},onSubmit:function(e,n){if(e.isValid){var o={stateData:JSON.stringify(e.data)},r=c.a.serialize(this.confirmOrderForm);"responseHandler"in t&&(this.responseHandler=t.responseHandler.bind(n,this)),this.confirmOrder(r,o)}else n.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",e)}.bind(this),onCancel:function(n,o){s.a.remove(document.body),t.onCancel(n,o,e)},onError:function(n,o){"PayPal"===o.props.name&&"CANCEL"===n.name&&e._client.post("".concat(adyenCheckoutOptions.cancelOrderTransactionUrl),JSON.stringify({orderId:e.orderId})),s.a.remove(document.body),t.onError(n,o,e),console.log(n)}}),a=this.adyenCheckout.create(o.type,r);try{"isAvailable"in a?a.isAvailable().then(function(){this.mountCustomPayButton(a)}.bind(this)).catch((function(e){console.log(o.type+" is not available",e)})):this.mountCustomPayButton(a)}catch(e){console.log(e)}}else console.error("Failed to fetch Cart/Order total amount.")}}},{key:"renderPrePaymentButton",value:function(e,t){var n=this;"amazonpay"===t.type&&(e.extra=this.setAddressDetails(e.extra));var o=y(e.extra,t,{configuration:t.configuration,amount:{value:adyenCheckoutOptions.amount,currency:adyenCheckoutOptions.currency},onClick:function(t,o){if(!e.onClick(t,o,n))return!1;s.a.create(document.body)},onError:function(t,o){s.a.remove(document.body),e.onError(t,o,n),console.log(t)}}),r=this.adyenCheckout.create(t.type,o);this.mountCustomPayButton(r)}},{key:"completePendingPayment",value:function(e,t){var n=new URL(location.href);if(n.searchParams.has(t.sessionKey)){var o;s.a.create(document.body);var r=this.adyenCheckout.create(e,(l(o={},t.sessionKey,n.searchParams.get(t.sessionKey)),l(o,"showOrderButton",!1),l(o,"onSubmit",function(e,t){if(e.isValid){var n={stateData:JSON.stringify(e.data)},o=c.a.serialize(this.confirmOrderForm);this.confirmOrder(o,n)}}.bind(this)),o));this.mountCustomPayButton(r),r.submit()}}},{key:"getSelectedPaymentMethodKey",value:function(){return Object.keys(d.a.paymentMethodTypeHandlers).find((function(e){return d.a.paymentMethodTypeHandlers[e]===adyenCheckoutOptions.selectedPaymentMethodHandler}))}},{key:"mountCustomPayButton",value:function(e){var t=document.querySelector("#confirmOrderForm");if(t){var n=t.querySelector("button[type=submit]");if(n&&!n.disabled){var o=document.createElement("div");o.id="adyen-confirm-button",o.setAttribute("data-adyen-confirm-button",""),t.appendChild(o),e.mount(o),n.remove()}}}},{key:"mountPaymentComponent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=y({},e,{data:{personalDetails:shopperDetails,billingAddress:activeBillingAddress,deliveryAddress:activeShippingAddress},onSubmit:function(n,o){if(n.isValid){t&&void 0!==e.holderName&&(n.data.paymentMethod.holderName=e.holderName);var r={stateData:JSON.stringify(n.data)},a=c.a.serialize(this.confirmOrderForm);s.a.create(document.body),this.confirmOrder(a,r)}else o.showValidation(),"test"===this.adyenCheckout.options.environment&&console.log("Payment failed: ",n)}.bind(this)});!t&&"scheme"===e.type&&adyenCheckoutOptions.displaySaveCreditCardOption&&(o.enableStoreDetails=!0);var r=t?n:"#"+this.el.id;try{var i=this.adyenCheckout.create(e.type,o);i.mount(r),this.confirmFormSubmit.addEventListener("click",function(e){a.a.querySelector(document,"#confirmOrderForm").checkValidity()&&(e.preventDefault(),this.el.parentNode.scrollIntoView({behavior:"smooth",block:"start"}),i.submit())}.bind(this))}catch(t){return console.error(e.type,t),!1}}},{key:"appendGiftcardSummary",value:function(){if(parseInt(adyenCheckoutOptions.giftcardDiscount,10)&&this.shoppingCartSummaryBlock.length){var e=parseFloat(this.giftcardDiscount).toFixed(2),t=parseFloat(this.remainingAmount).toFixed(2),n='
'+adyenCheckoutOptions.translationAdyenGiftcardDiscount+'
'+adyenCheckoutOptions.currencySymbol+e+'
'+adyenCheckoutOptions.translationAdyenGiftcardRemainingAmount+'
'+adyenCheckoutOptions.currencySymbol+t+"
";this.shoppingCartSummaryBlock[0].innerHTML+=n}}},{key:"setAddressDetails",value:function(e){return""!==activeShippingAddress.phoneNumber?e.addressDetails={name:shopperDetails.firstName+" "+shopperDetails.lastName,addressLine1:activeShippingAddress.street,city:activeShippingAddress.city,postalCode:activeShippingAddress.postalCode,countryCode:activeShippingAddress.country,phoneNumber:activeShippingAddress.phoneNumber}:e.productType="PayOnly",e}}])&&m(r.prototype,u),b&&m(r,b),n}(r.a)}).call(this,n("UoTJ"),n("UoTJ"))},jC4o:function(e,t,n){"use strict";n.r(t);var o=n("FGIj"),r=n("gHbT"),a=n("k8s9"),i=n("u0Tz");function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(){return(s=Object.assign||function(e){for(var t=1;t".concat(e.title,""),r.appendChild(i),r.innerHTML+='

'.concat(o,"


"),t.appendChild(r)})),this.remainingAmount=e.redeemedGiftcards.remainingAmount,this.giftcardDiscount=e.redeemedGiftcards.totalDiscount,this.paymentMethodInstance&&this.paymentMethodInstance.unmount(),this.giftcardComponentClose.style.display="none",this.giftcardItem.innerHTML="",this.giftcardHeader.innerHTML=" ",this.appendGiftcardSummary(),this.remainingAmount>0?n.style.display="block":(this.adyenGiftcardDropDown.length>0&&(this.adyenGiftcardDropDown[0].style.display="none"),n.style.display="none"),document.getElementById("giftcardsContainer")}.bind(this))}},{key:"saveGiftcardStateData",value:function(e){e=JSON.stringify(e),this._client.post(adyenGiftcardsConfiguration.setGiftcardUrl,JSON.stringify({stateData:e}),function(e){"token"in(e=JSON.parse(e))&&(this.fetchRedeemedGiftcards(),i.a.remove(document.body))}.bind(this))}},{key:"removeGiftcard",value:function(e){var t=this;i.a.create(document.body),this._client.post(adyenGiftcardsConfiguration.removeGiftcardUrl,JSON.stringify({stateDataId:e}),(function(e){"token"in(e=JSON.parse(e))&&(t.fetchRedeemedGiftcards(),i.a.remove(document.body))}))}},{key:"appendGiftcardSummary",value:function(){if(this.shoppingCartSummaryBlock.length)for(var e=this.shoppingCartSummaryBlock[0].querySelectorAll(".adyen-giftcard-summary"),t=0;t
'+adyenGiftcardsConfiguration.currencySymbol+n+'
'+adyenGiftcardsConfiguration.translationAdyenGiftcardRemainingAmount+'
'+adyenGiftcardsConfiguration.currencySymbol+o+"
";this.shoppingCartSummaryBlock[0].innerHTML+=r}}}])&&l(n.prototype,o),c&&l(n,c),t}(o.a),f=n("j5lx");function g(e){return(g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function v(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function b(e){for(var t=1;t1&&void 0!==i[1]?i[1]:{},o=document.querySelector('meta[itemprop="productID"]'),r=o?o.content:"-1",e.abrupt("return",new Promise((function(e,o){a._client.post(t,JSON.stringify(b({quantity:a.quantityInput?a.quantityInput.value:-1,productId:r},n)),(function(t){try{var n=JSON.parse(t);if(console.log("odgovor "),console.log(n),console.log("status "),console.log(a._client._request.status),a._client._request.status>=400)return void o({error:n.error});e(n)}catch(e){o({status:500,message:"Failed to parse server response."})}}))})));case 4:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"mountExpressCheckoutComponents",value:function(e){var t=this;if(document.getElementById("adyen-express-checkout")){var n=document.getElementsByClassName("adyen-express-checkout-element");if(0!==n.length)for(var o=function(o){var r=n[o].getElementsByClassName("adyen-type")[0].value;t.initializeCheckoutComponent(e).then(function(e){this.mountElement(r,e,n[o])}.bind(t))},r=0;r { console.log("onPaymentDataChanged triggered", intermediatePaymentData); return new Promise(async resolve => { - const { callbackTrigger, shippingAddress, shippingOptionData } = intermediatePaymentData; - const paymentDataRequestUpdate = {}; + try { + const {callbackTrigger, shippingAddress, shippingOptionData} = intermediatePaymentData; + const paymentDataRequestUpdate = {}; - if (callbackTrigger === 'INITIALIZE' || callbackTrigger === 'SHIPPING_ADDRESS') { - console.log("ADDRESS trigger"); + if (callbackTrigger === 'INITIALIZE' || callbackTrigger === 'SHIPPING_ADDRESS') { + console.log("ADDRESS trigger"); - const extraData = {}; + const extraData = {}; - if (shippingAddress) { - extraData.newAddress = shippingAddress; - } + if (shippingAddress) { + extraData.newAddress = shippingAddress; + } - const response = await this.fetchExpressCheckoutConfig(adyenExpressCheckoutOptions.expressCheckoutConfigUrl, extraData); + const response = await this.fetchExpressCheckoutConfig(adyenExpressCheckoutOptions.expressCheckoutConfigUrl, extraData); - let shippingMethodsArray = response.shippingMethodsResponse; + let shippingMethodsArray = response.shippingMethodsResponse; - paymentDataRequestUpdate.newShippingOptionParameters = { - defaultSelectedOptionId: shippingMethodsArray[0].id, - shippingOptions: shippingMethodsArray - }; + paymentDataRequestUpdate.newShippingOptionParameters = { + defaultSelectedOptionId: shippingMethodsArray[0].id, + shippingOptions: shippingMethodsArray + }; - paymentDataRequestUpdate.newTransactionInfo = { - currencyCode: response.currency, - totalPriceStatus: "FINAL", - totalPrice: (parseInt(response.amount) / 100).toString(), - totalPriceLabel: "Total", - countryCode: response.countryCode, - }; - } + paymentDataRequestUpdate.newTransactionInfo = { + currencyCode: response.currency, + totalPriceStatus: "FINAL", + totalPrice: (parseInt(response.amount) / 100).toString(), + totalPriceLabel: "Total", + countryCode: response.countryCode, + }; + } - if (callbackTrigger === 'SHIPPING_OPTION') { - console.log("SHIPPING trigger") + if (callbackTrigger === 'SHIPPING_OPTION') { + console.log("SHIPPING trigger") - const extraData = {}; + const extraData = {}; - if (shippingAddress) { - extraData.newAddress = shippingAddress; - } + if (shippingAddress) { + extraData.newAddress = shippingAddress; + } - if (shippingOptionData) { - extraData.newShippingMethod = shippingOptionData; - } + if (shippingOptionData) { + extraData.newShippingMethod = shippingOptionData; + } - const response = await this.fetchExpressCheckoutConfig(adyenExpressCheckoutOptions.expressCheckoutConfigUrl, extraData); + const response = await this.fetchExpressCheckoutConfig(adyenExpressCheckoutOptions.expressCheckoutConfigUrl, extraData); - paymentDataRequestUpdate.newTransactionInfo = { - currencyCode: response.currency, - totalPriceStatus: "FINAL", - totalPrice: (parseInt(response.amount) / 100).toString(), - totalPriceLabel: "Total", - countryCode: response.countryCode, - }; - } + paymentDataRequestUpdate.newTransactionInfo = { + currencyCode: response.currency, + totalPriceStatus: "FINAL", + totalPrice: (parseInt(response.amount) / 100).toString(), + totalPriceLabel: "Total", + countryCode: response.countryCode, + }; + } - resolve(paymentDataRequestUpdate); + resolve(paymentDataRequestUpdate); + } catch (error) { + console.error("Error in onPaymentDataChanged:", error); + resolve({ + error: error.error + }); + } }); }; @@ -130,11 +137,18 @@ export default class ExpressCheckoutPlugin extends Plugin { "paypal": {}, "applepay": {} }; + this.quantityInput = document.querySelector('.product-detail-quantity-select') || document.querySelector('.product-detail-quantity-input'); - console.log("kolicina" + this.quantityInput.value) + + if(this.quantityInput) { + console.log("kolicina" + this.quantityInput.value) + } + this.listenOnQuantityChange(); + console.log(adyenExpressCheckoutOptions); + this.mountExpressCheckoutComponents({ countryCode: adyenExpressCheckoutOptions.countryCode, amount: adyenExpressCheckoutOptions.amount, @@ -160,11 +174,26 @@ export default class ExpressCheckoutPlugin extends Plugin { (response) => { try { const parsedResponse = JSON.parse(response); - console.log("Controller Response:", parsedResponse); + console.log("odgovor ") + console.log(parsedResponse); + + console.log("status ") + console.log(this._client._request.status) + + if (this._client._request.status >= 400) { + // if valid resonse, but contains error data + reject({ + error: parsedResponse.error + }); + return; + } + resolve(parsedResponse); } catch (error) { - console.error("Failed to parse response:", error); - reject(error); + reject({ + status: 500, + message: "Failed to parse server response.", + }); } } ); diff --git a/src/Service/ExpressCheckoutService.php b/src/Service/ExpressCheckoutService.php index 5fe76727..b502079c 100755 --- a/src/Service/ExpressCheckoutService.php +++ b/src/Service/ExpressCheckoutService.php @@ -3,6 +3,8 @@ namespace Adyen\Shopware\Service; use Adyen\Model\Checkout\PaymentMethodsResponse; +use Adyen\Shopware\Exception\ResolveCountryException; +use Adyen\Shopware\Exception\ResolveShippingMethodException; use Adyen\Shopware\Util\Currency; use Shopware\Core\Checkout\Cart\Cart; use Shopware\Core\Checkout\Cart\Delivery\Struct\ShippingLocation; @@ -292,7 +294,7 @@ private function resolveCountry(SalesChannelContext $salesChannelContext, array $country = $this->countryRepository->search($criteria, $salesChannelContext->getContext())->first(); if (!$country) { - throw new \Exception('Invalid country information.'); + throw new ResolveCountryException("No shipping country found!"); } return $country; @@ -324,7 +326,7 @@ private function resolveShippingMethod( // If no shipping method is resolved, throw an exception if (!$shippingMethod) { - throw new \Exception('No valid shipping method is available.'); + throw new ResolveShippingMethodException("No shipping method found!"); } return $shippingMethod;