match latest refund API of the merchant

This commit is contained in:
Florian Dold 2020-08-20 11:39:34 +05:30
parent d9b73a30c1
commit 7ff93d8ef6
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 22 additions and 10 deletions

View File

@ -48,6 +48,7 @@ import {
MerchantCoinRefundFailureStatus,
codecForMerchantOrderStatusPaid,
AmountString,
codecForMerchantOrderRefundPickupResponse,
} from "../types/talerTypes";
import { guardOperationException } from "./errors";
import { getTimestampNow, Timestamp } from "../util/time";
@ -472,25 +473,22 @@ async function processPurchaseQueryRefundImpl(
return;
}
const requestUrl = new URL(
`orders/${purchase.contractData.orderId}`,
`orders/${purchase.contractData.orderId}/refund`,
purchase.contractData.merchantBaseUrl,
);
requestUrl.searchParams.set(
"h_contract",
purchase.contractData.contractTermsHash,
);
logger.trace(`making refund request to ${requestUrl.href}`);
const request = await ws.http.get(requestUrl.href);
const request = await ws.http.postJson(requestUrl.href, {
h_contract: purchase.contractData.contractTermsHash,
});
logger.trace("got json", JSON.stringify(await request.json(), undefined, 2));
const refundResponse = await readSuccessResponseJsonOrThrow(
request,
codecForMerchantOrderStatusPaid(),
codecForMerchantOrderRefundPickupResponse(),
);
await acceptRefunds(

View File

@ -849,6 +849,13 @@ interface MerchantOrderStatusPaid {
* Amount that was refunded in total.
*/
refund_amount: AmountString;
}
interface MerchantOrderRefundResponse {
/**
* Amount that was refunded in total.
*/
refund_amount: AmountString;
/**
* Successful refunds for this payment, empty array for none.
@ -1265,12 +1272,19 @@ export const codecForMerchantOrderStatusPaid = (): Codec<
MerchantOrderStatusPaid
> =>
buildCodecForObject<MerchantOrderStatusPaid>()
.property("merchant_pub", codecForString())
.property("refund_amount", codecForString())
.property("refunded", codecForBoolean)
.property("refunds", codecForList(codecForMerchantCoinRefundStatus()))
.build("MerchantOrderStatusPaid");
export const codecForMerchantOrderRefundPickupResponse = (): Codec<
MerchantOrderRefundResponse
> =>
buildCodecForObject<MerchantOrderRefundResponse>()
.property("merchant_pub", codecForString())
.property("refund_amount", codecForString())
.property("refunds", codecForList(codecForMerchantCoinRefundStatus()))
.build("MerchantOrderRefundPickupResponse");
export const codecForMerchantOrderStatusUnpaid = (): Codec<
MerchantOrderStatusUnpaid
> =>