summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r--packages/taler-wallet-core/src/operations/pay.ts8
-rw-r--r--packages/taler-wallet-core/src/types/walletTypes.ts9
2 files changed, 13 insertions, 4 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay.ts b/packages/taler-wallet-core/src/operations/pay.ts
index db5a56d18..0576f7eab 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -980,17 +980,17 @@ export async function preparePayForUri(
amountRaw: Amounts.stringify(purchase.contractData.amount),
amountEffective: Amounts.stringify(purchase.payCostInfo.totalCost),
};
- } else if (purchase.paymentSubmitPending) {
+ } else {
+ const paid = !purchase.paymentSubmitPending;
return {
status: PreparePayResultType.AlreadyConfirmed,
contractTerms: JSON.parse(purchase.contractTermsRaw),
- paid: false,
+ paid,
amountRaw: Amounts.stringify(purchase.contractData.amount),
amountEffective: Amounts.stringify(purchase.payCostInfo.totalCost),
+ ...(paid ? { nextUrl: purchase.contractData.orderId } : {}),
};
}
- // FIXME: we don't handle aborted payments correctly here.
- throw Error("BUG: invariant violation (purchase status)");
}
/**
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts b/packages/taler-wallet-core/src/types/walletTypes.ts
index 7a648dd56..ec57e7d2a 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -48,6 +48,7 @@ import {
codecForBoolean,
codecForConstString,
codecForAny,
+ buildCodecForUnion,
} from "../util/codec";
import { AmountString, codecForContractTerms } from "./talerTypes";
import { TransactionError } from "./transactions";
@@ -399,6 +400,14 @@ export const codecForPreparePayResultAlreadyConfirmed = (): Codec<
.property("contractTerms", codecForAny())
.build("PreparePayResultAlreadyConfirmed");
+export const codecForPreparePayResult = (): Codec<PreparePayResult> =>
+ buildCodecForUnion<PreparePayResult>()
+ .discriminateOn("status")
+ .alternative(PreparePayResultType.AlreadyConfirmed, codecForPreparePayResultAlreadyConfirmed())
+ .alternative(PreparePayResultType.InsufficientBalance, codecForPreparePayResultInsufficientBalance())
+ .alternative(PreparePayResultType.PaymentPossible, codecForPreparePayResultPaymentPossible())
+ .build("PreparePayResult");
+
export type PreparePayResult =
| PreparePayResultInsufficientBalance
| PreparePayResultAlreadyConfirmed