Skip to content

Commit

Permalink
Merge branch 'master-qa' of github.com:sap-labs-france/ev-dashboard i…
Browse files Browse the repository at this point in the history
…nto master-qa
  • Loading branch information
LucasBrazi06 committed Apr 15, 2021
2 parents c5694cb + 7fa6c27 commit 006ded5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TableSyncBillingInvoicesAction } from '../../../shared/table/actions/in
import { TableSyncBillingUsersAction } from '../../../shared/table/actions/users/table-sync-billing-users-action';
import { RestResponse } from '../../../types/GlobalType';
import { HTTPError } from '../../../types/HTTPError';
import { BillingSettings, BillingSettingsType } from '../../../types/Setting';
import { BillingSetting, BillingSettings, BillingSettingsType, StripeBillingSetting } from '../../../types/Setting';
import TenantComponents from '../../../types/TenantComponents';
import { Utils } from '../../../utils/Utils';

Expand Down Expand Up @@ -68,14 +68,21 @@ export class SettingsBillingComponent implements OnInit {
});
}

public save(content: BillingSettings) {
// Stripe
if (content.stripe) {
this.billingSettings.type = BillingSettingsType.STRIPE;
this.billingSettings.stripe = content.stripe;
} else {
return;
public save(newSettings: any) {
if (!newSettings.stripe) {
return ;
}
const { immediateBillingAllowed, periodicBillingAllowed, taxID } = newSettings.stripe; // TODO - ?? newSettings.billing?
const billing: BillingSetting = {
immediateBillingAllowed, periodicBillingAllowed, taxID
};
const { url, publicKey, secretKey } = newSettings.stripe;
const stripe: StripeBillingSetting = {
url, publicKey, secretKey
};
this.billingSettings.type = BillingSettingsType.STRIPE;
this.billingSettings.billing = billing;
this.billingSettings.stripe = stripe;
// Save
this.spinnerService.show();
this.componentService.saveBillingSettings(this.billingSettings).subscribe((response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class SettingsStripeComponent implements OnInit, OnChanges {
public publicKey!: AbstractControl;
public immediateBillingAllowed!: AbstractControl;
public periodicBillingAllowed!: AbstractControl;
public lastSynchronizedOn!: AbstractControl;
public taxID!: AbstractControl;
public taxes: BillingTax[] = [];

Expand Down Expand Up @@ -50,7 +49,6 @@ export class SettingsStripeComponent implements OnInit, OnChanges {
),
immediateBillingAllowed: new FormControl(''),
periodicBillingAllowed: new FormControl(''),
lastSynchronizedOn: new FormControl(''),
taxID: new FormControl('',
Validators.compose([
// Validators.required,
Expand All @@ -68,7 +66,6 @@ export class SettingsStripeComponent implements OnInit, OnChanges {
this.publicKey = this.stripe.controls['publicKey'];
this.immediateBillingAllowed = this.stripe.controls['immediateBillingAllowed'];
this.periodicBillingAllowed = this.stripe.controls['periodicBillingAllowed'];
this.lastSynchronizedOn = this.stripe.controls['lastSynchronizedOn'];
this.taxID = this.stripe.controls['taxID'];

// Set data
Expand Down Expand Up @@ -112,17 +109,18 @@ export class SettingsStripeComponent implements OnInit, OnChanges {

private updateFormData() {
if (this.stripe) {
// Set data
this.url.setValue(this.billingSettings.stripe.url ? this.billingSettings.stripe.url : '');
this.secretKey.setValue(this.billingSettings.stripe.secretKey ? this.billingSettings.stripe.secretKey : '');
this.publicKey.setValue(this.billingSettings.stripe.publicKey ? this.billingSettings.stripe.publicKey : '');
this.immediateBillingAllowed.setValue(this.billingSettings.stripe.immediateBillingAllowed
? this.billingSettings.stripe.immediateBillingAllowed : false);
this.periodicBillingAllowed.setValue(this.billingSettings.stripe.periodicBillingAllowed
? this.billingSettings.stripe.periodicBillingAllowed : false);
this.lastSynchronizedOn.setValue(this.billingSettings.stripe.lastSynchronizedOn
? this.billingSettings.stripe.lastSynchronizedOn : '');
this.taxID.setValue(this.billingSettings.stripe.taxID ? this.billingSettings.stripe.taxID : '');
const stripeSetting = this.billingSettings.stripe;
if ( stripeSetting ) {
this.url.setValue(stripeSetting.url);
this.secretKey.setValue(stripeSetting.secretKey);
this.publicKey.setValue(stripeSetting.publicKey);
}
const billingSetting = this.billingSettings.billing;
if ( billingSetting ) {
this.immediateBillingAllowed.setValue(!!billingSetting.immediateBillingAllowed);
this.periodicBillingAllowed.setValue(!!billingSetting.periodicBillingAllowed);
this.taxID.setValue(billingSetting.taxID);
}
}
}
}
7 changes: 4 additions & 3 deletions src/app/services/component.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ export class ComponentService {
if (settings.type === BillingSettingsType.STRIPE) {
settingsToSave.sensitiveData = ['content.stripe.secretKey'];
}
// Set some temporary defaults
settingsToSave.content.stripe.noCardAllowed = true;
settingsToSave.content.stripe.advanceBillingAllowed = false;
// Delete IDS
delete settingsToSave.content.id;
delete settingsToSave.content.identifier;
Expand Down Expand Up @@ -282,6 +279,10 @@ export class ComponentService {
// ID
billingSettings.id = settings.id;
billingSettings.sensitiveData = settings.sensitiveData;
// billing common properties
if (config.billing) {
billingSettings.billing = config.billing;
}
// Stripe
if (config.stripe) {
billingSettings.type = BillingSettingsType.STRIPE;
Expand Down
27 changes: 13 additions & 14 deletions src/app/types/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SettingDBContent {
oicp?: OicpSetting;
simple?: SimplePricingSetting;
convergentCharging?: ConvergentChargingPricingSetting;
billing?: BillingSetting;
stripe?: StripeBillingSetting;
sac?: SacAnalyticsSetting;
links?: SettingLink[];
Expand Down Expand Up @@ -195,30 +196,28 @@ export interface ConcurRefundSetting {
reportName: string;
}

export enum BillingSettingsType {
STRIPE = 'stripe',
}

export interface BillingSettings extends Setting {
export interface BillingSettings extends Setting{
identifier: TenantComponents.BILLING;
type: BillingSettingsType;
stripe: StripeBillingSetting;
billing: BillingSetting;
stripe?: StripeBillingSetting;
}

export interface BillingSetting {
lastSynchronizedOn?: Date;
immediateBillingAllowed: boolean;
periodicBillingAllowed: boolean;
taxID: string;
usersLastSynchronizedOn?: Date;
}

export interface StripeBillingSetting extends BillingSetting {
export interface StripeBillingSetting {
url: string;
secretKey: string;
publicKey: string;
noCardAllowed: boolean;
immediateBillingAllowed: boolean;
periodicBillingAllowed: boolean;
advanceBillingAllowed: boolean;
currency: string;
taxID: string;
}

export enum BillingSettingsType {
STRIPE = 'stripe',
}

export enum AssetSettingsType {
Expand Down

0 comments on commit 006ded5

Please sign in to comment.