I have an angular application that uses Stripe to save customer payment card info.
I include this script in my index.html
<script src="/"></script>
this script provides a "Stripe" object that I can use like this:
<script> var stripe = Stripe('pk_XXXXXXXXXXX') </script>
the question is: How can I access the Stripe object from my angular typescript code?
I have an angular application that uses Stripe to save customer payment card info.
I include this script in my index.html
<script src="https://js.stripe./v3/"></script>
this script provides a "Stripe" object that I can use like this:
<script> var stripe = Stripe('pk_XXXXXXXXXXX') </script>
the question is: How can I access the Stripe object from my angular typescript code?
Register the type in typings.d.ts
declare var Stripe: any;
Instantiate a Stripe object from a Service
import { Injectable } from '@angular/core';
@Injectable()
export class PaymentService {
stripe = Stripe('pk_test_XXXXX');
}
Now you can inject this service into your ponents and interact with elements, but make sure to use AfterViewInit.
export class SomeComponent implements AfterViewInit {
elements: any;
constructor(private pmt: PaymentService)
ngAfterViewInit() {
// initalize elements
this.elements = this.pmt.stripe.elements()
}
}
Try to use
npm i stripe-payment-ponent
for angular typescript version.
Try this npm: ngx-stripe-checkout
With this you can integrate stripe checkout easily in angular.
For more details : https://www.npmjs./package/ngx-stripe-checkout.