repurchase detection

- check that the old transaction is not refunded
 - if the old purchase was deleted fallback to no-repurchase detected
This commit is contained in:
Sebastian 2023-07-10 14:08:05 -03:00
parent 742b00028e
commit d759f08225
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
2 changed files with 12 additions and 13 deletions

View File

@ -539,7 +539,7 @@ async function processDownloadProposal(
} }
// FIXME: Adjust this to account for refunds, don't count as repurchase // FIXME: Adjust this to account for refunds, don't count as repurchase
// if original order is refunded. // if original order is refunded.
if (otherPurchase) { if (otherPurchase && otherPurchase.refundAmountAwaiting === undefined) {
logger.warn("repurchase detected"); logger.warn("repurchase detected");
p.purchaseStatus = PurchaseStatus.RepurchaseDetected; p.purchaseStatus = PurchaseStatus.RepurchaseDetected;
p.repurchaseProposalId = otherPurchase.proposalId; p.repurchaseProposalId = otherPurchase.proposalId;
@ -976,17 +976,16 @@ export async function checkPaymentByProposalId(
} }
if (proposal.purchaseStatus === PurchaseStatus.RepurchaseDetected) { if (proposal.purchaseStatus === PurchaseStatus.RepurchaseDetected) {
const existingProposalId = proposal.repurchaseProposalId; const existingProposalId = proposal.repurchaseProposalId;
if (!existingProposalId) { if (existingProposalId) {
throw Error("invalid proposal state");
}
logger.trace("using existing purchase for same product"); logger.trace("using existing purchase for same product");
proposal = await ws.db const oldProposal = await ws.db
.mktx((x) => [x.purchases]) .mktx((x) => [x.purchases])
.runReadOnly(async (tx) => { .runReadOnly(async (tx) => {
return tx.purchases.get(existingProposalId); return tx.purchases.get(existingProposalId);
}); });
if (!proposal) { if (oldProposal) {
throw Error("existing proposal is in wrong state"); proposal = oldProposal;
}
} }
} }
const d = await expectProposalDownload(ws, proposal); const d = await expectProposalDownload(ws, proposal);

View File

@ -1497,7 +1497,7 @@ export function PurchaseDetails({
{Amounts.isNonZero(price.fee) && ( {Amounts.isNonZero(price.fee) && (
<tr> <tr>
<td> <td>
<i18n.Translate>Transaction fees</i18n.Translate> <i18n.Translate>Fees</i18n.Translate>
</td> </td>
<td> <td>
<Amount value={price.fee} /> <Amount value={price.fee} />