richnologies / ngx-stripe

Angular 6+ wrapper for StripeJS
MIT License
219 stars 77 forks source link

Dynamic Public Keys #259

Open JonesWest opened 3 months ago

JonesWest commented 3 months ago

The docs has a short section about using dynamic public keys: https://ngx-stripe.dev/docs/setup-application, it refers to using the injectStripe method, and an example for it. However, the example is not do be found anywhere.

I've tried the following:

imports: [
...
     NgxStripeModule.forRoot(),
...
]

Notice no key in the module registration. In my component I then:

constructor(...){
     injectStripe(environment.stripePublishableKey);
}

But I get this error as soon as I begin using any Stripe directive:

TypeError: Cannot read properties of undefined (reading 'elements')
    at StripeService.elements (ngx-stripe.mjs:435:28)
    at StripeElementsService.elements (ngx-stripe.mjs:689:43)
    at ngx-stripe.mjs:1407:63
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (asyncToGenerator.js:3:1)
    at _next (asyncToGenerator.js:22:1)
    at asyncToGenerator.js:27:1
    at new ZoneAwarePromise (zone.js:2611:25)
    at asyncToGenerator.js:19:1
    at StripeCardGroupDirective.ngOnChanges (ngx-stripe.mjs:1410:30)