implement refusing proposals
This commit is contained in:
parent
aa37ef082d
commit
378d8dee58
@ -154,6 +154,13 @@ class AndroidWalletMessageHandler {
|
|||||||
this.wp.resolve(w);
|
this.wp.resolve(w);
|
||||||
return {};
|
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": {
|
case "getBalances": {
|
||||||
const wallet = await this.wp.promise;
|
const wallet = await this.wp.promise;
|
||||||
return await wallet.getBalances();
|
return await wallet.getBalances();
|
||||||
@ -182,7 +189,7 @@ class AndroidWalletMessageHandler {
|
|||||||
}
|
}
|
||||||
case "preparePay": {
|
case "preparePay": {
|
||||||
const wallet = await this.wp.promise;
|
const wallet = await this.wp.promise;
|
||||||
return await wallet.preparePay(args.url);
|
return await wallet.preparePayForUri(args.url);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "confirmPay": {
|
case "confirmPay": {
|
||||||
|
@ -40,7 +40,6 @@ export async function runIntegrationTest(args: {
|
|||||||
|
|
||||||
const myWallet = await getDefaultNodeWallet({ httpLib: myHttpLib });
|
const myWallet = await getDefaultNodeWallet({ httpLib: myHttpLib });
|
||||||
|
|
||||||
|
|
||||||
myWallet.runRetryLoop().catch((e) => {
|
myWallet.runRetryLoop().catch((e) => {
|
||||||
console.error("exception during retry loop:", 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");
|
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);
|
console.log("prepare pay result", preparePayResult);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ async function doPay(
|
|||||||
payUrl: string,
|
payUrl: string,
|
||||||
options: { alwaysYes: boolean } = { alwaysYes: true },
|
options: { alwaysYes: boolean } = { alwaysYes: true },
|
||||||
) {
|
) {
|
||||||
const result = await wallet.preparePay(payUrl);
|
const result = await wallet.preparePayForUri(payUrl);
|
||||||
if (result.status === "error") {
|
if (result.status === "error") {
|
||||||
console.error("Could not pay:", result.error);
|
console.error("Could not pay:", result.error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -317,7 +317,7 @@ advancedCli
|
|||||||
.requiredArgument("url", clk.STRING)
|
.requiredArgument("url", clk.STRING)
|
||||||
.action(async args => {
|
.action(async args => {
|
||||||
await withWallet(args, async wallet => {
|
await withWallet(args, async wallet => {
|
||||||
const res = await wallet.preparePay(args.payPrepare.url);
|
const res = await wallet.preparePayForUri(args.payPrepare.url);
|
||||||
switch (res.status) {
|
switch (res.status) {
|
||||||
case "error":
|
case "error":
|
||||||
console.log("error:", res.error);
|
console.log("error:", res.error);
|
||||||
|
@ -91,7 +91,7 @@ async function collectProposalHistory(
|
|||||||
case ProposalStatus.PROPOSED:
|
case ProposalStatus.PROPOSED:
|
||||||
// no history event needed
|
// no history event needed
|
||||||
break;
|
break;
|
||||||
case ProposalStatus.REJECTED:
|
case ProposalStatus.REFUSED:
|
||||||
{
|
{
|
||||||
const shortInfo = getOrderShortInfo(proposal);
|
const shortInfo = getOrderShortInfo(proposal);
|
||||||
if (!shortInfo) {
|
if (!shortInfo) {
|
||||||
|
@ -808,7 +808,7 @@ export async function submitPay(
|
|||||||
* If the payment is possible, the signature are already generated but not
|
* If the payment is possible, the signature are already generated but not
|
||||||
* yet send to the merchant.
|
* yet send to the merchant.
|
||||||
*/
|
*/
|
||||||
export async function preparePay(
|
export async function preparePayForUri(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
talerPayUri: string,
|
talerPayUri: string,
|
||||||
): Promise<PreparePayResult> {
|
): Promise<PreparePayResult> {
|
||||||
@ -1018,3 +1018,24 @@ async function processPurchasePayImpl(
|
|||||||
logger.trace(`processing purchase pay ${proposalId}`);
|
logger.trace(`processing purchase pay ${proposalId}`);
|
||||||
await submitPay(ws, 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -689,7 +689,7 @@ export const enum ProposalStatus {
|
|||||||
/**
|
/**
|
||||||
* The user has rejected the proposal.
|
* The user has rejected the proposal.
|
||||||
*/
|
*/
|
||||||
REJECTED = "rejected",
|
REFUSED = "refused",
|
||||||
/**
|
/**
|
||||||
* Downloaded proposal was detected as a re-purchase.
|
* Downloaded proposal was detected as a re-purchase.
|
||||||
*/
|
*/
|
||||||
|
@ -36,7 +36,8 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
abortFailedPayment,
|
abortFailedPayment,
|
||||||
preparePay,
|
preparePayForUri,
|
||||||
|
refuseProposal,
|
||||||
confirmPay,
|
confirmPay,
|
||||||
processDownloadProposal,
|
processDownloadProposal,
|
||||||
processPurchasePay,
|
processPurchasePay,
|
||||||
@ -355,8 +356,8 @@ export class Wallet {
|
|||||||
* If the payment is possible, the signature are already generated but not
|
* If the payment is possible, the signature are already generated but not
|
||||||
* yet send to the merchant.
|
* yet send to the merchant.
|
||||||
*/
|
*/
|
||||||
async preparePay(talerPayUri: string): Promise<PreparePayResult> {
|
async preparePayForUri(talerPayUri: string): Promise<PreparePayResult> {
|
||||||
return preparePay(this.ws, talerPayUri);
|
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> {
|
async getPurchaseDetails(hc: string): Promise<PurchaseDetails> {
|
||||||
const purchase = await this.db.get(Stores.purchases, hc);
|
const purchase = await this.db.get(Stores.purchases, hc);
|
||||||
if (!purchase) {
|
if (!purchase) {
|
||||||
|
@ -273,7 +273,7 @@ async function handleMessage(
|
|||||||
return diagnostics;
|
return diagnostics;
|
||||||
}
|
}
|
||||||
case "prepare-pay":
|
case "prepare-pay":
|
||||||
return needsWallet().preparePay(detail.talerPayUri);
|
return needsWallet().preparePayForUri(detail.talerPayUri);
|
||||||
default:
|
default:
|
||||||
// Exhaustiveness check.
|
// Exhaustiveness check.
|
||||||
// See https://www.typescriptlang.org/docs/handbook/advanced-types.html
|
// See https://www.typescriptlang.org/docs/handbook/advanced-types.html
|
||||||
|
Loading…
Reference in New Issue
Block a user