implement merchant API changes

This commit is contained in:
Florian Dold 2020-07-24 14:42:35 +05:30
parent 245564ec5c
commit 530f0b3f2e
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 22 additions and 21 deletions

View File

@ -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");
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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");