check bank's protocol version first, fix typo
This commit is contained in:
parent
a602e6714e
commit
f32062ccf0
@ -3279,6 +3279,13 @@ export enum TalerErrorCode {
|
|||||||
*/
|
*/
|
||||||
WALLET_TIPPING_COIN_SIGNATURE_INVALID = 7016,
|
WALLET_TIPPING_COIN_SIGNATURE_INVALID = 7016,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wallet does not implement a version of the bank integration API that is compatible with the version offered by the bank.
|
||||||
|
* Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
|
||||||
|
* (A value of 0 indicates that the error is generated client-side).
|
||||||
|
*/
|
||||||
|
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE = 7017,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End of error code range.
|
* End of error code range.
|
||||||
* Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
|
* Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
|
||||||
|
@ -28,6 +28,13 @@ export const WALLET_EXCHANGE_PROTOCOL_VERSION = "8:0:0";
|
|||||||
*/
|
*/
|
||||||
export const WALLET_MERCHANT_PROTOCOL_VERSION = "1:0:0";
|
export const WALLET_MERCHANT_PROTOCOL_VERSION = "1:0:0";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protocol version spoken with the merchant.
|
||||||
|
*
|
||||||
|
* Uses libtool's current:revision:age versioning.
|
||||||
|
*/
|
||||||
|
export const WALLET_BANK_INTEGRATION_PROTOCOL_VERSION = "0:0:0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache breaker that is appended to queries such as /keys and /wire
|
* Cache breaker that is appended to queries such as /keys and /wire
|
||||||
* to break through caching, if it has been accidentally/badly configured
|
* to break through caching, if it has been accidentally/badly configured
|
||||||
|
@ -37,12 +37,13 @@ import {
|
|||||||
codecForWithdrawResponse,
|
codecForWithdrawResponse,
|
||||||
WithdrawUriInfoResponse,
|
WithdrawUriInfoResponse,
|
||||||
WithdrawResponse,
|
WithdrawResponse,
|
||||||
|
codecForTalerConfigResponse,
|
||||||
} from "../types/talerTypes";
|
} from "../types/talerTypes";
|
||||||
import { InternalWalletState } from "./state";
|
import { InternalWalletState } from "./state";
|
||||||
import { parseWithdrawUri } from "../util/taleruri";
|
import { parseWithdrawUri } from "../util/taleruri";
|
||||||
import { Logger } from "../util/logging";
|
import { Logger } from "../util/logging";
|
||||||
import { updateExchangeFromUrl, getExchangeTrust } from "./exchanges";
|
import { updateExchangeFromUrl, getExchangeTrust } from "./exchanges";
|
||||||
import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "./versions";
|
import { WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_BANK_INTEGRATION_PROTOCOL_VERSION } from "./versions";
|
||||||
|
|
||||||
import * as LibtoolVersion from "../util/libtoolVersion";
|
import * as LibtoolVersion from "../util/libtoolVersion";
|
||||||
import {
|
import {
|
||||||
@ -62,6 +63,7 @@ import { URL } from "../util/url";
|
|||||||
import { TalerErrorCode } from "../TalerErrorCode";
|
import { TalerErrorCode } from "../TalerErrorCode";
|
||||||
import { encodeCrock } from "../crypto/talerCrypto";
|
import { encodeCrock } from "../crypto/talerCrypto";
|
||||||
import { updateRetryInfoTimeout, initRetryInfo } from "../util/retries";
|
import { updateRetryInfoTimeout, initRetryInfo } from "../util/retries";
|
||||||
|
import { compare } from "../util/libtoolVersion";
|
||||||
|
|
||||||
const logger = new Logger("withdraw.ts");
|
const logger = new Logger("withdraw.ts");
|
||||||
|
|
||||||
@ -152,8 +154,33 @@ export async function getBankWithdrawalInfo(
|
|||||||
if (!uriResult) {
|
if (!uriResult) {
|
||||||
throw Error(`can't parse URL ${talerWithdrawUri}`);
|
throw Error(`can't parse URL ${talerWithdrawUri}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const configReqUrl = new URL(
|
||||||
|
"config",
|
||||||
|
uriResult.bankIntegrationApiBaseUrl,
|
||||||
|
)
|
||||||
|
|
||||||
|
const configResp = await ws.http.get(configReqUrl.href);
|
||||||
|
const config = await readSuccessResponseJsonOrThrow(
|
||||||
|
configResp,
|
||||||
|
codecForTalerConfigResponse(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const versionRes = compare(WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, config.version);
|
||||||
|
if (versionRes?.compatible != true) {
|
||||||
|
const opErr = makeErrorDetails(
|
||||||
|
TalerErrorCode.WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE,
|
||||||
|
"bank integration protocol version not compatible with wallet",
|
||||||
|
{
|
||||||
|
exchangeProtocolVersion: config.version,
|
||||||
|
walletProtocolVersion: WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
throw new OperationFailedError(opErr);
|
||||||
|
}
|
||||||
|
|
||||||
const reqUrl = new URL(
|
const reqUrl = new URL(
|
||||||
`api/withdraw-operation/${uriResult.withdrawalOperationId}`,
|
`withdrawal-operation/${uriResult.withdrawalOperationId}`,
|
||||||
uriResult.bankIntegrationApiBaseUrl,
|
uriResult.bankIntegrationApiBaseUrl,
|
||||||
);
|
);
|
||||||
const resp = await ws.http.get(reqUrl.href);
|
const resp = await ws.http.get(reqUrl.href);
|
||||||
|
@ -1455,3 +1455,16 @@ export const codecForMerchantAbortPayRefundStatus = (): Codec<
|
|||||||
.alternative("success", codecForMerchantAbortPayRefundSuccessStatus())
|
.alternative("success", codecForMerchantAbortPayRefundSuccessStatus())
|
||||||
.alternative("failure", codecForMerchantAbortPayRefundFailureStatus())
|
.alternative("failure", codecForMerchantAbortPayRefundFailureStatus())
|
||||||
.build("MerchantAbortPayRefundStatus");
|
.build("MerchantAbortPayRefundStatus");
|
||||||
|
|
||||||
|
export interface TalerConfigResponse {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
currency?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const codecForTalerConfigResponse = (): Codec<TalerConfigResponse> =>
|
||||||
|
buildCodecForObject<TalerConfigResponse>()
|
||||||
|
.property("name", codecForString())
|
||||||
|
.property("version", codecForString())
|
||||||
|
.property("currency", codecOptional(codecForString()))
|
||||||
|
.build("TalerConfigResponse");
|
||||||
|
Loading…
Reference in New Issue
Block a user