diff --git a/.gitignore b/.gitignore index d526f5b..416e7aa 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ package.json.ember-try .DS_Store yarn-error.log + +#Eclipse +.settings +.project diff --git a/addon/components/stripe-element.js b/addon/components/stripe-element.js index 84a0665..3f0172c 100644 --- a/addon/components/stripe-element.js +++ b/addon/components/stripe-element.js @@ -43,7 +43,7 @@ export default Component.extend({ // Fetch autofocus, set by user let autofocus = get(this, 'autofocus'); let stripeElement = get(this, 'stripeElement'); - let iframe = this.element.querySelector('iframe') + let iframe = this.element.querySelector('iframe'); if (autofocus && iframe) { iframe.onload = () => { stripeElement.focus(); @@ -64,6 +64,25 @@ export default Component.extend({ setEventListeners() { let stripeElement = get(this, 'stripeElement'); + stripeElement.on('ready', (event) => this.sendAction('ready', stripeElement, event)); + stripeElement.on('blur', (event) => this.sendAction('blur', stripeElement, event)); + stripeElement.on('focus', (event) => this.sendAction('focus', stripeElement, event)); + stripeElement.on('change', (...args) => { + let [{ complete, error: stripeError }] = args; + this.sendAction('change', stripeElement, ...args); + + if (complete) { + this.sendAction('complete', stripeElement); + } else if (stripeError) { + this.sendAction('error', stripeError); + } + + set(this, 'stripeError', stripeError); + }); + } + + /*setEventListeners() { + let stripeElement = get(this, 'stripeElement'); stripeElement.on('ready', (event) => { this._invokeAction('ready', stripeElement, event) @@ -110,5 +129,5 @@ export default Component.extend({ focus() { }, change() { }, complete() { }, - error() { } + error() { }*/ }); diff --git a/addon/services/stripev3.js b/addon/services/stripev3.js index 67e1654..4c98a58 100644 --- a/addon/services/stripev3.js +++ b/addon/services/stripev3.js @@ -43,8 +43,13 @@ export default Service.extend({ this.configure(); } }, - - load(publishableKey = null) { + + unload() { + this.set('didConfigure', false); + this.set('didLoad', false); + }, + + load(publishableKey = null, params = null) { if (publishableKey) { this.set('publishableKey', publishableKey); } @@ -56,12 +61,12 @@ export default Service.extend({ let doLoad = shouldLoad ? loadScript("https://js.stripe.com/v3/") : resolve(); return doLoad.then(() => { - this.configure(); + this.configure(params); this.set('didLoad', true); }); }, - configure() { + configure(params) { let didConfigure = this.get('didConfigure'); if (!didConfigure) { @@ -71,7 +76,7 @@ export default Service.extend({ throw new EmberError("stripev3: Missing Stripe key, please set `ENV.stripe.publishableKey` in config.environment.js"); } - let stripe = new Stripe(publishableKey); + let stripe = new Stripe(publishableKey, params); let functions = getProperties(stripe, STRIPE_FUNCTIONS); setProperties(this, functions);