wallet-core: return purchase information in refund if available
This commit is contained in:
parent
72d0230a2e
commit
acf0dda83f
@ -545,17 +545,31 @@ export interface RefundInfoShort {
|
||||
amountRaw: AmountString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary information about the payment that we got a refund for.
|
||||
*/
|
||||
export interface RefundPaymentInfo {
|
||||
summary: string;
|
||||
summary_i18n?: InternationalizedString;
|
||||
/**
|
||||
* More information about the merchant
|
||||
*/
|
||||
merchant: MerchantInfo;
|
||||
}
|
||||
|
||||
export interface TransactionRefund extends TransactionCommon {
|
||||
type: TransactionType.Refund;
|
||||
|
||||
// ID for the transaction that is refunded
|
||||
refundedTransactionId: string;
|
||||
|
||||
// Amount that has been refunded by the merchant
|
||||
amountRaw: AmountString;
|
||||
|
||||
// Amount will be added to the wallet's balance after fees and refreshing
|
||||
amountEffective: AmountString;
|
||||
|
||||
// ID for the transaction that is refunded
|
||||
refundedTransactionId: string;
|
||||
|
||||
paymentInfo: RefundPaymentInfo | undefined;
|
||||
}
|
||||
|
||||
export interface TransactionTip extends TransactionCommon {
|
||||
|
@ -1518,7 +1518,6 @@ export interface WithdrawTestBalanceRequest {
|
||||
forcedDenomSel?: ForcedDenomSel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Request to the crypto worker to make a sync signature.
|
||||
*/
|
||||
@ -1590,36 +1589,6 @@ export const codecForWithdrawTestBalance =
|
||||
.property("bankAccessApiBaseUrl", codecForString())
|
||||
.build("WithdrawTestBalanceRequest");
|
||||
|
||||
export interface ApplyRefundResponse {
|
||||
contractTermsHash: string;
|
||||
|
||||
transactionId: string;
|
||||
|
||||
proposalId: string;
|
||||
|
||||
amountEffectivePaid: AmountString;
|
||||
|
||||
amountRefundGranted: AmountString;
|
||||
|
||||
amountRefundGone: AmountString;
|
||||
|
||||
pendingAtExchange: boolean;
|
||||
|
||||
info: OrderShortInfo;
|
||||
}
|
||||
|
||||
export const codecForApplyRefundResponse = (): Codec<ApplyRefundResponse> =>
|
||||
buildCodecForObject<ApplyRefundResponse>()
|
||||
.property("amountEffectivePaid", codecForAmountString())
|
||||
.property("amountRefundGone", codecForAmountString())
|
||||
.property("amountRefundGranted", codecForAmountString())
|
||||
.property("contractTermsHash", codecForString())
|
||||
.property("pendingAtExchange", codecForBoolean())
|
||||
.property("proposalId", codecForString())
|
||||
.property("transactionId", codecForString())
|
||||
.property("info", codecForOrderShortInfo())
|
||||
.build("ApplyRefundResponse");
|
||||
|
||||
export interface SetCoinSuspendedRequest {
|
||||
coinPub: string;
|
||||
suspended: boolean;
|
||||
@ -1658,12 +1627,12 @@ export interface StartRefundQueryRequest {
|
||||
transactionId: string;
|
||||
}
|
||||
|
||||
export const codecForStartRefundQueryRequest = (): Codec<StartRefundQueryRequest> =>
|
||||
export const codecForStartRefundQueryRequest =
|
||||
(): Codec<StartRefundQueryRequest> =>
|
||||
buildCodecForObject<StartRefundQueryRequest>()
|
||||
.property("transactionId", codecForString())
|
||||
.build("StartRefundQueryRequest");
|
||||
|
||||
|
||||
export interface PrepareTipRequest {
|
||||
talerTipUri: string;
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import {
|
||||
AbsoluteTime,
|
||||
AmountJson,
|
||||
Amounts,
|
||||
ApplyRefundResponse,
|
||||
codecForAbortResponse,
|
||||
codecForMerchantContractTerms,
|
||||
codecForMerchantOrderRefundPickupResponse,
|
||||
@ -39,7 +38,6 @@ import {
|
||||
codecForProposal,
|
||||
CoinDepositPermission,
|
||||
CoinRefreshRequest,
|
||||
CoinStatus,
|
||||
ConfirmPayResult,
|
||||
ConfirmPayResultType,
|
||||
constructPayUri,
|
||||
@ -53,20 +51,15 @@ import {
|
||||
Logger,
|
||||
makeErrorDetail,
|
||||
makePendingOperationFailedError,
|
||||
MerchantCoinRefundFailureStatus,
|
||||
MerchantCoinRefundStatus,
|
||||
MerchantCoinRefundSuccessStatus,
|
||||
MerchantContractTerms,
|
||||
MerchantPayResponse,
|
||||
MerchantRefundResponse,
|
||||
NotificationType,
|
||||
parsePayUri,
|
||||
parseRefundUri,
|
||||
parseTalerUri,
|
||||
PayCoinSelection,
|
||||
PreparePayResult,
|
||||
PreparePayResultType,
|
||||
PrepareRefundResult,
|
||||
randomBytes,
|
||||
RefreshReason,
|
||||
StartRefundQueryForUriResponse,
|
||||
|
@ -30,6 +30,7 @@ import {
|
||||
PaymentStatus,
|
||||
PeerContractTerms,
|
||||
RefundInfoShort,
|
||||
RefundPaymentInfo,
|
||||
TalerErrorCode,
|
||||
TalerProtocolTimestamp,
|
||||
Transaction,
|
||||
@ -64,6 +65,7 @@ import {
|
||||
PeerPushPaymentIncomingStatus,
|
||||
PeerPullPaymentInitiationRecord,
|
||||
RefundGroupRecord,
|
||||
ContractTermsRecord,
|
||||
} from "../db.js";
|
||||
import { InternalWalletState } from "../internal-wallet-state.js";
|
||||
import { PendingTaskType } from "../pending-types.js";
|
||||
@ -648,7 +650,18 @@ function buildTransactionForManualWithdraw(
|
||||
|
||||
function buildTransactionForRefund(
|
||||
refundRecord: RefundGroupRecord,
|
||||
maybeContractData: WalletContractData | undefined,
|
||||
): Transaction {
|
||||
let paymentInfo: RefundPaymentInfo | undefined = undefined;
|
||||
|
||||
if (maybeContractData) {
|
||||
paymentInfo = {
|
||||
merchant: maybeContractData.merchant,
|
||||
summary: maybeContractData.summary,
|
||||
summary_i18n: maybeContractData.summaryI18n,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: TransactionType.Refund,
|
||||
amountEffective: refundRecord.amountEffective,
|
||||
@ -666,6 +679,7 @@ function buildTransactionForRefund(
|
||||
extendedStatus: ExtendedStatus.Done,
|
||||
frozen: false,
|
||||
pending: false,
|
||||
paymentInfo,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1022,7 +1036,23 @@ export async function getTransactions(
|
||||
if (shouldSkipCurrency(transactionsRequest, currency)) {
|
||||
return;
|
||||
}
|
||||
transactions.push(buildTransactionForRefund(refundGroup))
|
||||
let contractData: WalletContractData | undefined = undefined;
|
||||
const purchaseTx = await tx.purchases.get(refundGroup.proposalId);
|
||||
if (purchaseTx && purchaseTx.download) {
|
||||
const download = purchaseTx.download;
|
||||
const contractTermsRecord = await tx.contractTerms.get(
|
||||
download.contractTermsHash,
|
||||
);
|
||||
if (!contractTermsRecord) {
|
||||
return;
|
||||
}
|
||||
contractData = extractContractData(
|
||||
contractTermsRecord?.contractTermsRaw,
|
||||
download.contractTermsHash,
|
||||
download.contractTermsMerchantSig,
|
||||
);
|
||||
}
|
||||
transactions.push(buildTransactionForRefund(refundGroup, contractData));
|
||||
});
|
||||
|
||||
tx.refreshGroups.iter().forEachAsync(async (rg) => {
|
||||
|
@ -35,9 +35,6 @@ import {
|
||||
AddExchangeRequest,
|
||||
AddKnownBankAccountsRequest,
|
||||
ApplyDevExperimentRequest,
|
||||
ApplyRefundFromPurchaseIdRequest,
|
||||
AcceptRefundRequest,
|
||||
ApplyRefundResponse,
|
||||
BackupRecovery,
|
||||
BalancesResponse,
|
||||
CancelAbortingTransactionRequest,
|
||||
@ -83,13 +80,13 @@ import {
|
||||
PreparePeerPushCredit,
|
||||
PreparePeerPushCreditResponse,
|
||||
PrepareRefundRequest,
|
||||
PrepareRefundResult,
|
||||
PrepareTipRequest,
|
||||
PrepareTipResult,
|
||||
RecoveryLoadRequest,
|
||||
RetryTransactionRequest,
|
||||
SetCoinSuspendedRequest,
|
||||
SetWalletDeviceIdRequest,
|
||||
StartRefundQueryForUriResponse,
|
||||
StartRefundQueryRequest,
|
||||
TestPayArgs,
|
||||
TestPayResult,
|
||||
@ -110,7 +107,6 @@ import {
|
||||
WithdrawFakebankRequest,
|
||||
WithdrawTestBalanceRequest,
|
||||
WithdrawUriInfoResponse,
|
||||
StartRefundQueryForUriResponse,
|
||||
} from "@gnu-taler/taler-util";
|
||||
import { AuditorTrustRecord, WalletContractData } from "./db.js";
|
||||
import {
|
||||
|
Loading…
Reference in New Issue
Block a user