aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/merchant.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/http-client/merchant.ts')
-rw-r--r--packages/taler-util/src/http-client/merchant.ts396
1 files changed, 356 insertions, 40 deletions
diff --git a/packages/taler-util/src/http-client/merchant.ts b/packages/taler-util/src/http-client/merchant.ts
index 32384f8b4..1d498fb57 100644
--- a/packages/taler-util/src/http-client/merchant.ts
+++ b/packages/taler-util/src/http-client/merchant.ts
@@ -17,7 +17,6 @@
import {
HttpStatusCode,
LibtoolVersion,
- MerchantApiClient,
TalerMerchantApi,
codecForMerchantConfig
} from "@gnu-taler/taler-util";
@@ -26,10 +25,8 @@ import {
createPlatformHttpLib,
} from "@gnu-taler/taler-util/http";
import {
- FailCasesByMethod,
- ResultByMethod,
opSuccessFromHttp,
- opUnknownFailure,
+ opUnknownFailure
} from "../operation.js";
import { CacheEvictor, nullEvictor } from "./utils.js";
@@ -242,7 +239,7 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#get--instances-$INSTANCE-private-kyc
*/
- async getCurrentIntanceKycStatus(params: { wireHash?: string, exchangeURL?: string, timeout: number }) {
+ async getCurrentIntanceKycStatus(params: TalerMerchantApi.GetKycStatusRequestParams) {
const url = new URL(`private/kyc`, this.baseUrl);
if (params.wireHash) {
@@ -329,37 +326,69 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-products
*/
- async addProduct() {
+ async addProduct(body: TalerMerchantApi.ProductAddDetail) {
+ const url = new URL(`private/products`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#patch-[-instances-$INSTANCE]-private-products-$PRODUCT_ID
*/
- async updateProduct() {
+ async updateProduct(productId: string, body: TalerMerchantApi.ProductAddDetail) {
+ const url = new URL(`private/products/${productId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "PATCH",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-products
*/
async listProducts() {
+ const url = new URL(`private/products`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-products-$PRODUCT_ID
*/
- async getProduct() {
+ async getProduct(productId: string) {
+ const url = new URL(`private/products/${productId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#reserving-inventory
*/
- async lockProduct() {
+ async lockProduct(productId: string) {
+ const url = new URL(`private/products/${productId}/lock`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#removing-products-from-inventory
*/
- async removeProduct() {
+ async removeProduct(productId: string) {
+ const url = new URL(`private/products/${productId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
//
@@ -369,31 +398,96 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-orders
*/
- async createOrder() {
+ async createOrder(body: TalerMerchantApi.PostOrderRequest) {
+ const url = new URL(`private/orders`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#inspecting-orders
*/
- async listOrders() {
+ async listOrders(params: TalerMerchantApi.ListOrdersRequestParams = {}) {
+ const url = new URL(`private/orders`, this.baseUrl);
+
+ if (params.date) {
+ url.searchParams.set("date_s", String(params.date))
+ }
+ if (params.delta) {
+ url.searchParams.set("delta", String(params.delta))
+ }
+ if (params.fulfillmentUrl) {
+ url.searchParams.set("fulfillment_url", params.fulfillmentUrl)
+ }
+ if (params.paid) {
+ url.searchParams.set("paid", "YES")
+ }
+ if (params.refunded) {
+ url.searchParams.set("refunded", "YES")
+ }
+ if (params.sessionId) {
+ url.searchParams.set("session_id", params.sessionId)
+ }
+ if (params.start) {
+ url.searchParams.set("start", String(params.start))
+ }
+ if (params.timeout) {
+ url.searchParams.set("timeout", String(params.timeout))
+ }
+ if (params.wired) {
+ url.searchParams.set("wired", "YES")
+ }
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-orders-$ORDER_ID
*/
- async getOrder() {
+ async getOrder(orderId: string, params: TalerMerchantApi.GetOrderRequestParams = {}) {
+ const url = new URL(`private/orders/${orderId}`, this.baseUrl);
+
+ if (params.allowRefundedForRepurchase) {
+ url.searchParams.set("allow_refunded_for_repurchase", "YES")
+ }
+ if (params.sessionId) {
+ url.searchParams.set("session_id", params.sessionId)
+ }
+ if (params.timeout) {
+ url.searchParams.set("timeout_ms", String(params.timeout))
+ }
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#private-order-data-cleanup
*/
- async forgetOrder() {
+ async forgetOrder(orderId: string, body: TalerMerchantApi.ForgetRequest) {
+ const url = new URL(`private/orders/${orderId}/forget`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "PATCH",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCE]-private-orders-$ORDER_ID
*/
- async deleteOrder() {
+ async deleteOrder(orderId: string) {
+ const url = new URL(`private/orders/${orderId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
//
@@ -403,7 +497,13 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-orders-$ORDER_ID-refund
*/
- async addRefund() {
+ async addRefund(orderId: string, body: TalerMerchantApi.RefundRequest) {
+ const url = new URL(`private/orders/${orderId}/refund`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
//
@@ -413,19 +513,54 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-transfers
*/
- async informWireTransfer() {
+ async informWireTransfer(body: TalerMerchantApi.TransferInformation) {
+ const url = new URL(`private/transfers`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-transfers
*/
- async listWireTransfers() {
+ async listWireTransfers(params: TalerMerchantApi.ListWireTransferRequestParams = {}) {
+ const url = new URL(`private/transfers`, this.baseUrl);
+
+ if (params.after) {
+ url.searchParams.set("after", String(params.after))
+ }
+ if (params.before) {
+ url.searchParams.set("before", String(params.before))
+ }
+ if (params.limit) {
+ url.searchParams.set("limit", String(params.limit))
+ }
+ if (params.offset) {
+ url.searchParams.set("offset", String(params.offset))
+ }
+ if (params.paytoURI) {
+ url.searchParams.set("payto_uri", params.paytoURI)
+ }
+ if (params.verified) {
+ url.searchParams.set("verified", "YES")
+ }
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCE]-private-transfers-$TID
*/
- async deleteWireTransfer() {
+ async deleteWireTransfer(transferId: string) {
+ const url = new URL(`private/transfers/${transferId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
//
@@ -435,31 +570,65 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-otp-devices
*/
- async addOtpDevice() {
+ async addOtpDevice(body: TalerMerchantApi.OtpDeviceAddDetails) {
+ const url = new URL(`private/otp-devices`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#patch-[-instances-$INSTANCE]-private-otp-devices-$DEVICE_ID
*/
- async updateOtpDevice() {
+ async updateOtpDevice(deviceId: string, body: TalerMerchantApi.OtpDevicePatchDetails) {
+ const url = new URL(`private/otp-devices/${deviceId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "PATCH",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-otp-devices
*/
async listOtpDevices() {
+ const url = new URL(`private/otp-devices`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-otp-devices-$DEVICE_ID
*/
- async getOtpDevice() {
+ async getOtpDevice(deviceId: string, params: TalerMerchantApi.GetOtpDeviceRequestParams = {}) {
+ const url = new URL(`private/otp-devices/${deviceId}`, this.baseUrl);
+
+ if (params.faketime) {
+ url.searchParams.set("faketime", String(params.faketime))
+ }
+ if (params.price) {
+ url.searchParams.set("price", params.price)
+ }
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
+
}
/**
* https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCE]-private-otp-devices-$DEVICE_ID
*/
- async deleteOtpDevice() {
+ async deleteOtpDevice(deviceId: string) {
+ const url = new URL(`private/otp-devices/${deviceId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
//
@@ -469,37 +638,82 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCE]-private-templates
*/
- async addTemplate() {
+ async addTemplate(body: TalerMerchantApi.TemplateAddDetails) {
+ const url = new URL(`private/templates`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#patch-[-instances-$INSTANCE]-private-templates-$TEMPLATE_ID
*/
- async updateTemplate() {
+ async updateTemplate(templateId: string, body: TalerMerchantApi.TemplatePatchDetails) {
+ const url = new URL(`private/templates/${templateId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "PATCH",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#inspecting-template
*/
async listTemplates() {
+ const url = new URL(`private/templates`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-private-templates-$TEMPLATE_ID
*/
- async getTemplate() {
+ async getTemplate(templateId: string) {
+ const url = new URL(`private/templates/${templateId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCE]-private-templates-$TEMPLATE_ID
*/
- async deleteTemplate() {
+ async deleteTemplate(templateId: string) {
+ const url = new URL(`private/templates/${templateId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
+ }
+
+ /**
+ * https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCE]-templates-$TEMPLATE_ID
+ */
+ async useTemplateGetInfo(templateId: string) {
+ const url = new URL(`templates/${templateId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
+
}
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCES]-templates-$TEMPLATE_ID
*/
- async useTemplate() {
+ async useTemplateCreateOrder(templateId: string, body: TalerMerchantApi.UsingTemplateDetails) {
+ const url = new URL(`templates/${templateId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
//
@@ -510,31 +724,58 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCES]-private-webhooks
*/
- async addWebhook() {
+ async addWebhook(body: TalerMerchantApi.WebhookAddDetails) {
+ const url = new URL(`private/webhooks`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#patch-[-instances-$INSTANCES]-private-webhooks-$WEBHOOK_ID
*/
- async updateWebhook() {
+ async updateWebhook(webhookId: string, body: TalerMerchantApi.WebhookPatchDetails) {
+ const url = new URL(`private/webhooks/${webhookId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "PATCH",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-webhooks
*/
async listWebhooks() {
+ const url = new URL(`private/webhooks`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-webhooks-$WEBHOOK_ID
*/
- async getWebhook() {
+ async getWebhook(webhookId: string) {
+ const url = new URL(`private/webhooks/${webhookId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCES]-private-webhooks-$WEBHOOK_ID
*/
- async removeWebhook() {
+ async removeWebhook(webhookId: string) {
+ const url = new URL(`private/webhooks/${webhookId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
//
@@ -544,31 +785,59 @@ class TalerMerchantInstanceHttpClient {
/**
* https://docs.taler.net/core/api-merchant.html#post-[-instances-$INSTANCES]-private-tokenfamilies
*/
- async createTokenFamily() {
+ async createTokenFamily(body: TalerMerchantApi.TokenFamilyCreateRequest) {
+ const url = new URL(`private/tokenfamilies`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#patch-[-instances-$INSTANCES]-private-tokenfamilies-$TOKEN_FAMILY_SLUG
*/
- async updateTokenFamily() {
+ async updateTokenFamily(tokenSlug: string,body: TalerMerchantApi.TokenFamilyCreateRequest) {
+ const url = new URL(`private/tokenfamilies/${tokenSlug}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-tokenfamilies
*/
async listTokenFamilies() {
+ const url = new URL(`private/tokenfamilies`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get-[-instances-$INSTANCES]-private-tokenfamilies-$TOKEN_FAMILY_SLUG
*/
- async getTokenFamily() {
+ async getTokenFamily(tokenSlug: string) {
+ const url = new URL(`private/tokenfamilies/${tokenSlug}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
+
}
/**
* https://docs.taler.net/core/api-merchant.html#delete-[-instances-$INSTANCES]-private-tokenfamilies-$TOKEN_FAMILY_SLUG
*/
- async deleteTokenFamily() {
+ async deleteTokenFamily(tokenSlug: string) {
+ const url = new URL(`private/tokenfamilies/${tokenSlug}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
}
@@ -591,6 +860,10 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp
return compare?.compatible ?? false;
}
+ getSubInstanceApi(instanceId: string) {
+ return new URL(`instances/${instanceId}`, this.baseUrl)
+ }
+
/**
* https://docs.taler.net/core/api-merchant.html#get--config
*
@@ -645,32 +918,75 @@ export class TalerMerchantManagementHttpClient extends TalerMerchantInstanceHttp
/**
* https://docs.taler.net/core/api-merchant.html#patch--management-instances-$INSTANCE
*/
- async updateInstance() {
+ async updateInstance(isntanceId: string, body: TalerMerchantApi.InstanceReconfigurationMessage) {
+ const url = new URL(`management/instances/${isntanceId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "PATCH",
+ body,
+ });
+
+
}
/**
* https://docs.taler.net/core/api-merchant.html#get--management-instances
*/
async listInstances() {
+ const url = new URL(`management/instances`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
+
}
/**
* https://docs.taler.net/core/api-merchant.html#get--management-instances-$INSTANCE
*
*/
- async getInstance() {
+ async getInstance(instanceId: string) {
+ const url = new URL(`management/instances/${instanceId}`, this.baseUrl);
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#delete--management-instances-$INSTANCE
*/
- async deleteInstance() {
+ async deleteInstance(instanceId: string, params: {purge?: boolean} = {}) {
+ const url = new URL(`management/instances/${instanceId}`, this.baseUrl);
+
+ if (params.purge) {
+ url.searchParams.set("purge", "YES")
+ }
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "DELETE",
+ });
}
/**
* https://docs.taler.net/core/api-merchant.html#get--management-instances-$INSTANCE-kyc
*/
- async getIntanceKycStatus() {
+ async getIntanceKycStatus(instanceId: string, params: TalerMerchantApi.GetKycStatusRequestParams) {
+ const url = new URL(`management/instances/${instanceId}/kyc`, this.baseUrl);
+
+ if (params.wireHash) {
+ url.searchParams.set("h_wire", params.wireHash)
+ }
+ if (params.exchangeURL) {
+ url.searchParams.set("exchange_url", params.exchangeURL)
+ }
+ if (params.timeout) {
+ url.searchParams.set("timeout_ms", String(params.timeout))
+ }
+
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ });
}