1- import { Component , Input , OnInit } from '@angular/core' ;
1+ import { Component , Inject , Input , OnInit } from '@angular/core' ;
22import { Plan } from "fusio-sdk/dist/src/generated/consumer/Plan" ;
33import { Message } from "fusio-sdk/dist/src/generated/consumer/Message" ;
44import { ConsumerService } from "../../service/consumer.service" ;
55import { LocationStrategy } from "@angular/common" ;
66import { ErrorConverter } from "../../util/error-converter" ;
7+ import { Config , FUSIO_CONFIG } from "../../config/config" ;
78
89@Component ( {
910 selector : 'fusio-subscription' ,
@@ -12,32 +13,28 @@ import {ErrorConverter} from "../../util/error-converter";
1213} )
1314export class SubscriptionComponent implements OnInit {
1415
15- @Input ( )
16- provider : string = 'stripe' ;
17-
18- @Input ( )
19- currencyCode : string = 'USD' ;
20-
21- @Input ( )
22- redirectPath : string = '/account' ;
23-
16+ currencyCode : string = 'EUR' ;
2417 plans ?: Array < Plan >
2518 response ?: Message ;
2619
27- constructor ( private consumer : ConsumerService , private location : LocationStrategy ) { }
20+ constructor ( private consumer : ConsumerService , private location : LocationStrategy , @ Inject ( FUSIO_CONFIG ) private config : Config ) { }
2821
2922 async ngOnInit ( ) : Promise < void > {
3023 const plan = await this . consumer . getClient ( ) . getConsumerPlan ( ) ;
3124 const response = await plan . consumerActionPlanGetAll ( { count : 1024 } ) ;
3225 this . plans = response . data . entry ;
26+
27+ if ( this . config . paymentCurrency ) {
28+ this . currencyCode = this . config . paymentCurrency ;
29+ }
3330 }
3431
3532 async doBillingPortal ( ) {
3633 try {
37- const path = this . location . prepareExternalUrl ( this . redirectPath ) ;
34+ const path = this . location . prepareExternalUrl ( this . getHomePath ( ) ) ;
3835 const redirectUrl = location . origin + path ;
3936
40- const portal = await this . consumer . getClient ( ) . getConsumerPaymentByProviderPortal ( this . provider ) ;
37+ const portal = await this . consumer . getClient ( ) . getConsumerPaymentByProviderPortal ( this . getPaymentProvider ( ) ) ;
4138 const response = await portal . consumerActionPaymentPortal ( {
4239 returnUrl : redirectUrl
4340 } ) ;
@@ -54,10 +51,10 @@ export class SubscriptionComponent implements OnInit {
5451
5552 async doPurchase ( plan : Plan ) {
5653 try {
57- const path = this . location . prepareExternalUrl ( this . redirectPath ) ;
54+ const path = this . location . prepareExternalUrl ( this . getHomePath ( ) ) ;
5855 const redirectUrl = location . origin + path ;
5956
60- const checkout = await this . consumer . getClient ( ) . getConsumerPaymentByProviderCheckout ( this . provider ) ;
57+ const checkout = await this . consumer . getClient ( ) . getConsumerPaymentByProviderCheckout ( this . getPaymentProvider ( ) ) ;
6158 const response = await checkout . consumerActionPaymentCheckout ( {
6259 planId : plan . id ,
6360 returnUrl : redirectUrl ,
@@ -71,4 +68,20 @@ export class SubscriptionComponent implements OnInit {
7168 }
7269 }
7370
71+ private getHomePath ( ) : string {
72+ if ( this . config . homePath ) {
73+ return this . config . homePath ;
74+ } else {
75+ return '/account' ;
76+ }
77+ }
78+
79+ private getPaymentProvider ( ) : string {
80+ if ( this . config . paymentProvider ) {
81+ return this . config . paymentProvider ;
82+ } else {
83+ return 'stripe' ;
84+ }
85+ }
86+
7487}
0 commit comments