Skip to content

Commit 7bf724b

Browse files
authored
Models for webhook setup via Management API (#77)
* Added models for webhook setup via Management API * Using Assert class for assert statements * Fixed assert statement
1 parent ea1ad5a commit 7bf724b

8 files changed

+359
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
@NamespaceAccessible
2+
public with sharing class WebhookSetupRequest {
3+
4+
@NamespaceAccessible
5+
public String url { get; set; }
6+
7+
@NamespaceAccessible
8+
public String description { get; set; }
9+
10+
@NamespaceAccessible
11+
public Boolean active { get; set; }
12+
13+
@NamespaceAccessible
14+
public String communicationFormat { get; set; }
15+
16+
@NamespaceAccessible
17+
public String type { get; set; }
18+
19+
@NamespaceAccessible
20+
public AdditionalSettings additionalSettings { get; set; }
21+
22+
@NamespaceAccessible
23+
public String encryptionProtocol { get; set; }
24+
25+
@NamespaceAccessible
26+
public Boolean equals(Object obj) {
27+
if (obj == null || !(obj instanceof WebhookSetupRequest)) return false;
28+
29+
WebhookSetupRequest other = (WebhookSetupRequest) obj;
30+
return this.url == other.url
31+
&& this.description == other.description
32+
&& this.active == other.active
33+
&& this.communicationFormat == other.communicationFormat
34+
&& this.type == other.type
35+
&& this.encryptionProtocol == other.encryptionProtocol
36+
&& this.additionalSettings.equals(other.additionalSettings);
37+
}
38+
39+
@NamespaceAccessible
40+
public Integer hashCode() {
41+
List<Object> requestFields = new List<Object>{
42+
url,
43+
description,
44+
active,
45+
communicationFormat,
46+
type,
47+
encryptionProtocol,
48+
additionalSettings
49+
};
50+
return ApiLibUtils.computeHashCode(requestFields);
51+
}
52+
53+
@NamespaceAccessible
54+
public static WebhookSetupRequest getExample() {
55+
56+
WebhookSetupRequest example = new WebhookSetupRequest();
57+
example.url = 'https://example.com/webhook';
58+
example.active = true;
59+
example.communicationFormat = 'json';
60+
example.type = 'standard';
61+
example.encryptionProtocol = 'TLSv1.3';
62+
example.description = 'Webhook for payment notifications';
63+
example.additionalSettings = new AdditionalSettings();
64+
example.additionalSettings.includeEventCodes = new List<String>{
65+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_AUTHORISE,
66+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_CAPTURE
67+
};
68+
return example;
69+
}
70+
71+
@NamespaceAccessible
72+
public class AdditionalSettings {
73+
@NamespaceAccessible
74+
public List<String> includeEventCodes { get; set; }
75+
76+
public Boolean equals(Object obj) {
77+
if (obj == null || !(obj instanceof AdditionalSettings)) return false;
78+
AdditionalSettings other = (AdditionalSettings) obj;
79+
return this.includeEventCodes == other.includeEventCodes;
80+
}
81+
82+
public Integer hashCode() {
83+
return ApiLibUtils.computeHashCode(new List<Object>{ includeEventCodes });
84+
}
85+
}
86+
87+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>63.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@IsTest
2+
private class WebhookSetupRequestTest {
3+
@IsTest
4+
static void getExampleTest() {
5+
WebhookSetupRequest request = WebhookSetupRequest.getExample();
6+
Assert.isNotNull(request);
7+
Assert.isNotNull(request.url);
8+
Assert.isNotNull(request.communicationFormat);
9+
Assert.isNotNull(request.type);
10+
Assert.isNotNull(request.encryptionProtocol);
11+
}
12+
13+
@IsTest
14+
static void testEqualsTrue() {
15+
// Given
16+
WebhookSetupRequest req1 = WebhookSetupRequest.getExample();
17+
WebhookSetupRequest req2 = WebhookSetupRequest.getExample();
18+
19+
// When
20+
Boolean result = req1.equals(req2);
21+
22+
// Then
23+
Assert.isTrue(result, 'Expected both WebhookSetupRequest objects to be equal');
24+
}
25+
26+
@IsTest
27+
static void testEqualsFalse() {
28+
// Given
29+
WebhookSetupRequest req1 = WebhookSetupRequest.getExample();
30+
WebhookSetupRequest req2 = WebhookSetupRequest.getExample();
31+
req2.url = 'https://different-url.com/webhook';
32+
33+
// When
34+
Boolean result = req1.equals(req2);
35+
36+
// Then
37+
Assert.isFalse(result, 'Expected WebhookSetupRequest objects to be different');
38+
}
39+
40+
@IsTest
41+
static void testHashCodeSame() {
42+
// Given
43+
WebhookSetupRequest req1 = WebhookSetupRequest.getExample();
44+
WebhookSetupRequest req2 = WebhookSetupRequest.getExample();
45+
46+
// When
47+
Integer hashCode1 = req1.hashCode();
48+
Integer hashCode2 = req2.hashCode();
49+
50+
// Then
51+
Assert.areEqual(hashCode1, hashCode2, 'Expected identical objects to have the same hash code');
52+
}
53+
54+
@IsTest
55+
static void testHashCodeDifferent() {
56+
// Given
57+
WebhookSetupRequest req1 = WebhookSetupRequest.getExample();
58+
WebhookSetupRequest req2 = WebhookSetupRequest.getExample();
59+
req2.url = 'https://different-url.com/webhook';
60+
61+
// When
62+
Integer hashCode1 = req1.hashCode();
63+
Integer hashCode2 = req2.hashCode();
64+
65+
// Then
66+
Assert.areNotEqual(hashCode1, hashCode2, 'Expected different objects to have different hash codes');
67+
}
68+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>63.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
@NamespaceAccessible
2+
public with sharing class WebhookSetupResponse {
3+
4+
@NamespaceAccessible
5+
public String id { get; set; }
6+
7+
@NamespaceAccessible
8+
public String url { get; set; }
9+
10+
@NamespaceAccessible
11+
public String description { get; set; }
12+
13+
@NamespaceAccessible
14+
public Boolean active { get; set; }
15+
16+
@NamespaceAccessible
17+
public String communicationFormat { get; set; }
18+
19+
@NamespaceAccessible
20+
public String type { get; set; }
21+
22+
@NamespaceAccessible
23+
public String encryptionProtocol { get; set; }
24+
25+
@NamespaceAccessible
26+
public Boolean hasError { get; set; }
27+
28+
@NamespaceAccessible
29+
public AdditionalSettings additionalSettings { get; set; }
30+
31+
@NamespaceAccessible
32+
public Boolean equals(Object obj) {
33+
if (obj == null || !(obj instanceof WebhookSetupResponse)) return false;
34+
35+
WebhookSetupResponse other = (WebhookSetupResponse) obj;
36+
return this.id == other.id
37+
&& this.url == other.url
38+
&& this.description == other.description
39+
&& this.active == other.active
40+
&& this.communicationFormat == other.communicationFormat
41+
&& this.type == other.type
42+
&& this.encryptionProtocol == other.encryptionProtocol
43+
&& this.hasError == other.hasError
44+
&& this.additionalSettings.equals(other.additionalSettings);
45+
}
46+
47+
48+
@NamespaceAccessible
49+
public Integer hashCode() {
50+
List<Object> responseFields = new List<Object>{
51+
id,
52+
url,
53+
description,
54+
active,
55+
communicationFormat,
56+
type,
57+
encryptionProtocol,
58+
hasError,
59+
additionalSettings != null ? additionalSettings.includeEventCodes : null,
60+
additionalSettings != null ? additionalSettings.excludeEventCodes : null
61+
};
62+
return ApiLibUtils.computeHashCode(responseFields);
63+
}
64+
65+
@NamespaceAccessible
66+
public static WebhookSetupResponse getExample() {
67+
WebhookSetupResponse example = new WebhookSetupResponse();
68+
example.id = 'WS123456789';
69+
example.url = 'https://example.com/webhook';
70+
example.description = 'Webhook for payment notifications';
71+
example.active = true;
72+
example.communicationFormat = 'json';
73+
example.type = 'standard';
74+
example.encryptionProtocol = 'TLSv1.3';
75+
example.hasError = false;
76+
77+
example.additionalSettings = new AdditionalSettings();
78+
example.additionalSettings.includeEventCodes = new List<String>{
79+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_AUTHORISE,
80+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_CAPTURE
81+
};
82+
83+
return example;
84+
}
85+
86+
@NamespaceAccessible
87+
public class AdditionalSettings {
88+
@NamespaceAccessible
89+
public List<String> includeEventCodes { get; set; }
90+
91+
@NamespaceAccessible
92+
public List<String> excludeEventCodes { get; set; }
93+
94+
public Boolean equals(Object obj) {
95+
if (obj == null || !(obj instanceof AdditionalSettings)) return false;
96+
AdditionalSettings other = (AdditionalSettings) obj;
97+
return this.includeEventCodes == other.includeEventCodes
98+
&& this.excludeEventCodes == other.excludeEventCodes;
99+
}
100+
101+
public Integer hashCode() {
102+
return ApiLibUtils.computeHashCode(new List<Object>{ includeEventCodes, excludeEventCodes });
103+
}
104+
105+
}
106+
107+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>63.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@IsTest
2+
private class WebhookSetupResponseTest {
3+
4+
@IsTest
5+
static void testEqualsTrue() {
6+
// Given
7+
WebhookSetupResponse res1 = WebhookSetupResponse.getExample();
8+
WebhookSetupResponse res2 = WebhookSetupResponse.getExample();
9+
10+
// When
11+
Boolean result = res1.equals(res2);
12+
13+
// Then
14+
Assert.isTrue(result, 'Expected both WebhookSetupResponse objects to be equal');
15+
}
16+
17+
@IsTest
18+
static void testEqualsFalse() {
19+
// Given
20+
WebhookSetupResponse res1 = WebhookSetupResponse.getExample();
21+
WebhookSetupResponse res2 = WebhookSetupResponse.getExample();
22+
res2.id = 'DIFFERENT_ID';
23+
24+
// When
25+
Boolean result = res1.equals(res2);
26+
27+
// Then
28+
Assert.isFalse(result, 'Expected WebhookSetupResponse objects to be different');
29+
}
30+
31+
@IsTest
32+
static void testHashCodeSame() {
33+
// Given
34+
WebhookSetupResponse res1 = WebhookSetupResponse.getExample();
35+
WebhookSetupResponse res2 = WebhookSetupResponse.getExample();
36+
37+
res1.additionalSettings = new WebhookSetupResponse.AdditionalSettings();
38+
res1.additionalSettings.includeEventCodes = new List<String>{
39+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_AUTHORISE,
40+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_CAPTURE
41+
};
42+
res1.additionalSettings.excludeEventCodes = new List<String>{
43+
'REFUND'
44+
};
45+
46+
res2.additionalSettings = new WebhookSetupResponse.AdditionalSettings();
47+
res2.additionalSettings.includeEventCodes = new List<String>{
48+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_AUTHORISE,
49+
AdyenConstants.NOTIFICATION_REQUEST_TYPE_CAPTURE
50+
};
51+
res2.additionalSettings.excludeEventCodes = new List<String>{
52+
'REFUND'
53+
};
54+
55+
// When
56+
Integer hashCode1 = res1.hashCode();
57+
Integer hashCode2 = res2.hashCode();
58+
59+
// Then
60+
Assert.areEqual(hashCode1, hashCode2, 'Expected identical objects to have the same hash code');
61+
}
62+
63+
@IsTest
64+
static void testHashCodeDifferent() {
65+
// Given
66+
WebhookSetupResponse res1 = WebhookSetupResponse.getExample();
67+
WebhookSetupResponse res2 = WebhookSetupResponse.getExample();
68+
res2.id = 'DIFFERENT_ID';
69+
70+
// When
71+
Integer hashCode1 = res1.hashCode();
72+
Integer hashCode2 = res2.hashCode();
73+
74+
// Then
75+
Assert.areNotEqual(hashCode1, hashCode2, 'Expected different objects to have different hash codes');
76+
}
77+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>63.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)