PW-6940: Management API merchant endpoints (#953)

* PW-6940: Update CI workflows

Remove redundant reviewers and push event. Upgrade Node for coverage report.

* PW-6940: Upgrade CodeQL

* PW-6940: Update models

* PW-6940: Add merchant level endpoints

* Revert "PW-6940: Update models"

This reverts commit 1044f2ab1b2ab90fd980588ba35ba5fb6b55d93e.

* PW-6940: Linking services

* PW-6940: Add documentation

* PW-6940: Add unit tests

* PW-6940: Fix delete methods return value

Co-authored-by: Ángel Campos <angel.campos@adyen.com>
Co-authored-by: Alexandros Moraitis <amoraitis@outlook.com>
This commit is contained in:
Michael Paul
2022-08-18 13:24:37 +02:00
committed by GitHub
parent 371d910fb6
commit de7cd45027
21 changed files with 3116 additions and 60 deletions

View File

@@ -5,11 +5,4 @@ updates:
schedule: schedule:
interval: daily interval: daily
time: "04:00" time: "04:00"
open-pull-requests-limit: 10 open-pull-requests-limit: 10
reviewers:
- zaiddreakh
maassenbas
msilvagarcia
AlexandrosMor
peterojo
wboereboom

View File

@@ -18,10 +18,10 @@ jobs:
# We must fetch at least the immediate parents so that if this is # We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head. # a pull request then we can checkout the head.
fetch-depth: 2 fetch-depth: 2
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages # Override language selection by uncommenting this and choosing your languages
# with: # with:
# languages: go, javascript, csharp, python, cpp, java # languages: go, javascript, csharp, python, cpp, java
@@ -29,7 +29,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@@ -43,4 +43,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v2

View File

@@ -1,4 +1,4 @@
on: ["push", "pull_request"] on: ["pull_request"]
name: Coveralls name: Coveralls
@@ -11,10 +11,10 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js 12.x - name: Use Node.js 16.x
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: 12.x node-version: 16.x
- name: npm install, npm test:coverage - name: npm install, npm test:coverage
run: | run: |

View File

@@ -1,6 +1,6 @@
name: Node.js CI name: Node.js CI
on: [push, pull_request] on: [pull_request]
jobs: jobs:
build: build:

View File

@@ -1,6 +1,6 @@
name: "Sonarcloud Analysis" name: "Sonarcloud Analysis"
on: ["push", "pull_request"] on: ["pull_request"]
jobs: jobs:
sonarcloud-analysis: sonarcloud-analysis:

View File

@@ -0,0 +1,225 @@
export const createMerchantRequest = {
"companyId": "YOUR_COMPANY_ACCOUNT",
"legalEntityId": "YOUR_LEGAL_ENTITY_ID",
"businessLineId": "YOUR_BUSINESS_LINE_ID",
"description": "YOUR_DESCRIPTION",
"reference": "YOUR_OWN_REFERENCE"
};
export const allowedOrigin = {
"_links": { "self": { "href": "string" } },
"domain": "string",
"id": "string"
};
export const createMerchantApiCredentialRequest = {
"roles": [
"Checkout webservice role"
],
"allowedOrigins": [
"https://www.mystore.com"
]
};
export const updateMerchantApiCredentialRequest = {
"active": false,
"allowedOrigins": ["string"],
"description": "string",
"roles": ["string"]
};
export const paymentMethodSetupInfo = {
"type": "visa",
"currencies": [
"USD"
],
"countries": [
"US"
]
};
export const updatePaymentMethodInfo = {
"countries": ["string"],
"currencies": ["string"],
"enabled": false
};
export const payoutSettingsRequest = {
"enabled": false,
"enabledFromDate": "string",
"transferInstrumentId": "string"
};
export const updatePayoutSettingsRequest = { "enabled": false };
export const shippingLocation = {
"name": "YOUR_MERCHANT_ACCOUNT Barcelona depot",
"address": {
"companyName": "YOUR_COMPANY",
"streetAddress": "El quinto pino 42",
"postalCode": "08012",
"city": "Barcelona",
"stateOrProvince": "",
"country": "ES"
},
"contact": {
"firstName": "Rita",
"lastName": "Perengano",
"phoneNumber": "+34 93 1234567",
"email": "Rita.Perengano@company.com"
}
};
export const terminalOrderRequest = {
"shippingLocation": "S2-73536B20665526704F30792642212044452F714622375D477270",
"items": [
{
"id": "TBOX-V400m-684-EU",
"name": "V400m Package",
"quantity": 1
},
{
"id": "PART-287001-EU",
"name": "Bluetooth Charging Base - V400m",
"quantity": 2
},
{
"id": "PART-620222-EU",
"name": "Receipt Roll",
"quantity": 20
}
]
};
export const logo = {
"data": ""
};
export const terminalSettings = {
"wifiProfiles": {
"profiles": [
{
"authType": "wpa-eap",
"autoWifi": false,
"bssType": "infra",
"channel": 0,
"defaultProfile": true,
"eap": "peap",
"eapCaCert": {
"data": "MD1rKS05M2JqRVFNQ...RTtLH1tLWo=",
"name": "eap-peap-ca.pem"
},
"eapIdentity": "admin",
"eapIntermediateCert": {
"data": "PD3tUS1CRDdJTiGDR...EFoLS0tLQg=",
"name": "eap-peap-client.pem"
},
"eapPwd": "EAP_PEAP_PASSWORD",
"hiddenSsid": false,
"name": "Profile-eap-peap-1",
"ssid": "your-network",
"wsec": "ccmp"
},
{
"authType": "wpa-psk",
"autoWifi": false,
"bssType": "infra",
"channel": 0,
"defaultProfile": false,
"hiddenSsid": false,
"name": "Profile-guest-wifi",
"psk": "WIFI_PASSWORD",
"ssid": "your-network",
"wsec": "ccmp"
}
],
"settings": {
"band": "2.4GHz",
"roaming": true,
"timeout": 5
}
}
};
export const createMerchantUserRequest = {
"name": {
"firstName": "John",
"lastName": "Smith"
},
"username": "johnsmith",
"email": "john.smith@example.com",
"timeZoneCode": "Europe/Amsterdam",
"roles": [
"Merchant standard role"
],
"associatedMerchantAccounts": [
"YOUR_MERCHANT_ACCOUNT"
]
};
export const updateMerchantUserRequest = {
"accountGroups": ["string"],
"active": false,
"email": "string",
"name": {
"firstName": "string",
"lastName": "string"
},
"roles": ["string"],
"timeZoneCode": "string"
};
export const createMerchantWebhookRequest = {
"acceptsExpiredCertificate": false,
"acceptsSelfSignedCertificate": false,
"acceptsUntrustedRootCertificate": false,
"active": false,
"additionalSettings": {
"includeEventCodes": ["string"],
"properties": { "sample": false }
},
"communicationFormat": "HTTP",
"description": "string",
"networkType": "LOCAL",
"password": "string",
"populateSoapActionHeader": false,
"sslVersion": "HTTP",
"type": "string",
"url": "string",
"username": "string"
};
export const updateMerchantWebhookRequest = {
"acceptsExpiredCertificate": false,
"acceptsSelfSignedCertificate": false,
"acceptsUntrustedRootCertificate": false,
"active": false,
"additionalSettings": {
"includeEventCodes": ["string"],
"properties": { "sample": false }
},
"communicationFormat": "HTTP",
"description": "string",
"networkType": "LOCAL",
"password": "string",
"populateSoapActionHeader": false,
"sslVersion": "HTTP",
"url": "string",
"username": "string"
};
export const testWebhookRequest = {
"notification": {
"amount": {
"currency": "string",
"value": 0
},
"eventCode": "string",
"eventDate": "string",
"merchantReference": "string",
"paymentMethod": "string",
"reason": "string",
"success": false
},
"types": ["string"]
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,25 @@
import nock from "nock"; import nock from "nock";
import Client from "../client"; import Client from "../client";
import {createClient} from "../__mocks__/base"; import { createClient } from "../__mocks__/base";
import { Management } from "../services"; import { Management } from "../services";
import { AllowedOrigin, AllowedOriginsResponse, MeApiCredential } from "../typings/management/models"; import { AllowedOrigin, AllowedOriginsResponse, MeApiCredential } from "../typings/management/models";
import * as models from "../typings/management/models";
import * as requests from "../__mocks__/management/requests";
import * as responses from "../__mocks__/management/responses";
let client: Client; let client: Client;
let management: Management; let management: Management;
let scope: nock.Scope; let scope: nock.Scope;
const merchantId = "merchantId";
const apiCredentialId = "apiCredentialId";
const originId = "originId";
const paymentMethodId = "paymentMethodId";
const payoutSettingsId = "payoutSettingsId";
const orderId = "orderId";
const userId = "userId";
const webhookId = "webhookId";
beforeEach((): void => { beforeEach((): void => {
if (!nock.isActive()) { if (!nock.isActive()) {
nock.activate(); nock.activate();
@@ -55,57 +67,57 @@ describe("Management", (): void => {
expect(meResponse.id).toEqual("S2-6262224667"); expect(meResponse.id).toEqual("S2-6262224667");
}); });
test("Should add an allowed origin to the list of allowed origins",async (): Promise<void> => { test("Should add an allowed origin to the list of allowed origins", async (): Promise<void> => {
scope.post("/me/allowedOrigins") scope.post("/me/allowedOrigins")
.reply(200, { .reply(200, {
"id": "S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921", "id": "S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921",
"domain": "https://www.us.mystore.com", "domain": "https://www.us.mystore.com",
"_links": { "_links": {
"self": { "self": {
"href": "https://management-test.adyen.com/v1/me/allowedOrigins/S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921" "href": "https://management-test.adyen.com/v1/me/allowedOrigins/S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921"
}
}
});
const allowedOriginRequest: AllowedOrigin = {
"domain": "https://www.us.mystore.com"
};
const allowedOriginsResponse: AllowedOrigin = await management.Me.createAllowedOrigin(allowedOriginRequest);
expect(allowedOriginsResponse.domain).toEqual("https://www.us.mystore.com");
});
test("Should get the list of allowed origins of a API credential based on the API key used in the request", async(): Promise<void> => {
scope.get("/me/allowedOrigins")
.reply(200, {
"data": [
{
"id": "S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921",
"domain": "https://www.us.mystore.com",
"_links": {
"self": {
"href": "https://management-test.adyen.com/v1/me/allowedOrigins/S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921"
}
} }
} }
] });
}); const allowedOriginRequest: AllowedOrigin = {
"domain": "https://www.us.mystore.com"
};
const allowedOriginsResponse : AllowedOriginsResponse = await management.Me.retrieveAllowedOrigins(); const allowedOriginsResponse: AllowedOrigin = await management.Me.createAllowedOrigin(allowedOriginRequest);
expect(allowedOriginsResponse.domain).toEqual("https://www.us.mystore.com");
});
test("Should get the list of allowed origins of a API credential based on the API key used in the request", async (): Promise<void> => {
scope.get("/me/allowedOrigins")
.reply(200, {
"data": [
{
"id": "S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921",
"domain": "https://www.us.mystore.com",
"_links": {
"self": {
"href": "https://management-test.adyen.com/v1/me/allowedOrigins/S2-45597C41735B6D75433E2B396553453ertcdt347675B4E3B413B4C4571522A6B2921"
}
}
}
]
});
const allowedOriginsResponse: AllowedOriginsResponse = await management.Me.retrieveAllowedOrigins();
expect(allowedOriginsResponse.data?.length).toEqual(1); expect(allowedOriginsResponse.data?.length).toEqual(1);
}); });
}); });
test("Should retrieve the details of the allowed origin specified in the path",async () => { test("Should retrieve the details of the allowed origin specified in the path", async () => {
scope.get("/me/allowedOrigins/S2-123123123123123") scope.get("/me/allowedOrigins/S2-123123123123123")
.reply(200, { .reply(200, {
"id": "S2-123123123123123", "id": "S2-123123123123123",
"domain": "https://www.us.mystore.com", "domain": "https://www.us.mystore.com",
"_links": { "_links": {
"self": { "self": {
"href": "https://management-test.adyen.com/v1/me/allowedOrigins/S2-123123123123123" "href": "https://management-test.adyen.com/v1/me/allowedOrigins/S2-123123123123123"
}
} }
} });
});
const allowedOriginResponse: AllowedOrigin = await management.Me.retrieveAllowedOrigin("S2-123123123123123"); const allowedOriginResponse: AllowedOrigin = await management.Me.retrieveAllowedOrigin("S2-123123123123123");
expect(allowedOriginResponse.id).toEqual("S2-123123123123123"); expect(allowedOriginResponse.id).toEqual("S2-123123123123123");
@@ -117,4 +129,539 @@ describe("Management", (): void => {
expect(scope.isDone()).toBe(true); expect(scope.isDone()).toBe(true);
expect(Object.entries(allowedOriginResponse).length).toBe(0); expect(Object.entries(allowedOriginResponse).length).toBe(0);
}); });
describe("MerchantAccount", (): void => {
it("should support GET /merchants", async (): Promise<void> => {
scope.get(`/merchants?pageNumber=1&pageSize=1`)
.reply(200, responses.listMerchantResponse);
const response: models.ListMerchantResponse = await management.MerchantAccount.list({
params: {
"pageNumber": "1",
"pageSize": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants", async (): Promise<void> => {
scope.post(`/merchants`)
.reply(200, responses.createMerchantResponse);
const response: models.CreateMerchantResponse = await management.MerchantAccount.create(requests.createMerchantRequest);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}`)
.reply(200, responses.merchant);
const response: models.Merchant = await management.MerchantAccount.retrieve(merchantId);
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/activate", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/activate`)
.reply(200, responses.requestActivationResponse);
const response: models.RequestActivationResponse = await management.MerchantAccount.activate(merchantId);
expect(response).toBeTruthy();
});
});
describe("MerchantAllowedOrigins", (): void => {
it("should support GET /merchants/{merchantId}/apiCredentials/{apiCredentialId}/allowedOrigins", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins`)
.reply(200, responses.allowedOriginsResponse);
const response: models.AllowedOriginsResponse = await management.MerchantAllowedOrigins.list(merchantId, apiCredentialId);
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/apiCredentials/{apiCredentialId}/allowedOrigins", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins`)
.reply(200, responses.allowedOriginsResponse);
const response: models.AllowedOriginsResponse = await management.MerchantAllowedOrigins.create(merchantId, apiCredentialId, requests.allowedOrigin);
expect(response).toBeTruthy();
});
it("should support DELETE /merchants/{merchantId}/apiCredentials/{apiCredentialId}/allowedOrigins/{originId}", async (): Promise<void> => {
scope.delete(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins/${originId}`)
.reply(204);
await management.MerchantAllowedOrigins.delete(merchantId, apiCredentialId, originId);
});
it("should support GET /merchants/{merchantId}/apiCredentials/{apiCredentialId}/allowedOrigins/{originId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins/${originId}`)
.reply(200, responses.allowedOrigin);
const response: models.AllowedOrigin = await management.MerchantAllowedOrigins.retrieve(merchantId, apiCredentialId, originId);
expect(response).toBeTruthy();
});
});
describe("MerchantApiCredentials", (): void => {
it("should support GET /merchants/{merchantId}/apiCredentials", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/apiCredentials?pageNumber=1&pageSize=1`)
.reply(200, responses.listMerchantApiCredentialsResponse);
const response: models.ListMerchantApiCredentialsResponse = await management.MerchantApiCredentials.list(merchantId, {
params: {
"pageNumber": "1",
"pageSize": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/apiCredentials", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/apiCredentials`)
.reply(200, responses.createApiCredentialResponse);
const response: models.CreateApiCredentialResponse = await management.MerchantApiCredentials.create(merchantId, requests.createMerchantApiCredentialRequest);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/apiCredentials/{apiCredentialId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}`)
.reply(200, responses.apiCredential);
const response: models.ApiCredential = await management.MerchantApiCredentials.retrieve(merchantId, apiCredentialId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/apiCredentials/{apiCredentialId}", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}`)
.reply(200, responses.apiCredential);
const response: models.ApiCredential = await management.MerchantApiCredentials.update(merchantId, apiCredentialId, requests.updateMerchantApiCredentialRequest);
expect(response).toBeTruthy();
});
});
describe("MerchantApiKey", (): void => {
it("should support POST /merchants/{merchantId}/apiCredentials/{apiCredentialId}/generateApiKey", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}/generateApiKey`)
.reply(200, responses.generateApiKeyResponse);
const response: models.GenerateApiKeyResponse = await management.MerchantApiKey.create(merchantId, apiCredentialId);
expect(response).toBeTruthy();
});
});
describe("MerchantClientKey", (): void => {
it("should support POST /merchants/{merchantId}/apiCredentials/{apiCredentialId}/generateClientKey", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/apiCredentials/${apiCredentialId}/generateClientKey`)
.reply(200, responses.generateClientKeyResponse);
const response: models.GenerateClientKeyResponse = await management.MerchantClientKey.create(merchantId, apiCredentialId);
expect(response).toBeTruthy();
});
});
describe("MerchantPaymentMethods", (): void => {
it("should support GET /merchants/{merchantId}/paymentMethodSettings", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/paymentMethodSettings?storeId=1&businessLineId=1&pageNumber=1&pageSize=1`)
.reply(200, responses.paymentMethodResponse);
const response: models.PaymentMethodResponse = await management.MerchantPaymentMethods.listPaymentMethodSettings(merchantId, {
params: {
"storeId": "1",
"businessLineId": "1",
"pageSize": "1",
"pageNumber": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/paymentMethodSettings", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/paymentMethodSettings`)
.reply(200, responses.paymentMethod);
const response: models.PaymentMethod = await management.MerchantPaymentMethods.create(merchantId, {
...requests.paymentMethodSetupInfo,
type: models.PaymentMethodSetupInfo.TypeEnum.Ideal
});
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/paymentMethodSettings/{paymentMethodId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/paymentMethodSettings/${paymentMethodId}`)
.reply(200, responses.paymentMethod);
const response: models.PaymentMethod = await management.MerchantPaymentMethods.retrieve(merchantId, paymentMethodId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/paymentMethodSettings/{paymentMethodId}", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/paymentMethodSettings/${paymentMethodId}`)
.reply(200, responses.paymentMethod);
const response: models.PaymentMethod = await management.MerchantPaymentMethods.update(merchantId, paymentMethodId, requests.updatePaymentMethodInfo);
expect(response).toBeTruthy();
});
});
describe("MerchantPayoutSettings", (): void => {
it("should support GET /merchants/{merchantId}/payoutSettings", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/payoutSettings`)
.reply(200, responses.payoutSettingsResponse);
const response: models.PayoutSettingsResponse = await management.MerchantPayoutSettings.listPayoutSettings(merchantId);
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/payoutSettings", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/payoutSettings`)
.reply(200, responses.payoutSettings);
const response: models.PayoutSettings = await management.MerchantPayoutSettings.create(merchantId, requests.payoutSettingsRequest);
expect(response).toBeTruthy();
});
it("should support DELETE /merchants/{merchantId}/payoutSettings/{payoutSettingsId}", async (): Promise<void> => {
scope.delete(`/merchants/${merchantId}/payoutSettings/${payoutSettingsId}`)
.reply(200);
await management.MerchantPayoutSettings.delete(merchantId, payoutSettingsId);
});
it("should support GET /merchants/{merchantId}/payoutSettings/{payoutSettingsId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/payoutSettings/${payoutSettingsId}`)
.reply(200, responses.payoutSettings);
const response: models.PayoutSettings = await management.MerchantPayoutSettings.retrieve(merchantId, payoutSettingsId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/payoutSettings/{payoutSettingsId}", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/payoutSettings/${payoutSettingsId}`)
.reply(200, responses.payoutSettings);
const response: models.PayoutSettings = await management.MerchantPayoutSettings.update(merchantId, payoutSettingsId, requests.updatePayoutSettingsRequest);
expect(response).toBeTruthy();
});
});
describe("MerchantTerminalOrders", (): void => {
it("should support GET /merchants/{merchantId}/billingEntities", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/billingEntities?name=bill`)
.reply(200, responses.billingEntitiesResponse);
const response: models.BillingEntitiesResponse = await management.MerchantTerminalOrders.listBillingEntities(merchantId, {
params: {
"name": "bill"
}
});
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/shippingLocations", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/shippingLocations?name=1&offset=1&limit=1`)
.reply(200, responses.shippingLocationsResponse);
const response: models.ShippingLocationsResponse = await management.MerchantTerminalOrders.listShippingLocations(merchantId, {
params: {
"name": "1",
"offset": "1",
"limit": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/shippingLocations", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/shippingLocations`)
.reply(200, responses.shippingLocation);
const response: models.ShippingLocation = await management.MerchantTerminalOrders.createShippingLocation(merchantId, requests.shippingLocation);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/terminalModels", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/terminalModels`)
.reply(200, responses.terminalModelsResponse);
const response: models.TerminalModelsResponse = await management.MerchantTerminalOrders.listTerminalModels(merchantId);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/terminalOrders", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/terminalOrders?customerOrderReference=1&status=1&offset=1&limit=1`)
.reply(200, responses.terminalOrdersResponse);
const response: models.TerminalOrdersResponse = await management.MerchantTerminalOrders.listTerminalOrders(merchantId, {
params: {
"customerOrderReference": "1",
"status": "1",
"offset": "1",
"limit": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/terminalOrders", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/terminalOrders`)
.reply(200, responses.terminalOrder);
const response: models.TerminalOrder = await management.MerchantTerminalOrders.create(merchantId, requests.terminalOrderRequest);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/terminalOrders/{orderId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/terminalOrders/${orderId}`)
.reply(200, responses.terminalOrder);
const response: models.TerminalOrder = await management.MerchantTerminalOrders.retrieve(merchantId, orderId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/terminalOrders/{orderId}", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/terminalOrders/${orderId}`)
.reply(200, responses.terminalOrder);
const response: models.TerminalOrder = await management.MerchantTerminalOrders.update(merchantId, orderId, requests.terminalOrderRequest);
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/terminalOrders/{orderId}/cancel", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/terminalOrders/${orderId}/cancel`)
.reply(200, responses.terminalOrder);
const response: models.TerminalOrder = await management.MerchantTerminalOrders.cancel(merchantId, orderId);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/terminalProducts", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/terminalProducts?country=1&terminalModelId=1&offset=1&limit=1`)
.reply(200, responses.terminalProductsResponse);
const response: models.TerminalProductsResponse = await management.MerchantTerminalOrders.listTerminalProducts(merchantId, {
params: {
"country": "1",
"terminalModelId": "1",
"offset": "1",
"limit": "1"
}
});
expect(response).toBeTruthy();
});
});
describe("MerchantTerminalSettings", (): void => {
it("should support GET /merchants/{merchantId}/terminalLogos", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/terminalLogos?model=1`)
.reply(200, responses.logo);
const response: models.Logo = await management.MerchantTerminalSettings.retrieveLogo(merchantId, {
params: {
"model": "1"
}
});
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/terminalLogos", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/terminalLogos?model=1`)
.reply(200, responses.logo);
const response: models.Logo = await management.MerchantTerminalSettings.updateLogo(merchantId, requests.logo, {
params: {
"model": "1"
}
});
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/terminalSettings", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/terminalSettings`)
.reply(200, responses.terminalSettings);
const response: models.TerminalSettings = await management.MerchantTerminalSettings.retrieve(merchantId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/terminalSettings", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/terminalSettings`)
.reply(200, responses.terminalSettings);
const response: models.TerminalSettings = await management.MerchantTerminalSettings.update(merchantId, requests.terminalSettings);
expect(response).toBeTruthy();
});
});
describe("MerchantUsers", (): void => {
it("should support GET /merchants/{merchantId}/users", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/users?pageNumber=1&pageSize=1`)
.reply(200, responses.listMerchantUsersResponse);
const response: models.ListMerchantUsersResponse = await management.MerchantUsers.list(merchantId, {
params: {
"pageNumber": "1",
"pageSize": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/users", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/users`)
.reply(200, responses.createUserResponse);
const response: models.CreateUserResponse = await management.MerchantUsers.create(merchantId, requests.createMerchantUserRequest);
expect(response).toBeTruthy();
});
it("should support GET /merchants/{merchantId}/users/{userId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/users/${userId}`)
.reply(200, responses.user);
const response: models.User = await management.MerchantUsers.retrieve(merchantId, userId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/users/{userId}", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/users/${userId}`)
.reply(200, responses.user);
const response: models.User = await management.MerchantUsers.update(merchantId, userId, requests.updateMerchantUserRequest);
expect(response).toBeTruthy();
});
});
describe("MerchantWebhooks", (): void => {
it("should support GET /merchants/{merchantId}/webhooks", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/webhooks?pageNumber=1&pageSize=1`)
.reply(200, responses.listWebhooksResponse);
const response: models.ListWebhooksResponse = await management.MerchantWebhooks.list(merchantId, {
params: {
"pageNumber": "1",
"pageSize": "1"
}
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/webhooks", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/webhooks`)
.reply(200, responses.webhook);
const response: models.Webhook = await management.MerchantWebhooks.create(merchantId, {
...requests.createMerchantWebhookRequest,
communicationFormat: models.CreateMerchantWebhookRequest.CommunicationFormatEnum.Json,
networkType: models.CreateMerchantWebhookRequest.NetworkTypeEnum.Public,
sslVersion: models.CreateMerchantWebhookRequest.SslVersionEnum.Tls
});
expect(response).toBeTruthy();
});
it("should support DELETE /merchants/{merchantId}/webhooks/{webhookId}", async (): Promise<void> => {
scope.delete(`/merchants/${merchantId}/webhooks/${webhookId}`)
.reply(204);
await management.MerchantWebhooks.delete(merchantId, webhookId);
});
it("should support GET /merchants/{merchantId}/webhooks/{webhookId}", async (): Promise<void> => {
scope.get(`/merchants/${merchantId}/webhooks/${webhookId}`)
.reply(200, responses.webhook);
const response: models.Webhook = await management.MerchantWebhooks.retrieve(merchantId, webhookId);
expect(response).toBeTruthy();
});
it("should support PATCH /merchants/{merchantId}/webhooks/{webhookId}", async (): Promise<void> => {
scope.patch(`/merchants/${merchantId}/webhooks/${webhookId}`)
.reply(200, responses.webhook);
const response: models.Webhook = await management.MerchantWebhooks.update(merchantId, webhookId, {
...requests.updateMerchantWebhookRequest,
communicationFormat: models.CreateMerchantWebhookRequest.CommunicationFormatEnum.Soap,
networkType: models.CreateMerchantWebhookRequest.NetworkTypeEnum.Local,
sslVersion: models.CreateMerchantWebhookRequest.SslVersionEnum.Sslv3
});
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/webhooks/{webhookId}/generateHmac", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/webhooks/${webhookId}/generateHmac`)
.reply(200, responses.generateHmacKeyResponse);
const response: models.GenerateHmacKeyResponse = await management.MerchantWebhooks.generateHmac(merchantId, webhookId);
expect(response).toBeTruthy();
});
it("should support POST /merchants/{merchantId}/webhooks/{webhookId}/test", async (): Promise<void> => {
scope.post(`/merchants/${merchantId}/webhooks/${webhookId}/test`, /2022-07-15T00:00:00.000Z/)
.reply(200, responses.testWebhookResponse);
let testWebhookRequest = {
"notification": {
"amount": {
"currency": "string",
"value": 0
},
"eventCode": "string",
"eventDate": new Date(2022, 6, 15),
"merchantReference": "string",
"paymentMethod": "string",
"reason": "string",
"success": false
},
"types": ["string"]
};
const response: models.TestWebhookResponse = await management.MerchantWebhooks.test(merchantId, webhookId, testWebhookRequest);
expect(response).toBeTruthy();
});
});
}); });

