App.ts
==========================================
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'testproj';
paymentHandler: any = null;
ngOnInit() {
this.invokeStripe();
}
makePayment(amount: any) {
const paymentHandler = (<any>window).StripeCheckout.configure({
key:
'pk_test_51HqKNkG7HcjhSjrfbDoLC6M1Ud7DFTpJkX9LKS98utMFAehGlVXa8qsEXYRV3mAKPKYwrJuZYemdpPYvxie3xPdg00TGxu9y0t',
locale: 'auto',
token: function (stripeToken: any) {
console.log(stripeToken.card);
alert('Stripe token generated!');
},
});
paymentHandler.open({
name: 'Technical Adda',
description: '4 Products Added',
amount: amount * 100,
});
}
invokeStripe() {
if (!window.document.getElementById('stripe-script')) {
const script = window.document.createElement('script');
script.id = 'stripe-script';
script.type = 'text/javascript';
script.src = 'https://checkout.stripe.com/checkout.js';
window.document.body.appendChild(script);
}
}
}
App.html
========================================
<div>
<h1>Angular Stripe Checkout Example</h1>
<button (click)="makePayment(10)">Pay $10</button>
<button (click)="makePayment(15)">Pay $15</button>
<button (click)="makePayment(20)">Pay $20</button>
</div>
there is no Secret Key used hence its not working
ReplyDelete