fix re-purchase detection

This commit is contained in:
Florian Dold 2019-12-06 00:56:31 +01:00
parent 65bccbd139
commit c8c84911ce
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 22 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import { Logger } from "../util/logging";
import * as Amounts from "../util/amounts"; import * as Amounts from "../util/amounts";
import { decodeCrock } from "../crypto/talerCrypto"; import { decodeCrock } from "../crypto/talerCrypto";
import { OperationFailedAndReportedError } from "../wallet-impl/errors"; import { OperationFailedAndReportedError } from "../wallet-impl/errors";
import { Bank } from "./bank";
const logger = new Logger("taler-wallet-cli.ts"); const logger = new Logger("taler-wallet-cli.ts");
@ -434,6 +435,23 @@ testCli
console.log(tipUri); console.log(tipUri);
}); });
testCli
.subcommand("genWithdrawUri", "gen-withdraw-uri", {
help: "Generate a taler://withdraw URI.",
})
.requiredOption("amount", ["-a", "--amount"], clk.STRING, {
default: "TESTKUDOS:20",
})
.requiredOption("bank", ["-b", "--bank"], clk.STRING, {
default: "https://bank.test.taler.net/",
})
.action(async (args) => {
const b = new Bank(args.genWithdrawUri.bank);
const user = await b.registerRandomUser();
const url = await b.generateWithdrawUri(user, args.genWithdrawUri.amount);
console.log(url);
});
testCli testCli
.subcommand("genRefundUri", "gen-refund-uri", { .subcommand("genRefundUri", "gen-refund-uri", {
help: "Generate a taler://refund URI.", help: "Generate a taler://refund URI.",

View File

@ -593,6 +593,7 @@ async function processDownloadProposalImpl(
fulfillmentUrl, fulfillmentUrl,
); );
if (differentPurchase) { if (differentPurchase) {
console.log("repurchase detected");
p.proposalStatus = ProposalStatus.REPURCHASE; p.proposalStatus = ProposalStatus.REPURCHASE;
p.repurchaseProposalId = differentPurchase.proposalId; p.repurchaseProposalId = differentPurchase.proposalId;
await tx.put(Stores.proposals, p); await tx.put(Stores.proposals, p);
@ -756,7 +757,7 @@ export async function preparePay(
}; };
} }
const proposalId = await startDownloadProposal( let proposalId = await startDownloadProposal(
ws, ws,
uriResult.downloadUrl, uriResult.downloadUrl,
uriResult.sessionId, uriResult.sessionId,
@ -771,6 +772,7 @@ export async function preparePay(
if (!existingProposalId) { if (!existingProposalId) {
throw Error("invalid proposal state"); throw Error("invalid proposal state");
} }
console.log("using existing purchase for same product");
proposal = await oneShotGet(ws.db, Stores.proposals, existingProposalId); proposal = await oneShotGet(ws.db, Stores.proposals, existingProposalId);
if (!proposal) { if (!proposal) {
throw Error("existing proposal is in wrong state"); throw Error("existing proposal is in wrong state");
@ -787,7 +789,7 @@ export async function preparePay(
throw Error("BUG: proposal is in invalid state"); throw Error("BUG: proposal is in invalid state");
} }
console.log("proposal", proposal); proposalId = proposal.proposalId;
// First check if we already payed for it. // First check if we already payed for it.
const purchase = await oneShotGet(ws.db, Stores.purchases, proposalId); const purchase = await oneShotGet(ws.db, Stores.purchases, proposalId);