diff options
author | Florian Dold <florian@dold.me> | 2023-09-06 11:23:33 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-09-06 11:23:33 +0200 |
commit | 9a1a3b350d4147243dbe2ecfcdcb846c0f3c6dcb (patch) | |
tree | f9b01f5748edf391146d2bbaec62aad285d261ec /packages/taler-harness | |
parent | c9a0d2eb968133b1ad156e1dc86e6c06dad09c7a (diff) | |
download | wallet-core-9a1a3b350d4147243dbe2ecfcdcb846c0f3c6dcb.tar.xz |
harness: get rid of deprecated merchant API client
Diffstat (limited to 'packages/taler-harness')
27 files changed, 306 insertions, 334 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 99151b219..a16cef7ba 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -1364,6 +1364,9 @@ export const harnessHttpLib = createPlatformHttpLib({ enableThrottling: false, }); +/** + * FIXME: Move this out of the harness. + */ export class MerchantApiClient { /** * Base URL for the particular instance that this merchant API client @@ -1513,95 +1516,32 @@ export class MerchantApiClient { ); } - private makeAuthHeader(): Record<string, string> { - switch (this.auth.method) { - 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, { + async giveTip(req: RewardCreateRequest): Promise<RewardCreateConfirmation> { + const reqUrl = new URL(`private/tips`, this.baseUrl); + const resp = await harnessHttpLib.fetch(reqUrl.href, { method: "POST", body: req, - headers: withAuthorization as Record<string, string>, }); - if (resp.status !== 204) { - throw Error("failed to create template"); - } + // FIXME: validate + return resp.json(); } - 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); - } + async queryTippingReserves(): Promise<TippingReserveStatus> { + const reqUrl = new URL(`private/reserves`, this.baseUrl); const resp = await harnessHttpLib.fetch(reqUrl.href, { - headers: withAuthorization as Record<string, string>, + headers: this.makeAuthHeader(), }); - return readSuccessResponseJsonOrThrow( - resp, - codecForMerchantOrderPrivateStatusResponse(), - ); + // FIXME: validate + return resp.json(); } - export async function giveRefund( - merchantService: MerchantServiceInterface, - r: { - instance: string; - orderId: string; - amount: string; - justification: string; - }, - ): Promise<{ talerRefundUri: string }> { - const reqUrl = new URL( - `private/orders/${r.orderId}/refund`, - merchantService.makeInstanceBaseUrl(r.instance), - ); + async giveRefund(r: { + instance: string; + 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, { method: "POST", body: { @@ -1615,34 +1555,27 @@ export namespace MerchantPrivateApi { }; } - export async function queryTippingReserves( - merchantService: MerchantServiceInterface, - instance: string, - ): 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, { + async createTemplate(req: MerchantTemplateAddDetails) { + let url = new URL("private/templates", this.baseUrl); + const resp = await harnessHttpLib.fetch(url.href, { method: "POST", body: req, + headers: this.makeAuthHeader(), }); - // FIXME: validate - return resp.json(); + if (resp.status !== 204) { + 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}`, + }; + } } } diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index ece003e1b..485e1baba 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -54,7 +54,6 @@ import { getPayto, GlobalTestState, MerchantApiClient, - MerchantPrivateApi, MerchantService, MerchantServiceInterface, setupDb, diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts index 3072badc0..45a035cc4 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts @@ -27,8 +27,6 @@ import { getWireMethodForTest, GlobalTestState, MerchantApiClient, - MerchantPrivateApi, - WalletCli, } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, @@ -214,7 +212,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { await exchange.runWirewatchOnce(); - const tip = await MerchantPrivateApi.giveTip(merchant, "default", { + const tip = await merchantClient.giveTip({ amount: "TESTKUDOS:5", justification: "why not?", next_url: "https://example.com/after-tip", diff --git a/packages/taler-harness/src/integrationtests/test-claim-loop.ts b/packages/taler-harness/src/integrationtests/test-claim-loop.ts index 32706c28b..52841dbab 100644 --- a/packages/taler-harness/src/integrationtests/test-claim-loop.ts +++ b/packages/taler-harness/src/integrationtests/test-claim-loop.ts @@ -19,7 +19,10 @@ */ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { URL } from "url"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { + GlobalTestState, + MerchantApiClient, +} from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -44,8 +47,10 @@ export async function runClaimLoopTest(t: GlobalTestState) { amount: "TESTKUDOS:20", }); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -54,12 +59,9 @@ export async function runClaimLoopTest(t: GlobalTestState) { }); // Query private order status before claiming it. - let orderStatusBefore = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - }, - ); + let orderStatusBefore = await merchantClient.queryPrivateOrderStatus({ + orderId: orderResp.order_id, + }); t.assertTrue(orderStatusBefore.order_status === "unpaid"); 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. - let orderStatusAfter = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - }, - ); + let orderStatusAfter = await merchantClient.queryPrivateOrderStatus({ + orderId: orderResp.order_id, + }); t.assertTrue(orderStatusAfter.order_status === "claimed"); await t.shutdown(); diff --git a/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts b/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts index 5a471b9aa..a9282f394 100644 --- a/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts +++ b/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts @@ -19,7 +19,10 @@ */ import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { + GlobalTestState, + MerchantApiClient, +} from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -62,11 +65,13 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { 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, }); - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + let orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts index 2a8ae39d8..3c71e0f7e 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts @@ -35,10 +35,9 @@ import { getPayto, GlobalTestState, harnessHttpLib, - MerchantPrivateApi, + MerchantApiClient, MerchantService, setupDb, - WalletCli, } from "../harness/harness.js"; import { createWalletDaemonWithClient, @@ -170,7 +169,9 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) { const merchant = faultyMerchant; - let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + + let orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, sessionId: "mysession-one", }); @@ -233,12 +234,9 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) { await publicOrderStatusResp.json(), ); - const confirmPayRes = await walletClient.call( - WalletApiOperation.ConfirmPay, - { - proposalId: proposalId, - }, - ); + const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, { + proposalId: proposalId, + }); t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done); } diff --git a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts index 8d271c5d1..d7ffa28d5 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts @@ -24,12 +24,15 @@ import { codecForMerchantOrderStatusUnpaid, } from "@gnu-taler/taler-util"; 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 { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, } from "../harness/helpers.js"; -import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; /** * Run test for basic, bank-integrated withdrawal. @@ -50,6 +53,8 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { await wres.withdrawalFinishedCond; + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + /** * ========================================================================= * 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: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -68,7 +73,7 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { create_token: false, }); - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + let orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, sessionId: "mysession-one", }); @@ -81,7 +86,9 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { // First, request order status without longpolling { console.log("requesting", publicOrderStatusUrl.href); - let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href); + let publicOrderStatusResp = await harnessHttpLib.fetch( + publicOrderStatusUrl.href, + ); if (publicOrderStatusResp.status != 402) { throw Error( @@ -94,7 +101,9 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { publicOrderStatusUrl.searchParams.set("timeout_ms", "500"); console.log("requesting", publicOrderStatusUrl.href); - let publicOrderStatusResp = await harnessHttpLib.fetch(publicOrderStatusUrl.href); + let publicOrderStatusResp = await harnessHttpLib.fetch( + publicOrderStatusUrl.href, + ); if (publicOrderStatusResp.status != 402) { throw Error( @@ -129,7 +138,9 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) { preparePayResp.contractTermsHash, ); - let publicOrderStatusPromise = harnessHttpLib.fetch(publicOrderStatusUrl.href); + let publicOrderStatusPromise = harnessHttpLib.fetch( + publicOrderStatusUrl.href, + ); t.assertTrue(preparePayResp.status === PreparePayResultType.PaymentPossible); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts index bc53cb533..ebca4f769 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts @@ -17,15 +17,13 @@ /** * Imports. */ -import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { GlobalTestState, - MerchantPrivateApi, MerchantServiceInterface, - WalletCli, ExchangeServiceInterface, harnessHttpLib, WalletClient, + MerchantApiClient, } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, @@ -51,10 +49,12 @@ async function testRefundApiWithFulfillmentUrl( exchange: ExchangeServiceInterface; }, ): Promise<void> { - const { walletClient, bank, exchange, merchant } = env; + const { walletClient, merchant } = env; + + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -93,7 +93,7 @@ async function testRefundApiWithFulfillmentUrl( // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); @@ -110,14 +110,14 @@ async function testRefundApiWithFulfillmentUrl( preparePayResult.status === PreparePayResultType.AlreadyConfirmed, ); - await MerchantPrivateApi.giveRefund(merchant, { + await merchantClient.giveRefund({ amount: "TESTKUDOS:5", instance: "default", justification: "foo", orderId: orderResp.order_id, }); - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); @@ -165,10 +165,12 @@ async function testRefundApiWithFulfillmentMessage( exchange: ExchangeServiceInterface; }, ): Promise<void> { - const { walletClient, bank, exchange, merchant } = env; + const { walletClient, merchant } = env; + + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -207,7 +209,7 @@ async function testRefundApiWithFulfillmentMessage( // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); @@ -224,14 +226,14 @@ async function testRefundApiWithFulfillmentMessage( preparePayResult.status === PreparePayResultType.AlreadyConfirmed, ); - await MerchantPrivateApi.giveRefund(merchant, { + await merchantClient.giveRefund({ amount: "TESTKUDOS:5", instance: "default", justification: "foo", orderId: orderResp.order_id, }); - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts index 08c9d4bb2..599a3fc16 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts @@ -29,9 +29,8 @@ import { BankService, ExchangeService, GlobalTestState, - MerchantPrivateApi, + MerchantApiClient, MerchantService, - WalletCli, harnessHttpLib, } from "../harness/harness.js"; import { @@ -66,7 +65,8 @@ async function testWithClaimToken( }); await wres.withdrawalFinishedCond; const sessionId = "mysession"; - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -255,18 +255,14 @@ async function testWithClaimToken( t.assertTrue(confirmPayRes2.type === ConfirmPayResultType.Done); // Create another order with identical fulfillment URL to test the "already paid" flow - const alreadyPaidOrderResp = await MerchantPrivateApi.createOrder( - merchant, - "default", - { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:5", - fulfillment_url: "https://example.com/article42", - public_reorder_url: "https://example.com/article42-share", - }, + const alreadyPaidOrderResp = await merchantClient.createOrder({ + order: { + summary: "Buy me!", + amount: "TESTKUDOS:5", + fulfillment_url: "https://example.com/article42", + public_reorder_url: "https://example.com/article42-share", }, - ); + }); const apOrderId = alreadyPaidOrderResp.order_id; const apToken = alreadyPaidOrderResp.token; @@ -319,6 +315,7 @@ async function testWithoutClaimToken( const sessionId = "mysession2"; const { bank, exchange } = c; const { merchant, merchantBaseUrl } = c; + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); const wres = await withdrawViaBankV2(t, { walletClient, bank, @@ -326,7 +323,7 @@ async function testWithoutClaimToken( amount: "TESTKUDOS:20", }); await wres.withdrawalFinishedCond; - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -514,18 +511,14 @@ async function testWithoutClaimToken( t.assertTrue(confirmPayRes2.type === ConfirmPayResultType.Done); // Create another order with identical fulfillment URL to test the "already paid" flow - const alreadyPaidOrderResp = await MerchantPrivateApi.createOrder( - merchant, - "default", - { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:5", - fulfillment_url: "https://example.com/article42", - public_reorder_url: "https://example.com/article42-share", - }, + const alreadyPaidOrderResp = await merchantClient.createOrder({ + order: { + summary: "Buy me!", + amount: "TESTKUDOS:5", + fulfillment_url: "https://example.com/article42", + public_reorder_url: "https://example.com/article42-share", }, - ); + }); const apOrderId = alreadyPaidOrderResp.order_id; const apToken = alreadyPaidOrderResp.token; diff --git a/packages/taler-harness/src/integrationtests/test-pay-paid.ts b/packages/taler-harness/src/integrationtests/test-pay-paid.ts index 8d39ad4f6..4fe13b3ae 100644 --- a/packages/taler-harness/src/integrationtests/test-pay-paid.ts +++ b/packages/taler-harness/src/integrationtests/test-pay-paid.ts @@ -19,7 +19,7 @@ */ import { GlobalTestState, - MerchantPrivateApi, + MerchantApiClient, harnessHttpLib, } from "../harness/harness.js"; import { @@ -71,7 +71,9 @@ export async function runPayPaidTest(t: GlobalTestState) { const merchant = faultyMerchant; - let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + + let orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, sessionId: "mysession-one", }); @@ -127,12 +129,9 @@ export async function runPayPaidTest(t: GlobalTestState) { publicOrderStatusResp.json(), ); - const confirmPayRes = await walletClient.call( - WalletApiOperation.ConfirmPay, - { - proposalId: proposalId, - }, - ); + const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, { + proposalId: proposalId, + }); 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, 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: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -189,13 +188,10 @@ export async function runPayPaidTest(t: GlobalTestState) { }, }); - let orderStatusTwo = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderRespTwo.order_id, - sessionId: "mysession-two", - }, - ); + let orderStatusTwo = await merchantClient.queryPrivateOrderStatus({ + orderId: orderRespTwo.order_id, + sessionId: "mysession-two", + }); t.assertTrue(orderStatusTwo.order_status === "unpaid"); diff --git a/packages/taler-harness/src/integrationtests/test-payment-abort.ts b/packages/taler-harness/src/integrationtests/test-payment-abort.ts index 99140b2ee..22e087161 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-abort.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-abort.ts @@ -19,7 +19,7 @@ */ import { GlobalTestState, - MerchantPrivateApi, + MerchantApiClient, harnessHttpLib, } from "../harness/harness.js"; import { @@ -55,7 +55,9 @@ export async function runPaymentAbortTest(t: GlobalTestState) { const merchant = faultyMerchant; - let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + + let orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, sessionId: "mysession-one", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim.ts b/packages/taler-harness/src/integrationtests/test-payment-claim.ts index 3e52cb5dd..df86b3cbf 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-claim.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-claim.ts @@ -19,11 +19,7 @@ */ import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { - GlobalTestState, - MerchantPrivateApi, - WalletCli, -} from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient, WalletCli } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -38,6 +34,8 @@ export async function runPaymentClaimTest(t: GlobalTestState) { const { walletClient, bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + const walletTwo = new WalletCli(t, "two"); // Withdraw digital cash into the wallet. @@ -53,7 +51,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) { // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -94,7 +92,7 @@ export async function runPaymentClaimTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-fault.ts b/packages/taler-harness/src/integrationtests/test-payment-fault.ts index 0cc369a6e..5d0fe6e13 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-fault.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-fault.ts @@ -28,8 +28,8 @@ import { setupDb, BankService, WalletCli, - MerchantPrivateApi, getPayto, + MerchantApiClient, } from "../harness/harness.js"; import { FaultInjectedExchangeService, @@ -120,6 +120,8 @@ export async function runPaymentFaultTest(t: GlobalTestState) { paytoUris: [getPayto("merchant-default")], }); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + console.log("setup done!"); const wallet = new WalletCli(t); @@ -161,7 +163,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) { // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -218,7 +220,7 @@ export async function runPaymentFaultTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts b/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts index 6373c2393..e06ef1322 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-idempotency.ts @@ -19,7 +19,7 @@ */ import { PreparePayResultType } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -46,9 +46,11 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) { await wres.withdrawalFinishedCond; + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -102,7 +104,7 @@ export async function runPaymentIdempotencyTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-multiple.ts b/packages/taler-harness/src/integrationtests/test-payment-multiple.ts index 29047e102..b22bba43f 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-multiple.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-multiple.ts @@ -23,9 +23,8 @@ import { BankService, ExchangeService, MerchantService, - WalletCli, - MerchantPrivateApi, getPayto, + MerchantApiClient, } from "../harness/harness.js"; import { coin_ct10, coin_u1 } from "../harness/denomStructures.js"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -120,6 +119,8 @@ export async function runPaymentMultipleTest(t: GlobalTestState) { name: "default", }); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. await withdrawViaBankV2(t, { @@ -131,7 +132,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) { // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -157,7 +158,7 @@ export async function runPaymentMultipleTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-share.ts b/packages/taler-harness/src/integrationtests/test-payment-share.ts index 156571372..c12140d06 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-share.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-share.ts @@ -22,7 +22,7 @@ import { PreparePayResultType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, @@ -41,6 +41,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { merchant, } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. await withdrawViaBankV2(t, { walletClient: firstWallet, @@ -62,7 +64,7 @@ export async function runPaymentShareTest(t: GlobalTestState) { }); await secondWallet.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); - //create two orders to pay + // create two orders to pay async function createOrder(amount: string) { const order = { summary: "Buy me!", @@ -70,26 +72,16 @@ export async function runPaymentShareTest(t: GlobalTestState) { fulfillment_url: "taler://fulfillment-success/thx", }; - const instance = "default"; const args = { order }; const auth = {}; - const orderResp = await MerchantPrivateApi.createOrder( - merchant, - instance, - { - order: args.order, - }, - auth, - ); + const orderResp = await merchantClient.createOrder({ + order: args.order, + }); - const orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - }, - auth, - ); + const orderStatus = await merchantClient.queryPrivateOrderStatus({ + orderId: orderResp.order_id, + }); t.assertTrue(orderStatus.order_status === "unpaid"); return { id: orderResp.order_id, uri: orderStatus.taler_pay_uri }; diff --git a/packages/taler-harness/src/integrationtests/test-payment-template.ts b/packages/taler-harness/src/integrationtests/test-payment-template.ts index 707be52e1..2058991d0 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-template.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-template.ts @@ -17,12 +17,16 @@ /** * 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 { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, - withdrawViaBankV2 + withdrawViaBankV2, } from "../harness/helpers.js"; /** @@ -34,7 +38,9 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { const { walletClient, bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(t); - await MerchantPrivateApi.createTemplate(merchant, "default", { + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + + await merchantClient.createTemplate({ template_id: "template1", template_description: "my test template", template_contract: { @@ -50,7 +56,12 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { // 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; // Request a template payment @@ -79,13 +90,10 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { // Check if payment was successful. - const orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: preparePayResult.contractTerms.order_id, - instance: "default", - }, - ); + const orderStatus = await merchantClient.queryPrivateOrderStatus({ + orderId: preparePayResult.contractTerms.order_id, + instance: "default", + }); t.assertTrue(orderStatus.order_status === "paid"); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); diff --git a/packages/taler-harness/src/integrationtests/test-payment-transient.ts b/packages/taler-harness/src/integrationtests/test-payment-transient.ts index 2cc0af309..3bc59aa8f 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-transient.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-transient.ts @@ -27,12 +27,16 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { FaultInjectionResponseContext } from "../harness/faultInjection.js"; -import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js"; import { - createFaultInjectedMerchantTestkudosEnvironment, withdrawViaBankV2, + GlobalTestState, + MerchantApiClient, + harnessHttpLib, +} from "../harness/harness.js"; +import { + createFaultInjectedMerchantTestkudosEnvironment, + withdrawViaBankV2, } from "../harness/helpers.js"; - /** * Run test for a payment where the merchant has a transient * failure in /pay @@ -40,9 +44,13 @@ import { export async function runPaymentTransientTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bank, exchange, faultyMerchant, faultyExchange } = + const { walletClient, bank, faultyMerchant, faultyExchange } = await createFaultInjectedMerchantTestkudosEnvironment(t); + const merchantClient = new MerchantApiClient( + faultyMerchant.makeInstanceBaseUrl(), + ); + // Withdraw digital cash into the wallet. await withdrawViaBankV2(t, { @@ -54,7 +62,7 @@ export async function runPaymentTransientTest(t: GlobalTestState) { const merchant = faultyMerchant; - let orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + let orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, sessionId: "mysession-one", }); diff --git a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts index 5f63d4fac..fd13f37d6 100644 --- a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts +++ b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts @@ -17,7 +17,11 @@ /** * Imports. */ -import { GlobalTestState, MerchantPrivateApi, harnessHttpLib } from "../harness/harness.js"; +import { + GlobalTestState, + MerchantApiClient, + harnessHttpLib, +} from "../harness/harness.js"; import { PreparePayResultType, codecForMerchantOrderStatusUnpaid, @@ -39,6 +43,8 @@ export async function runPaywallFlowTest(t: GlobalTestState) { const { walletClient, bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. 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: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -70,7 +76,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) { const firstOrderId = orderResp.order_id; - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + let orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, sessionId: "mysession-one", }); @@ -82,7 +88,9 @@ export async function runPaywallFlowTest(t: GlobalTestState) { t.assertTrue(orderStatus.already_paid_order_id === undefined); 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) { 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, sessionId: "mysession-two", }); @@ -169,7 +177,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) { * ========================================================================= */ - orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", amount: "TESTKUDOS:5", @@ -181,7 +189,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) { const secondOrderId = orderResp.order_id; - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: secondOrderId, sessionId: "mysession-three", }); @@ -206,7 +214,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) { // The first order should now be paid under "mysession-three", // as the wallet did re-purchase detection - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: firstOrderId, 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 // be paid. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: firstOrderId, sessionId: "mysession-four", }); diff --git a/packages/taler-harness/src/integrationtests/test-refund-auto.ts b/packages/taler-harness/src/integrationtests/test-refund-auto.ts index 5648835d5..9e1f31af2 100644 --- a/packages/taler-harness/src/integrationtests/test-refund-auto.ts +++ b/packages/taler-harness/src/integrationtests/test-refund-auto.ts @@ -19,7 +19,7 @@ */ import { Duration, durationFromSpec } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -34,6 +34,8 @@ export async function runRefundAutoTest(t: GlobalTestState) { const { walletClient, bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. const wres = await withdrawViaBankV2(t, { @@ -46,7 +48,7 @@ export async function runRefundAutoTest(t: GlobalTestState) { await wres.withdrawalFinishedCond; // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -78,13 +80,13 @@ export async function runRefundAutoTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); t.assertTrue(orderStatus.order_status === "paid"); - const ref = await MerchantPrivateApi.giveRefund(merchant, { + const ref = await merchantClient.giveRefund({ amount: "TESTKUDOS:5", instance: "default", justification: "foo", diff --git a/packages/taler-harness/src/integrationtests/test-refund-gone.ts b/packages/taler-harness/src/integrationtests/test-refund-gone.ts index 8e402f3fc..954262826 100644 --- a/packages/taler-harness/src/integrationtests/test-refund-gone.ts +++ b/packages/taler-harness/src/integrationtests/test-refund-gone.ts @@ -17,7 +17,7 @@ /** * Imports. */ -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV2, @@ -39,6 +39,8 @@ export async function runRefundGoneTest(t: GlobalTestState) { const { walletClient, bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. await withdrawViaBankV2(t, { @@ -50,7 +52,7 @@ export async function runRefundGoneTest(t: GlobalTestState) { // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -82,12 +84,12 @@ export async function runRefundGoneTest(t: GlobalTestState) { }); const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { - proposalId: r1.proposalId, + transactionId: r1.transactionId, }); // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); @@ -102,7 +104,7 @@ export async function runRefundGoneTest(t: GlobalTestState) { await exchange.runAggregatorOnce(); - const ref = await MerchantPrivateApi.giveRefund(merchant, { + const ref = await merchantClient.giveRefund({ amount: "TESTKUDOS:5", instance: "default", justification: "foo", diff --git a/packages/taler-harness/src/integrationtests/test-refund-incremental.ts b/packages/taler-harness/src/integrationtests/test-refund-incremental.ts index 8ac0948f2..7c895ad2b 100644 --- a/packages/taler-harness/src/integrationtests/test-refund-incremental.ts +++ b/packages/taler-harness/src/integrationtests/test-refund-incremental.ts @@ -26,7 +26,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState, - MerchantPrivateApi, + MerchantApiClient, delayMs, } from "../harness/harness.js"; import { @@ -43,6 +43,8 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { const { walletClient, bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. const wres = await withdrawViaBankV2(t, { @@ -56,7 +58,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -85,13 +87,13 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); t.assertTrue(orderStatus.order_status === "paid"); - let ref = await MerchantPrivateApi.giveRefund(merchant, { + let ref = await merchantClient.giveRefund({ amount: "TESTKUDOS:2.5", instance: "default", justification: "foo", @@ -120,7 +122,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { // refund will be grouped with the previous one. await delayMs(1200); - ref = await MerchantPrivateApi.giveRefund(merchant, { + ref = await merchantClient.giveRefund({ amount: "TESTKUDOS:5", instance: "default", justification: "bar", @@ -133,7 +135,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { // refund will be grouped with the previous one. await delayMs(1200); - ref = await MerchantPrivateApi.giveRefund(merchant, { + ref = await merchantClient.giveRefund({ amount: "TESTKUDOS:10", instance: "default", justification: "bar", @@ -153,7 +155,7 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { console.log(wr); } - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); diff --git a/packages/taler-harness/src/integrationtests/test-refund.ts b/packages/taler-harness/src/integrationtests/test-refund.ts index 44848d88a..3dc2748fe 100644 --- a/packages/taler-harness/src/integrationtests/test-refund.ts +++ b/packages/taler-harness/src/integrationtests/test-refund.ts @@ -24,7 +24,7 @@ import { TransactionMajorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -43,6 +43,8 @@ export async function runRefundTest(t: GlobalTestState) { merchant, } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. const withdrawalRes = await withdrawViaBankV2(t, { @@ -56,7 +58,7 @@ export async function runRefundTest(t: GlobalTestState) { // Set up order. - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { summary: "Buy me!", 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, }); @@ -85,13 +87,13 @@ export async function runRefundTest(t: GlobalTestState) { // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); t.assertTrue(orderStatus.order_status === "paid"); - const ref = await MerchantPrivateApi.giveRefund(merchant, { + const ref = await merchantClient.giveRefund({ amount: "TESTKUDOS:5", instance: "default", justification: "foo", diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts index 602b6629a..420e4fddc 100644 --- a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts +++ b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts @@ -32,14 +32,16 @@ import { BankService, ExchangeService, GlobalTestState, - MerchantPrivateApi, MerchantService, setupDb, - WalletCli, getPayto, + MerchantApiClient, } from "../harness/harness.js"; -import { applyTimeTravelV2, createWalletDaemonWithClient, withdrawViaBankV2 } from "../harness/helpers.js"; - +import { + applyTimeTravelV2, + createWalletDaemonWithClient, + withdrawViaBankV2, +} from "../harness/helpers.js"; /** * Basic time travel test. @@ -110,19 +112,29 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { name: "w1", }); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // 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; // Travel into the future, the deposit expiration is two years // into the future. console.log("applying first time travel"); - await applyTimeTravelV2(Duration.toMilliseconds(durationFromSpec({ days: 400 })), { - walletClient, - exchange, - merchant, - }); + await applyTimeTravelV2( + Duration.toMilliseconds(durationFromSpec({ days: 400 })), + { + walletClient, + exchange, + merchant, + }, + ); 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 // into the future. console.log("applying second time travel"); - await applyTimeTravelV2(Duration.toMilliseconds(durationFromSpec({ years: 2, months: 6 })), { - walletClient, - exchange, - merchant, - }); + await applyTimeTravelV2( + Duration.toMilliseconds(durationFromSpec({ years: 2, months: 6 })), + { + walletClient, + exchange, + merchant, + }, + ); // At this point, the original coins should've been refreshed. // 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, {}); - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order: { fulfillment_url: "http://example.com", summary: "foo", @@ -164,13 +179,10 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { }, }); - const orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - instance: "default", - }, - ); + const orderStatus = await merchantClient.queryPrivateOrderStatus({ + orderId: orderResp.order_id, + instance: "default", + }); t.assertTrue(orderStatus.order_status === "unpaid"); diff --git a/packages/taler-harness/src/integrationtests/test-tipping.ts b/packages/taler-harness/src/integrationtests/test-tipping.ts index 53d7f08c8..93855f546 100644 --- a/packages/taler-harness/src/integrationtests/test-tipping.ts +++ b/packages/taler-harness/src/integrationtests/test-tipping.ts @@ -25,7 +25,6 @@ import { import { GlobalTestState, MerchantApiClient, - MerchantPrivateApi, getWireMethodForTest, } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js"; @@ -46,12 +45,7 @@ export async function runTippingTest(t: GlobalTestState) { }); const mbu = await bankAccessApiClient.createRandomBankUser(); - const merchantClient = new MerchantApiClient( - merchant.makeInstanceBaseUrl("default"), - { - method: "external", - }, - ); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); const tipReserveResp = await merchantClient.createTippingReserve({ exchange_url: exchange.baseUrl, @@ -85,7 +79,7 @@ export async function runTippingTest(t: GlobalTestState) { await merchant.start(); await merchant.pingUntilAvailable(); - const r = await MerchantPrivateApi.queryTippingReserves(merchant, "default"); + const r = await merchantClient.queryTippingReserves(); console.log("tipping reserves:", JSON.stringify(r, undefined, 2)); t.assertTrue(r.reserves.length === 1); @@ -94,7 +88,7 @@ export async function runTippingTest(t: GlobalTestState) { r.reserves[0].merchant_initial_amount, ); - const tip = await MerchantPrivateApi.giveTip(merchant, "default", { + const tip = await merchantClient.giveTip({ amount: "TESTKUDOS:5", justification: "why not?", next_url: "https://example.com/after-tip", diff --git a/packages/taler-harness/src/integrationtests/test-wallet-backup-doublespend.ts b/packages/taler-harness/src/integrationtests/test-wallet-backup-doublespend.ts index 99adc1754..62ae89137 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-backup-doublespend.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-backup-doublespend.ts @@ -19,7 +19,7 @@ */ import { PreparePayResultType } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, @@ -34,6 +34,8 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) { const { commonDb, merchant, walletClient, bank, exchange } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + const sync = await SyncService.create(t, { currency: "TESTKUDOS", annualFee: "TESTKUDOS:0.5", @@ -116,7 +118,7 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) { { const instance = "default"; - const orderResp = await MerchantPrivateApi.createOrder(merchant, instance, { + const orderResp = await merchantClient.createOrder({ order: { amount: "TESTKUDOS:8", summary: "bla", @@ -124,8 +126,7 @@ export async function runWalletBackupDoublespendTest(t: GlobalTestState) { }, }); - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, + let orderStatus = await merchantClient.queryPrivateOrderStatus( { orderId: orderResp.order_id, }, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts index 15b0fd427..9711aff26 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts @@ -19,7 +19,7 @@ */ import { Amounts, PreparePayResultType } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js"; +import { GlobalTestState, MerchantApiClient } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2, @@ -37,6 +37,8 @@ export async function runWalletBalanceTest(t: GlobalTestState) { const { merchant, walletClient, exchange, bank } = await createSimpleTestkudosEnvironmentV2(t); + const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl()); + // Withdraw digital cash into the wallet. const wres = await withdrawViaBankV2(t, { @@ -54,11 +56,11 @@ export async function runWalletBalanceTest(t: GlobalTestState) { fulfillment_url: "taler://fulfillment-success/thx", }; - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { + const orderResp = await merchantClient.createOrder({ order, }); - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { + let orderStatus = await merchantClient.queryPrivateOrderStatus({ orderId: orderResp.order_id, }); |