harness: get rid of deprecated merchant API client

This commit is contained in:
Florian Dold 2023-09-06 11:23:33 +02:00
parent c9a0d2eb96
commit 9a1a3b350d
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
27 changed files with 311 additions and 339 deletions

View File

@ -1364,6 +1364,9 @@ export const harnessHttpLib = createPlatformHttpLib({
enableThrottling: false, enableThrottling: false,
}); });
/**
* FIXME: Move this out of the harness.
*/
export class MerchantApiClient { export class MerchantApiClient {
/** /**
* Base URL for the particular instance that this merchant API client * Base URL for the particular instance that this merchant API client
@ -1513,95 +1516,32 @@ export class MerchantApiClient {
); );
} }
private makeAuthHeader(): Record<string, string> { async giveTip(req: RewardCreateRequest): Promise<RewardCreateConfirmation> {
switch (this.auth.method) { const reqUrl = new URL(`private/tips`, this.baseUrl);
case "external":
return {};
case "token":
return {
Authorization: `Bearer ${this.auth.token}`,
};
}
}
}
/**
* FIXME: This should be deprecated in favor of MerchantApiClient
*
* @deprecated use MerchantApiClient instead
*/
export namespace MerchantPrivateApi {
export async function createOrder(
merchantService: MerchantServiceInterface,
instanceName: string,
req: MerchantPostOrderRequest,
withAuthorization: WithAuthorization = {},
): Promise<MerchantPostOrderResponse> {
const baseUrl = merchantService.makeInstanceBaseUrl(instanceName);
let url = new URL("private/orders", baseUrl);
const resp = await harnessHttpLib.fetch(url.href, {
method: "POST",
body: req,
headers: withAuthorization as Record<string, string>,
});
return readSuccessResponseJsonOrThrow(
resp,
codecForMerchantPostOrderResponse(),
);
}
export async function createTemplate(
merchantService: MerchantServiceInterface,
instanceName: string,
req: MerchantTemplateAddDetails,
withAuthorization: WithAuthorization = {},
) {
const baseUrl = merchantService.makeInstanceBaseUrl(instanceName);
let url = new URL("private/templates", baseUrl);
const resp = await harnessHttpLib.fetch(url.href, {
method: "POST",
body: req,
headers: withAuthorization as Record<string, string>,
});
if (resp.status !== 204) {
throw Error("failed to create template");
}
}
export async function queryPrivateOrderStatus(
merchantService: MerchantServiceInterface,
query: PrivateOrderStatusQuery,
withAuthorization: WithAuthorization = {},
): Promise<MerchantOrderPrivateStatusResponse> {
const reqUrl = new URL(
`private/orders/${query.orderId}`,
merchantService.makeInstanceBaseUrl(query.instance),
);
if (query.sessionId) {
reqUrl.searchParams.set("session_id", query.sessionId);
}
const resp = await harnessHttpLib.fetch(reqUrl.href, { const resp = await harnessHttpLib.fetch(reqUrl.href, {
headers: withAuthorization as Record<string, string>, method: "POST",
body: req,
}); });
return readSuccessResponseJsonOrThrow( // FIXME: validate
resp, return resp.json();
codecForMerchantOrderPrivateStatusResponse(),
);
} }
export async function giveRefund( async queryTippingReserves(): Promise<TippingReserveStatus> {
merchantService: MerchantServiceInterface, const reqUrl = new URL(`private/reserves`, this.baseUrl);
r: { const resp = await harnessHttpLib.fetch(reqUrl.href, {
instance: string; headers: this.makeAuthHeader(),
orderId: string; });
amount: string; // FIXME: validate
justification: string; return resp.json();
}, }
): Promise<{ talerRefundUri: string }> {
const reqUrl = new URL( async giveRefund(r: {
`private/orders/${r.orderId}/refund`, instance: string;
merchantService.makeInstanceBaseUrl(r.instance), orderId: string;
); amount: string;
justification: string;
}): Promise<{ talerRefundUri: string }> {
const reqUrl = new URL(`private/orders/${r.orderId}/refund`, this.baseUrl);
const resp = await harnessHttpLib.fetch(reqUrl.href, { const resp = await harnessHttpLib.fetch(reqUrl.href, {
method: "POST", method: "POST",
body: { body: {
@ -1615,34 +1555,27 @@ export namespace MerchantPrivateApi {
}; };
} }
export async function queryTippingReserves( async createTemplate(req: MerchantTemplateAddDetails) {
merchantService: MerchantServiceInterface, let url = new URL("private/templates", this.baseUrl);
instance: string, const resp = await harnessHttpLib.fetch(url.href, {
): Promise<TippingReserveStatus> {
const reqUrl = new URL(
`private/reserves`,
merchantService.makeInstanceBaseUrl(instance),
);
const resp = await harnessHttpLib.fetch(reqUrl.href);
// FIXME: validate
return resp.json();
}
export async function giveTip(
merchantService: MerchantServiceInterface,
instance: string,
req: RewardCreateRequest,
): Promise<RewardCreateConfirmation> {
const reqUrl = new URL(
`private/tips`,
merchantService.makeInstanceBaseUrl(instance),
);
const resp = await harnessHttpLib.fetch(reqUrl.href, {
method: "POST", method: "POST",
body: req, body: req,
headers: this.makeAuthHeader(),
}); });
// FIXME: validate if (resp.status !== 204) {
return resp.json(); throw Error("failed to create template");
}
}
private makeAuthHeader(): Record<string, string> {
switch (this.auth.method) {
case "external":
return {};
case "token":
return {
Authorization: `Bearer ${this.auth.token}`,
};
}
} }
} }

View File

@ -54,7 +54,6 @@ import {
getPayto, getPayto,
GlobalTestState, GlobalTestState,
MerchantApiClient, MerchantApiClient,
MerchantPrivateApi,
MerchantService, MerchantService,
MerchantServiceInterface, MerchantServiceInterface,
setupDb, setupDb,

View File

@ -27,8 +27,6 @@ import {
getWireMethodForTest, getWireMethodForTest,
GlobalTestState, GlobalTestState,
MerchantApiClient, MerchantApiClient,
MerchantPrivateApi,
WalletCli,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
@ -214,7 +212,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
await exchange.runWirewatchOnce(); await exchange.runWirewatchOnce();
const tip = await MerchantPrivateApi.giveTip(merchant, "default", { const tip = await merchantClient.giveTip({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
justification: "why not?", justification: "why not?",
next_url: "https://example.com/after-tip", next_url: "https://example.com/after-tip",

View File

@ -19,7 +19,10 @@
*/ */
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { URL } from "url"; import { URL } from "url";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import {
GlobalTestState,
MerchantApiClient,
} from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -44,8 +47,10 @@ export async function runClaimLoopTest(t: GlobalTestState) {
amount: "TESTKUDOS:20", amount: "TESTKUDOS:20",
}); });
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -54,12 +59,9 @@ export async function runClaimLoopTest(t: GlobalTestState) {
}); });
// Query private order status before claiming it. // Query private order status before claiming it.
let orderStatusBefore = await MerchantPrivateApi.queryPrivateOrderStatus( let orderStatusBefore = await merchantClient.queryPrivateOrderStatus({
merchant, orderId: orderResp.order_id,
{ });
orderId: orderResp.order_id,
},
);
t.assertTrue(orderStatusBefore.order_status === "unpaid"); t.assertTrue(orderStatusBefore.order_status === "unpaid");
let statusUrlBefore = new URL(orderStatusBefore.order_status_url); let statusUrlBefore = new URL(orderStatusBefore.order_status_url);
@ -71,12 +73,9 @@ export async function runClaimLoopTest(t: GlobalTestState) {
}); });
// Query private order status after claiming it. // Query private order status after claiming it.
let orderStatusAfter = await MerchantPrivateApi.queryPrivateOrderStatus( let orderStatusAfter = await merchantClient.queryPrivateOrderStatus({
merchant, orderId: orderResp.order_id,
{ });
orderId: orderResp.order_id,
},
);
t.assertTrue(orderStatusAfter.order_status === "claimed"); t.assertTrue(orderStatusAfter.order_status === "claimed");
await t.shutdown(); await t.shutdown();

View File

@ -19,7 +19,10 @@
*/ */
import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util"; import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import {
GlobalTestState,
MerchantApiClient,
} from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -62,11 +65,13 @@ export async function runDenomUnofferedTest(t: GlobalTestState) {
fulfillment_url: "taler://fulfillment-success/thx", fulfillment_url: "taler://fulfillment-success/thx",
}; };
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
const orderResp = await merchantClient.createOrder({
order: order, order: order,
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -35,10 +35,9 @@ import {
getPayto, getPayto,
GlobalTestState, GlobalTestState,
harnessHttpLib, harnessHttpLib,
MerchantPrivateApi, MerchantApiClient,
MerchantService, MerchantService,
setupDb, setupDb,
WalletCli,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
createWalletDaemonWithClient, createWalletDaemonWithClient,
@ -170,7 +169,9 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
const merchant = faultyMerchant; const merchant = faultyMerchant;
let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
let orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -178,7 +179,7 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-one", sessionId: "mysession-one",
}); });
@ -233,12 +234,9 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) {
await publicOrderStatusResp.json(), await publicOrderStatusResp.json(),
); );
const confirmPayRes = await walletClient.call( const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, {
WalletApiOperation.ConfirmPay, proposalId: proposalId,
{ });
proposalId: proposalId,
},
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
} }

