UNPKG

vue3-paystack

Version:
1 lines 3.65 kB
var Vue3Paystack=function(t){"use strict";function e(t,e,n,r,a,o,u){try{var i=t[o](u),c=i.value}catch(t){return void n(t)}i.done?e(c):Promise.resolve(c).then(r,a)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(a,o){var u=t.apply(n,r);function i(t){e(u,a,o,i,c,"next",t)}function c(t){e(u,a,o,i,c,"throw",t)}i(void 0)}))}}function r(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var r,a,o=[],u=!0,i=!1;try{for(n=n.call(t);!(u=(r=n.next()).done)&&(o.push(r.value),!e||o.length!==e);u=!0);}catch(t){i=!0,a=t}finally{try{u||null==n.return||n.return()}finally{if(i)throw a}}return o}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var o=t.defineComponent({name:"Vue3Paystack",props:{buttonClass:{type:String,default:""},buttonText:{type:String,default:""},publicKey:{type:String,requird:!0},email:{type:String,required:!0},amount:{type:Number,required:!0},reference:{type:String,required:!0},currency:{type:String,default:"NGN"},onSuccess:{type:Function,default:function(t){console.log(t)}},onCancel:{type:Function,default:function(){console.log("payment closed")}},channels:{type:Array,default:function(){return["card","bank","ussd","qr","mobile_money"]}},metadata:{type:Object,default:function(){return{}}},label:{type:String,default:""}},created:function(){var t=this;return n(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.mountScript().then((function(){t.hasScriptLoaded=!0}));case 1:case"end":return e.stop()}}),e)})))()},data:function(){return{hasScriptLoaded:!1}},methods:{mountScript:function(){return n(regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,e){var n=document.createElement("script");n.setAttribute("src","https://js.paystack.co/v2/inline.js"),n.setAttribute("type","text/javascript"),document.head.appendChild(n),n.onload=function(){return t()},n.onerror=function(){return e()}})));case 1:case"end":return t.stop()}}),t)})))()},payWithPaystack:function(){var t=this,e={key:this.publicKey,email:this.email,amount:this.amount,reference:this.reference,currency:this.currency,channels:this.channels,metadata:this.metadata,label:this.label,onSuccess:function(e){t.onSuccess(e)},onCanel:function(){t.onCanel()}};(new window.PaystackPop).newTransaction(e)}}}),u=["disabled"];o.render=function(e,n,r,a,o,i){return t.openBlock(),t.createElementBlock("button",{disabled:!e.hasScriptLoaded,class:t.normalizeClass(e.buttonClass),onClick:n[0]||(n[0]=function(){return e.payWithPaystack&&e.payWithPaystack.apply(e,arguments)})},[t.createElementVNode("span",null,t.toDisplayString(e.buttonText),1)],10,u)};var i=function(){var t=o;return t.install=function(e){e.component("Vue3Paystack",t)},t}(),c=Object.freeze({__proto__:null,default:i});return Object.entries(c).forEach((function(t){var e=r(t,2),n=e[0],a=e[1];"default"!==n&&(i[n]=a)})),i}(Vue);