latest merchant protocol for refunds
This commit is contained in:
parent
880f335ee6
commit
694d913d1f
@ -35,7 +35,6 @@ import {
|
|||||||
initRetryInfo,
|
initRetryInfo,
|
||||||
CoinStatus,
|
CoinStatus,
|
||||||
RefundReason,
|
RefundReason,
|
||||||
RefundEventRecord,
|
|
||||||
RefundState,
|
RefundState,
|
||||||
PurchaseRecord,
|
PurchaseRecord,
|
||||||
} from "../types/dbTypes";
|
} from "../types/dbTypes";
|
||||||
@ -44,10 +43,10 @@ import { parseRefundUri } from "../util/taleruri";
|
|||||||
import { createRefreshGroup, getTotalRefreshCost } from "./refresh";
|
import { createRefreshGroup, getTotalRefreshCost } from "./refresh";
|
||||||
import { Amounts } from "../util/amounts";
|
import { Amounts } from "../util/amounts";
|
||||||
import {
|
import {
|
||||||
codecForMerchantOrderStatus,
|
|
||||||
MerchantCoinRefundStatus,
|
MerchantCoinRefundStatus,
|
||||||
MerchantCoinRefundSuccessStatus,
|
MerchantCoinRefundSuccessStatus,
|
||||||
MerchantCoinRefundFailureStatus,
|
MerchantCoinRefundFailureStatus,
|
||||||
|
codecForMerchantOrderStatusPaid,
|
||||||
} from "../types/talerTypes";
|
} from "../types/talerTypes";
|
||||||
import { guardOperationException } from "./errors";
|
import { guardOperationException } from "./errors";
|
||||||
import { getTimestampNow } from "../util/time";
|
import { getTimestampNow } from "../util/time";
|
||||||
@ -414,14 +413,9 @@ async function processPurchaseQueryRefundImpl(
|
|||||||
|
|
||||||
const refundResponse = await readSuccessResponseJsonOrThrow(
|
const refundResponse = await readSuccessResponseJsonOrThrow(
|
||||||
request,
|
request,
|
||||||
codecForMerchantOrderStatus(),
|
codecForMerchantOrderStatusPaid(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (refundResponse.order_status !== "paid") {
|
|
||||||
logger.error("can't refund unpaid order");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await acceptRefunds(
|
await acceptRefunds(
|
||||||
ws,
|
ws,
|
||||||
proposalId,
|
proposalId,
|
||||||
|
@ -839,15 +839,7 @@ export interface ExchangeRevealResponse {
|
|||||||
ev_sigs: ExchangeRevealItem[];
|
ev_sigs: ExchangeRevealItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MerchantOrderStatus =
|
|
||||||
| MerchantOrderStatusPaid
|
|
||||||
| MerchantOrderStatusUnpaid;
|
|
||||||
|
|
||||||
interface MerchantOrderStatusPaid {
|
interface MerchantOrderStatusPaid {
|
||||||
/**
|
|
||||||
* Has the payment for this order (ever) been completed?
|
|
||||||
*/
|
|
||||||
order_status: "paid";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Was the payment refunded (even partially, via refund or abort)?
|
* Was the payment refunded (even partially, via refund or abort)?
|
||||||
@ -930,11 +922,6 @@ export interface MerchantCoinRefundFailureStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MerchantOrderStatusUnpaid {
|
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.
|
* URI that the wallet must process to complete the payment.
|
||||||
*/
|
*/
|
||||||
@ -1250,7 +1237,6 @@ export const codecForMerchantOrderStatusPaid = (): Codec<
|
|||||||
MerchantOrderStatusPaid
|
MerchantOrderStatusPaid
|
||||||
> =>
|
> =>
|
||||||
makeCodecForObject<MerchantOrderStatusPaid>()
|
makeCodecForObject<MerchantOrderStatusPaid>()
|
||||||
.property("order_status", makeCodecForConstString("paid"))
|
|
||||||
.property("merchant_pub", codecForString)
|
.property("merchant_pub", codecForString)
|
||||||
.property("refund_amount", codecForString)
|
.property("refund_amount", codecForString)
|
||||||
.property("refunded", codecForBoolean)
|
.property("refunded", codecForBoolean)
|
||||||
@ -1261,14 +1247,6 @@ export const codecForMerchantOrderStatusUnpaid = (): Codec<
|
|||||||
MerchantOrderStatusUnpaid
|
MerchantOrderStatusUnpaid
|
||||||
> =>
|
> =>
|
||||||
makeCodecForObject<MerchantOrderStatusUnpaid>()
|
makeCodecForObject<MerchantOrderStatusUnpaid>()
|
||||||
.property("order_status", makeCodecForConstString("unpaid"))
|
|
||||||
.property("taler_pay_uri", codecForString)
|
.property("taler_pay_uri", codecForString)
|
||||||
.property("already_paid_order_id", makeCodecOptional(codecForString))
|
.property("already_paid_order_id", makeCodecOptional(codecForString))
|
||||||
.build("MerchantOrderStatusUnpaid");
|
.build("MerchantOrderStatusUnpaid");
|
||||||
|
|
||||||
export const codecForMerchantOrderStatus = (): Codec<MerchantOrderStatus> =>
|
|
||||||
makeCodecForUnion<MerchantOrderStatus>()
|
|
||||||
.discriminateOn("order_status")
|
|
||||||
.alternative("paid", codecForMerchantOrderStatusPaid())
|
|
||||||
.alternative("unpaid", codecForMerchantOrderStatusUnpaid())
|
|
||||||
.build("MerchantOrderStatus");
|
|
||||||
|
@ -176,6 +176,11 @@ class UnionCodecBuilder<
|
|||||||
const baseCodec = this.baseCodec;
|
const baseCodec = this.baseCodec;
|
||||||
return {
|
return {
|
||||||
decode(x: any, c?: Context): R {
|
decode(x: any, c?: Context): R {
|
||||||
|
if (!c) {
|
||||||
|
c = {
|
||||||
|
path: [`(${objectDisplayName})`],
|
||||||
|
};
|
||||||
|
}
|
||||||
const d = x[discriminator];
|
const d = x[discriminator];
|
||||||
if (d === undefined) {
|
if (d === undefined) {
|
||||||
throw new DecodingError(
|
throw new DecodingError(
|
||||||
|
Loading…
Reference in New Issue
Block a user