Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/services/capital/grantAccountsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/


import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import Client from "../../client";
import { IRequest } from "../../typings/requestOptions";
import Resource from "../resource";

import { ObjectSerializer } from "../../typings/capital/objectSerializer";
import { GrantAccount } from "../../typings/capital/models";

/**
* API handler for GrantAccountsApi
*/
export class GrantAccountsApi extends Service {

private readonly API_BASEPATH: string = "https://balanceplatform-api-test.adyen.com/capital/v1";
private baseUrl: string;

public constructor(client: Client){
super(client);
this.baseUrl = this.createBaseUrl(this.API_BASEPATH);
}

/**
* @summary Get the information of your grant account
* @param id {@link string } The unique identifier of the grant account.
* @param requestOptions {@link IRequest.Options }
* @return {@link GrantAccount }
*/
public async getGrantAccountInformation(id: string, requestOptions?: IRequest.Options): Promise<GrantAccount> {
const endpoint = `${this.baseUrl}/grantAccounts/{id}`
.replace("{" + "id" + "}", encodeURIComponent(String(id)));
const resource = new Resource(this, endpoint);

const response = await getJsonResponse<string, GrantAccount>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "GrantAccount");
}

}
79 changes: 79 additions & 0 deletions src/services/capital/grantOffersApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/


import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import Client from "../../client";
import { IRequest } from "../../typings/requestOptions";
import Resource from "../resource";

import { ObjectSerializer } from "../../typings/capital/objectSerializer";
import { GrantOffer } from "../../typings/capital/models";
import { GrantOffers } from "../../typings/capital/models";

/**
* API handler for GrantOffersApi
*/
export class GrantOffersApi extends Service {

private readonly API_BASEPATH: string = "https://balanceplatform-api-test.adyen.com/capital/v1";
private baseUrl: string;

public constructor(client: Client){
super(client);
this.baseUrl = this.createBaseUrl(this.API_BASEPATH);
}

/**
* @summary Get all available grant offers
* @param requestOptions {@link IRequest.Options }
* @param accountHolderId {@link string } The unique identifier of the account holder for which you want to get the available grant offers.
* @return {@link GrantOffers }
*/
public async getAllGrantOffers(accountHolderId?: string, requestOptions?: IRequest.Options): Promise<GrantOffers> {
const endpoint = `${this.baseUrl}/grantOffers`;
const resource = new Resource(this, endpoint);

const hasDefinedQueryParams = accountHolderId;
if(hasDefinedQueryParams) {
if(!requestOptions) requestOptions = {};
if(!requestOptions.params) requestOptions.params = {};
if(accountHolderId) requestOptions.params["accountHolderId"] = accountHolderId;
}
Comment on lines +44 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic for handling query parameters is not robust and could lead to runtime errors. It assumes requestOptions.params is an object that can be assigned properties to, but its type QueryString also allows for string, string[][], or URLSearchParams. If a caller provides requestOptions.params as one of these other types, this code would fail. Additionally, the logic is verbose and contains redundant checks (if(hasDefinedQueryParams) followed by if(accountHolderId)). A more robust and concise implementation is recommended.

const response = await getJsonResponse<string, GrantOffers>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "GrantOffers");
}

/**
* @summary Get the details of a grant offer
* @param id {@link string } The unique identifier of the grant offer.
* @param requestOptions {@link IRequest.Options }
* @return {@link GrantOffer }
*/
public async getGrantOffer(id: string, requestOptions?: IRequest.Options): Promise<GrantOffer> {
const endpoint = `${this.baseUrl}/grantOffers/{id}`
.replace("{" + "id" + "}", encodeURIComponent(String(id)));
const resource = new Resource(this, endpoint);

const response = await getJsonResponse<string, GrantOffer>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "GrantOffer");
}

}
169 changes: 169 additions & 0 deletions src/services/capital/grantsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/


import getJsonResponse from "../../helpers/getJsonResponse";
import Service from "../../service";
import Client from "../../client";
import { IRequest } from "../../typings/requestOptions";
import Resource from "../resource";

import { ObjectSerializer } from "../../typings/capital/objectSerializer";
import { Disbursement } from "../../typings/capital/models";
import { DisbursementInfoUpdate } from "../../typings/capital/models";
import { Disbursements } from "../../typings/capital/models";
import { Grant } from "../../typings/capital/models";
import { GrantInfo } from "../../typings/capital/models";
import { Grants } from "../../typings/capital/models";

