|
| 1 | +/* |
| 2 | + * The version of the OpenAPI document: v2 |
| 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/balancePlatform/objectSerializer"; |
| 18 | +import { ListMandatesResponse } from "../../typings/balancePlatform/models"; |
| 19 | +import { Mandate } from "../../typings/balancePlatform/models"; |
| 20 | +import { PatchableMandate } from "../../typings/balancePlatform/models"; |
| 21 | + |
| 22 | +/** |
| 23 | + * API handler for DirectDebitMandatesApi |
| 24 | + */ |
| 25 | +export class DirectDebitMandatesApi extends Service { |
| 26 | + |
| 27 | + private readonly API_BASEPATH: string = "https://balanceplatform-api-test.adyen.com/bcl/v2"; |
| 28 | + private baseUrl: string; |
| 29 | + |
| 30 | + public constructor(client: Client){ |
| 31 | + super(client); |
| 32 | + this.baseUrl = this.createBaseUrl(this.API_BASEPATH); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @summary Cancel a mandate |
| 37 | + * @param mandateId {@link string } The unique identifier of the mandate. |
| 38 | + * @param requestOptions {@link IRequest.Options } |
| 39 | + * @return {@link void } |
| 40 | + */ |
| 41 | + public async cancelMandate(mandateId: string, requestOptions?: IRequest.Options): Promise<void> { |
| 42 | + const endpoint = `${this.baseUrl}/mandates/{mandateId}/cancel` |
| 43 | + .replace("{" + "mandateId" + "}", encodeURIComponent(String(mandateId))); |
| 44 | + const resource = new Resource(this, endpoint); |
| 45 | + |
| 46 | + await getJsonResponse<string, void>( |
| 47 | + resource, |
| 48 | + "", |
| 49 | + { ...requestOptions, method: "POST" } |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @summary Get a list of mandates |
| 55 | + * @param requestOptions {@link IRequest.Options } |
| 56 | + * @param balanceAccountId {@link string } The unique identifier of the balance account linked to the payment instrument. |
| 57 | + * @param paymentInstrumentId {@link string } The unique identifier of the payment instrument linked to the mandate. |
| 58 | + * @param cursor {@link string } The pagination cursor returned in a previous GET `/mandates` request. |
| 59 | + * @return {@link ListMandatesResponse } |
| 60 | + */ |
| 61 | + public async getListOfMandates(balanceAccountId?: string, paymentInstrumentId?: string, cursor?: string, requestOptions?: IRequest.Options): Promise<ListMandatesResponse> { |
| 62 | + const endpoint = `${this.baseUrl}/mandates`; |
| 63 | + const resource = new Resource(this, endpoint); |
| 64 | + |
| 65 | + const hasDefinedQueryParams = balanceAccountId ?? paymentInstrumentId ?? cursor; |
| 66 | + if(hasDefinedQueryParams) { |
| 67 | + if(!requestOptions) requestOptions = {}; |
| 68 | + if(!requestOptions.params) requestOptions.params = {}; |
| 69 | + if(balanceAccountId) requestOptions.params["balanceAccountId"] = balanceAccountId; |
| 70 | + if(paymentInstrumentId) requestOptions.params["paymentInstrumentId"] = paymentInstrumentId; |
| 71 | + if(cursor) requestOptions.params["cursor"] = cursor; |
| 72 | + } |
| 73 | + const response = await getJsonResponse<string, ListMandatesResponse>( |
| 74 | + resource, |
| 75 | + "", |
| 76 | + { ...requestOptions, method: "GET" } |
| 77 | + ); |
| 78 | + |
| 79 | + return ObjectSerializer.deserialize(response, "ListMandatesResponse"); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @summary Get a specific mandate |
| 84 | + * @param mandateId {@link string } The unique identifier of the mandate. |
| 85 | + * @param requestOptions {@link IRequest.Options } |
| 86 | + * @return {@link Mandate } |
| 87 | + */ |
| 88 | + public async getMandateById(mandateId: string, requestOptions?: IRequest.Options): Promise<Mandate> { |
| 89 | + const endpoint = `${this.baseUrl}/mandates/{mandateId}` |
| 90 | + .replace("{" + "mandateId" + "}", encodeURIComponent(String(mandateId))); |
| 91 | + const resource = new Resource(this, endpoint); |
| 92 | + |
| 93 | + const response = await getJsonResponse<string, Mandate>( |
| 94 | + resource, |
| 95 | + "", |
| 96 | + { ...requestOptions, method: "GET" } |
| 97 | + ); |
| 98 | + |
| 99 | + return ObjectSerializer.deserialize(response, "Mandate"); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @summary Amend a mandate |
| 104 | + * @param mandateId {@link string } The unique identifier of the mandate. |
| 105 | + * @param patchableMandate {@link PatchableMandate } |
| 106 | + * @param requestOptions {@link IRequest.Options } |
| 107 | + * @return {@link void } |
| 108 | + */ |
| 109 | + public async updateMandate(mandateId: string, patchableMandate: PatchableMandate, requestOptions?: IRequest.Options): Promise<void> { |
| 110 | + const endpoint = `${this.baseUrl}/mandates/{mandateId}` |
| 111 | + .replace("{" + "mandateId" + "}", encodeURIComponent(String(mandateId))); |
| 112 | + const resource = new Resource(this, endpoint); |
| 113 | + |
| 114 | + const request: PatchableMandate = ObjectSerializer.serialize(patchableMandate, "PatchableMandate"); |
| 115 | + await getJsonResponse<PatchableMandate, void>( |
| 116 | + resource, |
| 117 | + request, |
| 118 | + { ...requestOptions, method: "PATCH" } |
| 119 | + ); |
| 120 | + } |
| 121 | + |
| 122 | +} |
0 commit comments