Using Stripe with Angular 5

戏子无情 提交于 2019-12-05 12:14:50

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 components 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-component

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.com/package/ngx-stripe-checkout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!