View File

@@ -2,6 +2,17 @@ import Service from "../service";
import Client from "../client"; import Client from "../client";
import MeApi from "./management/meApi"; import MeApi from "./management/meApi";
import MerchantAccount from "./management/merchantAccount";
import MerchantAllowedOrigins from "./management/merchantAllowedOrigins";
import MerchantApiCredentials from "./management/merchantApiCredentials";
import MerchantApiKey from "./management/merchantApiKey";
import MerchantClientKey from "./management/merchantClientKey";
import MerchantPaymentMethods from "./management/merchantPaymentMethods";
import MerchantPayoutSettings from "./management/merchantPayoutSettings";
import MerchantTerminalOrders from "./management/merchantTerminalOrders";
import MerchantTerminalSettings from "./management/merchantTerminalSettings";
import MerchantUsers from "./management/merchantUsers";
import MerchantWebhooks from "./management/merchantWebhooks";
class Management extends Service { class Management extends Service {
public constructor(client: Client) { public constructor(client: Client) {
@@ -11,7 +22,51 @@ class Management extends Service {
public get Me() { public get Me() {
const meApi = new MeApi(this.client); const meApi = new MeApi(this.client);
return meApi.Me; return meApi.Me;
} }
public get MerchantAccount() {
return new MerchantAccount(this.client);
}
public get MerchantAllowedOrigins() {
return new MerchantAllowedOrigins(this.client);
}
public get MerchantApiCredentials() {
return new MerchantApiCredentials(this.client);
}
public get MerchantApiKey() {
return new MerchantApiKey(this.client);
}
public get MerchantClientKey() {
return new MerchantClientKey(this.client);
}
public get MerchantPaymentMethods() {
return new MerchantPaymentMethods(this.client);
}
public get MerchantPayoutSettings() {
return new MerchantPayoutSettings(this.client);
}
public get MerchantTerminalOrders() {
return new MerchantTerminalOrders(this.client);
}
public get MerchantTerminalSettings() {
return new MerchantTerminalSettings(this.client);
}
public get MerchantUsers() {
return new MerchantUsers(this.client);
}
public get MerchantWebhooks() {
return new MerchantWebhooks(this.client);
}
} }
export default Management; export default Management;

View File

@@ -0,0 +1,61 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { CreateMerchantRequest, CreateMerchantResponse, ListMerchantResponse, Merchant, ObjectSerializer, RequestActivationResponse } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantAccount extends Service {
/**
* Get a list of merchant accounts
*/
public async list(requestOptions?: IRequest.Options): Promise<ListMerchantResponse> {
const resource = new ManagementResource(this, `/merchants`);
const response = await getJsonResponse<string, ListMerchantResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "ListMerchantResponse");
}
/**
* Create a merchant account
*/
public async create(request: CreateMerchantRequest): Promise<CreateMerchantResponse> {
const resource = new ManagementResource(this, `/merchants`);
const response = await getJsonResponse<CreateMerchantRequest, CreateMerchantResponse>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "CreateMerchantResponse");
}
/**
* Get a merchant account
*/
public async retrieve(merchantId: string): Promise<Merchant> {
const resource = new ManagementResource(this, `/merchants/${merchantId}`);
const response = await getJsonResponse<string, Merchant>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "Merchant");
}
/**
* Request to activate a merchant account
*/
public async activate(merchantId: string): Promise<RequestActivationResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/activate`);
const response = await getJsonResponse<string, RequestActivationResponse>(
resource,
"",
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "RequestActivationResponse");
}
}
export default MerchantAccount;

View File

@@ -0,0 +1,59 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { AllowedOrigin, AllowedOriginsResponse, ObjectSerializer } from "../../typings/management/models";
import ManagementResource from "../resource/management/managementResource";
class MerchantAllowedOrigins extends Service {
/**
* Get a list of allowed origins
*/
public async list(merchantId: string, apiCredentialId: string): Promise<AllowedOriginsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins`);
const response = await getJsonResponse<string, AllowedOriginsResponse>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "AllowedOriginsResponse");
}
/**
* Create an allowed origin
*/
public async create(merchantId: string, apiCredentialId: string, request: AllowedOrigin): Promise<AllowedOriginsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins`);
const response = await getJsonResponse<AllowedOrigin, AllowedOriginsResponse>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "AllowedOriginsResponse");
}
/**
* Delete an allowed origin
*/
public async delete(merchantId: string, apiCredentialId: string, originId: string): Promise<void> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins/${originId}`);
await getJsonResponse<string, void>(
resource,
"",
{ method: "DELETE" }
);
}
/**
* Get an allowed origin
*/
public async retrieve(merchantId: string, apiCredentialId: string, originId: string): Promise<AllowedOrigin> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}/allowedOrigins/${originId}`);
const response = await getJsonResponse<string, AllowedOrigin>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "AllowedOrigin");
}
}
export default MerchantAllowedOrigins;

View File

@@ -0,0 +1,61 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { ApiCredential, CreateApiCredentialResponse, CreateMerchantApiCredentialRequest, ListMerchantApiCredentialsResponse, ObjectSerializer, UpdateMerchantApiCredentialRequest } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantApiCredentials extends Service {
/**
* Get a list of API credentials
*/
public async list(merchantId: string, requestOptions?: IRequest.Options): Promise<ListMerchantApiCredentialsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials`);
const response = await getJsonResponse<string, ListMerchantApiCredentialsResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "ListMerchantApiCredentialsResponse");
}
/**
* Create an API credential
*/
public async create(merchantId: string, request: CreateMerchantApiCredentialRequest): Promise<CreateApiCredentialResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials`);
const response = await getJsonResponse<CreateMerchantApiCredentialRequest, CreateApiCredentialResponse>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "CreateApiCredentialResponse");
}
/**
* Get an API credential
*/
public async retrieve(merchantId: string, apiCredentialId: string): Promise<ApiCredential> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}`);
const response = await getJsonResponse<string, ApiCredential>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "ApiCredential");
}
/**
* Update an API credential
*/
public async update(merchantId: string, apiCredentialId: string, request: UpdateMerchantApiCredentialRequest): Promise<ApiCredential> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}`);
const response = await getJsonResponse<UpdateMerchantApiCredentialRequest, ApiCredential>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "ApiCredential");
}
}
export default MerchantApiCredentials;

View File

@@ -0,0 +1,21 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { GenerateApiKeyResponse, ObjectSerializer } from "../../typings/management/models";
import ManagementResource from "../resource/management/managementResource";
class MerchantApiKey extends Service {
/**
* Generate new API key
*/
public async create(merchantId: string, apiCredentialId: string): Promise<GenerateApiKeyResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}/generateApiKey`);
const response = await getJsonResponse<string, GenerateApiKeyResponse>(
resource,
"",
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "GenerateApiKeyResponse");
}
}
export default MerchantApiKey;

