Skip to content

Commit 4af1bf1

Browse files
committed
add subscription callback component and add checkput event
1 parent ff5558d commit 4af1bf1

File tree

9 files changed

+72
-7
lines changed

9 files changed

+72
-7
lines changed

projects/fusio-sdk/src/lib/component/subscription/callback/callback.component.css

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
<ngb-alert type="success">Thank you for purchasing {{plan.name}}!</ngb-alert>
3+
<button class="btn btn-primary" [routerLink]="homePath">Home</button>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import {ConsumerService} from "../../../service/consumer.service";
3+
import {ActivatedRoute} from "@angular/router";
4+
import {Plan} from "fusio-sdk/dist/src/generated/consumer/Plan";
5+
import {EventService} from "../../../service/event.service";
6+
import {ErrorService} from "../../../service/error.service";
7+
import {Message} from "fusio-sdk/dist/src/generated/consumer/Message";
8+
import {ConfigService} from "../../../service/config.service";
9+
10+
@Component({
11+
selector: 'fusio-subscription-callback',
12+
templateUrl: './callback.component.html',
13+
styleUrls: ['./callback.component.css']
14+
})
15+
export class CallbackComponent implements OnInit {
16+
17+
homePath?: string;
18+
plan?: Plan;
19+
response?: Message;
20+
21+
constructor(private consumer: ConsumerService, private event: EventService, private error: ErrorService, private config: ConfigService, private route: ActivatedRoute) { }
22+
23+
async ngOnInit(): Promise<void> {
24+
this.homePath = this.config.getHomePath();
25+
26+
this.route.paramMap.subscribe(async params => {
27+
const id = params.get('plan_id');
28+
if (id) {
29+
await this.loadPlan(id);
30+
}
31+
});
32+
}
33+
34+
async loadPlan(id: string) {
35+
try {
36+
const plan = await this.consumer.getClient().getConsumerPlanByPlanId(id);
37+
const response = await plan.consumerActionPlanGet();
38+
this.plan = response.data;
39+
40+
this.event.dispatchPurchase(this.plan);
41+
} catch (error) {
42+
this.response = this.error.convert(error);
43+
}
44+
}
45+
46+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class SubscriptionComponent implements OnInit {
4949

5050
async doPurchase(plan: Plan) {
5151
try {
52-
const path = this.location.prepareExternalUrl(this.config.getHomePath());
52+
const path = this.location.prepareExternalUrl('/account/subscription/callback/' + plan.id);
5353
const redirectUrl = location.origin + path;
5454

5555
const checkout = await this.consumer.getClient().getConsumerPaymentByProviderCheckout(this.config.getPaymentProvider());
@@ -59,7 +59,7 @@ export class SubscriptionComponent implements OnInit {
5959
});
6060

6161
if (response.data.approvalUrl) {
62-
this.event.dispatchPurchase(plan);
62+
this.event.dispatchCheckout(plan);
6363

6464
location.href = response.data.approvalUrl;
6565
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ export interface EventListener {
4646
password_reset?: () => void,
4747

4848
/**
49-
* Invoked in case a user purchases a specific plan
49+
* Invoked in case a user starts a checkout of a plan
50+
*/
51+
checkout?: (plan: Plan) => void,
52+
53+
/**
54+
* Invoked in case a user has purchased a plan
5055
*/
5156
purchase?: (plan: Plan) => void,
5257

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {NgbModule} from "@ng-bootstrap/ng-bootstrap";
33
import {CommonModule} from "@angular/common";
44
import {FormsModule} from "@angular/forms";
55
import {RouterModule} from '@angular/router';
6+
import {NgxCaptchaModule} from "ngx-captcha";
7+
import {GravatarModule} from "ngx-gravatar";
8+
import {Config, FUSIO_CONFIG} from "./config/config";
69
import {EmptyComponent} from "./component/empty/empty.component";
710
import {MessageComponent} from "./component/message/message.component";
811
import {SearchComponent} from "./component/search/search.component";
@@ -19,10 +22,8 @@ import {RegisterComponent} from "./component/register/register.component";
1922
import {ActivateComponent} from "./component/register/activate/activate.component";
2023
import {AccountComponent} from './component/account/account.component';
2124
import {SecurityComponent} from './component/security/security.component';
22-
import {Config, FUSIO_CONFIG} from "./config/config";
23-
import {NgxCaptchaModule} from "ngx-captcha";
24-
import {GravatarModule} from "ngx-gravatar";
2525
import {SubscriptionComponent} from './component/subscription/subscription.component';
26+
import {CallbackComponent} from './component/subscription/callback/callback.component';
2627
import {DetailComponent as AppDetail} from './component/app/detail/detail.component';
2728
import {ListComponent as AppList} from './component/app/list/list.component';
2829
import {ModalComponent as AppModal} from './component/app/modal/modal.component';
@@ -50,6 +51,7 @@ import {AccountContainerComponent} from "./component/account-container/account-c
5051
SecurityComponent,
5152
SidebarComponent,
5253
SubscriptionComponent,
54+
CallbackComponent,
5355
AppDetail,
5456
AppList,
5557
AppModal,
@@ -102,7 +104,7 @@ export class FusioSdkModule {
102104
}
103105

104106
static forRoot(config?: Config): ModuleWithProviders<FusioSdkModule> {
105-
return({
107+
return ({
106108
ngModule: FusioSdkModule,
107109
providers: [{
108110
provide: FUSIO_CONFIG,

projects/fusio-sdk/src/lib/service/event.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export class EventService {
5353
}
5454
}
5555

56+
public dispatchCheckout(plan: Plan): void {
57+
if (this.eventListener.checkout) {
58+
this.eventListener.checkout.call(this, plan);
59+
}
60+
}
61+
5662
public dispatchPurchase(plan: Plan): void {
5763
if (this.eventListener.purchase) {
5864
this.eventListener.purchase.call(this, plan);

projects/fusio-sdk/src/lib/util/route-builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {RegisterComponent} from "../component/register/register.component";
1111
import {ActivateComponent} from "../component/register/activate/activate.component";
1212
import {ResetComponent} from "../component/password/reset/reset.component";
1313
import {ConfirmComponent} from "../component/password/confirm/confirm.component";
14+
import {CallbackComponent} from "../component/subscription/callback/callback.component";
1415
import {ListComponent as AppListComponent} from '../component/app/list/list.component';
1516
import {ListComponent as EventListComponent} from '../component/event/list/list.component';
1617

@@ -26,6 +27,7 @@ export class RouteBuilder {
2627
{path: 'event', component: EventListComponent, canActivate: [AuthenticationGuard]},
2728
{path: 'event/:id', component: EventListComponent, canActivate: [AuthenticationGuard]},
2829
{path: 'subscription', component: SubscriptionComponent, canActivate: [AuthenticationGuard]},
30+
{path: 'subscription/callback/:plan_id', component: CallbackComponent, canActivate: [AuthenticationGuard]},
2931
]},
3032
{path: 'login', component: LoginComponent},
3133
{path: 'login/:provider', component: ProviderComponent},

projects/fusio-sdk/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export * from './lib/component/search/search.component';
2323
export * from './lib/component/security/security.component';
2424
export * from './lib/component/sidebar/sidebar.component';
2525
export * from './lib/component/subscription/subscription.component';
26+
export * from './lib/component/subscription/callback/callback.component';
2627

2728
export {DetailComponent as AppDetailComponent} from './lib/component/app/detail/detail.component';
2829
export {ListComponent as AppListComponent} from './lib/component/app/list/list.component';

0 commit comments

Comments
 (0)