code-corps/ember-stripe-elements

Lazy initialize stripe configuration

josemarluedke opened this issue · 1 comments

The lazy option to load Stripe is amazing. Thanks for having that already.

We have a use case where we need to set up the stripe publishable key in runtime instead of having it hardcoded in config/environment.js. (We fetch this information from our API.)

Today I can do that using a hack, but it would be nice to have an official way set stripe configuration at runtime.

Here is the approach I have.

// in beforeModel 
this.stripe.config.publishableKey = 'pk_my-new-key';
return this.stripe.load();

This relies on the fact that the initializer injects the config in the service, so we just override the value.

We also need to set some value in config/environment.js for publishableKey, otherwise, we get an error.

A possible alternative is to have configure method from the service take arguments to be used in the initialization of stripe.

The error from the initializer should be moved to the configure method instead. Currently defined here.

I guess #39 is trying to solve the same issue.