Skip to content

Commit 3d4165c

Browse files
committed
add home path, payment provider and payment currency to config
1 parent 402be28 commit 3d4165c

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

projects/fusio-sdk/src/lib/component/login/login.component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, Inject, OnInit} from '@angular/core';
22
import {Message} from "fusio-sdk/dist/src/generated/consumer/Message";
33
import axios from "axios";
44
import {Router} from "@angular/router";
55
import {UserAccount} from "fusio-sdk/dist/src/generated/consumer/UserAccount";
66
import {ProviderService} from "../../service/provider.service";
77
import {UserService} from "../../service/user.service";
88
import {ConsumerService} from "../../service/consumer.service";
9-
import {Provider} from "../../config/config";
9+
import {Config, FUSIO_CONFIG, Provider} from "../../config/config";
1010

1111
@Component({
1212
selector: 'fusio-login',
@@ -25,7 +25,7 @@ export class LoginComponent implements OnInit {
2525

2626
providers: Array<Provider> = [];
2727

28-
constructor(private consumer: ConsumerService, private router: Router, private user: UserService<UserAccount>, private provider: ProviderService) {
28+
constructor(private consumer: ConsumerService, private router: Router, private user: UserService<UserAccount>, private provider: ProviderService, @Inject(FUSIO_CONFIG) private config: Config) {
2929
}
3030

3131
ngOnInit(): void {
@@ -42,7 +42,12 @@ export class LoginComponent implements OnInit {
4242

4343
this.user.login(response.data);
4444

45-
this.router.navigate(['/account']).then(() => {
45+
let homePath = '/account';
46+
if (this.config.homePath) {
47+
homePath = this.config.homePath;
48+
}
49+
50+
this.router.navigate([homePath]).then(() => {
4651
location.reload();
4752
});
4853
} catch (error) {

projects/fusio-sdk/src/lib/component/login/provider/provider.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, Inject, OnInit} from '@angular/core';
22
import axios from "axios";
33
import {Message} from "fusio-sdk/dist/src/generated/consumer/Message";
44
import {SessionTokenStore} from "sdkgen-client";
@@ -9,6 +9,7 @@ import {ProviderService} from "../../../service/provider.service";
99
import {UserService} from "../../../service/user.service";
1010
import {ConsumerService} from "../../../service/consumer.service";
1111
import {ErrorConverter} from "../../../util/error-converter";
12+
import {Config, FUSIO_CONFIG} from "../../../config/config";
1213

1314
@Component({
1415
selector: 'fusio-login-provider',
@@ -19,7 +20,7 @@ export class ProviderComponent implements OnInit {
1920

2021
response?: Message;
2122

22-
constructor(private consumer: ConsumerService, private router: Router, private user: UserService<UserAccount>, protected route: ActivatedRoute, private provider: ProviderService) { }
23+
constructor(private consumer: ConsumerService, private router: Router, private user: UserService<UserAccount>, protected route: ActivatedRoute, private provider: ProviderService, @Inject(FUSIO_CONFIG) private config: Config) { }
2324

2425
async ngOnInit(): Promise<void> {
2526
const provider = this.route.snapshot.paramMap.get('provider');
@@ -74,7 +75,12 @@ export class ProviderComponent implements OnInit {
7475

7576
this.user.login(response.data);
7677

77-
this.router.navigate(['/account']).then(() => {
78+
let homePath = '/account';
79+
if (this.config.homePath) {
80+
homePath = this.config.homePath;
81+
}
82+
83+
this.router.navigate([homePath]).then(() => {
7884
location.reload();
7985
});
8086
}

projects/fusio-sdk/src/lib/component/subscription/subscription.component.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import {Component, Input, OnInit} from '@angular/core';
1+
import {Component, Inject, Input, OnInit} from '@angular/core';
22
import {Plan} from "fusio-sdk/dist/src/generated/consumer/Plan";
33
import {Message} from "fusio-sdk/dist/src/generated/consumer/Message";
44
import {ConsumerService} from "../../service/consumer.service";
55
import {LocationStrategy} from "@angular/common";
66
import {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
})
1314
export 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
}

projects/fusio-sdk/src/lib/config/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {InjectionToken} from "@angular/core";
22

33
export interface Config {
44
baseUrl: string,
5+
homePath: string,
6+
paymentProvider: string,
7+
paymentCurrency: string,
58
providers?: Array<Provider>,
69
recaptcha?: string,
710
}

0 commit comments

Comments
 (0)