View File

@@ -0,0 +1,21 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { GenerateClientKeyResponse, ObjectSerializer } from "../../typings/management/models";
import ManagementResource from "../resource/management/managementResource";
class MerchantClientKey extends Service {
/**
* Generate new client key
*/
public async create(merchantId: string, apiCredentialId: string): Promise<GenerateClientKeyResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/apiCredentials/${apiCredentialId}/generateClientKey`);
const response = await getJsonResponse<string, GenerateClientKeyResponse>(
resource,
"",
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "GenerateClientKeyResponse");
}
}
export default MerchantClientKey;

View File

@@ -0,0 +1,61 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { ObjectSerializer, PaymentMethod, PaymentMethodResponse, PaymentMethodSetupInfo, UpdatePaymentMethodInfo } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantPaymentMethods extends Service {
/**
* Get all payment methods
*/
public async listPaymentMethodSettings(merchantId: string, requestOptions?: IRequest.Options): Promise<PaymentMethodResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/paymentMethodSettings`);
const response = await getJsonResponse<string, PaymentMethodResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "PaymentMethodResponse");
}
/**
* Request a payment method
*/
public async create(merchantId: string, request: PaymentMethodSetupInfo): Promise<PaymentMethod> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/paymentMethodSettings`);
const response = await getJsonResponse<PaymentMethodSetupInfo, PaymentMethod>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "PaymentMethod");
}
/**
* Get payment method details
*/
public async retrieve(merchantId: string, paymentMethodId: string): Promise<PaymentMethod> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/paymentMethodSettings/${paymentMethodId}`);
const response = await getJsonResponse<string, PaymentMethod>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "PaymentMethod");
}
/**
* Update a payment method
*/
public async update(merchantId: string, paymentMethodId: string, request: UpdatePaymentMethodInfo): Promise<PaymentMethod> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/paymentMethodSettings/${paymentMethodId}`);
const response = await getJsonResponse<UpdatePaymentMethodInfo, PaymentMethod>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "PaymentMethod");
}
}
export default MerchantPaymentMethods;

View File

@@ -0,0 +1,72 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { ObjectSerializer, PayoutSettings, PayoutSettingsRequest, PayoutSettingsResponse, UpdatePayoutSettingsRequest } from "../../typings/management/models";
import ManagementResource from "../resource/management/managementResource";
class MerchantPayoutSettings extends Service {
/**
* Get a list of payout settings
*/
public async listPayoutSettings(merchantId: string): Promise<PayoutSettingsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/payoutSettings`);
const response = await getJsonResponse<string, PayoutSettingsResponse>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "PayoutSettingsResponse");
}
/**
* Add a payout setting
*/
public async create(merchantId: string, request: PayoutSettingsRequest): Promise<PayoutSettings> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/payoutSettings`);
const response = await getJsonResponse<PayoutSettingsRequest, PayoutSettings>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "PayoutSettings");
}
/**
* Delete a payout setting
*/
public async delete(merchantId: string, payoutSettingsId: string): Promise<void> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/payoutSettings/${payoutSettingsId}`);
await getJsonResponse<string, void>(
resource,
"",
{ method: "DELETE" }
);
}
/**
* Get a payout setting
*/
public async retrieve(merchantId: string, payoutSettingsId: string): Promise<PayoutSettings> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/payoutSettings/${payoutSettingsId}`);
const response = await getJsonResponse<string, PayoutSettings>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "PayoutSettings");
}
/**
* Update a payout setting
*/
public async update(merchantId: string, payoutSettingsId: string, request: UpdatePayoutSettingsRequest): Promise<PayoutSettings> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/payoutSettings/${payoutSettingsId}`);
const response = await getJsonResponse<UpdatePayoutSettingsRequest, PayoutSettings>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "PayoutSettings");
}
}
export default MerchantPayoutSettings;

