UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 3.44 kB
import s from"../Services/sessions/make-payment.js";import t from"../Services/sessions/submit-details.js";import e from"../Services/sessions/fetch-donation-campaigns.js";import i from"../Services/sessions/make-donation.js";import o from"../Services/sessions/setup-session.js";import n from"../Services/sessions/check-balance.js";import r from"../../utils/Storage.js";import a from"../Services/sessions/create-order.js";import{sanitizeSession as c}from"./utils.js";import h from"../Services/sessions/cancel-order.js";import u from"../../utils/browserInfo.js";function p(s,t,e){return t in s?Object.defineProperty(s,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):s[t]=e,s}function d(s){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{},i=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(e).filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable}))),i.forEach(function(t){p(s,t,e[t])})}return s}function l(s,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):function(s){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(s);t.push.apply(t,e)}return t}(Object(t)).forEach(function(e){Object.defineProperty(s,e,Object.getOwnPropertyDescriptor(t,e))}),s}class D{get shopperLocale(){return this.session.shopperLocale}get id(){return this.session.id}get data(){return this.session.sessionData}set sessionsDonationInitiated(s){this._sessionsDonationInitiated=s}get sessionsDonationInitiated(){return this._sessionsDonationInitiated}updateSessionData(s){this.session.sessionData=s,this.storeSession()}setupSession(s){const t=l(d({},s),{browserInfo:u()});return o(this,t).then(s=>(s.configuration&&(this.configuration=d({},s.configuration)),s.sessionData&&this.updateSessionData(s.sessionData),s))}submitPayment(t){return s(t,this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}submitDetails(s){return t(s,this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}fetchDonationCampaigns(){return e(this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}makeDonation(s){return i(s,this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}checkBalance(s){return n(s,this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}createOrder(){return a(this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}cancelOrder(s){return h(s.order,this).then(s=>(s.sessionData&&this.updateSessionData(s.sessionData),s))}getStoredSession(){const s=this.storage.get();return this.id===(null==s?void 0:s.id)?s:this.session}storeSession(){this.storage.set({id:this.session.id,sessionData:this.session.sessionData})}removeStoredSession(){this.storage.remove()}constructor(s,t,e){p(this,"storage",void 0),p(this,"session",void 0),p(this,"clientKey",void 0),p(this,"loadingContext",void 0),p(this,"configuration",void 0),p(this,"_sessionsDonationInitiated",void 0);const i=c(s);if(!t)throw new Error("No clientKey available");if(!e)throw new Error("No loadingContext available");this.storage=new r("session","localStorage"),this.clientKey=t,this.loadingContext=e,this.session=i,this._sessionsDonationInitiated=!1,this.session.sessionData?this.storeSession():this.session=this.getStoredSession()}}export{D as default}; //# sourceMappingURL=CheckoutSession.js.map