aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/accounts
diff options
context:
space:
mode:
authorChristian Blättler <blatc2@bfh.ch>2024-06-13 11:35:52 +0200
committerChristian Blättler <blatc2@bfh.ch>2024-06-13 11:35:52 +0200
commiteb964dfae0a12f9a90eb066d610f627538f8997c (patch)
tree26a6cd74c9a29edce05b2dcd51cf497374bf8e30 /packages/merchant-backoffice-ui/src/paths/instance/accounts
parent9d0fc80a905e02a0a0b63dd547daac6e7b17fb52 (diff)
parentf9d4ff5b43e48a07ac81d7e7ef800ddb12f5f90a (diff)
downloadwallet-core-eb964dfae0a12f9a90eb066d610f627538f8997c.tar.xz
Merge branch 'master' into feature/tokens
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/accounts')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx30
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx126
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/accounts/list/Table.tsx11
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx36
4 files changed, 98 insertions, 105 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx
index d05375b6c..d0e7a83cd 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx
@@ -31,6 +31,7 @@ import {
import { Input } from "../../../../components/form/Input.js";
import { InputPaytoForm } from "../../../../components/form/InputPaytoForm.js";
import { InputSelector } from "../../../../components/form/InputSelector.js";
+import { ImportingAccountModal } from "../../../../components/modal/index.js";
import { undefinedIfEmpty } from "../../../../utils/table.js";
import { safeConvertURL } from "../update/UpdatePage.js";
@@ -46,6 +47,7 @@ const accountAuthType = ["none", "basic"];
export function CreatePage({ onCreate, onBack }: Props): VNode {
const { i18n } = useTranslationContext();
+ const [importing, setImporting] = useState(false);
const [state, setState] = useState<Partial<Entity>>({});
const facadeURL = safeConvertURL(state.credit_facade_url);
const errors: FormErrors<Entity> = {
@@ -115,9 +117,25 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
credit_facade_url,
});
};
-
return (
<div>
+ {importing && <ImportingAccountModal onCancel={()=> {setImporting(false)}} onConfirm={(ac) => {
+ state.payto_uri = ac.accountURI
+ const u = new URL(ac.infoURL)
+ u.password = ""
+ if (u.username || u.password) {
+ state.credit_facade_credentials = {
+ type: "basic",
+ password: u.password,
+ username: u.username,
+ }
+ state.repeatPassword = u.password
+ }
+ u.password = ""
+ u.username = ""
+ state.credit_facade_url = u.href;
+ setImporting(false)
+ }} />}
<section class="section is-main-section">
<div class="columns">
<div class="column" />
@@ -171,6 +189,16 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
</FormProvider>
<div class="buttons is-right mt-5">
+ <button
+ class="button is-info"
+ data-tooltip={i18n.str`Need to complete marked fields`}
+ onClick={() => {
+ setImporting(true)
+ }}
+ >
+ <i18n.Translate>Import from bank</i18n.Translate>
+ </button>
+
{onBack && (
<button class="button" onClick={onBack}>
<i18n.Translate>Cancel</i18n.Translate>
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx
index 9bab33f6f..aa1481a2e 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx
@@ -24,6 +24,7 @@ import {
HttpStatusCode,
OperationFail,
OperationOk,
+ PaytoString,
TalerError,
TalerMerchantApi,
TalerRevenueHttpClient,
@@ -67,51 +68,55 @@ export default function CreateValidator({ onConfirm, onBack }: Props): VNode {
const resp = await testRevenueAPI(
revenueAPI,
request.credit_facade_credentials,
+ request.payto_uri,
);
+ if (resp instanceof TalerError) {
+ setNotif({
+ message: i18n.str`Could not add bank account`,
+ type: "ERROR",
+ description: i18n.str`The request to check the revenue API failed.`,
+ details: JSON.stringify(resp.errorDetail, undefined, 2),
+ });
+ return;
+ }
if (resp.type === "fail") {
switch (resp.case) {
- case TestRevenueErrorType.NO_CONFIG: {
- setNotif({
- message: i18n.str`Could not create account`,
- type: "ERROR",
- description: i18n.str`The endpoint doesn't seems to be a Taler Revenue API`,
- });
- return;
- }
- case TestRevenueErrorType.CLIENT_BAD_REQUEST: {
+ case HttpStatusCode.BadRequest: {
setNotif({
- message: i18n.str`Could not create account`,
+ message: i18n.str`Could not add bank account`,
type: "ERROR",
description: i18n.str`Server replied with "bad request".`,
});
return;
+
}
- case TestRevenueErrorType.UNAUTHORIZED: {
+ case HttpStatusCode.Unauthorized: {
setNotif({
- message: i18n.str`Could not create account`,
+ message: i18n.str`Could not add bank account`,
type: "ERROR",
description: i18n.str`Unauthorized, try with another credentials.`,
});
return;
+
}
- case TestRevenueErrorType.NOT_FOUND: {
+ case HttpStatusCode.NotFound: {
setNotif({
- message: i18n.str`Could not create account`,
+ message: i18n.str`Could not add bank account`,
type: "ERROR",
- description: i18n.str`Check facade URL, server replied with "not found".`,
+ description: i18n.str`The endpoint doesn't seems to be a Taler Revenue API`,
});
return;
}
- case TestRevenueErrorType.GENERIC_ERROR: {
+ case TestRevenueErrorType.ANOTHER_ACCOUNT: {
setNotif({
- message: i18n.str`Could not create account`,
+ message: i18n.str`Could not add bank account`,
type: "ERROR",
- description: resp.detail.hint,
+ description: i18n.str`The account info URL returned information from an account which is not the same in the account form: ${resp.detail.hint}`,
});
return;
}
default: {
- assertUnreachable(resp.case);
+ assertUnreachable(resp);
}
}
}
@@ -136,17 +141,18 @@ export default function CreateValidator({ onConfirm, onBack }: Props): VNode {
}
export enum TestRevenueErrorType {
- NO_CONFIG,
- CLIENT_BAD_REQUEST,
- UNAUTHORIZED,
- NOT_FOUND,
- GENERIC_ERROR,
+ ANOTHER_ACCOUNT,
}
export async function testRevenueAPI(
revenueAPI: URL,
creds: FacadeCredentials | undefined,
-): Promise<OperationOk<void> | OperationFail<TestRevenueErrorType>> {
+ account: PaytoString,
+): Promise<OperationOk<void> | OperationFail<HttpStatusCode.NotFound>
+| OperationFail<HttpStatusCode.Unauthorized>
+| OperationFail<HttpStatusCode.BadRequest>
+| OperationFail<TestRevenueErrorType.ANOTHER_ACCOUNT>
+| TalerError> {
const api = new TalerRevenueHttpClient(
revenueAPI.href,
new BrowserFetchHttpLib(),
@@ -167,69 +173,33 @@ export async function testRevenueAPI(
const config = await api.getConfig(auth);
if (config.type === "fail") {
- switch (config.case) {
- case HttpStatusCode.Unauthorized: {
- return {
- type: "fail",
- case: TestRevenueErrorType.UNAUTHORIZED,
- detail: {
- code: 1,
- },
- };
- }
- case HttpStatusCode.NotFound: {
- return {
- type: "fail",
- case: TestRevenueErrorType.NO_CONFIG,
- detail: {
- code: 1,
- },
- };
- }
- }
+ return config;
}
const history = await api.getHistory(auth);
if (history.type === "fail") {
- switch (history.case) {
- case HttpStatusCode.BadRequest: {
- return {
- type: "fail",
- case: TestRevenueErrorType.CLIENT_BAD_REQUEST,
- detail: {
- code: 1,
- },
- };
- }
- case HttpStatusCode.Unauthorized: {
- return {
- type: "fail",
- case: TestRevenueErrorType.UNAUTHORIZED,
- detail: {
- code: 1,
- },
- };
- }
- case HttpStatusCode.NotFound: {
- return {
- type: "fail",
- case: TestRevenueErrorType.NOT_FOUND,
- detail: {
- code: 1,
- },
- };
- }
- }
+ return history;
}
- } catch (err) {
- if (err instanceof TalerError) {
+ if (history.body.credit_account !== account) {
return {
type: "fail",
- case: TestRevenueErrorType.GENERIC_ERROR,
- detail: err.errorDetail,
+ case: TestRevenueErrorType.ANOTHER_ACCOUNT,
+ detail: {
+ code: 1,
+ hint: history.body.credit_account
+ },
};
}
+ } catch (err) {
+ if (err instanceof TalerError) {
+ return err;
+ // return {
+ // type: "fail",
+ // case: TestRevenueErrorType.GENERIC_ERROR,
+ // detail: err.errorDetail,
+ // };
+ }
}
return opFixedSuccess(undefined);
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/Table.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/Table.tsx
index efe484402..a9cb2805b 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/Table.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/Table.tsx
@@ -48,7 +48,7 @@ export function CardTable({
<header class="card-header">
<p class="card-header-title">
<span class="icon">
- <i class="mdi mdi-newspaper" />
+ <i class="mdi mdi-bank" />
</span>
<i18n.Translate>Bank accounts</i18n.Translate>
</p>
@@ -240,9 +240,6 @@ function Table({
<th>
<i18n.Translate>IBAN</i18n.Translate>
</th>
- <th>
- <i18n.Translate>BIC</i18n.Translate>
- </th>
<th />
</tr>
</thead>
@@ -263,12 +260,6 @@ function Table({
>
{ac.iban}
</td>
- <td
- onClick={(): void => onSelect(acc)}
- style={{ cursor: "pointer" }}
- >
- {ac.bic ?? ""}
- </td>
<td class="is-actions-cell right-sticky">
<div class="buttons is-right">
<button
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx
index 70942fd55..9116aaa62 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/index.tsx
@@ -88,51 +88,55 @@ export default function UpdateValidator({
const resp = await testRevenueAPI(
revenueAPI,
request.credit_facade_credentials,
+ result.body.payto_uri,
);
+ if (resp instanceof TalerError) {
+ setNotif({
+ message: i18n.str`Could not create account`,
+ type: "ERROR",
+ description: i18n.str`The request to check the revenue API failed.`,
+ details: JSON.stringify(resp.errorDetail, undefined, 2),
+ });
+ return;
+ }
if (resp.type === "fail") {
switch (resp.case) {
- case TestRevenueErrorType.NO_CONFIG: {
- setNotif({
- message: i18n.str`Could not create account`,
- type: "ERROR",
- description: i18n.str`The endpoint doesn't seems to be a Taler Revenue API`,
- });
- return;
- }
- case TestRevenueErrorType.CLIENT_BAD_REQUEST: {
+ case HttpStatusCode.BadRequest: {
setNotif({
message: i18n.str`Could not create account`,
type: "ERROR",
description: i18n.str`Server replied with "bad request".`,
});
return;
+
}
- case TestRevenueErrorType.UNAUTHORIZED: {
+ case HttpStatusCode.Unauthorized: {
setNotif({
message: i18n.str`Could not create account`,
type: "ERROR",
description: i18n.str`Unauthorized, try with another credentials.`,
});
return;
+
}
- case TestRevenueErrorType.NOT_FOUND: {
+ case HttpStatusCode.NotFound: {
setNotif({
message: i18n.str`Could not create account`,
type: "ERROR",
- description: i18n.str`Check facade URL, server replied with "not found".`,
+ description: i18n.str`The endpoint doesn't seems to be a Taler Revenue API`,
});
return;
}
- case TestRevenueErrorType.GENERIC_ERROR: {
+ case TestRevenueErrorType.ANOTHER_ACCOUNT: {
setNotif({
- message: i18n.str`Could not create account`,
+ message: i18n.str`Could not add bank account`,
type: "ERROR",
- description: resp.detail.hint,
+ description: i18n.str`The account info URL returned information from an account which is not the same in the account form: ${resp.detail.hint}`,
});
return;
}
default: {
- assertUnreachable(resp.case)
+ assertUnreachable(resp);
}
}
}