{"version":3,"file":"fireflysemantics-angular-stripe-service.mjs","sources":["../../../projects/angular-stripe-service/src/lib/angular-stripe.service.ts","../../../projects/angular-stripe-service/src/public-api.ts","../../../projects/angular-stripe-service/src/fireflysemantics-angular-stripe-service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { Stripe, StripeFactory } from './types';\n\nconst STRIPE_API_URL = \"https://js.stripe.com/v3/\";\n\n@Injectable({\n  providedIn: 'root'\n})\n/**\n * This service has a `stripe` property to that gets\n * initialized to `window[\"Stripe\"]`.\n * \n * The constructor calls `inject()` which will\n * inject a script tag with containing the URL that loads\n * stripe and return a `Promise<StripeFactory>`.\n * \n * The script tag will only load stripe if \n * c is not available.\n * \n * If `window[\"Stripe\"]` is available then `inject()` resolves \n * the promise with that instance immediately, and does not create and \n * wait for the script tag to load.\n * \n *  \n */\nexport class AngularStripeService{\n\n  // @ts-ignore\n  private _stripe:StripeFactory = window['Stripe']\n  private stripePromise:Promise<any>\n\n  constructor() { \n    this.stripePromise = this.inject()\n  }\n\n  get stripe() {\n    return this._stripe;\n  } \n  set stripe(s:StripeFactory) {\n    this._stripe = s;\n  }\n\n  setPublishableKey(key:string, options?:any):Promise<Stripe>{\n    return this.stripePromise.then( () => {\n      return this.stripe(key, options)\n    })\n  }\n\n  inject():Promise<StripeFactory>{\n\n    if( this.stripe ){\n      return Promise.resolve( this.stripe )\n    }\n\n    return new Promise((res,rej)=>{\n      const head = this.getHeadElement()\n      const script = document.createElement(\"script\")\n      script.setAttribute(\"type\", \"text/javascript\")\n      script.setAttribute(\"src\", STRIPE_API_URL)      \n      head.appendChild(script)      \n      script.addEventListener(\"load\",()=>{\n        // @ts-ignore\n        this.stripe = window[\"Stripe\"];\n        res( this.stripe )\n      })\n    })\n  }\n\n  /**\n   * Returns the `head` element.\n   * @throws Error('Application does not have a head element');\n   */\n  getHeadElement(){\n    let elm:HTMLElement = document.getElementsByTagName(\"head\")[0]\n\n    if(!elm) {\n      throw new Error('Application does not have a head element');\n    }    \n    return elm;\n  }  \n}\n","/*\n * Public API Surface of angular-stripe-service\n */\n\nexport * from './lib/angular-stripe.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAGA,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAKnD;;;;;;;;;;;;;;;;;MAiBa,oBAAoB;IAM/B;;QAHQ,YAAO,GAAiB,MAAM,CAAC,QAAQ,CAAC,CAAA;QAI9C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;KACnC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;KACrB;IACD,IAAI,MAAM,CAAC,CAAe;QACxB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;KAClB;IAED,iBAAiB,CAAC,GAAU,EAAE,OAAY;QACxC,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAE;YAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;SACjC,CAAC,CAAA;KACH;IAED,MAAM;QAEJ,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,OAAO,CAAC,OAAO,CAAE,IAAI,CAAC,MAAM,CAAE,CAAA;SACtC;QAED,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAC,GAAG;YACzB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;YAClC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;YAC/C,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;YAC9C,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;YAC1C,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;YACxB,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAC;;gBAE7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAA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