/**
* API handler for GrantsApi
*/
export class GrantsApi extends Service {

private readonly API_BASEPATH: string = "https://balanceplatform-api-test.adyen.com/capital/v1";
private baseUrl: string;

public constructor(client: Client){
super(client);
this.baseUrl = this.createBaseUrl(this.API_BASEPATH);
}

/**
* @summary Get all the disbursements of a grant
* @param grantId {@link string } The unique identifier of the grant reference.
* @param requestOptions {@link IRequest.Options }
* @return {@link Disbursements }
*/
public async getAllGrantDisbursements(grantId: string, requestOptions?: IRequest.Options): Promise<Disbursements> {
const endpoint = `${this.baseUrl}/grants/{grantId}/disbursements`
.replace("{" + "grantId" + "}", encodeURIComponent(String(grantId)));
const resource = new Resource(this, endpoint);

const response = await getJsonResponse<string, Disbursements>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "Disbursements");
}

/**
* @summary Get all the grants of an account holder
* @param requestOptions {@link IRequest.Options }
* @param counterpartyAccountHolderId {@link string } (Required) The unique identifier of the account holder that received the grants.
* @return {@link Grants }
*/
public async getAllGrants(counterpartyAccountHolderId: string, requestOptions?: IRequest.Options): Promise<Grants> {
const endpoint = `${this.baseUrl}/grants`;
const resource = new Resource(this, endpoint);

const hasDefinedQueryParams = counterpartyAccountHolderId;
if(hasDefinedQueryParams) {
if(!requestOptions) requestOptions = {};
if(!requestOptions.params) requestOptions.params = {};
if(counterpartyAccountHolderId) requestOptions.params["counterpartyAccountHolderId"] = counterpartyAccountHolderId;
}
Comment on lines +68 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic for handling query parameters is not robust and could lead to runtime errors. It assumes requestOptions.params is an object that can be assigned properties to, but its type QueryString also allows for string, string[][], or URLSearchParams. If a caller provides requestOptions.params as one of these other types, this code would fail. Additionally, the logic is verbose and contains redundant checks (if(hasDefinedQueryParams) followed by if(counterpartyAccountHolderId)). A more robust and concise implementation is recommended.

const response = await getJsonResponse<string, Grants>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "Grants");
}

/**
* @summary Get the details of a grant
* @param grantId {@link string } The unique identifier of the grant reference.
* @param requestOptions {@link IRequest.Options }
* @return {@link Grant }
*/
public async getGrant(grantId: string, requestOptions?: IRequest.Options): Promise<Grant> {
const endpoint = `${this.baseUrl}/grants/{grantId}`
.replace("{" + "grantId" + "}", encodeURIComponent(String(grantId)));
const resource = new Resource(this, endpoint);

const response = await getJsonResponse<string, Grant>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "Grant");
}

/**
* @summary Get disbursement details
* @param grantId {@link string } The unique identifier of the grant reference.
* @param disbursementId {@link string } The unique identifier of the disbursement.
* @param requestOptions {@link IRequest.Options }
* @return {@link Disbursement }
*/
public async getGrantDisbursement(grantId: string, disbursementId: string, requestOptions?: IRequest.Options): Promise<Disbursement> {
const endpoint = `${this.baseUrl}/grants/{grantId}/disbursements/{disbursementId}`
.replace("{" + "grantId" + "}", encodeURIComponent(String(grantId)))
.replace("{" + "disbursementId" + "}", encodeURIComponent(String(disbursementId)));
const resource = new Resource(this, endpoint);

const response = await getJsonResponse<string, Disbursement>(
resource,
"",
{ ...requestOptions, method: "GET" }
);

return ObjectSerializer.deserialize(response, "Disbursement");
}

/**
* @summary Make a request for a grant
* @param grantInfo {@link GrantInfo }
* @param requestOptions {@link IRequest.Options }
* @return {@link Grant }
*/
public async requestGrant(grantInfo: GrantInfo, requestOptions?: IRequest.Options): Promise<Grant> {
const endpoint = `${this.baseUrl}/grants`;
const resource = new Resource(this, endpoint);

const request: GrantInfo = ObjectSerializer.serialize(grantInfo, "GrantInfo");
const response = await getJsonResponse<GrantInfo, Grant>(
resource,
request,
{ ...requestOptions, method: "POST" }
);

return ObjectSerializer.deserialize(response, "Grant");
}

