diff options
-rw-r--r-- | src/headless/integrationtest.ts | 2 | ||||
-rw-r--r-- | src/headless/taler-wallet-cli.ts | 2 | ||||
-rw-r--r-- | src/operations/refund.ts | 6 | ||||
-rw-r--r-- | src/types/talerTypes.ts | 33 |
4 files changed, 22 insertions, 21 deletions
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts index 51e93f30b..8e1effbea 100644 --- a/src/headless/integrationtest.ts +++ b/src/headless/integrationtest.ts @@ -77,7 +77,7 @@ async function makePayment( paymentStatus = await merchant.checkPayment(orderResp.orderId); - if (!paymentStatus.paid) { + if (paymentStatus.order_status !== "paid") { console.log("payment status:", paymentStatus); throw Error("payment did not succeed"); } diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index 2502ec7db..63698bf69 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -907,7 +907,7 @@ testCli const checkPayResp2 = await merchantBackend.checkPayment( orderResp.orderId, ); - if (checkPayResp2.paid) { + if (checkPayResp2.order_status === "paid") { console.log("payment successfully received!"); break; } diff --git a/src/operations/refund.ts b/src/operations/refund.ts index af3325cfd..b91d42a3f 100644 --- a/src/operations/refund.ts +++ b/src/operations/refund.ts @@ -227,7 +227,7 @@ async function acceptRefunds( // Still pending. if ( - refundStatus.success === false && + refundStatus.type === "failure" && existingRefundInfo?.type === RefundState.Pending ) { continue; @@ -235,7 +235,7 @@ async function acceptRefunds( // Invariant: (!existingRefundInfo) || (existingRefundInfo === Pending) - if (refundStatus.success === true) { + if (refundStatus.type === "success") { await applySuccessfulRefund(tx, p, refreshCoinsMap, refundStatus); } else { await storePendingRefund(tx, p, refundStatus); @@ -417,7 +417,7 @@ async function processPurchaseQueryRefundImpl( codecForMerchantOrderStatus(), ); - if (!refundResponse.paid) { + if (refundResponse.order_status !== "paid") { logger.error("can't refund unpaid order"); return; } diff --git a/src/types/talerTypes.ts b/src/types/talerTypes.ts index b2d8f6a37..2730da4b2 100644 --- a/src/types/talerTypes.ts +++ b/src/types/talerTypes.ts @@ -41,6 +41,7 @@ import { makeCodecForUnion, makeCodecForConstTrue, makeCodecForConstFalse, + makeCodecForConstString, } from "../util/codec"; import { Timestamp, @@ -690,7 +691,7 @@ export class Proposal { * Response from the internal merchant API. */ export class CheckPaymentResponse { - paid: boolean; + order_status: string; refunded: boolean | undefined; refunded_amount: string | undefined; contract_terms: any | undefined; @@ -846,7 +847,7 @@ interface MerchantOrderStatusPaid { /** * Has the payment for this order (ever) been completed? */ - paid: true; + order_status: "paid"; /** * Was the payment refunded (even partially, via refund or abort)? @@ -874,7 +875,7 @@ export type MerchantCoinRefundStatus = | MerchantCoinRefundFailureStatus; export interface MerchantCoinRefundSuccessStatus { - success: true; + type: "success"; // HTTP status of the exchange request, 200 (integer) required for refund confirmations. exchange_status: 200; @@ -904,7 +905,7 @@ export interface MerchantCoinRefundSuccessStatus { } export interface MerchantCoinRefundFailureStatus { - success: false; + type: "failure"; // HTTP status of the exchange request, must NOT be 200. exchange_status: number; @@ -932,7 +933,7 @@ export interface MerchantOrderStatusUnpaid { /** * Has the payment for this order (ever) been completed? */ - paid: false; + order_status: "unpaid"; /** * URI that the wallet must process to complete the payment. @@ -1141,7 +1142,7 @@ export const codecForProposal = (): Codec<Proposal> => export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> => makeCodecForObject<CheckPaymentResponse>() - .property("paid", codecForBoolean) + .property("order_status", codecForString) .property("refunded", makeCodecOptional(codecForBoolean)) .property("refunded_amount", makeCodecOptional(codecForString)) .property("contract_terms", makeCodecOptional(codecForAny)) @@ -1212,7 +1213,7 @@ export const codecForMerchantCoinRefundSuccessStatus = (): Codec< MerchantCoinRefundSuccessStatus > => makeCodecForObject<MerchantCoinRefundSuccessStatus>() - .property("success", makeCodecForConstTrue()) + .property("type", makeCodecForConstString("success")) .property("coin_pub", codecForString) .property("exchange_status", makeCodecForConstNumber(200)) .property("exchange_sig", codecForString) @@ -1226,7 +1227,7 @@ export const codecForMerchantCoinRefundFailureStatus = (): Codec< MerchantCoinRefundFailureStatus > => makeCodecForObject<MerchantCoinRefundFailureStatus>() - .property("success", makeCodecForConstFalse()) + .property("type", makeCodecForConstString("failure")) .property("coin_pub", codecForString) .property("exchange_status", makeCodecForConstNumber(200)) .property("rtransaction_id", codecForNumber) @@ -1240,16 +1241,16 @@ export const codecForMerchantCoinRefundStatus = (): Codec< MerchantCoinRefundStatus > => makeCodecForUnion<MerchantCoinRefundStatus>() - .discriminateOn("success") - .alternative(true, codecForMerchantCoinRefundSuccessStatus()) - .alternative(false, codecForMerchantCoinRefundFailureStatus()) + .discriminateOn("type") + .alternative("success", codecForMerchantCoinRefundSuccessStatus()) + .alternative("failure", codecForMerchantCoinRefundFailureStatus()) .build("MerchantCoinRefundStatus"); export const codecForMerchantOrderStatusPaid = (): Codec< MerchantOrderStatusPaid > => makeCodecForObject<MerchantOrderStatusPaid>() - .property("paid", makeCodecForConstTrue()) + .property("order_status", makeCodecForConstString("paid")) .property("merchant_pub", codecForString) .property("refund_amount", codecForString) .property("refunded", codecForBoolean) @@ -1260,14 +1261,14 @@ export const codecForMerchantOrderStatusUnpaid = (): Codec< MerchantOrderStatusUnpaid > => makeCodecForObject<MerchantOrderStatusUnpaid>() - .property("paid", makeCodecForConstFalse()) + .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("paid") - .alternative(true, codecForMerchantOrderStatusPaid()) - .alternative(false, codecForMerchantOrderStatusUnpaid()) + .discriminateOn("order_status") + .alternative("paid", codecForMerchantOrderStatusPaid()) + .alternative("unpaid", codecForMerchantOrderStatusUnpaid()) .build("MerchantOrderStatus"); |