Compare commits
No commits in common. "55cd5fefede54ad91b2f4b1a94ee13c8a79b5bd4" and "1d0162d250e132eaab746f5bc71222376b30aa48" have entirely different histories.
55cd5fefed
...
1d0162d250
@ -18,5 +18,5 @@ export const routes: Routes = [
|
|||||||
path: 'deposit',
|
path: 'deposit',
|
||||||
component: DepositComponent,
|
component: DepositComponent,
|
||||||
canActivate: [authGuard],
|
canActivate: [authGuard],
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
<form [formGroup]="form">
|
<form [formGroup]="form">
|
||||||
@if (errorMsg) {
|
<input type="number" formControlName="amount">€
|
||||||
<div>{{ errorMsg }}</div>
|
<br>
|
||||||
}
|
|
||||||
<input type="number" formControlName="amount" />€
|
|
||||||
<br />
|
|
||||||
<button type="button" (click)="submit()">Einzahlen</button>
|
<button type="button" (click)="submit()">Einzahlen</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,51 +1,32 @@
|
|||||||
import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
|
import { Component, inject, OnInit } from '@angular/core';
|
||||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { loadStripe, Stripe } from '@stripe/stripe-js';
|
import { loadStripe, Stripe } from '@stripe/stripe-js';
|
||||||
import { DepositService } from '../service/deposit.service';
|
import { DepositService } from '../service/deposit.service';
|
||||||
import { debounceTime } from 'rxjs';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-deposit',
|
selector: 'app-deposit',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [ReactiveFormsModule],
|
imports: [
|
||||||
|
ReactiveFormsModule,
|
||||||
|
],
|
||||||
templateUrl: './deposit.component.html',
|
templateUrl: './deposit.component.html',
|
||||||
styleUrl: './deposit.component.css',
|
styleUrl: './deposit.component.css'
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
||||||
})
|
})
|
||||||
export class DepositComponent implements OnInit{
|
export class DepositComponent implements OnInit{
|
||||||
protected form!: FormGroup;
|
protected form = new FormGroup({amount: new FormControl(50, [Validators.min(50)])});
|
||||||
protected errorMsg: string = '';
|
|
||||||
private stripe: Stripe | null = null;
|
private stripe: Stripe | null = null;
|
||||||
private service: DepositService = inject(DepositService);
|
private service: DepositService = inject(DepositService);
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.form = new FormGroup({
|
this.stripe = await loadStripe('pk_test_51QrePYIvCfqz7ANgMizBorPpVjJ8S6gcaL4yvcMQnVaKyReqcQ6jqaQEF7aDZbDu8rNVsTZrw8ABek4ToxQX7KZe00jpGh8naG');
|
||||||
amount: new FormControl(50, [Validators.min(50)]),
|
|
||||||
});
|
|
||||||
|
|
||||||
this.form.controls['amount'].valueChanges.pipe(debounceTime(1000)).subscribe((value) => {
|
|
||||||
if (value < 50) {
|
|
||||||
this.errorMsg = 'Minimum Einzahlungsbetrag ist 50€';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.stripe = await loadStripe(
|
|
||||||
'pk_test_51QrePYIvCfqz7ANgMizBorPpVjJ8S6gcaL4yvcMQnVaKyReqcQ6jqaQEF7aDZbDu8rNVsTZrw8ABek4ToxQX7KZe00jpGh8naG'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
if (!this.stripe) {
|
if (this.stripe) {
|
||||||
this.errorMsg = 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.';
|
console.log(JSON.stringify(this.form.value.amount as number));
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.form.valid) {
|
|
||||||
this.errorMsg = 'Bitte geben Sie einen gültigen Betrag ein.';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.service.handleDeposit(this.form.value.amount as number).subscribe(({sessionId}) => {
|
this.service.handleDeposit(this.form.value.amount as number).subscribe(({sessionId}) => {
|
||||||
this.stripe?.redirectToCheckout({sessionId});
|
this.stripe?.redirectToCheckout({sessionId});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -2,8 +2,9 @@ import { inject, Injectable } from '@angular/core';
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class DepositService {
|
export class DepositService {
|
||||||
private http: HttpClient = inject(HttpClient);
|
private http: HttpClient = inject(HttpClient);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user