/**
* @summary Update the repayment configuration of a disbursement
* @param grantId {@link string } The unique identifier of the grant reference.
* @param disbursementId {@link string } The unique identifier of the disbursement.
* @param disbursementInfoUpdate {@link DisbursementInfoUpdate }
* @param requestOptions {@link IRequest.Options }
* @return {@link Disbursement }
*/
public async updateGrantDisbursement(grantId: string, disbursementId: string, disbursementInfoUpdate: DisbursementInfoUpdate, requestOptions?: IRequest.Options): Promise<Disbursement> {
const endpoint = `${this.baseUrl}/grants/{grantId}/disbursements/{disbursementId}`
.replace("{" + "grantId" + "}", encodeURIComponent(String(grantId)))
.replace("{" + "disbursementId" + "}", encodeURIComponent(String(disbursementId)));
const resource = new Resource(this, endpoint);

const request: DisbursementInfoUpdate = ObjectSerializer.serialize(disbursementInfoUpdate, "DisbursementInfoUpdate");
const response = await getJsonResponse<DisbursementInfoUpdate, Disbursement>(
resource,
request,
{ ...requestOptions, method: "PATCH" }
);

return ObjectSerializer.deserialize(response, "Disbursement");
}

}
34 changes: 34 additions & 0 deletions src/services/capital/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/

import { GrantAccountsApi } from "./grantAccountsApi";
import { GrantOffersApi } from "./grantOffersApi";
import { GrantsApi } from "./grantsApi";

import Service from "../../service";
import Client from "../../client";

export default class CapitalAPI extends Service {

public constructor(client: Client) {
super(client);
}

public get GrantAccountsApi() {
return new GrantAccountsApi(this.client);
}

public get GrantOffersApi() {
return new GrantOffersApi(this.client);
}

public get GrantsApi() {
return new GrantsApi(this.client);
}
}
Comment on lines +17 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The API getters create a new instance of the respective API class every time they are accessed. This is inefficient, especially if an API is used multiple times. It's better to use lazy initialization to create and cache the instance on first access. This improves performance by avoiding repeated object creation.

export default class CapitalAPI extends Service {
    private _grantAccountsApi?: GrantAccountsApi;
    private _grantOffersApi?: GrantOffersApi;
    private _grantsApi?: GrantsApi;

    public constructor(client: Client) {
        super(client);
    }

    public get GrantAccountsApi(): GrantAccountsApi {
        return this._grantAccountsApi ?? (this._grantAccountsApi = new GrantAccountsApi(this.client));
    }

    public get GrantOffersApi(): GrantOffersApi {
        return this._grantOffersApi ?? (this._grantOffersApi = new GrantOffersApi(this.client));
    }

    public get GrantsApi(): GrantsApi {
        return this._grantsApi ?? (this._grantsApi = new GrantsApi(this.client));
    }
}

59 changes: 59 additions & 0 deletions src/typings/capital/aULocalAccountIdentification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/

import { BankAccountIdentification } from "./bankAccountIdentification";


export class AULocalAccountIdentification extends BankAccountIdentification {
/**
* The bank account number, without separators or whitespace.
*/
"accountNumber": string;
/**
* The 6-digit [Bank State Branch (BSB) code](https://en.wikipedia.org/wiki/Bank_state_branch), without separators or whitespace.
*/
"bsbCode": string;
/**
* **auLocal**
*/
"type": string;

static override readonly discriminator: string | undefined = undefined;

static override readonly mapping: {[index: string]: string} | undefined = undefined;

static override readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
{
"name": "accountNumber",
"baseName": "accountNumber",
"type": "string",
"format": ""
},
{
"name": "bsbCode",
"baseName": "bsbCode",
"type": "string",
"format": ""
},
{
"name": "type",
"baseName": "type",
"type": "string",
"format": ""
} ];

static override getAttributeTypeMap() {
return super.getAttributeTypeMap().concat(AULocalAccountIdentification.attributeTypeMap);
}

public constructor() {
super();
}
Comment on lines +55 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The constructor for this class is unnecessary as it only calls the parent constructor with no arguments, which is the default behavior. It can be removed for cleaner code.

}

Loading