forked from craftgate/craftgate-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HookSample.java
61 lines (48 loc) · 2.12 KB
/
HookSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package io.craftgate.sample;
import io.craftgate.Craftgate;
import io.craftgate.model.WebhookData;
import io.craftgate.model.WebhookEventType;
import io.craftgate.model.WebhookStatus;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class HookSample {
private final Craftgate craftgate = new Craftgate("api-key", "secret-key", "https://sandbox-api.craftgate.io");
@Test
void should_verify_webhook_signature() {
//given
String merchantHookKey = "Aoh7tReTybO6wOjBmOJFFsOR53SBojEp";
String incomingSignature = "0wRB5XqWJxwwPbn5Z9TcbHh8EGYFufSYTsRMB74N094=";
LocalDateTime eventTime = LocalDateTime.of(2022, 8, 26, 16, 40, 21, 395655000);
WebhookData webhookData = WebhookData.builder()
.eventType(WebhookEventType.API_VERIFY_AND_AUTH)
.eventTime(eventTime)
.eventTimestamp(1661521221L)
.status(WebhookStatus.SUCCESS)
.payloadId("584")
.build();
//when
boolean isWebhookVerified = craftgate.hook().isWebhookVerified(merchantHookKey, incomingSignature, webhookData);
//then
assertTrue(isWebhookVerified);
}
@Test
void should_not_verify_webhook_signature() {
//given
String merchantHookKey = "Aoh7tReTybO6wOjBmOJFFsOR53SBojEp";
String incomingSignature = "Bsa498wcnaasd4bhx8anxıxcsdnxanalkdjcahxhd";
LocalDateTime eventTime = LocalDateTime.of(2022, 8, 26, 16, 40, 21, 395655000);
WebhookData webhookData = WebhookData.builder()
.eventType(WebhookEventType.API_VERIFY_AND_AUTH)
.eventTime(eventTime)
.eventTimestamp(1661521221L)
.status(WebhookStatus.SUCCESS)
.payloadId("584")
.build();
//when
boolean isWebhookVerified = craftgate.hook().isWebhookVerified(merchantHookKey, incomingSignature, webhookData);
//then
assertFalse(isWebhookVerified);
}
}