UNPKG

@apicart/vue-components

Version:

Apicart Vue.Js components for simple e-commerce platform development

8 lines (6 loc) 7.66 kB
/** * @apicart/vue-components v1.0.0-alpha7 * (c) 2018-2020 Apicart Company * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@apicart/core-sdk"),require("../.."),require("./..")):"function"==typeof define&&define.amd?define(["@apicart/core-sdk","../..","./.."],e):(t=t||self).ApicartOrderDialog=e(t.Apicart,t.src,t.components)}(this,(function(t,e,r){"use strict";function o(t,e,r,o){return new(r||(r=Promise))((function(i,n){function a(t){try{c(o.next(t))}catch(t){n(t)}}function s(t){try{c(o.throw(t))}catch(t){n(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}c((o=o.apply(t,e||[])).next())}))}function i(t,e){var r,o,i,n,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return n={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(n){return function(s){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,o&&(i=2&n[0]?o.return:n[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,n[1])).done)return i;switch(o=0,i&&(n=[2&n[0],i.value]),n[0]){case 0:case 1:i=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,o=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==n[0]&&2!==n[0])){a=0;continue}if(3===n[0]&&(!i||n[1]>i[0]&&n[1]<i[3])){a.label=n[1];break}if(6===n[0]&&a.label<i[1]){a.label=i[1],i=n;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(n);break}i[2]&&a.ops.pop(),a.trys.pop();continue}n=e.call(t,a)}catch(t){n=[6,t],o=0}finally{r=i=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,s])}}}var n,a=((t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t).VueComponentsTranslator||e.Translator).getI18n(),s="undefined"!=typeof window,c={name:"apicart-order-dialog",i18n:a,components:{"apicart-button":s&&window.ApicartButton?window.ApicartButton:r.ApicartButton,"apicart-dialog":s&&window.ApicartDialog?window.ApicartDialog:r.ApicartDialog},data:function(){return{title:"",text:"",variableSymbol:null,totalPrice:null,order:null,showPayButton:!1,paymentError:!1,payButtonText:null,dialogType:"order",processingPayment:!1,showCloseButton:!0,selectedPaymentProcessorId:null}},created:function(){n=t.getConfigParameter("paymentsProcessors"),t.getConfigParameter("store")},mounted:function(){var e=this,r=window.location.search.match(/orderVariableSymbol=(\d+)/),a=window.location.search.match(/orderPrice=(\d+)/),s=window.location.search.match(/orderResult=(success|error)/),c=r?r[1]:null,l=a?a[1]:null,d=s?s[1]:null;d&&("success"===d?(this.variableSymbol=c,this.totalPrice=l,this.openPaymentSuccess()):this.openPaymentError()),t.Utils.EventDispatcher.addListener("apicart-order-dialog-cart-finished"+this._uid,"apicart:cart:finished",(function(t){return o(e,void 0,void 0,(function(){var e,r,o,a,s;return i(this,(function(i){switch(i.label){case 0:return t?(this.order=t,[4,t.getCart()]):(this.openError(),[2]);case 1:return[4,(e=i.sent()).getEntity()];case 2:return r=i.sent(),o=r.getPaymentMethod().getUid(),a=this,[4,t.getVariableSymbol()];case 3:return a.variableSymbol=i.sent(),s=this,[4,e.getTotalPrice()];case 4:return s.totalPrice=i.sent(),this.selectedPaymentProcessorId=n&&"function"==typeof n[o]?o:null,this.showPayButton=null!==this.selectedPaymentProcessorId,this.openOrderSuccess(),[2]}}))}))})),t.Utils.EventDispatcher.addListener("apicart-order-dialog-payment-finished"+this._uid,"apicart:payment:finished",(function(t,r,n){return void 0===n&&(n={}),o(e,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return this.showPayButton=!1,t?this.totalPrice&&this.variableSymbol?[3,4]:[4,r.getCart()]:[3,5];case 1:return[4,e.sent().getTotalPrice()];case 2:return e.sent(),[4,r.getVariableSymbol()];case 3:e.sent(),e.label=4;case 4:return this.openPaymentSuccess(),[3,6];case 5:this.openPaymentError(n),e.label=6;case 6:return[2]}}))}))}))},methods:{openOrderSuccess:function(){this.title=this.$t("orderDialog.order.success.title"),this.text=this.$t("orderDialog.order.success.text",{variableSymbol:this.variableSymbol,totalPrice:this.$n(this.totalPrice,"currency")}),this.dialogType="order",this.$refs.apicartDialog.open(),this.$emit("open")},openOrderError:function(){this.title=this.$t("orderDialog.order.error.title"),this.text=this.$t("orderDialog.order.error.text"),this.dialogType="order",this.$refs.apicartDialog.open(),this.$emit("open")},openPaymentSuccess:function(){this.title=this.$t("orderDialog.payment.success.title"),this.text=this.$t("orderDialog.payment.success.text",{variableSymbol:this.variableSymbol,totalPrice:this.$n(this.totalPrice,"currency")}),this.dialogType="payment",this.$refs.apicartDialog.open(),window.history.pushState({},document.title,window.location.pathname),this.$emit("open")},openPaymentError:function(t){void 0===t&&(t={}),this.title=this.$t("orderDialog.payment.error.title"),this.text=this.$t("orderDialog.payment.error.text",{error:t.description||"Error"}),this.dialogType="payment",this.showPayButton=!1,this.paymentError=!0,this.$refs.apicartDialog.open(),this.$emit("open")},processPayment:function(t){this.close(),n[t](this.order)},redirect:function(){window.location.href=window.location.href.split("#")[0]},close:function(){this.$refs.apicartDialog.close()}}};!function(t,e){void 0===e&&(e={});var r=e.insertAt;if(t&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===r&&o.firstChild?o.insertBefore(i,o.firstChild):o.appendChild(i),i.styleSheet?i.styleSheet.cssText=t:i.appendChild(document.createTextNode(t))}}(".apicart-order-dialog.apicart-dialog__mask{z-index:9999}.apicart-order-dialog .apicart-dialog__container{max-width:500px}");return function(t,e,r,o,i,n,a,s,c,l){"boolean"!=typeof a&&(c=s,s=a,a=!1);const d="function"==typeof r?r.options:r;let u;if(t&&t.render&&(d.render=t.render,d.staticRenderFns=t.staticRenderFns,d._compiled=!0,i&&(d.functional=!0)),o&&(d._scopeId=o),n?(u=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,c(t)),t&&t._registeredComponents&&t._registeredComponents.add(n)},d._ssrRegister=u):e&&(u=a?function(t){e.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,s(t))}),u)if(d.functional){const t=d.render;d.render=function(e,r){return u.call(r),t(e,r)}}else{const t=d.beforeCreate;d.beforeCreate=t?[].concat(t,u):[u]}return r}({render:function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("apicart-dialog",{ref:"apicartDialog",staticClass:"apicart-order-dialog",attrs:{id:this.$t("orderDialog.id")}},[r("h1",{attrs:{slot:"header"},slot:"header"},[t._v(t._s(t.title))]),r("div",{attrs:{slot:"body"},domProps:{innerHTML:t._s(t.text)},slot:"body"}),r("div",{attrs:{slot:"footer-buttons"},slot:"footer-buttons"},[t.showPayButton?r("apicart-button",{attrs:{type:"outlined"},nativeOn:{click:function(e){return t.processPayment(t.selectedPaymentProcessorId)}}},[t._v(t._s(this.$t("orderDialog.closeButton.pay")))]):r("apicart-button",{attrs:{type:"outlined"},nativeOn:{click:function(e){return t.redirect(e)}}},[t.paymentError?r("span",[t._v(t._s(this.$t("orderDialog.closeButton.close")))]):r("span",[t._v(t._s(this.$t("orderDialog.closeButton.ok")))])])],1)])},staticRenderFns:[]},void 0,c,void 0,!1,void 0,!1,void 0,void 0,void 0)}));