said-ngx-paypal
Version:
Paypal integration for Angular
2 lines • 6.76 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/common"),require("@angular/core"),require("rxjs")):"function"==typeof define&&define.amd?define("ngx-paypal",["exports","@angular/common","@angular/core","rxjs"],t):t((e=e||self)["ngx-paypal"]={},e.ng.common,e.ng.core,e.rxjs)}(this,function(e,t,n,r){"use strict";function i(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(c){i={error:c}}finally{try{r&&!r.done&&(n=o["return"])&&n.call(o)}finally{if(i)throw i.error}}return a}var o=function(){function e(e){this.zone=e}return e.prototype.registerScript=function(e,t,n,r){var i=this,o=window[t];if(o)this.zone.run(function(){n(o)});else{var a=document.createElement("script");a.id=this.getElemId(t),a.innerHTML="",a.onload=function(){i.zone.run(function(){n(window[t])})},a.onerror=function(){i.zone.run(function(){r(a.src)})},a.src=e,a.async=!0,a.defer=!0,document.getElementsByTagName("head")[0].appendChild(a)}},e.prototype.cleanup=function(e){var t=document.getElementById(this.getElemId(e));t&&t.remove()},e.prototype.getElemId=function(e){return"ngx-paypal-script-elem-"+e},e.decorators=[{type:n.Injectable}],e.ctorParameters=function(){return[{type:n.NgZone}]},e}(),a=function(){function e(e){this.scriptService=e,this.paypalWindowName="paypal"}return e.prototype.registerPayPalScript=function(e,t,n){this.scriptService.registerScript(this.getUrlForConfig(e),this.paypalWindowName,t,n)},e.prototype.destroyPayPalScript=function(){this.scriptService.cleanup(this.paypalWindowName)},e.prototype.getUrlForConfig=function(e){var t=[{name:"client-id",value:e.clientId}];return e.currency&&t.push({name:"currency",value:e.currency}),e.commit&&t.push({name:"commit",value:e.commit}),e.extraParams&&t.push.apply(t,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e}(e.extraParams)),"https://www.paypal.com/sdk/js"+this.getQueryString(t)},e.prototype.getQueryString=function(e){for(var t="",n=0;n<e.length;n++){var r=e[n];t+=0===n?"?":"&",t+=r.name+"="+r.value}return t},e.decorators=[{type:n.Injectable}],e.ctorParameters=function(){return[{type:o}]},e}(),c=function(){function e(e,t,i){this.paypalScriptService=e,this.cdr=t,this.ngZone=i,this.registerScript=!0,this.scriptLoaded=new n.EventEmitter,this.scriptLoadError=new n.EventEmitter,this.ngUnsubscribe=new r.Subject,this.initializePayPal=!0}return Object.defineProperty(e.prototype,"payPalButtonContainer",{set:function(e){this.payPalButtonContainerElem=e},enumerable:!0,configurable:!0}),e.prototype.ngOnChanges=function(e){var t=this;this.payPalButtonContainerId||(this.payPalButtonContainerId=this.generateElementId());var n=this.config;e.config.isFirstChange()&&n&&this.registerScript&&this.initPayPalScript(n,function(e){t.payPal=e,t.doPayPalCheck()}),e.config.isFirstChange()||this.reinitialize(n)},e.prototype.ngOnDestroy=function(){this.paypalScriptService.destroyPayPalScript(),this.ngUnsubscribe.next(),this.ngUnsubscribe.complete()},e.prototype.ngAfterViewInit=function(){this.doPayPalCheck()},e.prototype.customInit=function(e){this.payPal=e,this.doPayPalCheck()},e.prototype.reinitialize=function(e){var t=this;if(this.config=e,this.payPal=undefined,this.paypalScriptService.destroyPayPalScript(),this.payPalButtonContainerId=this.generateElementId(),this.initializePayPal=!0,this.payPalButtonContainerElem)for(;this.payPalButtonContainerElem.nativeElement.firstChild;)this.payPalButtonContainerElem.nativeElement.removeChild(this.payPalButtonContainerElem.nativeElement.firstChild);this.cdr.detectChanges(),this.config&&(this.payPal?this.doPayPalCheck():this.initPayPalScript(this.config,function(e){t.payPal=e,t.doPayPalCheck()}))},e.prototype.doPayPalCheck=function(){this.initializePayPal&&this.config&&this.payPal&&this.payPalButtonContainerElem&&this.payPalButtonContainerElem.nativeElement.id&&(this.initializePayPal=!1,this.initPayPal(this.config,this.payPal))},e.prototype.initPayPalScript=function(e,t){var n=this;this.paypalScriptService.registerPayPalScript({clientId:e.clientId,commit:e.advanced&&e.advanced.commit?e.advanced.commit:undefined,currency:e.currency,extraParams:e.advanced&&e.advanced.extraQueryParams?e.advanced.extraQueryParams:[]},function(e){n.scriptLoaded.next(e),t(e)},function(e){n.scriptLoadError.emit(e)})},e.prototype.generateElementId=function(){return"ngx-captcha-id-"+(new Date).valueOf()},e.prototype.initPayPal=function(e,t){var n=this;this.ngZone.runOutsideAngular(function(){t.Buttons({style:e.style,createOrder:function(t,r){return n.ngZone.run(function(){if(e.createOrderOnClient&&e.createOrderOnServer)throw Error("Both 'createOrderOnClient' and 'createOrderOnServer' are defined.\n Please choose one or the other.");if(!e.createOrderOnClient&&!e.createOrderOnServer)throw Error("Neither 'createOrderOnClient' or 'createOrderOnServer' are defined.\n Please define one of these to create order.");if(e.createOrderOnClient)return r.order.create(e.createOrderOnClient(t));if(e.createOrderOnServer)return e.createOrderOnServer(t);throw Error("Invalid state for 'createOrder'.")})},onApprove:function(t,r){return n.ngZone.run(function(){if(e.onApprove&&e.onApprove(t,r),e.authorizeOnServer)return e.authorizeOnServer(t,r);var n=e.onClientAuthorization;n&&r.order.capture().then(function(e){n(e)})})},onError:function(t){n.ngZone.run(function(){e.onError&&e.onError(t)})},onCancel:function(t,r){n.ngZone.run(function(){e.onCancel&&e.onCancel(t,r)})},onShippingChange:function(t,r){return n.ngZone.run(function(){if(e.onShippingChange)return e.onShippingChange(t,r)})},onClick:function(t,r){n.ngZone.run(function(){e.onClick&&e.onClick(t,r)})},onInit:function(t,r){n.ngZone.run(function(){e.onInit&&e.onInit(t,r)})}}).render("#"+n.payPalButtonContainerId)})},e.decorators=[{type:n.Component,args:[{changeDetection:n.ChangeDetectionStrategy.OnPush,selector:"ngx-paypal",template:'\n <div #payPalButtonContainer [id]="payPalButtonContainerId"></div>\n '}]}],e.ctorParameters=function(){return[{type:a},{type:n.ChangeDetectorRef},{type:n.NgZone}]},e.propDecorators={config:[{type:n.Input}],registerScript:[{type:n.Input}],scriptLoaded:[{type:n.Output}],scriptLoadError:[{type:n.Output}],payPalButtonContainer:[{type:n.ViewChild,args:["payPalButtonContainer",{"static":!1}]}]},e}(),p=function(){function e(){}return e.decorators=[{type:n.NgModule,args:[{imports:[t.CommonModule],declarations:[c],exports:[c],providers:[o,a]}]}],e}();e.NgxPayPalModule=p,e.NgxPaypalComponent=c,e.PayPalScriptService=a,e.ɵa=o,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-paypal.umd.min.js.map