@@ -4,6 +4,7 @@ import { getProperties, setProperties } from '@ember/object';
44import { readOnly } from '@ember/object/computed' ;
55import { resolve } from 'rsvp' ;
66import loadScript from 'ember-stripe-elements/utils/load-script' ;
7+ import EmberError from '@ember/error' ;
78
89// As listed at https://stripe.com/docs/stripe-js/reference#the-stripe-object
910const STRIPE_FUNCTIONS = [
@@ -30,10 +31,11 @@ export default Service.extend({
3031
3132 lazyLoad : readOnly ( 'config.lazyLoad' ) ,
3233 mock : readOnly ( 'config.mock' ) ,
33- publishableKey : readOnly ( 'config.publishableKey' ) ,
34+ publishableKey : null ,
3435
3536 init ( ) {
3637 this . _super ( ...arguments ) ;
38+ this . set ( 'publishableKey' , this . get ( 'config.publishableKey' ) )
3739
3840 let lazyLoad = this . get ( 'lazyLoad' ) ;
3941
@@ -42,7 +44,11 @@ export default Service.extend({
4244 }
4345 } ,
4446
45- load ( ) {
47+ load ( publishableKey = null ) {
48+ if ( publishableKey ) {
49+ this . set ( 'publishableKey' , publishableKey ) ;
50+ }
51+
4652 let lazyLoad = this . get ( 'lazyLoad' ) ;
4753 let mock = this . get ( 'mock' ) ;
4854 let shouldLoad = lazyLoad && ! mock
@@ -61,6 +67,9 @@ export default Service.extend({
6167 if ( ! didConfigure ) {
6268 let publishableKey = this . get ( 'publishableKey' ) ;
6369
70+ if ( ! publishableKey ) {
71+ throw new EmberError ( "stripev3: Missing Stripe key, please set `ENV.stripe.publishableKey` in config.environment.js" ) ;
72+ }
6473
6574 let stripe = new Stripe ( publishableKey ) ;
6675 let functions = getProperties ( stripe , STRIPE_FUNCTIONS ) ;
0 commit comments