implement refusing proposals

This commit is contained in:
Florian Dold 2019-12-20 01:25:22 +01:00
parent aa37ef082d
commit 378d8dee58
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
8 changed files with 44 additions and 12 deletions

View File

@ -154,6 +154,13 @@ class AndroidWalletMessageHandler {
this.wp.resolve(w);
return {};
}
case "abortProposal": {
const wallet = await this.wp.promise;
if (typeof args.proposalId !== "string") {
throw Error("propsalId must be a string");
}
return await wallet.refuseProposal(args.proposalId);
}
case "getBalances": {
const wallet = await this.wp.promise;
return await wallet.getBalances();
@ -182,7 +189,7 @@ class AndroidWalletMessageHandler {
}
case "preparePay": {
const wallet = await this.wp.promise;
return await wallet.preparePay(args.url);
return await wallet.preparePayForUri(args.url);
break;
}
case "confirmPay": {

View File

@ -40,7 +40,6 @@ export async function runIntegrationTest(args: {
const myWallet = await getDefaultNodeWallet({ httpLib: myHttpLib });
myWallet.runRetryLoop().catch((e) => {
console.error("exception during retry loop:", e);
});
@ -75,7 +74,7 @@ export async function runIntegrationTest(args: {
throw Error("no taler://pay/ URI in payment response");
}
const preparePayResult = await myWallet.preparePay(talerPayUri);
const preparePayResult = await myWallet.preparePayForUri(talerPayUri);
console.log("prepare pay result", preparePayResult);

View File

@ -43,7 +43,7 @@ async function doPay(
payUrl: string,
options: { alwaysYes: boolean } = { alwaysYes: true },
) {
const result = await wallet.preparePay(payUrl);
const result = await wallet.preparePayForUri(payUrl);
if (result.status === "error") {
console.error("Could not pay:", result.error);
process.exit(1);
@ -317,7 +317,7 @@ advancedCli
.requiredArgument("url", clk.STRING)
.action(async args => {
await withWallet(args, async wallet => {
const res = await wallet.preparePay(args.payPrepare.url);
const res = await wallet.preparePayForUri(args.payPrepare.url);
switch (res.status) {
case "error":
console.log("error:", res.error);

View File

@ -91,7 +91,7 @@ async function collectProposalHistory(
case ProposalStatus.PROPOSED:
// no history event needed
break;
case ProposalStatus.REJECTED:
case ProposalStatus.REFUSED:
{
const shortInfo = getOrderShortInfo(proposal);
if (!shortInfo) {

View File

@ -808,7 +808,7 @@ export async function submitPay(
* If the payment is possible, the signature are already generated but not
* yet send to the merchant.
*/
export async function preparePay(
export async function preparePayForUri(
ws: InternalWalletState,
talerPayUri: string,
): Promise<PreparePayResult> {
@ -1018,3 +1018,24 @@ async function processPurchasePayImpl(
logger.trace(`processing purchase pay ${proposalId}`);
await submitPay(ws, proposalId);
}
export async function refuseProposal(ws: InternalWalletState, proposalId: string) {
const success = await ws.db.runWithWriteTransaction([Stores.proposals], async (tx) => {
const proposal = await tx.get(Stores.proposals, proposalId);
if (!proposal) {
logger.trace(`proposal ${proposalId} not found, won't refuse proposal`);
return false ;
}
if (proposal.proposalStatus !== ProposalStatus.PROPOSED) {
return false;
}
proposal.proposalStatus = ProposalStatus.REFUSED;
await tx.put(Stores.proposals, proposal);
return true;
});
if (success) {
ws.notify({
type: NotificationType.Wildcard,
});
}
}

View File

@ -689,7 +689,7 @@ export const enum ProposalStatus {
/**
* The user has rejected the proposal.
*/
REJECTED = "rejected",
REFUSED = "refused",
/**
* Downloaded proposal was detected as a re-purchase.
*/

View File

@ -36,7 +36,8 @@ import {
import {
abortFailedPayment,
preparePay,
preparePayForUri,
refuseProposal,
confirmPay,
processDownloadProposal,
processPurchasePay,
@ -355,8 +356,8 @@ export class Wallet {
* If the payment is possible, the signature are already generated but not
* yet send to the merchant.
*/
async preparePay(talerPayUri: string): Promise<PreparePayResult> {
return preparePay(this.ws, talerPayUri);
async preparePayForUri(talerPayUri: string): Promise<PreparePayResult> {
return preparePayForUri(this.ws, talerPayUri);
}
/**
@ -681,6 +682,10 @@ export class Wallet {
}
}
async refuseProposal(proposalId: string): Promise<void> {
return refuseProposal(this.ws, proposalId);
}
async getPurchaseDetails(hc: string): Promise<PurchaseDetails> {
const purchase = await this.db.get(Stores.purchases, hc);
if (!purchase) {

View File

@ -273,7 +273,7 @@ async function handleMessage(
return diagnostics;
}
case "prepare-pay":
return needsWallet().preparePay(detail.talerPayUri);
return needsWallet().preparePayForUri(detail.talerPayUri);
default:
// Exhaustiveness check.
// See https://www.typescriptlang.org/docs/handbook/advanced-types.html