From 71abddec5e3dc9cc407f468feaaa3284ef528aba Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 9 Sep 2020 12:45:49 +0530 Subject: make withdrawal, pay and refunds work in the WebExtension --- .../taler-wallet-core/src/operations/refund.ts | 10 +++++++++ .../taler-wallet-core/src/types/walletTypes.ts | 4 ++++ packages/taler-wallet-core/src/util/amounts.ts | 3 ++- packages/taler-wallet-core/src/wallet.ts | 5 ++--- .../taler-wallet-webextension/src/pages/refund.tsx | 25 +++++++++++----------- packages/taler-wallet-webextension/src/wxApi.ts | 3 ++- .../taler-wallet-webextension/src/wxBackend.ts | 10 ++++++--- .../taler-wallet-webextension/static/refund.html | 8 +++---- .../static/return-coins.html | 16 -------------- 9 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 packages/taler-wallet-webextension/static/return-coins.html diff --git a/packages/taler-wallet-core/src/operations/refund.ts b/packages/taler-wallet-core/src/operations/refund.ts index 10a57f909..ff08fc93d 100644 --- a/packages/taler-wallet-core/src/operations/refund.ts +++ b/packages/taler-wallet-core/src/operations/refund.ts @@ -527,6 +527,16 @@ export async function applyRefund( amountRefundGone: Amounts.stringify(amountRefundGone), amountRefundGranted: Amounts.stringify(amountRefundGranted), pendingAtExchange, + info: { + contractTermsHash: purchase.contractData.contractTermsHash, + merchant: purchase.contractData.merchant, + orderId: purchase.contractData.orderId, + products: purchase.contractData.products, + summary: purchase.contractData.summary, + fulfillmentMessage: purchase.contractData.fulfillmentMessage, + summary_i18n: purchase.contractData.summaryI18n, + fulfillmentMessage_i18n: purchase.contractData.fulfillmentMessageI18n, + } }; } diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts index b8d8be668..1b20d7b47 100644 --- a/packages/taler-wallet-core/src/types/walletTypes.ts +++ b/packages/taler-wallet-core/src/types/walletTypes.ts @@ -55,6 +55,7 @@ import { codecForContractTerms, ContractTerms, } from "./talerTypes"; +import { OrderShortInfo, codecForOrderShortInfo } from "./transactions"; /** * Response for the create reserve request to the wallet. @@ -880,6 +881,8 @@ export interface ApplyRefundResponse { amountRefundGone: AmountString; pendingAtExchange: boolean; + + info: OrderShortInfo; } export const codecForApplyRefundResponse = (): Codec => @@ -890,6 +893,7 @@ export const codecForApplyRefundResponse = (): Codec => .property("contractTermsHash", codecForString()) .property("pendingAtExchange", codecForBoolean()) .property("proposalId", codecForString()) + .property("info", codecForOrderShortInfo()) .build("ApplyRefundResponse"); export interface SetCoinSuspendedRequest { diff --git a/packages/taler-wallet-core/src/util/amounts.ts b/packages/taler-wallet-core/src/util/amounts.ts index 533005b18..e6bee2d1d 100644 --- a/packages/taler-wallet-core/src/util/amounts.ts +++ b/packages/taler-wallet-core/src/util/amounts.ts @@ -257,7 +257,8 @@ export function isNonZero(a: AmountJson): boolean { return a.value > 0 || a.fraction > 0; } -export function isZero(a: AmountJson): boolean { +export function isZero(a: AmountLike): boolean { + a = jsonifyAmount(a); return a.value === 0 && a.fraction === 0; } diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 768d5eb0f..1140a13c3 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -70,7 +70,6 @@ import { AcceptManualWithdrawalResult, BalancesResponse, TestPayArgs, - PreparePayResultType, IntegrationTestArgs, codecForAddExchangeRequest, codecForGetWithdrawalDetailsForUri, @@ -80,7 +79,6 @@ import { codecForApplyRefundRequest, codecForAcceptBankIntegratedWithdrawalRequest, codecForGetExchangeTosRequest, - codecForAbortProposalRequest, codecForConfirmPayRequest, CoreApiResponse, codecForPreparePayRequest, @@ -95,6 +93,7 @@ import { codecForPrepareTipRequest, codecForAcceptTipRequest, codecForAbortPayWithRefundRequest, + ApplyRefundResponse, } from "./types/walletTypes"; import { Logger } from "./util/logging"; @@ -723,7 +722,7 @@ export class Wallet { */ async applyRefund( talerRefundUri: string, - ): Promise<{ contractTermsHash: string; proposalId: string }> { + ): Promise { return applyRefund(this.ws, talerRefundUri); } diff --git a/packages/taler-wallet-webextension/src/pages/refund.tsx b/packages/taler-wallet-webextension/src/pages/refund.tsx index 1ace50226..74c33c020 100644 --- a/packages/taler-wallet-webextension/src/pages/refund.tsx +++ b/packages/taler-wallet-webextension/src/pages/refund.tsx @@ -23,22 +23,17 @@ import React, { useEffect, useState } from "react"; import * as wxApi from "../wxApi"; import { AmountView } from "../renderHtml"; -import { PurchaseDetails } from "taler-wallet-core"; +import { PurchaseDetails, ApplyRefundResponse, Amounts } from "taler-wallet-core"; function RefundStatusView(props: { talerRefundUri: string }): JSX.Element { - const [applied, setApplied] = useState(false); - const [purchaseDetails, setPurchaseDetails] = useState< - PurchaseDetails | undefined - >(undefined); + const [applyResult, setApplyResult] = useState(); const [errMsg, setErrMsg] = useState(undefined); useEffect(() => { const doFetch = async (): Promise => { try { const result = await wxApi.applyRefund(props.talerRefundUri); - setApplied(true); - // const r = await wxApi.getPurchaseDetails(result.proposalId); - // setPurchaseDetails(r); + setApplyResult(result); } catch (e) { console.error(e); setErrMsg(e.message); @@ -54,7 +49,7 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element { return Error: {errMsg}; } - if (!applied || !purchaseDetails) { + if (!applyResult) { return Updating refund status; } @@ -62,11 +57,15 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element { <>

Refund Status

- The product {purchaseDetails.contractTerms.summary} has - received a total refund of{" "} - . + The product {applyResult.info.summary} has + received a total effective refund of{" "} + .

-

Note that additional fees from the exchange may apply.

+ {applyResult.pendingAtExchange ?

Refund processing is still in progress.

: null} + {!Amounts.isZero(applyResult.amountRefundGone) ?

+ The refund amount of + could not be applied. +

: null} ); } diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index 9bc4a08e6..9b7697c99 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -32,6 +32,7 @@ import { GetWithdrawalDetailsForUriRequest, WithdrawUriInfoResponse, TransactionsResponse, + ApplyRefundResponse, } from "taler-wallet-core"; export interface ExtendedPermissionsResponse { @@ -131,7 +132,7 @@ export function getTransactions(): Promise { */ export function applyRefund( talerRefundUri: string, -): Promise<{ contractTermsHash: string; proposalId: string }> { +): Promise { return callBackend("applyRefund", { talerRefundUri }); } diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index a77b173fe..e1dcdde49 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -203,7 +203,7 @@ function makeSyncWalletRedirect( oldUrl: string, params?: { [name: string]: string | undefined }, ): Record { - const innerUrl = new URL(chrome.extension.getURL("/" + url)); + const innerUrl = new URL(chrome.extension.getURL(url)); if (params) { for (const key in params) { const p = params[key]; @@ -296,7 +296,11 @@ function headerListener( return; } console.log("in header listener"); - if (details.statusCode === 402 || details.statusCode === 202) { + if ( + details.statusCode === 402 || + details.statusCode === 202 || + details.statusCode === 200 + ) { console.log(`got 402/202 from ${details.url}`); for (const header of details.responseHeaders || []) { if (header.name.toLowerCase() === "taler") { @@ -332,7 +336,7 @@ function headerListener( ); case TalerUriType.TalerRefund: return makeSyncWalletRedirect( - "refund.html", + "/static/refund.html", details.tabId, details.url, { diff --git a/packages/taler-wallet-webextension/static/refund.html b/packages/taler-wallet-webextension/static/refund.html index 3c1d78a24..68c826bcf 100644 --- a/packages/taler-wallet-webextension/static/refund.html +++ b/packages/taler-wallet-webextension/static/refund.html @@ -4,10 +4,10 @@ Taler Wallet: Refund Status - - - - + + + + diff --git a/packages/taler-wallet-webextension/static/return-coins.html b/packages/taler-wallet-webextension/static/return-coins.html deleted file mode 100644 index 90703b447..000000000 --- a/packages/taler-wallet-webextension/static/return-coins.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Taler Wallet: Return Coins to Bank Account - - - - - - - - -
- - -- cgit v1.2.3