View File

@@ -0,0 +1,139 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { BillingEntitiesResponse, ObjectSerializer, ShippingLocation, ShippingLocationsResponse, TerminalModelsResponse, TerminalOrder, TerminalOrderRequest, TerminalOrdersResponse, TerminalProductsResponse } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantTerminalOrders extends Service {
/**
* Get a list of billing entities
*/
public async listBillingEntities(merchantId: string, requestOptions?: IRequest.Options): Promise<BillingEntitiesResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/billingEntities`);
const response = await getJsonResponse<string, BillingEntitiesResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "BillingEntitiesResponse");
}
/**
* Get a list of shipping locations
*/
public async listShippingLocations(merchantId: string, requestOptions?: IRequest.Options): Promise<ShippingLocationsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/shippingLocations`);
const response = await getJsonResponse<string, ShippingLocationsResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "ShippingLocationsResponse");
}
/**
* Create a shipping location
*/
public async createShippingLocation(merchantId: string, request: ShippingLocation): Promise<ShippingLocation> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/shippingLocations`);
const response = await getJsonResponse<ShippingLocation, ShippingLocation>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "ShippingLocation");
}
/**
* Get a list of terminal models
*/
public async listTerminalModels(merchantId: string): Promise<TerminalModelsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalModels`);
const response = await getJsonResponse<string, TerminalModelsResponse>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "TerminalModelsResponse");
}
/**
* Get a list of orders
*/
public async listTerminalOrders(merchantId: string, requestOptions?: IRequest.Options): Promise<TerminalOrdersResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalOrders`);
const response = await getJsonResponse<string, TerminalOrdersResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "TerminalOrdersResponse");
}
/**
* Create an order
*/
public async create(merchantId: string, request: TerminalOrderRequest): Promise<TerminalOrder> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalOrders`);
const response = await getJsonResponse<TerminalOrderRequest, TerminalOrder>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "TerminalOrder");
}
/**
* Get an order
*/
public async retrieve(merchantId: string, orderId: string): Promise<TerminalOrder> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalOrders/${orderId}`);
const response = await getJsonResponse<string, TerminalOrder>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "TerminalOrder");
}
/**
* Update an order
*/
public async update(merchantId: string, orderId: string, request: TerminalOrderRequest): Promise<TerminalOrder> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalOrders/${orderId}`);
const response = await getJsonResponse<TerminalOrderRequest, TerminalOrder>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "TerminalOrder");
}
/**
* Cancel an order
*/
public async cancel(merchantId: string, orderId: string): Promise<TerminalOrder> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalOrders/${orderId}/cancel`);
const response = await getJsonResponse<string, TerminalOrder>(
resource,
"",
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "TerminalOrder");
}
/**
* Get a list of terminal products
*/
public async listTerminalProducts(merchantId: string, requestOptions?: IRequest.Options): Promise<TerminalProductsResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalProducts`);
const response = await getJsonResponse<string, TerminalProductsResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "TerminalProductsResponse");
}
}
export default MerchantTerminalOrders;

