towards the improved confirmPay API

This commit is contained in:
Florian Dold 2020-08-11 17:32:11 +05:30
parent 172a51a43a
commit ff3f965661
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 31 additions and 3 deletions

View File

@ -49,6 +49,7 @@ import {
PreparePayResult, PreparePayResult,
RefreshReason, RefreshReason,
PreparePayResultType, PreparePayResultType,
ConfirmPayResultType,
} from "../types/walletTypes"; } from "../types/walletTypes";
import * as Amounts from "../util/amounts"; import * as Amounts from "../util/amounts";
import { AmountJson } from "../util/amounts"; import { AmountJson } from "../util/amounts";
@ -853,7 +854,10 @@ export async function submitPay(
lastSessionId: sessionId, lastSessionId: sessionId,
}; };
return { nextUrl }; return {
type: ConfirmPayResultType.Done,
nextUrl,
};
} }
/** /**
@ -957,6 +961,9 @@ export async function preparePayForUri(
await tx.put(Stores.purchases, p); await tx.put(Stores.purchases, p);
}); });
const r = await submitPay(ws, proposalId); const r = await submitPay(ws, proposalId);
if (r.type !== ConfirmPayResultType.Done) {
throw Error("submitting pay failed");
}
return { return {
status: PreparePayResultType.AlreadyConfirmed, status: PreparePayResultType.AlreadyConfirmed,
contractTerms: JSON.parse(purchase.contractTermsRaw), contractTerms: JSON.parse(purchase.contractTermsRaw),

View File

@ -53,7 +53,7 @@ export interface TransactionsResponse {
transactions: Transaction[]; transactions: Transaction[];
} }
interface TransactionError { export interface TransactionError {
/** /**
* TALER_EC_* unique error code. * TALER_EC_* unique error code.
* The action(s) offered and message displayed on the transaction item depend on this code. * The action(s) offered and message displayed on the transaction item depend on this code.

View File

@ -45,6 +45,7 @@ import {
} from "../util/codec"; } from "../util/codec";
import { AmountString } from "./talerTypes"; import { AmountString } from "./talerTypes";
import { codec } from ".."; import { codec } from "..";
import { TransactionError } from "./transactions";
/** /**
* Response for the create reserve request to the wallet. * Response for the create reserve request to the wallet.
@ -192,13 +193,30 @@ export function mkAmount(
return { value, fraction, currency }; return { value, fraction, currency };
} }
export const enum ConfirmPayResultType {
Done = "done",
Pending = "pending",
}
/** /**
* Result for confirmPay * Result for confirmPay
*/ */
export interface ConfirmPayResult { export interface ConfirmPayResultDone {
type: ConfirmPayResultType.Done,
nextUrl: string; nextUrl: string;
} }
export interface ConfirmPayResultPending {
type: ConfirmPayResultType.Pending,
lastError: TransactionError;
}
export type ConfirmPayResult =
| ConfirmPayResultDone
| ConfirmPayResultPending
/** /**
* Information about all sender wire details known to the wallet, * Information about all sender wire details known to the wallet,
* as well as exchanges that accept these wire types. * as well as exchanges that accept these wire types.

View File

@ -109,6 +109,9 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
try { try {
setLoading(true); setLoading(true);
const res = await wxApi.confirmPay(proposalId, undefined); const res = await wxApi.confirmPay(proposalId, undefined);
if (res.type !== walletTypes.ConfirmPayResultType.Done) {
throw Error("payment pending");
}
document.location.href = res.nextUrl; document.location.href = res.nextUrl;
} catch (e) { } catch (e) {
console.error(e); console.error(e);