diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx | 36 |
1 files changed, 27 insertions, 9 deletions
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 4849d1d6c..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,10 +68,11 @@ 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 create account`, + 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), @@ -81,7 +83,7 @@ export default function CreateValidator({ onConfirm, onBack }: Props): VNode { switch (resp.case) { 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".`, }); @@ -90,7 +92,7 @@ export default function CreateValidator({ onConfirm, onBack }: Props): VNode { } 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.`, }); @@ -99,12 +101,20 @@ export default function CreateValidator({ onConfirm, onBack }: Props): VNode { } case HttpStatusCode.NotFound: { setNotif({ - message: i18n.str`Could not create account`, + message: i18n.str`Could not add bank account`, type: "ERROR", description: i18n.str`The endpoint doesn't seems to be a Taler Revenue API`, }); return; } + case TestRevenueErrorType.ANOTHER_ACCOUNT: { + setNotif({ + message: i18n.str`Could not add bank account`, + type: "ERROR", + 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); } @@ -131,19 +141,17 @@ 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, + 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, @@ -173,6 +181,16 @@ export async function testRevenueAPI( if (history.type === "fail") { return history; } + if (history.body.credit_account !== account) { + return { + type: "fail", + case: TestRevenueErrorType.ANOTHER_ACCOUNT, + detail: { + code: 1, + hint: history.body.credit_account + }, + }; + } } catch (err) { if (err instanceof TalerError) { return err; |