refund awating is empty when puchase is paid, returning last refund id

This commit is contained in:
Sebastian 2023-02-20 13:23:49 -03:00
parent 26aca142fe
commit 5ad96b178e
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1

View File

@ -2321,7 +2321,6 @@ async function acceptRefunds(
}
const refreshCoinsMap: Record<string, CoinRefreshRequest> = {};
for (const refundStatus of refunds) {
const refundKey = getRefundKey(refundStatus);
const existingRefundInfo = p.refunds[refundKey];
@ -2412,6 +2411,7 @@ async function acceptRefunds(
}
} else if (p.purchaseStatus === PurchaseStatus.QueryingRefund) {
p.purchaseStatus = PurchaseStatus.Paid;
p.refundAmountAwaiting = undefined;
}
logger.trace("refund query done");
ws.notify({
@ -2572,10 +2572,26 @@ export async function applyRefundFromPurchaseId(
const summary = await calculateRefundSummary(ws, purchase);
const download = await expectProposalDownload(ws, purchase);
const lastExec = Object.values(purchase.refunds).reduce(
(prev, cur) => {
return TalerProtocolTimestamp.max(cur.executionTime, prev);
},
{ t_s: 0 } as TalerProtocolTimestamp,
);
const transactionId =
lastExec.t_s === "never" || lastExec.t_s === 0
? makeTransactionId(TransactionType.Payment, proposalId)
: makeTransactionId(
TransactionType.Refund,
proposalId,
String(lastExec.t_s),
);
return {
contractTermsHash: download.contractData.contractTermsHash,
proposalId: purchase.proposalId,
transactionId: makeTransactionId(TransactionType.Payment, proposalId), //FIXME: can we have the tx id of the refund
transactionId,
amountEffectivePaid: Amounts.stringify(summary.amountEffectivePaid),
amountRefundGone: Amounts.stringify(summary.amountRefundGone),
amountRefundGranted: Amounts.stringify(summary.amountRefundGranted),