View File

@ -24,12 +24,15 @@ import {
codecForMerchantOrderStatusUnpaid, codecForMerchantOrderStatusUnpaid,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js"; import {
GlobalTestState,
MerchantApiClient,
harnessHttpLib,
} from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
} from "../harness/helpers.js"; } from "../harness/helpers.js";
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -50,6 +53,8 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
/** /**
* ========================================================================= * =========================================================================
* Create an order and let the wallet pay under a session ID * Create an order and let the wallet pay under a session ID
@ -59,7 +64,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
* ========================================================================= * =========================================================================
*/ */
let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { let orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -68,7 +73,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
create_token: false, create_token: false,
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-one", sessionId: "mysession-one",
}); });
@ -81,7 +86,9 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
// First, request order status without longpolling // First, request order status without longpolling
{ {
console.log("requesting", publicOrderStatusUrl.href); console.log("requesting", publicOrderStatusUrl.href);
let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href); let publicOrderStatusResp = await harnessHttpLib.fetch(
publicOrderStatusUrl.href,
);
if (publicOrderStatusResp.status != 402) { if (publicOrderStatusResp.status != 402) {
throw Error( throw Error(
@ -94,7 +101,9 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
publicOrderStatusUrl.searchParams.set("timeout_ms", "500"); publicOrderStatusUrl.searchParams.set("timeout_ms", "500");
console.log("requesting", publicOrderStatusUrl.href); console.log("requesting", publicOrderStatusUrl.href);
let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href); let publicOrderStatusResp = await harnessHttpLib.fetch(
publicOrderStatusUrl.href,
);
if (publicOrderStatusResp.status != 402) { if (publicOrderStatusResp.status != 402) {
throw Error( throw Error(
@ -129,7 +138,9 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
preparePayResp.contractTermsHash, preparePayResp.contractTermsHash,
); );
let publicOrderStatusPromise = harnessHttpLib.fetch(publicOrderStatusUrl.href); let publicOrderStatusPromise = harnessHttpLib.fetch(
publicOrderStatusUrl.href,
);
t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible);

View File

@ -17,15 +17,13 @@
/** /**
* Imports. * Imports.
*/ */
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import { import {
GlobalTestState, GlobalTestState,
MerchantPrivateApi,
MerchantServiceInterface, MerchantServiceInterface,
WalletCli,
ExchangeServiceInterface, ExchangeServiceInterface,
harnessHttpLib, harnessHttpLib,
WalletClient, WalletClient,
MerchantApiClient,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
@ -51,10 +49,12 @@ async function testRefundApiWithFulfillmentUrl(
exchange: ExchangeServiceInterface; exchange: ExchangeServiceInterface;
}, },
): Promise<void> { ): Promise<void> {
const { walletClient, bank, exchange, merchant } = env; const { walletClient, merchant } = env;
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -65,7 +65,7 @@ async function testRefundApiWithFulfillmentUrl(
), ),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -93,7 +93,7 @@ async function testRefundApiWithFulfillmentUrl(
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -110,14 +110,14 @@ async function testRefundApiWithFulfillmentUrl(
preparePayResult.status === PreparePayResultType.AlreadyConfirmed, preparePayResult.status === PreparePayResultType.AlreadyConfirmed,
); );
await MerchantPrivateApi.giveRefund(merchant, { await merchantClient.giveRefund({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
instance: "default", instance: "default",
justification: "foo", justification: "foo",
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -165,10 +165,12 @@ async function testRefundApiWithFulfillmentMessage(
exchange: ExchangeServiceInterface; exchange: ExchangeServiceInterface;
}, },
): Promise<void> { ): Promise<void> {
const { walletClient, bank, exchange, merchant } = env; const { walletClient, merchant } = env;
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -179,7 +181,7 @@ async function testRefundApiWithFulfillmentMessage(
), ),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -207,7 +209,7 @@ async function testRefundApiWithFulfillmentMessage(
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -224,14 +226,14 @@ async function testRefundApiWithFulfillmentMessage(
preparePayResult.status === PreparePayResultType.AlreadyConfirmed, preparePayResult.status === PreparePayResultType.AlreadyConfirmed,
); );
await MerchantPrivateApi.giveRefund(merchant, { await merchantClient.giveRefund({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
instance: "default", instance: "default",
justification: "foo", justification: "foo",
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -29,9 +29,8 @@ import {
BankService, BankService,
ExchangeService, ExchangeService,
GlobalTestState, GlobalTestState,
MerchantPrivateApi, MerchantApiClient,
MerchantService, MerchantService,
WalletCli,
harnessHttpLib, harnessHttpLib,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
@ -66,7 +65,8 @@ async function testWithClaimToken(
}); });
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
const sessionId = "mysession"; const sessionId = "mysession";
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -255,18 +255,14 @@ async function testWithClaimToken(
t.assertTrue(confirmPayRes2.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes2.type === ConfirmPayResultType.Done);
// Create another order with identical fulfillment URL to test the "already paid" flow // Create another order with identical fulfillment URL to test the "already paid" flow
const alreadyPaidOrderResp = await MerchantPrivateApi.createOrder( const alreadyPaidOrderResp = await merchantClient.createOrder({
merchant, order: {
"default", summary: "Buy me!",
{ amount: "TESTKUDOS:5",
order: { fulfillment_url: "https://example.com/article42",
summary: "Buy me!", public_reorder_url: "https://example.com/article42-share",
amount: "TESTKUDOS:5",
fulfillment_url: "https://example.com/article42",
public_reorder_url: "https://example.com/article42-share",
},
}, },
); });
const apOrderId = alreadyPaidOrderResp.order_id; const apOrderId = alreadyPaidOrderResp.order_id;
const apToken = alreadyPaidOrderResp.token; const apToken = alreadyPaidOrderResp.token;
@ -319,6 +315,7 @@ async function testWithoutClaimToken(
const sessionId = "mysession2"; const sessionId = "mysession2";
const { bank, exchange } = c; const { bank, exchange } = c;
const { merchant, merchantBaseUrl } = c; const { merchant, merchantBaseUrl } = c;
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
const wres = await withdrawViaBankV2(t, { const wres = await withdrawViaBankV2(t, {
walletClient, walletClient,
bank, bank,
@ -326,7 +323,7 @@ async function testWithoutClaimToken(
amount: "TESTKUDOS:20", amount: "TESTKUDOS:20",
}); });
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -514,18 +511,14 @@ async function testWithoutClaimToken(
t.assertTrue(confirmPayRes2.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes2.type === ConfirmPayResultType.Done);
// Create another order with identical fulfillment URL to test the "already paid" flow // Create another order with identical fulfillment URL to test the "already paid" flow
const alreadyPaidOrderResp = await MerchantPrivateApi.createOrder( const alreadyPaidOrderResp = await merchantClient.createOrder({
merchant, order: {
"default", summary: "Buy me!",
{ amount: "TESTKUDOS:5",
order: { fulfillment_url: "https://example.com/article42",
summary: "Buy me!", public_reorder_url: "https://example.com/article42-share",
amount: "TESTKUDOS:5",
fulfillment_url: "https://example.com/article42",
public_reorder_url: "https://example.com/article42-share",
},
}, },
); });
const apOrderId = alreadyPaidOrderResp.order_id; const apOrderId = alreadyPaidOrderResp.order_id;
const apToken = alreadyPaidOrderResp.token; const apToken = alreadyPaidOrderResp.token;

View File

@ -19,7 +19,7 @@
*/ */
import { import {
GlobalTestState, GlobalTestState,
MerchantPrivateApi, MerchantApiClient,
harnessHttpLib, harnessHttpLib,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
@ -71,7 +71,9 @@ export async function runPayPaidTest(t: GlobalTestState) {
const merchant = faultyMerchant; const merchant = faultyMerchant;
let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
let orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -80,7 +82,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-one", sessionId: "mysession-one",
}); });
@ -127,12 +129,9 @@ export async function runPayPaidTest(t: GlobalTestState) {
publicOrderStatusResp.json(), publicOrderStatusResp.json(),
); );
const confirmPayRes = await walletClient.call( const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, {
WalletApiOperation.ConfirmPay, proposalId: proposalId,
{ });
proposalId: proposalId,
},
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
@ -153,7 +152,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
* ========================================================================= * =========================================================================
*/ */
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-two", sessionId: "mysession-two",
}); });
@ -180,7 +179,7 @@ export async function runPayPaidTest(t: GlobalTestState) {
}, },
}); });
let orderRespTwo = await MerchantPrivateApi.createOrder(merchant, "default", { let orderRespTwo = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -189,13 +188,10 @@ export async function runPayPaidTest(t: GlobalTestState) {
}, },
}); });
let orderStatusTwo = await MerchantPrivateApi.queryPrivateOrderStatus( let orderStatusTwo = await merchantClient.queryPrivateOrderStatus({
merchant, orderId: orderRespTwo.order_id,
{ sessionId: "mysession-two",
orderId: orderRespTwo.order_id, });
sessionId: "mysession-two",
},
);
t.assertTrue(orderStatusTwo.order_status === "unpaid"); t.assertTrue(orderStatusTwo.order_status === "unpaid");

