|
| 1 | +/* |
| 2 | + * The version of the OpenAPI document: v1 |
| 3 | + * |
| 4 | + * |
| 5 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 6 | + * https://openapi-generator.tech |
| 7 | + * Do not edit this class manually. |
| 8 | + */ |
| 9 | + |
| 10 | + |
| 11 | +import getJsonResponse from "../../helpers/getJsonResponse"; |
| 12 | +import Service from "../../service"; |
| 13 | +import Client from "../../client"; |
| 14 | +import { IRequest } from "../../typings/requestOptions"; |
| 15 | +import Resource from "../resource"; |
| 16 | + |
| 17 | +import { ObjectSerializer } from "../../typings/capital/objectSerializer"; |
| 18 | +import { CalculateGrantOfferRequest } from "../../typings/capital/models"; |
| 19 | +import { CalculatedGrantOffer } from "../../typings/capital/models"; |
| 20 | +import { CreateGrantOfferRequest } from "../../typings/capital/models"; |
| 21 | +import { FinancingType } from "../../typings/capital/models"; |
| 22 | +import { GetDynamicOffersResponse } from "../../typings/capital/models"; |
| 23 | +import { GrantOffer } from "../../typings/capital/models"; |
| 24 | + |
| 25 | +/** |
| 26 | + * API handler for DynamicOffersApi |
| 27 | + */ |
| 28 | +export class DynamicOffersApi extends Service { |
| 29 | + |
| 30 | + private readonly API_BASEPATH: string = "https://balanceplatform-api-test.adyen.com/capital/v1"; |
| 31 | + private baseUrl: string; |
| 32 | + |
| 33 | + public constructor(client: Client){ |
| 34 | + super(client); |
| 35 | + this.baseUrl = this.createBaseUrl(this.API_BASEPATH); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @summary Calculate a preliminary offer for a selected financing amount |
| 40 | + * @param id {@link string } The unique identifier of the dynamic offer from which the user selected the financing amount. |
| 41 | + * @param calculateGrantOfferRequest {@link CalculateGrantOfferRequest } |
| 42 | + * @param requestOptions {@link IRequest.Options } |
| 43 | + * @return {@link CalculatedGrantOffer } |
| 44 | + */ |
| 45 | + public async calculatePreliminaryOfferFromDynamicOffer(id: string, calculateGrantOfferRequest: CalculateGrantOfferRequest, requestOptions?: IRequest.Options): Promise<CalculatedGrantOffer> { |
| 46 | + const endpoint = `${this.baseUrl}/dynamicOffers/{id}/calculate` |
| 47 | + .replace("{" + "id" + "}", encodeURIComponent(String(id))); |
| 48 | + const resource = new Resource(this, endpoint); |
| 49 | + |
| 50 | + const request: CalculateGrantOfferRequest = ObjectSerializer.serialize(calculateGrantOfferRequest, "CalculateGrantOfferRequest"); |
| 51 | + const response = await getJsonResponse<CalculateGrantOfferRequest, CalculatedGrantOffer>( |
| 52 | + resource, |
| 53 | + request, |
| 54 | + { ...requestOptions, method: "POST" } |
| 55 | + ); |
| 56 | + |
| 57 | + return ObjectSerializer.deserialize(response, "CalculatedGrantOffer"); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @summary Create a static offer for a selected financing amount |
| 62 | + * @param id {@link string } The unique identifier of the dynamic offer from which the user selected the financing amount. |
| 63 | + * @param createGrantOfferRequest {@link CreateGrantOfferRequest } |
| 64 | + * @param requestOptions {@link IRequest.Options } |
| 65 | + * @return {@link GrantOffer } |
| 66 | + */ |
| 67 | + public async createStaticOfferFromDynamicOffer(id: string, createGrantOfferRequest: CreateGrantOfferRequest, requestOptions?: IRequest.Options): Promise<GrantOffer> { |
| 68 | + const endpoint = `${this.baseUrl}/dynamicOffers/{id}/grantOffer` |
| 69 | + .replace("{" + "id" + "}", encodeURIComponent(String(id))); |
| 70 | + const resource = new Resource(this, endpoint); |
| 71 | + |
| 72 | + const request: CreateGrantOfferRequest = ObjectSerializer.serialize(createGrantOfferRequest, "CreateGrantOfferRequest"); |
| 73 | + const response = await getJsonResponse<CreateGrantOfferRequest, GrantOffer>( |
| 74 | + resource, |
| 75 | + request, |
| 76 | + { ...requestOptions, method: "POST" } |
| 77 | + ); |
| 78 | + |
| 79 | + return ObjectSerializer.deserialize(response, "GrantOffer"); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @summary Get all available dynamic offers |
| 84 | + * @param requestOptions {@link IRequest.Options } |
| 85 | + * @param accountHolderId {@link string } (Required) The unique identifier of the account holder that the dynamic offer is for. |
| 86 | + * @param financingType {@link FinancingType } The type of financing that the offer is for. If the value is not specified, returns all available types. Possible values: **businessFinancing** |
| 87 | + * @return {@link GetDynamicOffersResponse } |
| 88 | + */ |
| 89 | + public async getAllDynamicOffers(accountHolderId: string, financingType?: FinancingType, requestOptions?: IRequest.Options): Promise<GetDynamicOffersResponse> { |
| 90 | + const endpoint = `${this.baseUrl}/dynamicOffers`; |
| 91 | + const resource = new Resource(this, endpoint); |
| 92 | + |
| 93 | + const hasDefinedQueryParams = accountHolderId ?? financingType; |
| 94 | + if(hasDefinedQueryParams) { |
| 95 | + if(!requestOptions) requestOptions = {}; |
| 96 | + if(!requestOptions.params) requestOptions.params = {}; |
| 97 | + if(accountHolderId) requestOptions.params["accountHolderId"] = accountHolderId; |
| 98 | + if(financingType) requestOptions.params["financingType"] = financingType; |
| 99 | + } |
| 100 | + const response = await getJsonResponse<string, GetDynamicOffersResponse>( |
| 101 | + resource, |
| 102 | + "", |
| 103 | + { ...requestOptions, method: "GET" } |
| 104 | + ); |
| 105 | + |
| 106 | + return ObjectSerializer.deserialize(response, "GetDynamicOffersResponse"); |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments