feat(console): stripe (#1590)

* prepare request for sub service

* show detail, i18n

* form dialog

* country

* stripe button

* feature

* flex

* rm logs

* org creationdate, lint

* rm log
This commit is contained in:
Max Peintner
2021-04-15 18:30:50 +02:00
committed by GitHub
parent c2fedbbfc6
commit 6a3a541848
272 changed files with 2270 additions and 193 deletions
@@ -0,0 +1,89 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { StorageService } from './storage.service';
const authorizationKey = 'Authorization';
const bearerPrefix = 'Bearer';
const accessTokenStorageKey = 'access_token';
export interface StripeCustomer {
contact: string;
company?: string;
address: string;
city: string;
postal_code: string;
country: string;
}
@Injectable({
providedIn: 'root',
})
export class SubscriptionService {
constructor(private http: HttpClient, private storageService: StorageService) { }
public getLink(orgId: string, redirectURI: string): Promise<any> {
return this.http.get('./assets/environment.json')
.toPromise().then((data: any) => {
if (data && data.subscriptionServiceUrl) {
const serviceUrl = data.subscriptionServiceUrl;
const accessToken = this.storageService.getItem(accessTokenStorageKey);
return this.http.get(`${serviceUrl}/redirect`, {
headers: {
// 'Content-Type': 'application/json; charset=utf-8',
[authorizationKey]: `${bearerPrefix} ${accessToken}`,
},
params: {
'org': orgId,
'return_url': encodeURI(redirectURI),
'country': 'ch',
},
}).toPromise();
} else {
return Promise.reject('Could not load environment');
}
});
}
public getCustomer(orgId: string): Promise<any> {
return this.http.get('./assets/environment.json')
.toPromise().then((data: any) => {
if (data && data.subscriptionServiceUrl) {
const serviceUrl = data.subscriptionServiceUrl;
const accessToken = this.storageService.getItem(accessTokenStorageKey);
return this.http.get(`${serviceUrl}/customer`, {
headers: {
// 'Content-Type': 'application/json; charset=utf-8',
[authorizationKey]: `${bearerPrefix} ${accessToken}`,
},
params: {
'org': orgId,
},
}).toPromise();
} else {
return Promise.reject('Could not load environment');
}
});
}
public updateCustomer(orgId: string, body: StripeCustomer): Promise<any> {
return this.http.get('./assets/environment.json')
.toPromise().then((data: any) => {
if (data && data.subscriptionServiceUrl) {
const serviceUrl = data.subscriptionServiceUrl;
const accessToken = this.storageService.getItem(accessTokenStorageKey);
return this.http.put(`${serviceUrl}/customer`, body, {
headers: {
// 'Content-Type': 'application/json; charset=utf-8',
[authorizationKey]: `${bearerPrefix} ${accessToken}`,
},
params: {
'org': orgId,
},
}).toPromise();
} else {
return Promise.reject('Could not load environment');
}
});
}
}