diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-01-29 16:41:17 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-01-29 16:41:17 +0100 |
commit | 1a66e232a55dff8c889e5554f637f4d4e475179c (patch) | |
tree | e02390f0edfecf5e925d44a71c62056060819886 /src/webex/wxApi.ts | |
parent | c8c03e381e252dc3a73a2c35bb1cd2ee24eeaabb (diff) | |
download | wallet-core-1a66e232a55dff8c889e5554f637f4d4e475179c.tar.gz wallet-core-1a66e232a55dff8c889e5554f637f4d4e475179c.tar.bz2 wallet-core-1a66e232a55dff8c889e5554f637f4d4e475179c.zip |
implement aborting and getting refunds from failed payments
Diffstat (limited to 'src/webex/wxApi.ts')
-rw-r--r-- | src/webex/wxApi.ts | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index a1b0380b9..ee1ca23ba 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -43,7 +43,7 @@ import { } from "../walletTypes"; import { - RefundPermission, + MerchantRefundPermission, TipToken, } from "../talerTypes"; @@ -72,14 +72,22 @@ export interface UpgradeResponse { } +export class WalletApiError extends Error { + constructor(message: string, public detail: any) { + super(message); + } +} + + async function callBackend<T extends MessageType>( type: T, detail: MessageMap[T]["request"], ): Promise<MessageMap[T]["response"]> { return new Promise<MessageMap[T]["response"]>((resolve, reject) => { chrome.runtime.sendMessage({ type, detail }, (resp) => { - if (resp && resp.error) { - reject(resp); + if (typeof resp === "object" && resp && resp.error) { + const e = new WalletApiError(resp.error.message, resp); + reject(e); } else { resolve(resp); } @@ -327,7 +335,7 @@ export function getPurchase(contractTermsHash: string): Promise<PurchaseRecord> * Get the refund fees for a refund permission, including * subsequent refresh and unrefreshable coins. */ -export function getFullRefundFees(args: { refundPermissions: RefundPermission[] }): Promise<AmountJson> { +export function getFullRefundFees(args: { refundPermissions: MerchantRefundPermission[] }): Promise<AmountJson> { return callBackend("get-full-refund-fees", { refundPermissions: args.refundPermissions }); } @@ -374,3 +382,10 @@ export function downloadProposal(url: string): Promise<number> { export function acceptRefund(refundUrl: string): Promise<string> { return callBackend("accept-refund", { refundUrl }); } + +/** + * Abort a failed payment and try to get a refund. + */ +export function abortFailedPayment(contractTermsHash: string) { + return callBackend("abort-failed-payment", { contractTermsHash }); +} |