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