1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[252],{28711:function(e,s,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/payment",function(){return a(16487)}])},16487:function(e,s,a){"use strict";a.r(s),a.d(s,{PaymentPage:function(){return p}});var d=a(52322),i=a(6812),r=a(12524),l=a.n(r),n=a(5632),t=a(2784),o=a(63955),c=a(36314),m=a(83106),u=a(85998),h=a(67817),x=a(17819);function p(){var e;(0,h.c7)();let{push:s,query:a}=(0,n.useRouter)(),{userInfoData:r}=(0,h.n6)(),p=Object.keys(a).includes("flexipass"),[_,v]=(0,t.useState)(!1),[b,f]=(0,t.useState)(!p),[y,j]=(0,t.useState)(!1),[N,g]=(0,t.useState)(""),[C,k]=(0,t.useState)(null),{data:w}=(0,h.kP)(),S=!!(null==w?void 0:w.isLoggedIn),A=(0,h.Li)(),{order:L,amountToPay:P,isLoading:E,isUsingFlexipassVouchers:F,isChangeOfJourney:I}=(0,c.Aj)(void 0,{revalidateOnFocus:!1}),T=(0,t.useId)(),V=(0,t.useId)(),D=(0,t.useMemo)(()=>b?T:V,[b,T,V]),{price:M,flexipassCost:O,isLoading:U,prefferedCode:R}=(0,h.AE)(),B=(0,h.H4)(),[W,Y]=(0,t.useState)(),G=(0,t.useCallback)(()=>{document.location.href="/"},[]),{token:H,isTokenLoading:X}=(0,h.pW)(P,W,{revalidateOnFocus:!1}),$=E||U||X,q=(0,t.useRef)();(0,t.useEffect)(()=>{q.current&&(q.current.contentWindow.__assertis=q.current.contentWindow.__assertis||{},q.current.contentWindow.__assertis.payment={token:X?"":H,closePaymentFrame:()=>{v(!1)},handleBackToSleeperClick:()=>{G()},handlePaymentDone:async e=>{if(v(!1),e&&W){let e=await A();await s("/confirmation"+e.data.order+(p?"?flexipass":""))}else console.log("Payment failed or was cancelled")}})},[W,s,v,A,p,G,X,q,H]);let z=(0,t.useMemo)(()=>(null==L?void 0:L.delivery.address)?{title:L.delivery.address.title,firstName:L.delivery.address.firstNames,lastName:L.delivery.address.surname,email:L.delivery.address.email,mobile:L.delivery.address.telephoneNumber,addressLine:L.delivery.address.address1,addressLine2:L.delivery.address.address2,city:L.delivery.address.town,country:"GB",postCode:L.delivery.address.postCode,tosChecked:!1,marketingSignup:!1}:void 0,[null==L?void 0:L.delivery.address]),J=(0,t.useMemo)(()=>{var e;return S&&(null==r?void 0:null===(e=r.data)||void 0===e?void 0:e.baseAddress)?{title:r.data.title,firstName:r.data.firstNames,lastName:r.data.surname,email:r.data.email,mobile:r.data.phone,addressLine:r.data.baseAddress.address1,addressLine2:r.data.baseAddress.address2,city:r.data.baseAddress.town,country:r.data.baseAddress.country,postCode:r.data.baseAddress.postCode,tosChecked:!1,marketingSignup:!1}:void 0},[r,S]),{handleSubmit:K,control:Q,formState:{errors:Z,dirtyFields:ee},register:es,reset:ea,watch:ed,setValue:ei}=(0,o.cI)({defaultValues:z,resolver:(0,i.X)((0,u.Lp)(C)),mode:"all"});(0,t.useEffect)(()=>{y?ea(J):b?ea(z):ea({addressLine:"",addressLine2:"",city:"",country:"GB",email:"",firstName:"",lastName:"",mobile:"",postCode:"",title:""},{keepValues:!1,keepDefaultValues:!1})},[b,z,ea,y,J]);let[er,el]=(0,t.useState)(null),en=(0,m.Nr)(er,250),{suggestions:et}=(0,h.Vc)(en),{chosenAddress:eo}=(0,h.yd)(N),ec=ed("country"),em=(0,t.useMemo)(()=>"GB"===ec,[ec]);(0,t.useEffect)(()=>{null===er?(g(""),ei("postCode",""),ei("city",""),ei("addressLine",""),ei("addressLine2","")):eo&&(ei("postCode",eo.postcode,{shouldValidate:ee.postCode}),ei("city",eo.town_or_city,{shouldValidate:ee.city}),ei("addressLine",eo.line_1,{shouldValidate:ee.addressLine}),ei("addressLine2",eo.line_2,{shouldValidate:ee.addressLine2}))},[eo,er]);let[eu,eh]=(0,t.useState)(!1);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("header",{className:"header",children:(0,d.jsx)(u.Du,{activeStep:u.as.PAY,isBuyingFlexipasses:p})}),(0,d.jsx)("main",{className:"content",children:(0,d.jsx)(u.SV,{children:(0,d.jsx)("div",{className:"container",children:(0,d.jsx)("div",{className:"row",children:(0,d.jsxs)("div",{className:"col-12 col-xl-10 offset-xl-1 mob-np",children:[(0,d.jsxs)("section",{className:"heading",children:[(0,d.jsx)("h1",{className:"heading__title",children:"Payment"}),(0,d.jsxs)("p",{className:"heading__subtitle",children:[p&&"Please add the cardholderâs details where prompted to reserve your tickets.",!p&&"Please check cardholderâs details and edit if different from Lead Guest."]})]}),(0,d.jsx)("section",{className:"box box--payment",children:(0,d.jsxs)("form",{className:"form",onSubmit:K(e=>{B(M,new Date,h.is.CARD_PAYMENT_OPEN_MODAL),window.scrollTo({top:0,left:0,behavior:"smooth"}),v(!0),Y(e)}),id:D,children:[(0,d.jsx)("h2",{className:"box__title mb-2",children:"Cardholder details"}),(0,d.jsxs)("div",{className:"row",children:[(0,d.jsx)("div",{className:"col-12 col-lg-7",children:(0,d.jsxs)("div",{className:"accordion",children:[!p&&(0,d.jsxs)("div",{className:l()("accordion__item",{selected:b&&!y}),children:[(0,d.jsx)("div",{role:"heading","aria-level":3,className:"accordion__heading",children:(0,d.jsxs)("div",{className:"accordion__button",id:"accordion__heading-1","aria-disabled":b&&!y,"aria-expanded":b&&!y,"aria-controls":"accordion__panel-1",role:"button",tabIndex:0,onClick:()=>{f(!0),j(!1),g(""),el(""),Y(null)},children:["Use ",(0,d.jsx)("strong",{children:"Lead guest"})," details"]}
1)}),b&&z&&!y&&(0,d.jsx)(u.xE,{control:Q,errors:Z,isAddressFinderEnabled:em,setChosenAddressUrl:g,setTypedAddress:el,setCountryCode:k,suggestions:et,isPreFilled:!0}),(E||!z)&&(0,d.jsx)("div",{className:"row",children:(0,d.jsx)("div",{className:"col-12 centered",children:(0,d.jsx)("div",{className:"loader"})})})]}),(0,d.jsxs)("div",{className:l()("accordion__item",{"accordion__item selected":!b&&!y}),children:[(0,d.jsx)("div",{role:"heading","aria-level":3,className:"accordion__heading",children:(0,d.jsxs)("div",{className:"accordion__button",id:"accordion__heading-2","aria-disabled":!b&&!y,"aria-expanded":!b&&!y,"aria-controls":"accordion__panel-2",role:"button",tabIndex:0,onClick:()=>{f(!1),j(!1),g(""),el(""),Y(null)},children:[p&&"Cardholder address",!p&&"Use other payment details"]})}),!b&&!y&&(0,d.jsx)(u.xE,{control:Q,errors:Z,isAddressFinderEnabled:em,setChosenAddressUrl:g,setCountryCode:k,setTypedAddress:el,suggestions:et})]}),S&&(null==r?void 0:null===(e=r.data)||void 0===e?void 0:e.baseAddress)&&(0,d.jsxs)("div",{className:l()("accordion__item",{"accordion__item selected":y}),children:[(0,d.jsx)("div",{role:"heading","aria-level":3,className:"accordion__heading",children:(0,d.jsx)("div",{className:"accordion__button",id:"accordion__heading-2","aria-disabled":y,"aria-expanded":y,"aria-controls":"accordion__panel-2",role:"button",tabIndex:0,onClick:()=>{j(!0),g(""),el(""),Y(null)},children:"Use saved address"})}),y&&(0,d.jsx)(u.xE,{control:Q,errors:Z,isAddressFinderEnabled:em,setTypedAddress:el,setCountryCode:k,setChosenAddressUrl:g,suggestions:et})]})]})}),(0,d.jsxs)("div",{className:"col-12 col-lg-5 payment__space",children:[I&&(0,d.jsxs)("aside",{className:"sidebar sidebar--payment",children:[(0,d.jsx)("h2",{className:"sidebar__title",children:"Change date of travel"}),E&&(0,d.jsx)("div",{className:"loader mb-3"}),!E&&!!(null==L?void 0:L.items)&&L.items.length>0&&(0,d.jsx)(u.YY,{trip:L.items[0]})]}),(0,d.jsxs)("div",{className:"textfield",children:[(0,d.jsx)(x.o2,{label:(0,d.jsxs)(d.Fragment,{children:["I would like to receive periodic email communications about Caledonian Sleepersâ services, news updates and promotions; and to Caledonian Sleeper processing my personal information in accordance with their"," ",(0,d.jsx)("a",{href:"https://www.sleeper.scot/privacy-policy/",rel:"noreferrer",target:"_blank",children:"Privacy Policy"}),". Caledonian Sleeper will not share your data with any third parties for marketing purposes. I understand that I can easily unsubscribe from receiving Caledonian Sleeper e-mail communications at any time by following the unsubscribe links in the relevant e-mail communication or by directly"," ",(0,d.jsx)("a",{href:"https://www.sleeper.scot/contact-us/",rel:"noreferrer",target:"_blank",children:"emailing Caledonian Sleeper"})," ","with the subject line âunsubscribeâ."]}),isModal:!0,customClass:"checkbox--boxed",...es("marketingSignup")}),Z.marketingSignup&&(0,d.jsx)("p",{className:"textfield__error",children:Z.marketingSignup.message})]}),(0,d.jsxs)("div",{className:"textfield",children:[(0,d.jsx)(x.o2,{label:(0,d.jsxs)(d.Fragment,{children:["I have read and accept the"," ",(0,d.jsx)("a",{href:"/auxiliary/terms-and-conditions/",rel:"noreferrer",target:"_blank",children:"Caledonian Sleeper terms & conditions"})," ","and"," ",(0,d.jsx)("a",{href:"http://www.nationalrail.co.uk/National%20Rail%20Conditions%20of%20Travel.pdf",rel:"noreferrer",target:"_blank",children:"National Rail Conditions of Travel"})]}),isModal:!0,customClass:l()("checkbox--boxed",{"checkbox--error":Z.tosChecked}),...es("tosChecked")}),Z.tosChecked&&(0,d.jsx)("p",{className:"textfield__error textfield__error--checkbox",children:Z.tosChecked.message})]})]})]})]})})]})})})})}),_&&!X&&H&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{onClick:()=>v(!1),className:"overlay"}),(0,d.jsxs)("div",{className:"payment",children:[(0,d.jsx)("div",{className:"payment__loader",children:(0,d.jsx)("div",{className:"row",children:(0,d.jsx)("div",{className:"col-12 centered",children:(0,d.jsx)("div",{className:"loader",children:(0,d.jsx)("h1",{className:"loader__title",children:"Loading Payment"})})})})}),(0,d.jsx)("iframe",{className:"payment__iframe",src:"/booking/payment-frame",ref:q})]})]}),(0,d.jsx)(u.PH,{nextStepName:"PAY WITH CARD",totalPrice:M,totalFlexipassCost:O,buttonFormId:D,buttonType:"submit",isLoading:$,isCtaDisabled:$,isUsingFlexipass:F,prefferedFlexipassCode:R}),(0,d.jsx)(u.$_,{})]})}s.default=p}},function(e){e.O(0,[888,774,179],function(){return e(e.s=28711)}),_N_E=e.O()}]); 2//# sourceMappingURL=payment-04267d4e6c495d52.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.