View File

@ -19,7 +19,7 @@
*/ */
import { import {
GlobalTestState, GlobalTestState,
MerchantPrivateApi, MerchantApiClient,
harnessHttpLib, harnessHttpLib,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
@ -55,7 +55,9 @@ export async function runPaymentAbortTest(t: GlobalTestState) {
const merchant = faultyMerchant; const merchant = faultyMerchant;
let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
let orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -64,7 +66,7 @@ export async function runPaymentAbortTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-one", sessionId: "mysession-one",
}); });

View File

@ -19,11 +19,7 @@
*/ */
import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util"; import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { import { GlobalTestState, MerchantApiClient, WalletCli } from "../harness/harness.js";
GlobalTestState,
MerchantPrivateApi,
WalletCli,
} from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -38,6 +34,8 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant } = const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
const walletTwo = new WalletCli(t, "two"); const walletTwo = new WalletCli(t, "two");
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
@ -53,7 +51,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -61,7 +59,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -94,7 +92,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -28,8 +28,8 @@ import {
setupDb, setupDb,
BankService, BankService,
WalletCli, WalletCli,
MerchantPrivateApi,
getPayto, getPayto,
MerchantApiClient,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
FaultInjectedExchangeService, FaultInjectedExchangeService,
@ -120,6 +120,8 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
paytoUris: [getPayto("merchant-default")], paytoUris: [getPayto("merchant-default")],
}); });
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
console.log("setup done!"); console.log("setup done!");
const wallet = new WalletCli(t); const wallet = new WalletCli(t);
@ -161,7 +163,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -169,7 +171,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -218,7 +220,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -19,7 +19,7 @@
*/ */
import { PreparePayResultType } from "@gnu-taler/taler-util"; import { PreparePayResultType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -46,9 +46,11 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -56,7 +58,7 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -102,7 +104,7 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -23,9 +23,8 @@ import {
BankService, BankService,
ExchangeService, ExchangeService,
MerchantService, MerchantService,
WalletCli,
MerchantPrivateApi,
getPayto, getPayto,
MerchantApiClient,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { coin_ct10, coin_u1 } from "../harness/denomStructures.js"; import { coin_ct10, coin_u1 } from "../harness/denomStructures.js";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
@ -120,6 +119,8 @@ export async function runPaymentMultipleTest(t: GlobalTestState) {
name: "default", name: "default",
}); });
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, { await withdrawViaBankV2(t, {
@ -131,7 +132,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) {
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:80", amount: "TESTKUDOS:80",
@ -139,7 +140,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -157,7 +158,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -22,7 +22,7 @@ import {
PreparePayResultType, PreparePayResultType,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
createWalletDaemonWithClient, createWalletDaemonWithClient,
@ -41,6 +41,8 @@ export async function runPaymentShareTest(t: GlobalTestState) {
merchant, merchant,
} = await createSimpleTestkudosEnvironmentV2(t); } = await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, { await withdrawViaBankV2(t, {
walletClient: firstWallet, walletClient: firstWallet,
@ -62,7 +64,7 @@ export async function runPaymentShareTest(t: GlobalTestState) {
}); });
await secondWallet.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); await secondWallet.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
//create two orders to pay // create two orders to pay
async function createOrder(amount: string) { async function createOrder(amount: string) {
const order = { const order = {
summary: "Buy me!", summary: "Buy me!",
@ -70,26 +72,16 @@ export async function runPaymentShareTest(t: GlobalTestState) {
fulfillment_url: "taler://fulfillment-success/thx", fulfillment_url: "taler://fulfillment-success/thx",
}; };
const instance = "default";
const args = { order }; const args = { order };
const auth = {}; const auth = {};
const orderResp = await MerchantPrivateApi.createOrder( const orderResp = await merchantClient.createOrder({
merchant, order: args.order,
instance, });
{
order: args.order,
},
auth,
);
const orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( const orderStatus = await merchantClient.queryPrivateOrderStatus({
merchant, orderId: orderResp.order_id,
{ });
orderId: orderResp.order_id,
},
auth,
);
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "unpaid");
return { id: orderResp.order_id, uri: orderStatus.taler_pay_uri }; return { id: orderResp.order_id, uri: orderStatus.taler_pay_uri };

View File

@ -17,12 +17,16 @@
/** /**
* Imports. * Imports.
*/ */
import { ConfirmPayResultType, Duration, PreparePayResultType } from "@gnu-taler/taler-util"; import {
ConfirmPayResultType,
Duration,
PreparePayResultType,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2 withdrawViaBankV2,
} from "../harness/helpers.js"; } from "../harness/helpers.js";
/** /**
@ -34,7 +38,9 @@ export async function runPaymentTemplateTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant } = const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
await MerchantPrivateApi.createTemplate(merchant, "default", { const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
await merchantClient.createTemplate({
template_id: "template1", template_id: "template1",
template_description: "my test template", template_description: "my test template",
template_contract: { template_contract: {
@ -50,7 +56,12 @@ export async function runPaymentTemplateTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const wres = await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:20" }); const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
// Request a template payment // Request a template payment
@ -79,13 +90,10 @@ export async function runPaymentTemplateTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
const orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( const orderStatus = await merchantClient.queryPrivateOrderStatus({
merchant, orderId: preparePayResult.contractTerms.order_id,
{ instance: "default",
orderId: preparePayResult.contractTerms.order_id, });
instance: "default",
},
);
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});

View File

@ -27,12 +27,16 @@ import {
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { FaultInjectionResponseContext } from "../harness/faultInjection.js"; import { FaultInjectionResponseContext } from "../harness/faultInjection.js";
import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js";
import { import {
createFaultInjectedMerchantTestkudosEnvironment, withdrawViaBankV2, GlobalTestState,
MerchantApiClient,
harnessHttpLib,
} from "../harness/harness.js";
import {
createFaultInjectedMerchantTestkudosEnvironment,
withdrawViaBankV2,
} from "../harness/helpers.js"; } from "../harness/helpers.js";
/** /**
* Run test for a payment where the merchant has a transient * Run test for a payment where the merchant has a transient
* failure in /pay * failure in /pay
@ -40,9 +44,13 @@ import {
export async function runPaymentTransientTest(t: GlobalTestState) { export async function runPaymentTransientTest(t: GlobalTestState) {
// Set up test environment // Set up test environment
const { walletClient, bank, exchange, faultyMerchant, faultyExchange } = const { walletClient, bank, faultyMerchant, faultyExchange } =
await createFaultInjectedMerchantTestkudosEnvironment(t); await createFaultInjectedMerchantTestkudosEnvironment(t);
const merchantClient = new MerchantApiClient(
faultyMerchant.makeInstanceBaseUrl(),
);
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, { await withdrawViaBankV2(t, {
@ -54,7 +62,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
const merchant = faultyMerchant; const merchant = faultyMerchant;
let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { let orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -63,7 +71,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-one", sessionId: "mysession-one",
}); });

View File

@ -17,7 +17,11 @@
/** /**
* Imports. * Imports.
*/ */
import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js"; import {
GlobalTestState,
MerchantApiClient,
harnessHttpLib,
} from "../harness/harness.js";
import { import {
PreparePayResultType, PreparePayResultType,
codecForMerchantOrderStatusUnpaid, codecForMerchantOrderStatusUnpaid,
@ -39,6 +43,8 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant } = const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const wres = await withdrawViaBankV2(t, { const wres = await withdrawViaBankV2(t, {
@ -59,7 +65,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
* ========================================================================= * =========================================================================
*/ */
let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { let orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -70,7 +76,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
const firstOrderId = orderResp.order_id; const firstOrderId = orderResp.order_id;
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-one", sessionId: "mysession-one",
}); });
@ -82,7 +88,9 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined); t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = new URL(orderStatus.order_status_url); let publicOrderStatusUrl = new URL(orderStatus.order_status_url);
let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href); let publicOrderStatusResp = await harnessHttpLib.fetch(
publicOrderStatusUrl.href,
);
if (publicOrderStatusResp.status != 402) { if (publicOrderStatusResp.status != 402) {
throw Error( throw Error(
@ -142,7 +150,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
* ========================================================================= * =========================================================================
*/ */
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
sessionId: "mysession-two", sessionId: "mysession-two",
}); });
@ -169,7 +177,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
* ========================================================================= * =========================================================================
*/ */
orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -181,7 +189,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
const secondOrderId = orderResp.order_id; const secondOrderId = orderResp.order_id;
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: secondOrderId, orderId: secondOrderId,
sessionId: "mysession-three", sessionId: "mysession-three",
}); });
@ -206,7 +214,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
// The first order should now be paid under "mysession-three", // The first order should now be paid under "mysession-three",
// as the wallet did re-purchase detection // as the wallet did re-purchase detection
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: firstOrderId, orderId: firstOrderId,
sessionId: "mysession-three", sessionId: "mysession-three",
}); });
@ -215,7 +223,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
// Check that with a completely new session ID, the status would NOT // Check that with a completely new session ID, the status would NOT
// be paid. // be paid.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: firstOrderId, orderId: firstOrderId,
sessionId: "mysession-four", sessionId: "mysession-four",
}); });

