implement merchant API changes
This commit is contained in:
parent
245564ec5c
commit
530f0b3f2e
@ -77,7 +77,7 @@ async function makePayment(
|
|||||||
|
|
||||||
paymentStatus = await merchant.checkPayment(orderResp.orderId);
|
paymentStatus = await merchant.checkPayment(orderResp.orderId);
|
||||||
|
|
||||||
if (!paymentStatus.paid) {
|
if (paymentStatus.order_status !== "paid") {
|
||||||
console.log("payment status:", paymentStatus);
|
console.log("payment status:", paymentStatus);
|
||||||
throw Error("payment did not succeed");
|
throw Error("payment did not succeed");
|
||||||
}
|
}
|
||||||
|
@ -907,7 +907,7 @@ testCli
|
|||||||
const checkPayResp2 = await merchantBackend.checkPayment(
|
const checkPayResp2 = await merchantBackend.checkPayment(
|
||||||
orderResp.orderId,
|
orderResp.orderId,
|
||||||
);
|
);
|
||||||
if (checkPayResp2.paid) {
|
if (checkPayResp2.order_status === "paid") {
|
||||||
console.log("payment successfully received!");
|
console.log("payment successfully received!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ async function acceptRefunds(
|
|||||||
|
|
||||||
// Still pending.
|
// Still pending.
|
||||||
if (
|
if (
|
||||||
refundStatus.success === false &&
|
refundStatus.type === "failure" &&
|
||||||
existingRefundInfo?.type === RefundState.Pending
|
existingRefundInfo?.type === RefundState.Pending
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
@ -235,7 +235,7 @@ async function acceptRefunds(
|
|||||||
|
|
||||||
// Invariant: (!existingRefundInfo) || (existingRefundInfo === Pending)
|
// Invariant: (!existingRefundInfo) || (existingRefundInfo === Pending)
|
||||||
|
|
||||||
if (refundStatus.success === true) {
|
if (refundStatus.type === "success") {
|
||||||
await applySuccessfulRefund(tx, p, refreshCoinsMap, refundStatus);
|
await applySuccessfulRefund(tx, p, refreshCoinsMap, refundStatus);
|
||||||
} else {
|
} else {
|
||||||
await storePendingRefund(tx, p, refundStatus);
|
await storePendingRefund(tx, p, refundStatus);
|
||||||
@ -417,7 +417,7 @@ async function processPurchaseQueryRefundImpl(
|
|||||||
codecForMerchantOrderStatus(),
|
codecForMerchantOrderStatus(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!refundResponse.paid) {
|
if (refundResponse.order_status !== "paid") {
|
||||||
logger.error("can't refund unpaid order");
|
logger.error("can't refund unpaid order");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import {
|
|||||||
makeCodecForUnion,
|
makeCodecForUnion,
|
||||||
makeCodecForConstTrue,
|
makeCodecForConstTrue,
|
||||||
makeCodecForConstFalse,
|
makeCodecForConstFalse,
|
||||||
|
makeCodecForConstString,
|
||||||
} from "../util/codec";
|
} from "../util/codec";
|
||||||
import {
|
import {
|
||||||
Timestamp,
|
Timestamp,
|
||||||
@ -690,7 +691,7 @@ export class Proposal {
|
|||||||
* Response from the internal merchant API.
|
* Response from the internal merchant API.
|
||||||
*/
|
*/
|
||||||
export class CheckPaymentResponse {
|
export class CheckPaymentResponse {
|
||||||
paid: boolean;
|
order_status: string;
|
||||||
refunded: boolean | undefined;
|
refunded: boolean | undefined;
|
||||||
refunded_amount: string | undefined;
|
refunded_amount: string | undefined;
|
||||||
contract_terms: any | undefined;
|
contract_terms: any | undefined;
|
||||||
@ -846,7 +847,7 @@ interface MerchantOrderStatusPaid {
|
|||||||
/**
|
/**
|
||||||
* Has the payment for this order (ever) been completed?
|
* Has the payment for this order (ever) been completed?
|
||||||
*/
|
*/
|
||||||
paid: true;
|
order_status: "paid";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Was the payment refunded (even partially, via refund or abort)?
|
* Was the payment refunded (even partially, via refund or abort)?
|
||||||
@ -874,7 +875,7 @@ export type MerchantCoinRefundStatus =
|
|||||||
| MerchantCoinRefundFailureStatus;
|
| MerchantCoinRefundFailureStatus;
|
||||||
|
|
||||||
export interface MerchantCoinRefundSuccessStatus {
|
export interface MerchantCoinRefundSuccessStatus {
|
||||||
success: true;
|
type: "success";
|
||||||
|
|
||||||
// HTTP status of the exchange request, 200 (integer) required for refund confirmations.
|
// HTTP status of the exchange request, 200 (integer) required for refund confirmations.
|
||||||
exchange_status: 200;
|
exchange_status: 200;
|
||||||
@ -904,7 +905,7 @@ export interface MerchantCoinRefundSuccessStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MerchantCoinRefundFailureStatus {
|
export interface MerchantCoinRefundFailureStatus {
|
||||||
success: false;
|
type: "failure";
|
||||||
|
|
||||||
// HTTP status of the exchange request, must NOT be 200.
|
// HTTP status of the exchange request, must NOT be 200.
|
||||||
exchange_status: number;
|
exchange_status: number;
|
||||||
@ -932,7 +933,7 @@ export interface MerchantOrderStatusUnpaid {
|
|||||||
/**
|
/**
|
||||||
* Has the payment for this order (ever) been completed?
|
* Has the payment for this order (ever) been completed?
|
||||||
*/
|
*/
|
||||||
paid: false;
|
order_status: "unpaid";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URI that the wallet must process to complete the payment.
|
* URI that the wallet must process to complete the payment.
|
||||||
@ -1141,7 +1142,7 @@ export const codecForProposal = (): Codec<Proposal> =>
|
|||||||
|
|
||||||
export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> =>
|
export const codecForCheckPaymentResponse = (): Codec<CheckPaymentResponse> =>
|
||||||
makeCodecForObject<CheckPaymentResponse>()
|
makeCodecForObject<CheckPaymentResponse>()
|
||||||
.property("paid", codecForBoolean)
|
.property("order_status", codecForString)
|
||||||
.property("refunded", makeCodecOptional(codecForBoolean))
|
.property("refunded", makeCodecOptional(codecForBoolean))
|
||||||
.property("refunded_amount", makeCodecOptional(codecForString))
|
.property("refunded_amount", makeCodecOptional(codecForString))
|
||||||
.property("contract_terms", makeCodecOptional(codecForAny))
|
.property("contract_terms", makeCodecOptional(codecForAny))
|
||||||
@ -1212,7 +1213,7 @@ export const codecForMerchantCoinRefundSuccessStatus = (): Codec<
|
|||||||
MerchantCoinRefundSuccessStatus
|
MerchantCoinRefundSuccessStatus
|
||||||
> =>
|
> =>
|
||||||
makeCodecForObject<MerchantCoinRefundSuccessStatus>()
|
makeCodecForObject<MerchantCoinRefundSuccessStatus>()
|
||||||
.property("success", makeCodecForConstTrue())
|
.property("type", makeCodecForConstString("success"))
|
||||||
.property("coin_pub", codecForString)
|
.property("coin_pub", codecForString)
|
||||||
.property("exchange_status", makeCodecForConstNumber(200))
|
.property("exchange_status", makeCodecForConstNumber(200))
|
||||||
.property("exchange_sig", codecForString)
|
.property("exchange_sig", codecForString)
|
||||||
@ -1226,7 +1227,7 @@ export const codecForMerchantCoinRefundFailureStatus = (): Codec<
|
|||||||
MerchantCoinRefundFailureStatus
|
MerchantCoinRefundFailureStatus
|
||||||
> =>
|
> =>
|
||||||
makeCodecForObject<MerchantCoinRefundFailureStatus>()
|
makeCodecForObject<MerchantCoinRefundFailureStatus>()
|
||||||
.property("success", makeCodecForConstFalse())
|
.property("type", makeCodecForConstString("failure"))
|
||||||
.property("coin_pub", codecForString)
|
.property("coin_pub", codecForString)
|
||||||
.property("exchange_status", makeCodecForConstNumber(200))
|
.property("exchange_status", makeCodecForConstNumber(200))
|
||||||
.property("rtransaction_id", codecForNumber)
|
.property("rtransaction_id", codecForNumber)
|
||||||
@ -1240,16 +1241,16 @@ export const codecForMerchantCoinRefundStatus = (): Codec<
|
|||||||
MerchantCoinRefundStatus
|
MerchantCoinRefundStatus
|
||||||
> =>
|
> =>
|
||||||
makeCodecForUnion<MerchantCoinRefundStatus>()
|
makeCodecForUnion<MerchantCoinRefundStatus>()
|
||||||
.discriminateOn("success")
|
.discriminateOn("type")
|
||||||
.alternative(true, codecForMerchantCoinRefundSuccessStatus())
|
.alternative("success", codecForMerchantCoinRefundSuccessStatus())
|
||||||
.alternative(false, codecForMerchantCoinRefundFailureStatus())
|
.alternative("failure", codecForMerchantCoinRefundFailureStatus())
|
||||||
.build("MerchantCoinRefundStatus");
|
.build("MerchantCoinRefundStatus");
|
||||||
|
|
||||||
export const codecForMerchantOrderStatusPaid = (): Codec<
|
export const codecForMerchantOrderStatusPaid = (): Codec<
|
||||||
MerchantOrderStatusPaid
|
MerchantOrderStatusPaid
|
||||||
> =>
|
> =>
|
||||||
makeCodecForObject<MerchantOrderStatusPaid>()
|
makeCodecForObject<MerchantOrderStatusPaid>()
|
||||||
.property("paid", makeCodecForConstTrue())
|
.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)
|
||||||
@ -1260,14 +1261,14 @@ export const codecForMerchantOrderStatusUnpaid = (): Codec<
|
|||||||
MerchantOrderStatusUnpaid
|
MerchantOrderStatusUnpaid
|
||||||
> =>
|
> =>
|
||||||
makeCodecForObject<MerchantOrderStatusUnpaid>()
|
makeCodecForObject<MerchantOrderStatusUnpaid>()
|
||||||
.property("paid", makeCodecForConstFalse())
|
.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> =>
|
export const codecForMerchantOrderStatus = (): Codec<MerchantOrderStatus> =>
|
||||||
makeCodecForUnion<MerchantOrderStatus>()
|
makeCodecForUnion<MerchantOrderStatus>()
|
||||||
.discriminateOn("paid")
|
.discriminateOn("order_status")
|
||||||
.alternative(true, codecForMerchantOrderStatusPaid())
|
.alternative("paid", codecForMerchantOrderStatusPaid())
|
||||||
.alternative(false, codecForMerchantOrderStatusUnpaid())
|
.alternative("unpaid", codecForMerchantOrderStatusUnpaid())
|
||||||
.build("MerchantOrderStatus");
|
.build("MerchantOrderStatus");
|
||||||
|
Loading…
Reference in New Issue
Block a user