File tree 3 files changed +27
-3
lines changed
3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ service cloud.firestore {
28
28
29
29
}
30
30
31
+ match / purchaseSessions/ {purchaseId } {
32
+ allow read : if resource.data.userId == request .auth.uid ;
33
+ }
34
+
31
35
}
32
36
33
37
}
Original file line number Diff line number Diff line change @@ -2,14 +2,18 @@ import {Injectable} from '@angular/core';
2
2
import { HttpClient } from '@angular/common/http' ;
3
3
import { Observable } from 'rxjs' ;
4
4
import { CheckoutSession } from '../model/checkout-session.model' ;
5
+ import { AngularFirestore } from '@angular/fire/firestore' ;
6
+ import { filter , first } from 'rxjs/operators' ;
5
7
6
8
7
9
@Injectable ( {
8
10
providedIn : 'root'
9
11
} )
10
12
export class CheckoutService {
11
13
12
- constructor ( private http : HttpClient ) {
14
+ constructor (
15
+ private http : HttpClient ,
16
+ private afs : AngularFirestore ) {
13
17
14
18
}
15
19
@@ -31,5 +35,12 @@ export class CheckoutService {
31
35
}
32
36
33
37
34
-
38
+ waitForPurchaseToComplete ( ongoingPurchaseSessionId : string ) : Observable < any > {
39
+ return this . afs . doc < any > ( `purchaseSessions/${ ongoingPurchaseSessionId } ` )
40
+ . valueChanges ( )
41
+ . pipe (
42
+ filter ( purchase => purchase . status == "completed" ) ,
43
+ first ( )
44
+ )
45
+ }
35
46
}
Original file line number Diff line number Diff line change @@ -26,10 +26,19 @@ export class StripeCheckoutComponent implements OnInit {
26
26
27
27
if ( result == "success" ) {
28
28
29
+ const ongoingPurchaseSessionId = this . route . snapshot . queryParamMap . get ( 'ongoingPurchaseSessionId' ) ;
30
+
31
+ this . checkout . waitForPurchaseToComplete ( ongoingPurchaseSessionId )
32
+ . subscribe (
33
+ ( ) => {
34
+ this . waiting = false ;
35
+ this . message = "Purchase SUCCESSFUL, redirecting..." ;
36
+ setTimeout ( ( ) => this . router . navigateByUrl ( "/courses" ) , 3000 ) ;
37
+ } ) ;
29
38
}
30
39
else {
31
40
this . waiting = false ;
32
- this . message = "Purchase canceled or failed , redirecting..." ;
41
+ this . message = "Purchase CANCELED or FAILED , redirecting..." ;
33
42
setTimeout ( ( ) => this . router . navigateByUrl ( "/courses" ) , 3000 ) ;
34
43
}
35
44
You can’t perform that action at this time.
0 commit comments