View File

@ -19,7 +19,7 @@
*/ */
import { Duration, durationFromSpec } from "@gnu-taler/taler-util"; import { Duration, durationFromSpec } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -34,6 +34,8 @@ export async function runRefundAutoTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant } = const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const wres = await withdrawViaBankV2(t, { const wres = await withdrawViaBankV2(t, {
@ -46,7 +48,7 @@ export async function runRefundAutoTest(t: GlobalTestState) {
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -60,7 +62,7 @@ export async function runRefundAutoTest(t: GlobalTestState) {
), ),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -78,13 +80,13 @@ export async function runRefundAutoTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
const ref = await MerchantPrivateApi.giveRefund(merchant, { const ref = await merchantClient.giveRefund({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
instance: "default", instance: "default",
justification: "foo", justification: "foo",

View File

@ -17,7 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
applyTimeTravelV2, applyTimeTravelV2,
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
@ -39,6 +39,8 @@ export async function runRefundGoneTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant } = const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, { await withdrawViaBankV2(t, {
@ -50,7 +52,7 @@ export async function runRefundGoneTest(t: GlobalTestState) {
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -69,7 +71,7 @@ export async function runRefundGoneTest(t: GlobalTestState) {
), ),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -82,12 +84,12 @@ export async function runRefundGoneTest(t: GlobalTestState) {
}); });
const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, {
proposalId: r1.proposalId, transactionId: r1.transactionId,
}); });
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -102,7 +104,7 @@ export async function runRefundGoneTest(t: GlobalTestState) {
await exchange.runAggregatorOnce(); await exchange.runAggregatorOnce();
const ref = await MerchantPrivateApi.giveRefund(merchant, { const ref = await merchantClient.giveRefund({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
instance: "default", instance: "default",
justification: "foo", justification: "foo",

View File

@ -26,7 +26,7 @@ import {
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { import {
GlobalTestState, GlobalTestState,
MerchantPrivateApi, MerchantApiClient,
delayMs, delayMs,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { import {
@ -43,6 +43,8 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
const { walletClient, bank, exchange, merchant } = const { walletClient, bank, exchange, merchant } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const wres = await withdrawViaBankV2(t, { const wres = await withdrawViaBankV2(t, {
@ -56,7 +58,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:10", amount: "TESTKUDOS:10",
@ -67,7 +69,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
), ),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -85,13 +87,13 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
let ref = await MerchantPrivateApi.giveRefund(merchant, { let ref = await merchantClient.giveRefund({
amount: "TESTKUDOS:2.5", amount: "TESTKUDOS:2.5",
instance: "default", instance: "default",
justification: "foo", justification: "foo",
@ -120,7 +122,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
// refund will be grouped with the previous one. // refund will be grouped with the previous one.
await delayMs(1200); await delayMs(1200);
ref = await MerchantPrivateApi.giveRefund(merchant, { ref = await merchantClient.giveRefund({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
instance: "default", instance: "default",
justification: "bar", justification: "bar",
@ -133,7 +135,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
// refund will be grouped with the previous one. // refund will be grouped with the previous one.
await delayMs(1200); await delayMs(1200);
ref = await MerchantPrivateApi.giveRefund(merchant, { ref = await merchantClient.giveRefund({
amount: "TESTKUDOS:10", amount: "TESTKUDOS:10",
instance: "default", instance: "default",
justification: "bar", justification: "bar",
@ -153,7 +155,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) {
console.log(wr); console.log(wr);
} }
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });

View File

@ -24,7 +24,7 @@ import {
TransactionMajorState, TransactionMajorState,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -43,6 +43,8 @@ export async function runRefundTest(t: GlobalTestState) {
merchant, merchant,
} = await createSimpleTestkudosEnvironmentV2(t); } = await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const withdrawalRes = await withdrawViaBankV2(t, { const withdrawalRes = await withdrawViaBankV2(t, {
@ -56,7 +58,7 @@ export async function runRefundTest(t: GlobalTestState) {
// Set up order. // Set up order.
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
summary: "Buy me!", summary: "Buy me!",
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
@ -67,7 +69,7 @@ export async function runRefundTest(t: GlobalTestState) {
), ),
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
@ -85,13 +87,13 @@ export async function runRefundTest(t: GlobalTestState) {
// Check if payment was successful. // Check if payment was successful.
orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });
t.assertTrue(orderStatus.order_status === "paid"); t.assertTrue(orderStatus.order_status === "paid");
const ref = await MerchantPrivateApi.giveRefund(merchant, { const ref = await merchantClient.giveRefund({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
instance: "default", instance: "default",
justification: "foo", justification: "foo",

View File

@ -32,14 +32,16 @@ import {
BankService, BankService,
ExchangeService, ExchangeService,
GlobalTestState, GlobalTestState,
MerchantPrivateApi,
MerchantService, MerchantService,
setupDb, setupDb,
WalletCli,
getPayto, getPayto,
MerchantApiClient,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { applyTimeTravelV2, createWalletDaemonWithClient, withdrawViaBankV2 } from "../harness/helpers.js"; import {
applyTimeTravelV2,
createWalletDaemonWithClient,
withdrawViaBankV2,
} from "../harness/helpers.js";
/** /**
* Basic time travel test. * Basic time travel test.
@ -110,19 +112,29 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
name: "w1", name: "w1",
}); });
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const wres = await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:15" }); const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:15",
});
await wres.withdrawalFinishedCond; await wres.withdrawalFinishedCond;
// Travel into the future, the deposit expiration is two years // Travel into the future, the deposit expiration is two years
// into the future. // into the future.
console.log("applying first time travel"); console.log("applying first time travel");
await applyTimeTravelV2(Duration.toMilliseconds(durationFromSpec({ days: 400 })), { await applyTimeTravelV2(
walletClient, Duration.toMilliseconds(durationFromSpec({ days: 400 })),
exchange, {
merchant, walletClient,
}); exchange,
merchant,
},
);
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
@ -144,11 +156,14 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
// Travel into the future, the deposit expiration is two years // Travel into the future, the deposit expiration is two years
// into the future. // into the future.
console.log("applying second time travel"); console.log("applying second time travel");
await applyTimeTravelV2(Duration.toMilliseconds(durationFromSpec({ years: 2, months: 6 })), { await applyTimeTravelV2(
walletClient, Duration.toMilliseconds(durationFromSpec({ years: 2, months: 6 })),
exchange, {
merchant, walletClient,
}); exchange,
merchant,
},
);
// At this point, the original coins should've been refreshed. // At this point, the original coins should've been refreshed.
// It would be too late to refresh them now, as we're past // It would be too late to refresh them now, as we're past
@ -156,7 +171,7 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order: { order: {
fulfillment_url: "http://example.com", fulfillment_url: "http://example.com",
summary: "foo", summary: "foo",
@ -164,13 +179,10 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
}, },
}); });
const orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( const orderStatus = await merchantClient.queryPrivateOrderStatus({
merchant, orderId: orderResp.order_id,
{ instance: "default",
orderId: orderResp.order_id, });
instance: "default",
},
);
t.assertTrue(orderStatus.order_status === "unpaid"); t.assertTrue(orderStatus.order_status === "unpaid");

View File

@ -25,7 +25,6 @@ import {
import { import {
GlobalTestState, GlobalTestState,
MerchantApiClient, MerchantApiClient,
MerchantPrivateApi,
getWireMethodForTest, getWireMethodForTest,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js"; import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js";
@ -46,12 +45,7 @@ export async function runTippingTest(t: GlobalTestState) {
}); });
const mbu = await bankAccessApiClient.createRandomBankUser(); const mbu = await bankAccessApiClient.createRandomBankUser();
const merchantClient = new MerchantApiClient( const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
merchant.makeInstanceBaseUrl("default"),
{
method: "external",
},
);
const tipReserveResp = await merchantClient.createTippingReserve({ const tipReserveResp = await merchantClient.createTippingReserve({
exchange_url: exchange.baseUrl, exchange_url: exchange.baseUrl,
@ -85,7 +79,7 @@ export async function runTippingTest(t: GlobalTestState) {
await merchant.start(); await merchant.start();
await merchant.pingUntilAvailable(); await merchant.pingUntilAvailable();
const r = await MerchantPrivateApi.queryTippingReserves(merchant, "default"); const r = await merchantClient.queryTippingReserves();
console.log("tipping reserves:", JSON.stringify(r, undefined, 2)); console.log("tipping reserves:", JSON.stringify(r, undefined, 2));
t.assertTrue(r.reserves.length === 1); t.assertTrue(r.reserves.length === 1);
@ -94,7 +88,7 @@ export async function runTippingTest(t: GlobalTestState) {
r.reserves[0].merchant_initial_amount, r.reserves[0].merchant_initial_amount,
); );
const tip = await MerchantPrivateApi.giveTip(merchant, "default", { const tip = await merchantClient.giveTip({
amount: "TESTKUDOS:5", amount: "TESTKUDOS:5",
justification: "why not?", justification: "why not?",
next_url: "https://example.com/after-tip", next_url: "https://example.com/after-tip",

View File

@ -19,7 +19,7 @@
*/ */
import { PreparePayResultType } from "@gnu-taler/taler-util"; import { PreparePayResultType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
createWalletDaemonWithClient, createWalletDaemonWithClient,
@ -34,6 +34,8 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
const { commonDb, merchant, walletClient, bank, exchange } = const { commonDb, merchant, walletClient, bank, exchange } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
const sync = await SyncService.create(t, { const sync = await SyncService.create(t, {
currency: "TESTKUDOS", currency: "TESTKUDOS",
annualFee: "TESTKUDOS:0.5", annualFee: "TESTKUDOS:0.5",
@ -116,7 +118,7 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
{ {
const instance = "default"; const instance = "default";
const orderResp = await MerchantPrivateApi.createOrder(merchant, instance, { const orderResp = await merchantClient.createOrder({
order: { order: {
amount: "TESTKUDOS:8", amount: "TESTKUDOS:8",
summary: "bla", summary: "bla",
@ -124,8 +126,7 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) {
}, },
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( let orderStatus = await merchantClient.queryPrivateOrderStatus(
merchant,
{ {
orderId: orderResp.order_id, orderId: orderResp.order_id,
}, },

View File

@ -19,7 +19,7 @@
*/ */
import { Amounts, PreparePayResultType } from "@gnu-taler/taler-util"; import { Amounts, PreparePayResultType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; import { GlobalTestState, MerchantApiClient } from "../harness/harness.js";
import { import {
createSimpleTestkudosEnvironmentV2, createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2, withdrawViaBankV2,
@ -37,6 +37,8 @@ export async function runWalletBalanceTest(t: GlobalTestState) {
const { merchant, walletClient, exchange, bank } = const { merchant, walletClient, exchange, bank } =
await createSimpleTestkudosEnvironmentV2(t); await createSimpleTestkudosEnvironmentV2(t);
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
// Withdraw digital cash into the wallet. // Withdraw digital cash into the wallet.
const wres = await withdrawViaBankV2(t, { const wres = await withdrawViaBankV2(t, {
@ -54,11 +56,11 @@ export async function runWalletBalanceTest(t: GlobalTestState) {
fulfillment_url: "taler://fulfillment-success/thx", fulfillment_url: "taler://fulfillment-success/thx",
}; };
const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { const orderResp = await merchantClient.createOrder({
order, order,
}); });
let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { let orderStatus = await merchantClient.queryPrivateOrderStatus({
orderId: orderResp.order_id, orderId: orderResp.order_id,
}); });