View File

@@ -0,0 +1,61 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { Logo, ObjectSerializer, TerminalSettings } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantTerminalSettings extends Service {
/**
* Get the terminal logo
*/
public async retrieveLogo(merchantId: string, requestOptions?: IRequest.Options): Promise<Logo> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalLogos`);
const response = await getJsonResponse<string, Logo>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "Logo");
}
/**
* Update the terminal logo
*/
public async updateLogo(merchantId: string, request: Logo, requestOptions?: IRequest.Options): Promise<Logo> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalLogos`);
const response = await getJsonResponse<Logo, Logo>(
resource,
request,
{ ...requestOptions, method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "Logo");
}
/**
* Get terminal settings
*/
public async retrieve(merchantId: string): Promise<TerminalSettings> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalSettings`);
const response = await getJsonResponse<string, TerminalSettings>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "TerminalSettings");
}
/**
* Update terminal settings
*/
public async update(merchantId: string, request: TerminalSettings): Promise<TerminalSettings> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/terminalSettings`);
const response = await getJsonResponse<TerminalSettings, TerminalSettings>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "TerminalSettings");
}
}
export default MerchantTerminalSettings;

View File

@@ -0,0 +1,61 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { CreateMerchantUserRequest, CreateUserResponse, ListMerchantUsersResponse, ObjectSerializer, UpdateMerchantUserRequest, User } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantUsers extends Service {
/**
* Get a list of users
*/
public async list(merchantId: string, requestOptions?: IRequest.Options): Promise<ListMerchantUsersResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/users`);
const response = await getJsonResponse<string, ListMerchantUsersResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "ListMerchantUsersResponse");
}
/**
* Create a new user
*/
public async create(merchantId: string, request: CreateMerchantUserRequest): Promise<CreateUserResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/users`);
const response = await getJsonResponse<CreateMerchantUserRequest, CreateUserResponse>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "CreateUserResponse");
}
/**
* Get user details
*/
public async retrieve(merchantId: string, userId: string): Promise<User> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/users/${userId}`);
const response = await getJsonResponse<string, User>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "User");
}
/**
* Update a user
*/
public async update(merchantId: string, userId: string, request: UpdateMerchantUserRequest): Promise<User> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/users/${userId}`);
const response = await getJsonResponse<UpdateMerchantUserRequest, User>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "User");
}
}
export default MerchantUsers;

