File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import {Course} from '../model/course';
3
3
import { Observable } from 'rxjs' ;
4
4
import { map } from 'rxjs/operators' ;
5
5
import { CoursesService } from '../services/courses.service' ;
6
+ import { CheckoutService } from '../services/checkout.service' ;
6
7
7
8
8
9
@Component ( {
@@ -21,7 +22,8 @@ export class HomeComponent implements OnInit {
21
22
processingOngoing = false ;
22
23
23
24
constructor (
24
- private coursesService : CoursesService ) {
25
+ private coursesService : CoursesService ,
26
+ private checkout : CheckoutService ) {
25
27
26
28
}
27
29
@@ -46,7 +48,14 @@ export class HomeComponent implements OnInit {
46
48
47
49
48
50
subscribeToPlan ( ) {
49
-
51
+ this . checkout . startSubscriptionCheckoutSession ( "STRIPE_MONTHLY" )
52
+ . subscribe (
53
+ session => this . checkout . redirectToCheckout ( session ) ,
54
+ err => {
55
+ console . log ( "Error creating checkout session" , err ) ;
56
+ this . processingOngoing = false ;
57
+ }
58
+ ) ;
50
59
}
51
60
52
61
}
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ export class CheckoutService {
34
34
} , { headers} )
35
35
}
36
36
37
+ startSubscriptionCheckoutSession ( pricingPlanId :string ) : Observable < CheckoutSession > {
38
+
39
+ const headers = new HttpHeaders ( ) . set ( "Authorization" , this . jwtAuth ) ;
40
+
41
+ return this . http . post < CheckoutSession > ( "/api/checkout" , {
42
+ pricingPlanId,
43
+ callbackUrl : this . buildCallbackUrl ( )
44
+ } , { headers} )
45
+ }
46
+
37
47
buildCallbackUrl ( ) {
38
48
39
49
const protocol = window . location . protocol ,
You can’t perform that action at this time.
0 commit comments