Skip to content
Merged
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
42 changes: 42 additions & 0 deletions src/__tests__/webhooks/bankingWebhooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { NegativeBalanceWarningWebhooksHandler } from "../../typings/negativeBal
import { TransactionWebhooksHandler } from "../../typings/transactionWebhooks/transactionWebhooksHandler";
import { BalanceWebhooksHandler } from "../../typings/balanceWebhooks/balanceWebhooksHandler";
import { ReportNotificationRequest } from "../../typings/reportWebhooks/reportNotificationRequest";
import { DisputeWebhooksHandler } from "../../typings/disputeWebhooks/disputeWebhooksHandler";
import { DisputeNotificationRequest } from "../../typings/disputeWebhooks/disputeNotificationRequest";
import { DisputeEventNotification } from "../../typings/disputeWebhooks/disputeEventNotification";

describe("BankingWebhooks Tests", function (): void {

Expand Down Expand Up @@ -514,4 +517,43 @@ describe("BankingWebhooks Tests", function (): void {

});

it("should deserialize DisputeWebhooks DisputeNotificationRequest", function (): void {
const json = {
"type": "balancePlatform.dispute.created",
"data": {
"id": "DS00000000000000000001",
"balancePlatform": "YOUR_BALANCE_PLATFORM",
"disputedAmount": {
"currency": "EUR",
"value": 10000
},
"status": "open",
"type": DisputeEventNotification.TypeEnum.NotDelivered,

}
};
const jsonString = JSON.stringify(json);
const disputeWebhooksHandler = new DisputeWebhooksHandler(jsonString);
const disputeNotificationRequest: DisputeNotificationRequest = disputeWebhooksHandler.getDisputeNotificationRequest();

expect(disputeNotificationRequest).toBeTruthy();
expect(disputeNotificationRequest.type).toBe("balancePlatform.dispute.created");
expect(disputeNotificationRequest.data).toBeDefined();
expect(disputeNotificationRequest.data.id).toBe("DS00000000000000000001");
expect(disputeNotificationRequest.data.balancePlatform).toBe("YOUR_BALANCE_PLATFORM");
expect(disputeNotificationRequest.data.status).toBe("open");
expect(disputeNotificationRequest.data.type).toBe(DisputeEventNotification.TypeEnum.NotDelivered);
// test getGenericWebhook
const genericWebhook = disputeWebhooksHandler.getGenericWebhook();
expect(genericWebhook instanceof DisputeNotificationRequest).toBe(true);
expect(genericWebhook.type).toEqual("balancePlatform.dispute.created");
});

it("should throw SyntaxError when JSON is invalid", function (): void {
const invalidJsonString = "{ invalid json }";
expect(() => {
new DisputeWebhooksHandler(invalidJsonString);
}).toThrowError(SyntaxError);
});

});
20 changes: 10 additions & 10 deletions src/services/payment/paymentsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export class PaymentsApi extends Service {
const endpoint = `${this.baseUrl}/authorise`;
const resource = new Resource(this, endpoint);

const request: PaymentRequest = ObjectSerializer.serialize(paymentRequest, "PaymentRequest", "");
const request: PaymentRequest = ObjectSerializer.serialize(paymentRequest, "PaymentRequest");
const response = await getJsonResponse<PaymentRequest, PaymentResult>(
resource,
request,
{ ...requestOptions, method: "POST" }
);

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

/**
Expand All @@ -67,14 +67,14 @@ export class PaymentsApi extends Service {
const endpoint = `${this.baseUrl}/authorise3d`;
const resource = new Resource(this, endpoint);

const request: PaymentRequest3d = ObjectSerializer.serialize(paymentRequest3d, "PaymentRequest3d", "");
const request: PaymentRequest3d = ObjectSerializer.serialize(paymentRequest3d, "PaymentRequest3d");
const response = await getJsonResponse<PaymentRequest3d, PaymentResult>(
resource,
request,
{ ...requestOptions, method: "POST" }
);

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

/**
Expand All @@ -87,14 +87,14 @@ export class PaymentsApi extends Service {
const endpoint = `${this.baseUrl}/authorise3ds2`;
const resource = new Resource(this, endpoint);

const request: PaymentRequest3ds2 = ObjectSerializer.serialize(paymentRequest3ds2, "PaymentRequest3ds2", "");
const request: PaymentRequest3ds2 = ObjectSerializer.serialize(paymentRequest3ds2, "PaymentRequest3ds2");
const response = await getJsonResponse<PaymentRequest3ds2, PaymentResult>(
resource,
request,
{ ...requestOptions, method: "POST" }
);

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

/**
Expand All @@ -107,14 +107,14 @@ export class PaymentsApi extends Service {
const endpoint = `${this.baseUrl}/getAuthenticationResult`;
const resource = new Resource(this, endpoint);

const request: AuthenticationResultRequest = ObjectSerializer.serialize(authenticationResultRequest, "AuthenticationResultRequest", "");
const request: AuthenticationResultRequest = ObjectSerializer.serialize(authenticationResultRequest, "AuthenticationResultRequest");
const response = await getJsonResponse<AuthenticationResultRequest, AuthenticationResultResponse>(
resource,
request,
{ ...requestOptions, method: "POST" }
);

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

/**
Expand All @@ -127,14 +127,14 @@ export class PaymentsApi extends Service {
const endpoint = `${this.baseUrl}/retrieve3ds2Result`;
const resource = new Resource(this, endpoint);

const request: ThreeDS2ResultRequest = ObjectSerializer.serialize(threeDS2ResultRequest, "ThreeDS2ResultRequest", "");
const request: ThreeDS2ResultRequest = ObjectSerializer.serialize(threeDS2ResultRequest, "ThreeDS2ResultRequest");
const response = await getJsonResponse<ThreeDS2ResultRequest, ThreeDS2ResultResponse>(
resource,
request,
{ ...requestOptions, method: "POST" }
);

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

}
59 changes: 59 additions & 0 deletions src/typings/disputeWebhooks/disputeWebhooksHandler.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 { disputeWebhooks } from "..";

/**
* Union type for all supported webhook requests.
* Allows generic handling of configuration-related webhook events.
*/
export type GenericWebhook =
| disputeWebhooks.DisputeNotificationRequest;

/**
* Handler for processing DisputeWebhooks.
*
* This class provides functionality to deserialize the payload of DisputeWebhooks events.
*/
export class DisputeWebhooksHandler {

private readonly payload: Record<string, any>;

public constructor(jsonPayload: string) {
this.payload = JSON.parse(jsonPayload);
}

/**
* This method checks the type of the webhook payload and returns the appropriate deserialized object.
*
* @returns A deserialized object of type GenericWebhook.
* @throws Error if the type is not recognized.
*/
public getGenericWebhook(): GenericWebhook {

const type = this.payload["type"];

if(Object.values(disputeWebhooks.DisputeNotificationRequest.TypeEnum).includes(type)) {
return this.getDisputeNotificationRequest();
}

throw new Error("Could not parse the json payload: " + this.payload);

}

/**
* Deserialize the webhook payload into a DisputeNotificationRequest
*
* @returns Deserialized DisputeNotificationRequest object.
*/
public getDisputeNotificationRequest(): disputeWebhooks.DisputeNotificationRequest {
return disputeWebhooks.ObjectSerializer.deserialize(this.payload, "DisputeNotificationRequest");
}

}
3 changes: 2 additions & 1 deletion src/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export * as managementWebhooks from "./managementWebhooks/models";
export * as acsWebhooks from "./acsWebhooks/models";
export * as transactionWebhooks from "./transactionWebhooks/models";
export * as negativeBalanceWarningWebhooks from "./negativeBalanceWarningWebhooks/models";
export * as balanceWebhooks from "./balanceWebhooks/models";
export * as balanceWebhooks from "./balanceWebhooks/models";
export * as disputeWebhooks from "./disputeWebhooks/models";
4 changes: 2 additions & 2 deletions templates-v7/typescript/api/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class {{classname}} extends Service {
const resource = new Resource(this, endpoint);

{{#bodyParam}}
const request: {{{dataType}}} = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "");
const request: {{{dataType}}} = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
{{/bodyParam}}
{{#hasQueryParams}}
const hasDefinedQueryParams = {{#queryParams}}{{paramName}}{{^-last}} ?? {{/-last}}{{/queryParams}};
Expand All @@ -61,7 +61,7 @@ export class {{classname}} extends Service {
);
{{#returnProperty}}

return ObjectSerializer.deserialize(response, "{{{returnType}}}", "");
return ObjectSerializer.deserialize(response, "{{{returnType}}}");
{{/returnProperty}}
}

Expand Down