summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-27 13:36:32 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-27 13:36:32 +0530
commit694d913d1f226b3d284258286c73a035fd43da7d (patch)
tree20bb4f1e2d4eddb9720b4700c99ebf0803b3fbaa
parent880f335ee648743f6e58918b5a62b42c4f0962bb (diff)
downloadwallet-core-694d913d1f226b3d284258286c73a035fd43da7d.tar.gz
wallet-core-694d913d1f226b3d284258286c73a035fd43da7d.tar.bz2
wallet-core-694d913d1f226b3d284258286c73a035fd43da7d.zip
latest merchant protocol for refunds
-rw-r--r--src/operations/refund.ts10
-rw-r--r--src/types/talerTypes.ts22
-rw-r--r--src/util/codec.ts5
3 files changed, 7 insertions, 30 deletions
diff --git a/src/operations/refund.ts b/src/operations/refund.ts
index b91d42a3..35384c08 100644
--- a/src/operations/refund.ts
+++ b/src/operations/refund.ts
@@ -35,7 +35,6 @@ import {
initRetryInfo,
CoinStatus,
RefundReason,
- RefundEventRecord,
RefundState,
PurchaseRecord,
} from "../types/dbTypes";
@@ -44,10 +43,10 @@ import { parseRefundUri } from "../util/taleruri";
import { createRefreshGroup, getTotalRefreshCost } from "./refresh";
import { Amounts } from "../util/amounts";
import {
- codecForMerchantOrderStatus,
MerchantCoinRefundStatus,
MerchantCoinRefundSuccessStatus,
MerchantCoinRefundFailureStatus,
+ codecForMerchantOrderStatusPaid,
} from "../types/talerTypes";
import { guardOperationException } from "./errors";
import { getTimestampNow } from "../util/time";
@@ -414,14 +413,9 @@ async function processPurchaseQueryRefundImpl(
const refundResponse = await readSuccessResponseJsonOrThrow(
request,
- codecForMerchantOrderStatus(),
+ codecForMerchantOrderStatusPaid(),
);
- if (refundResponse.order_status !== "paid") {
- logger.error("can't refund unpaid order");
- return;
- }
-
await acceptRefunds(
ws,
proposalId,
diff --git a/src/types/talerTypes.ts b/src/types/talerTypes.ts
index 2730da4b..1dfcd80a 100644
--- a/src/types/talerTypes.ts
+++ b/src/types/talerTypes.ts
@@ -839,15 +839,7 @@ export interface ExchangeRevealResponse {
ev_sigs: ExchangeRevealItem[];
}
-export type MerchantOrderStatus =
- | MerchantOrderStatusPaid
- | MerchantOrderStatusUnpaid;
-
interface MerchantOrderStatusPaid {
- /**
- * Has the payment for this order (ever) been completed?
- */
- order_status: "paid";
/**
* Was the payment refunded (even partially, via refund or abort)?
@@ -931,11 +923,6 @@ export interface MerchantCoinRefundFailureStatus {
export interface MerchantOrderStatusUnpaid {
/**
- * Has the payment for this order (ever) been completed?
- */
- order_status: "unpaid";
-
- /**
* URI that the wallet must process to complete the payment.
*/
taler_pay_uri: string;
@@ -1250,7 +1237,6 @@ export const codecForMerchantOrderStatusPaid = (): Codec<
MerchantOrderStatusPaid
> =>
makeCodecForObject<MerchantOrderStatusPaid>()
- .property("order_status", makeCodecForConstString("paid"))
.property("merchant_pub", codecForString)
.property("refund_amount", codecForString)
.property("refunded", codecForBoolean)
@@ -1261,14 +1247,6 @@ export const codecForMerchantOrderStatusUnpaid = (): Codec<
MerchantOrderStatusUnpaid
> =>
makeCodecForObject<MerchantOrderStatusUnpaid>()
- .property("order_status", makeCodecForConstString("unpaid"))
.property("taler_pay_uri", codecForString)
.property("already_paid_order_id", makeCodecOptional(codecForString))
.build("MerchantOrderStatusUnpaid");
-
-export const codecForMerchantOrderStatus = (): Codec<MerchantOrderStatus> =>
- makeCodecForUnion<MerchantOrderStatus>()
- .discriminateOn("order_status")
- .alternative("paid", codecForMerchantOrderStatusPaid())
- .alternative("unpaid", codecForMerchantOrderStatusUnpaid())
- .build("MerchantOrderStatus");
diff --git a/src/util/codec.ts b/src/util/codec.ts
index c468704b..383a2d99 100644
--- a/src/util/codec.ts
+++ b/src/util/codec.ts
@@ -176,6 +176,11 @@ class UnionCodecBuilder<
const baseCodec = this.baseCodec;
return {
decode(x: any, c?: Context): R {
+ if (!c) {
+ c = {
+ path: [`(${objectDisplayName})`],
+ };
+ }
const d = x[discriminator];
if (d === undefined) {
throw new DecodingError(