diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-07-29 23:10:41 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-07-29 23:10:41 +0530 |
commit | c8553f3bc53064d157b56220e9d2333b8931e7a5 (patch) | |
tree | 408159da65252498e7f676d54dbde3c2c3275c0b | |
parent | dfe5e95bc8537e13c482fff42cfefeb090eb2e09 (diff) |
tweaks to pay APIv0.7.1-dev.13
-rw-r--r-- | src/headless/taler-wallet-cli.ts | 7 | ||||
-rw-r--r-- | src/operations/pay.ts | 20 | ||||
-rw-r--r-- | src/types/walletTypes.ts | 9 | ||||
-rw-r--r-- | src/webex/pages/pay.tsx | 12 |
4 files changed, 25 insertions, 23 deletions
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index ed6146a6b..ba629537e 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -60,7 +60,7 @@ async function doPay( ): Promise<void> { const result = await wallet.preparePayForUri(payUrl); if (result.status === PreparePayResultType.InsufficientBalance) { - console.log("contract", result.contractTermsRaw); + console.log("contract", result.contractTerms); console.error("insufficient balance"); process.exit(1); return; @@ -80,8 +80,9 @@ async function doPay( } else { throw Error("not reached"); } - console.log("contract", result.contractTermsRaw); - console.log("total fees:", Amounts.stringify(result.totalFees)); + console.log("contract", result.contractTerms); + console.log("raw amount:", result.amountRaw); + console.log("effective amount:", result.amountEffective); let pay; if (options.alwaysYes) { pay = true; diff --git a/src/operations/pay.ts b/src/operations/pay.ts index 08bbe43a1..c2877da64 100644 --- a/src/operations/pay.ts +++ b/src/operations/pay.ts @@ -915,26 +915,26 @@ export async function preparePayForUri( console.log("not confirming payment, insufficient coins"); return { status: PreparePayResultType.InsufficientBalance, - contractTermsRaw: d.contractTermsRaw, + contractTerms: d.contractTermsRaw, proposalId: proposal.proposalId, }; } const costInfo = await getTotalPaymentCost(ws, res); - console.log("costInfo", costInfo); - console.log("coinsForPayment", res); - const totalFees = Amounts.sub(costInfo.totalCost, res.paymentAmount).amount; + logger.trace("costInfo", costInfo); + logger.trace("coinsForPayment", res); return { status: PreparePayResultType.PaymentPossible, - contractTermsRaw: d.contractTermsRaw, + contractTerms: d.contractTermsRaw, proposalId: proposal.proposalId, - totalFees, + amountEffective: Amounts.stringify(costInfo.totalCost), + amountRaw: Amounts.stringify(res.paymentAmount), }; } if (purchase.lastSessionId !== uriResult.sessionId) { - console.log( + logger.trace( "automatically re-submitting payment with different session ID", ); await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => { @@ -948,20 +948,20 @@ export async function preparePayForUri( const r = await submitPay(ws, proposalId); return { status: PreparePayResultType.AlreadyConfirmed, - contractTermsRaw: purchase.contractTermsRaw, + contractTerms: purchase.contractTermsRaw, paid: true, nextUrl: r.nextUrl, }; } else if (!purchase.timestampFirstSuccessfulPay) { return { status: PreparePayResultType.AlreadyConfirmed, - contractTermsRaw: purchase.contractTermsRaw, + contractTerms: purchase.contractTermsRaw, paid: false, }; } else if (purchase.paymentSubmitPending) { return { status: PreparePayResultType.AlreadyConfirmed, - contractTermsRaw: purchase.contractTermsRaw, + contractTerms: purchase.contractTermsRaw, paid: false, }; } diff --git a/src/types/walletTypes.ts b/src/types/walletTypes.ts index a6bc26d88..9f0bfaf37 100644 --- a/src/types/walletTypes.ts +++ b/src/types/walletTypes.ts @@ -329,19 +329,20 @@ export type PreparePayResult = export interface PreparePayResultPaymentPossible { status: PreparePayResultType.PaymentPossible; proposalId: string; - contractTermsRaw: string; - totalFees: AmountJson; + contractTerms: string; + amountRaw: string; + amountEffective: string; } export interface PreparePayResultInsufficientBalance { status: PreparePayResultType.InsufficientBalance; proposalId: string; - contractTermsRaw: any; + contractTerms: any; } export interface PreparePayResultAlreadyConfirmed { status: PreparePayResultType.AlreadyConfirmed; - contractTermsRaw: any; + contractTerms: any; paid: boolean; // Only specified if paid. nextUrl?: string; diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx index 87f3c83d3..d255ab6e5 100644 --- a/src/webex/pages/pay.tsx +++ b/src/webex/pages/pay.tsx @@ -39,7 +39,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { const [payErrMsg, setPayErrMsg] = useState<string | undefined>(""); const [numTries, setNumTries] = useState(0); const [loading, setLoading] = useState(false); - let totalFees: Amounts.AmountJson | undefined = undefined; + let amountEffective: Amounts.AmountJson | undefined = undefined; useEffect(() => { const doFetch = async (): Promise<void> => { @@ -59,7 +59,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { } if (payStatus.status === "payment-possible") { - totalFees = payStatus.totalFees; + amountEffective = Amounts.parseOrThrow(payStatus.amountEffective); } if (payStatus.status === PreparePayResultType.AlreadyConfirmed && numTries === 0) { @@ -75,13 +75,13 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { try { contractTerms = codecForContractTerms().decode( - JSON.parse(payStatus.contractTermsRaw), + JSON.parse(payStatus.contractTerms), ); } catch (e) { // This should never happen, as the wallet is supposed to check the contract terms // before storing them. console.error(e); - console.log("raw contract terms were", payStatus.contractTermsRaw); + console.log("raw contract terms were", payStatus.contractTerms); return <span>Invalid contract terms.</span>; } @@ -129,10 +129,10 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { <div style={{ textAlign: "center" }}> <strong>{contractTerms.summary}</strong> </div> - {totalFees ? ( + {amountEffective ? ( <i18n.Translate wrap="p"> The total price is <span>{amount} </span> - (plus <span>{renderAmount(totalFees)}</span> fees). + (plus <span>{renderAmount(amountEffective)}</span> fees). </i18n.Translate> ) : ( <i18n.Translate wrap="p"> |