UNPKG

angular-rave

Version:

Angular wrapper for integrating rave transactions

2 lines 7.14 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("angular-rave",["exports","@angular/core","@angular/common"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["angular-rave"]={},t.ng.core,t.ng.common)}(this,(function(t,e,n){"use strict";var r=new e.InjectionToken("Rave.PubKey"),i=function(){function t(t){this.publicKey=t}return t.prototype.createRaveOptionsObject=function(t,e,n){var r={};return r.amount=t.amount,r.public_key=t.public_key||this.publicKey,r.currency=t.currency||"NGN",t.customer&&(r.customer=t.customer),t.customizations&&(r.customizations=t.customizations),t.integrity_hash&&(r.integrity_hash=t.integrity_hash),t.meta&&(r.meta=t.meta),t.paymentOptions&&t.paymentOptions.length&&(r.payment_options=t.paymentOptions.join(", ")),t.payment_plan&&(r.payment_plan=t.payment_plan),t.redirect_url&&(r.redirect_url=t.redirect_url),t.subaccounts&&(r.subaccounts=t.subaccounts),t.tx_ref&&(r.tx_ref=t.tx_ref),r.callback=e,r.onclose=n,r},t.prototype.loadScript=function(){return new Promise((function(t){if("function"!=typeof window.FlutterwaveCheckout){var e=window.document.createElement("script");window.document.head.appendChild(e);var n=function(){e.removeEventListener("load",n),t()};e.addEventListener("load",n);e.setAttribute("src","https://checkout.flutterwave.com/v3.js")}else t()}))},t.prototype.isInvalidOptions=function(t){return console.log("Transaction Reference",t.tx_ref),t.public_key||this.publicKey?t.tx_ref?t.amount?t.customer.email&&t.customer.phonenumber?"":"ANGULAR-RAVE: Customer email or phone number is required":"ANGULAR-RAVE: Amount to charge is required":"ANGULAR-RAVE: A unique transaction reference is required":"ANGULAR-RAVE: Merchant public key is required"},t.prototype.checkout=function(t){return window.FlutterwaveCheckout(t)},t}();i.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new i(e.ɵɵinject(r))},token:i,providedIn:"root"}),i.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],i.ctorParameters=function(){return[{type:String,decorators:[{type:e.Inject,args:[r]}]}]};function o(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{s(r.next(t))}catch(t){o(t)}}function c(t){try{s(r.throw(t))}catch(t){o(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}s((r=r.apply(t,e||[])).next())}))}function a(t,e){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}Object.create;Object.create;var c=function(){function t(t){this.raveService=t,this.onclose=new e.EventEmitter,this.callback=new e.EventEmitter,this.init=new e.EventEmitter}return t.prototype.pay=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return t="",this.raveOptions&&Object.keys(this.raveOptions).length>1?(t=this.raveService.isInvalidOptions(this.raveOptions),this.insertRaveOptions(this.raveOptions)):(t=this.raveService.isInvalidOptions(this),this.insertRaveOptions(this)),t?(console.error(t),[2,t]):[4,this.raveService.loadScript()];case 1:return e.sent(),this.raveService.checkout(this._raveOptions),this.init.observers.length>0&&this.init.emit(),[2]}}))}))},t.prototype.insertRaveOptions=function(t){var e=this;this._raveOptions=this.raveService.createRaveOptionsObject(t,(function(t){e.callback.emit(t)}),(function(){e.onclose.observers.length&&e.onclose.emit()}))},t.prototype.ngOnInit=function(){this.pay()},t}();c.decorators=[{type:e.Component,args:[{selector:"angular-rave",template:"<ng-content></ng-content>"}]}],c.ctorParameters=function(){return[{type:i}]},c.propDecorators={amount:[{type:e.Input}],public_key:[{type:e.Input}],currency:[{type:e.Input}],customer:[{type:e.Input}],customizations:[{type:e.Input}],integrity_hash:[{type:e.Input}],meta:[{type:e.Input}],paymentOptions:[{type:e.Input}],payment_plan:[{type:e.Input}],redirect_url:[{type:e.Input}],subaccounts:[{type:e.Input}],tx_ref:[{type:e.Input}],raveOptions:[{type:e.Input}],onclose:[{type:e.Output}],callback:[{type:e.Output}],init:[{type:e.Output}]};var s=function(){function t(t){this.raveService=t,this.onclose=new e.EventEmitter,this.callback=new e.EventEmitter,this.init=new e.EventEmitter}return t.prototype.buttonClick=function(){this.pay()},t.prototype.pay=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return t="",this.raveOptions&&Object.keys(this.raveOptions).length>1?(t=this.raveService.isInvalidOptions(this.raveOptions),this.insertRaveOptions(this.raveOptions)):(t=this.raveService.isInvalidOptions(this),this.insertRaveOptions(this)),t?(console.error(t),[2]):[4,this.raveService.loadScript()];case 1:return e.sent(),this.raveService.checkout(this._raveOptions),this.init.observers.length>0&&this.init.emit(),[2]}}))}))},t.prototype.insertRaveOptions=function(t){var e=this;this._raveOptions=this.raveService.createRaveOptionsObject(t,(function(t){e.callback.emit(t)}),(function(){e.onclose.observers.length&&e.onclose.emit()}))},t}();s.decorators=[{type:e.Directive,args:[{selector:"[angular-rave]"}]}],s.ctorParameters=function(){return[{type:i}]},s.propDecorators={amount:[{type:e.Input}],public_key:[{type:e.Input}],currency:[{type:e.Input}],customer:[{type:e.Input}],customizations:[{type:e.Input}],integrity_hash:[{type:e.Input}],meta:[{type:e.Input}],paymentOptions:[{type:e.Input}],payment_plan:[{type:e.Input}],redirect_url:[{type:e.Input}],subaccounts:[{type:e.Input}],tx_ref:[{type:e.Input}],raveOptions:[{type:e.Input}],onclose:[{type:e.Output}],callback:[{type:e.Output}],init:[{type:e.Output}],buttonClick:[{type:e.HostListener,args:["click"]}]};var u=function(){function t(){}return t.forRoot=function(e){return{ngModule:t,providers:[i,{provide:r,useValue:e}]}},t}();u.decorators=[{type:e.NgModule,args:[{imports:[n.CommonModule],declarations:[s,c],exports:[s,c]}]}],t.AngularRaveComponent=c,t.AngularRaveDirective=s,t.AngularRaveModule=u,t.AngularRaveService=i,t.ɵa=r,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=angular-rave.umd.min.js.map