UNPKG

stripe-angular

Version:

Angular to Stripe module containing useful providers, components, and directives

16 lines (14 loc) 9.33 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("stripe-angular",["exports","@angular/core","@angular/common"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["stripe-angular"]={},t.ng.core,t.ng.common)}(this,(function(t,e,r){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function i(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function o(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}var a=new e.InjectionToken("Stripe Publishable Key"),p=new e.InjectionToken("Stripe Options"),s=function(){function t(t,e,r){this.document=t,this.src="https://js.stripe.com/v3/",this.window=this.document.defaultView,this.load=this.injectIntoHead(),e&&this.setPublishableKey(e,r)}return t.prototype.promiseStripe=function(){return this.load},t.prototype.promiseInstance=function(){var t=this;return this.promiseStripe().then((function(e){if(!t.StripeInstance){var r=new Error("Stripe PublishableKey NOT SET. Use method StripeScriptTag.setPublishableKey()");throw r.code="STRIPEKEYNOTSET",r}return t.StripeInstance}))},t.prototype.setPublishableKey=function(t,e){var r=this;return this.load.then((function(){return r.StripeInstance=r.Stripe(t,e)}))},t.prototype.injectIntoHead=function(){var t=this;return this.window&&this.window.Stripe?Promise.resolve(this.Stripe=this.window.Stripe):new Promise((function(e,r){var n=t.getTargetTagDropElement(),i=t.document.createElement("script");i.setAttribute("src",t.src),i.setAttribute("type","text/javascript"),i.addEventListener("load",(function(){t.Stripe=t.grabStripe(),e(t.Stripe)})),n.appendChild(i)}))},t.prototype.grabStripe=function(){return window.Stripe},t.prototype.getTargetTagDropElement=function(){var t=this.document.getElementsByTagName("head");return t.length?t[0]:this.document.getElementsByTagName("body")[0]},t}();s.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new s(e.ɵɵinject(r.DOCUMENT),e.ɵɵinject(a),e.ɵɵinject(p))},token:s,providedIn:"root"}),s.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],s.ctorParameters=function(){return[{type:void 0,decorators:[{type:e.Inject,args:[r.DOCUMENT]}]},{type:String,decorators:[{type:e.Inject,args:[a]}]},{type:void 0,decorators:[{type:e.Inject,args:[p]}]}]};var c=function(){function t(t){this.StripeScriptTag=t,this.catcher=new e.EventEmitter,this.invalidChange=new e.EventEmitter}return t.prototype.ngOnInit=function(){this.init()},t.prototype.init=function(){var t=this;return this.StripeScriptTag.promiseInstance().then((function(e){return t.stripe=e}))},t}();c.decorators=[{type:e.Component,args:[{selector:"stripe-component",template:""}]}],c.ctorParameters=function(){return[{type:s}]},c.propDecorators={catcher:[{type:e.Output,args:["catch"]}],invalid:[{type:e.Input}],invalidChange:[{type:e.Output}]};var u=function(t){function r(r){var n=t.call(this,r)||this;return n.StripeScriptTag=r,n.sourceChange=new e.EventEmitter,n.paymentMethodChange=new e.EventEmitter,n}return i(r,t),r.prototype.createSource=function(t){var e=this;return delete this.invalid,this.invalidChange.emit(this.invalid),this.stripe.createSource(this.elements,t).then((function(t){return e.processSourceResult(t)}))},r.prototype.processSourceResult=function(t){if(t.error){var e=t.error;if("validation_error"!==e.type)throw this.catcher.emit(e),e;this.invalidChange.emit(this.invalid=e)}var r=t.source;if(r)return this.sourceChange.emit(this.source=r),r},r.prototype.createPaymentMethod=function(t){var e=this;return delete this.invalid,this.invalidChange.emit(this.invalid),this.stripe.createPaymentMethod("card",this.elements,t).then((function(t){return e.processPaymentMethodResult(t)}))},r.prototype.processPaymentMethodResult=function(t){if(t.error){var e=t.error;if("validation_error"!==e.type)throw this.catcher.emit(e),e;this.invalidChange.emit(this.invalid=e)}var r=t.paymentMethod;if(r)return this.paymentMethodChange.emit(this.paymentMethod=r),r},r}(c);u.decorators=[{type:e.Component,args:[{selector:"stripe-source",template:'\n <ng-container *ngIf="!StripeScriptTag.StripeInstance">\n <div style="color:red;">Stripe PublishableKey NOT SET. Use method StripeScriptTag.setPublishableKey()</div>\n </ng-container>\n ',exportAs:"StripeSource"}]}],u.ctorParameters=function(){return[{type:s}]},u.propDecorators={source:[{type:e.Input}],sourceChange:[{type:e.Output}],paymentMethod:[{type:e.Input}],paymentMethodChange:[{type:e.Output}]};var h=function(t){function r(r,n){var i=t.call(this,n)||this;return i.ElementRef=r,i.StripeScriptTag=n,i.tokenChange=new e.EventEmitter,i.cardMounted=new e.EventEmitter,i.complete=!1,i.completeChange=new e.EventEmitter,i.changed=new e.EventEmitter,i.drawn=!1,i}return i(r,t),r.prototype.ngOnInit=function(){var e=this;t.prototype.init.call(this).then((function(){return e.redraw()}))},r.prototype.ngOnChanges=function(t){this.drawn&&(t.options||t.createOptions)&&this.redraw()},r.prototype.redraw=function(){var t=this;this.drawn&&(this.elements.unmount(),this.elements.destroy()),this.elements=this.stripe.elements(this.createOptions).create("card",this.options),this.elements.mount(this.ElementRef.nativeElement),this.cardMounted.emit(this.elements),this.elements.on("change",(function(e){t.changed.emit(e),(e.complete||t.complete&&!e.complete)&&t.completeChange.emit(t.complete=e.complete)})),this.elements.addEventListener("change",(function(e){e.error&&t.invalidChange.emit(t.invalid=e.error)})),this.drawn=!0},r.prototype.createToken=function(t){var e=this;return delete this.invalid,this.invalidChange.emit(this.invalid),this.stripe.createToken(this.elements,t).then((function(t){if(!t.error)return e.tokenChange.emit(e.token=t.token),t.token;if("validation_error"!=t.error.type)throw e.catcher.emit(t.error),t.error;e.invalidChange.emit(e.invalid=t.error)}))},r}(u);h.decorators=[{type:e.Component,args:[{selector:"stripe-card",template:'\n <ng-container *ngIf="!StripeScriptTag.StripeInstance">\n <div style="color:red;">Stripe PublishableKey NOT SET. Use method StripeScriptTag.setPublishableKey()</div>\n </ng-container>\n ',exportAs:"StripeCard"}]}],h.ctorParameters=function(){return[{type:e.ElementRef},{type:s}]},h.propDecorators={createOptions:[{type:e.Input}],options:[{type:e.Input}],token:[{type:e.Input}],tokenChange:[{type:e.Output}],cardMounted:[{type:e.Output}],complete:[{type:e.Input}],completeChange:[{type:e.Output}],changed:[{type:e.Output}]};var l=function(t){function r(r){var n=t.call(this,r)||this;return n.StripeScriptTag=r,n.tokenChange=new e.EventEmitter,n}return i(r,t),r.prototype.createToken=function(t){var e=this;return delete this.invalid,this.invalidChange.emit(this.invalid),this.stripe.createToken("bank_account",t).then((function(t){if(!t.error)return e.tokenChange.emit(e.token=t.token),t.token;if("validation_error"!=t.error.type)throw e.catcher.emit(t.error),t.error;e.invalidChange.emit(e.invalid=t.error)}))},r}(c);l.decorators=[{type:e.Component,args:[{selector:"stripe-bank",template:'\n <ng-container *ngIf="!StripeScriptTag.StripeInstance">\n <div style="color:red;">Stripe PublishableKey NOT SET. Use method StripeScriptTag.setPublishableKey()</div>\n </ng-container>\n ',exportAs:"StripeBank"}]}],l.ctorParameters=function(){return[{type:s}]},l.propDecorators={options:[{type:e.Input}],token:[{type:e.Input}],tokenChange:[{type:e.Output}]};var d=[c,u,h,l],m=function(){function t(){}return t.forRoot=function(e,r){return{ngModule:t,providers:[s,{provide:a,useValue:e},{provide:p,useValue:r}]}},t}();m.decorators=[{type:e.NgModule,args:[{imports:[r.CommonModule],declarations:d,exports:function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}(d)}]}];var y=m;t.Module=y,t.STRIPE_OPTIONS=p,t.STRIPE_PUBLISHABLE_KEY=a,t.StripeBank=l,t.StripeCard=h,t.StripeModule=m,t.StripeScriptTag=s,t.StripeSource=u,t.ɵa=c,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=stripe-angular.umd.min.js.map