mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-05 13:52:15 +00:00
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:
@@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user