diff --git a/src/app/invoice/invoice.component.html b/src/app/invoice/invoice.component.html
index 923f99b..91ac922 100644
--- a/src/app/invoice/invoice.component.html
+++ b/src/app/invoice/invoice.component.html
@@ -89,14 +89,14 @@
{{ vE.settingsVkeyLbl }}
-
diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts
index 1d1a431..30c73e7 100644
--- a/src/app/settings/settings.component.ts
+++ b/src/app/settings/settings.component.ts
@@ -29,7 +29,6 @@ export class SettingsComponent implements OnInit {
owner: Owner;
useZats: boolean;
proVersion: boolean = false;
- useVKey: boolean = false;
linkMsg: string = '';
xeroAccCod: string = '';
saveAccOk: boolean = false;
@@ -117,6 +116,7 @@ export class SettingsComponent implements OnInit {
};
//
languageRdy = new Subject();
+ vKaccess = true;
// ------------------------------------------------------------
constructor(
@@ -128,13 +128,11 @@ export class SettingsComponent implements OnInit {
private dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: {o: Owner}) {
this.useZats = data.o.zats;
- this.useVKey = data.o.payconf;
this.settingsForm = fb.group({
name: [data.o.name, Validators.required],
currency: [data.o.currency, Validators.required],
useZats: [data.o.zats, Validators.required],
useVKey: [data.o.payconf, Validators.required],
- // proVersion: [data.invoices, Validators.required],
vKey: [data.o.viewkey]
});
this.accCodForm = fb.group ({
@@ -142,7 +140,8 @@ export class SettingsComponent implements OnInit {
});
if (data.o.payconf) {
- this.settingsForm.get('vKey')!.enable();
+ this.vKaccess = false;
+ //this.settingsForm.get('vKey')!.enable();
}
this.owner = data.o;
this.viewkey = data.o.viewkey;
@@ -181,23 +180,24 @@ export class SettingsComponent implements OnInit {
ngOnInit() {
- this.settingsForm.get('vKey')!.disable();
- //
- this.chgUILanguage();
- //console.log('SETTINGS: Return from chgUILanguage()');
- //
- this.languageRdy.subscribe (
- data => {
- this.linkMsg = this.vE.settingsLink2Xero;
- this.pmtServiceURL + '';
- if ( this.linked2Xero ) {
- this.linkMsg = this.vE.settingsRelink2Xero; //'Relink to Xero';
- this.pmtServiceURL =
- 'https://zgo.cash/pmtservice?owner=' +
- this.owner._id +
- '&invoiceNo=[INVOICENUMBER]¤cy=[CURRENCY]&amount=[AMOUNTDUE]&shortCode=[SHORTCODE]';
- }
- });
+ //this.settingsForm.get('vKey')!.disable();
+ //
+ this.vKaccess = true;
+ this.chgUILanguage();
+ //console.log('SETTINGS: Return from chgUILanguage()');
+ //
+ this.languageRdy.subscribe (
+ data => {
+ this.linkMsg = this.vE.settingsLink2Xero;
+ this.pmtServiceURL + '';
+ if ( this.linked2Xero ) {
+ this.linkMsg = this.vE.settingsRelink2Xero; //'Relink to Xero';
+ this.pmtServiceURL =
+ 'https://zgo.cash/pmtservice?owner=' +
+ this.owner._id +
+ '&invoiceNo=[INVOICENUMBER]¤cy=[CURRENCY]&amount=[AMOUNTDUE]&shortCode=[SHORTCODE]';
+ }
+ });
}
safeURL(s: string){
@@ -206,7 +206,7 @@ export class SettingsComponent implements OnInit {
close() {
- this.dialogRef.close();
+ this.dialogRef.close(null);
}
closeIntegration() {
@@ -223,8 +223,8 @@ export class SettingsComponent implements OnInit {
this.owner.currency = this.settingsForm.value.currency;
this.owner.zats = this.settingsForm.value.useZats;
this.owner.payconf = this.settingsForm.value.useVKey;
- this.viewkey = this.settingsForm.value.vKey;
- //this.owner.invoices = this.settingsForm.value.proVersion
+ this.owner.viewkey = this.settingsForm.value.vKey;
+ console.log('Settings component key: ' + this.owner.viewkey);
this.dialogRef.close(this.owner);
}
@@ -237,15 +237,16 @@ export class SettingsComponent implements OnInit {
}
onChangeVKeyOn(ob: MatSlideToggleChange) {
-// console.log("Viewing key switch is " +
-// ( ob.checked ? "[ON]." : "[OFF]." ) );
-
- this.useVKey = ob.checked;
+ // console.log("Viewing key switch is " +
+ // ( ob.checked ? "[ON]." : "[OFF]." ) );
- if ( ob.checked )
- this.settingsForm.get('vKey')!.enable();
- else
- this.settingsForm.get('vKey')!.disable();
+ if ( ob.checked ) {
+ //this.settingsForm.get('vKey')!.enable();
+ this.vKaccess = false;
+ } else {
+ //this.settingsForm.get('vKey')!.disable();
+ this.vKaccess = true;
+ }
}
diff --git a/src/app/user.service.ts b/src/app/user.service.ts
index 5756115..d21baba 100644
--- a/src/app/user.service.ts
+++ b/src/app/user.service.ts
@@ -162,17 +162,54 @@ export class UserService{
}
saveOwnerSettings(o: Owner) {
- let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams});
+ console.log('saveOwnerSettings: ' + o.viewkey);
+ if(o.viewkey.length > 20) {
+ this.saveOwnerViewingKey(o.viewkey).subscribe({
+ next: () => {
+ let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams});
+ obs.subscribe({
+ next: () => {
+ this.getOwner();
+ },
+ error: (error) => {
+ if ( error.status == 500 ){
+ this.notifierService.showNotification("Saving settings failed", "Close", "error")
+ }
+ }
+ });
+ }
+ });
+ } else {
+ let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams});
+ obs.subscribe({
+ next: () => {
+ this.getOwner();
+ },
+ error: (error) => {
+ if ( error.status == 500 ){
+ this.notifierService.showNotification("Saving settings failed", "Close", "error")
+ }
+ }
+ });
+ }
+ }
+
+ saveOwnerViewingKey(vk: string){
+ let obs = this.http.post(this.beUrl + 'api/ownervk', {payload: vk}, {headers: this.reqHeaders, params: this.reqParams});
obs.subscribe({
next: () => {
this.getOwner();
},
error: (error) => {
- if ( error.status == 500 ){
- this.notifierService.showNotification("Saving settings failed", "Close", "error")
+ if (error.status == 400) {
+ this.notifierService.showNotification('Invalid viewing key, changes not saved', 'Close', 'error');
+ } else if (error.status == 403) {
+ this.notifierService.showNotification('Viewing key does not match shop, changes not saved', 'Close', 'error');
}
}
- })
+ });
+
+ return obs;
}
getOwner() {