View File

@@ -0,0 +1,99 @@
import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import { CreateMerchantWebhookRequest, GenerateHmacKeyResponse, ListWebhooksResponse, ObjectSerializer, TestWebhookRequest, TestWebhookResponse, UpdateMerchantWebhookRequest, Webhook } from "../../typings/management/models";
import { IRequest } from "../../typings/requestOptions";
import ManagementResource from "../resource/management/managementResource";
class MerchantWebhooks extends Service {
/**
* List all webhooks
*/
public async list(merchantId: string, requestOptions?: IRequest.Options): Promise<ListWebhooksResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks`);
const response = await getJsonResponse<string, ListWebhooksResponse>(
resource,
"",
{ ...requestOptions, method: "GET" }
);
return ObjectSerializer.deserialize(response, "ListWebhooksResponse");
}
/**
* Set up a webhook
*/
public async create(merchantId: string, request: CreateMerchantWebhookRequest): Promise<Webhook> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks`);
const response = await getJsonResponse<CreateMerchantWebhookRequest, Webhook>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "Webhook");
}
/**
* Remove a webhook
*/
public async delete(merchantId: string, webhookId: string): Promise<void> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks/${webhookId}`);
await getJsonResponse<string, void>(
resource,
"",
{ method: "DELETE" }
);
}
/**
* Get a webhook
*/
public async retrieve(merchantId: string, webhookId: string): Promise<Webhook> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks/${webhookId}`);
const response = await getJsonResponse<string, Webhook>(
resource,
"",
{ method: "GET" }
);
return ObjectSerializer.deserialize(response, "Webhook");
}
/**
* Update a webhook
*/
public async update(merchantId: string, webhookId: string, request: UpdateMerchantWebhookRequest): Promise<Webhook> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks/${webhookId}`);
const response = await getJsonResponse<UpdateMerchantWebhookRequest, Webhook>(
resource,
request,
{ method: "PATCH" }
);
return ObjectSerializer.deserialize(response, "Webhook");
}
/**
* Generate an HMAC key
*/
public async generateHmac(merchantId: string, webhookId: string): Promise<GenerateHmacKeyResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks/${webhookId}/generateHmac`);
const response = await getJsonResponse<string, GenerateHmacKeyResponse>(
resource,
"",
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "GenerateHmacKeyResponse");
}
/**
* Test a webhook
*/
public async test(merchantId: string, webhookId: string, request: TestWebhookRequest): Promise<TestWebhookResponse> {
const resource = new ManagementResource(this, `/merchants/${merchantId}/webhooks/${webhookId}/test`);
const response = await getJsonResponse<TestWebhookRequest, TestWebhookResponse>(
resource,
request,
{ method: "POST" }
);
return ObjectSerializer.deserialize(response, "TestWebhookResponse");
}
}
export default MerchantWebhooks;

View File

@@ -0,0 +1,14 @@
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";
class ManagementResource extends Resource {
public constructor(service: Service, endpoint: string) {
super(
service,
`${service.client.config.managementEndpoint}/${Client.MANAGEMENT_API_VERSION}${endpoint}`
);
}
}
export default ManagementResource;