From 56ca560f7f4c2d01d74c14460a86d81e2b883052 Mon Sep 17 00:00:00 2001 From: Jonathan Martins Date: Tue, 19 Nov 2024 16:18:48 -0300 Subject: [PATCH] ips() method added to Webhooks resource --- src/Resources/Webhooks.php | 29 +++++++++++++++++++++++++++++ tests/Resources/WebhooksTest.php | 20 ++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/Resources/Webhooks.php b/src/Resources/Webhooks.php index d679d66..5740e37 100644 --- a/src/Resources/Webhooks.php +++ b/src/Resources/Webhooks.php @@ -141,6 +141,35 @@ public function create(array $webhook): array return $this->requestTransport->transport($request); } + /** + * Get a list of webhook IPs. + * + * ## Usage + * ```php + * $result = $client->webhooks()->ips(); + * + * foreach ($result["ips"] as $ip) { + * echo $ip; // string + * } + * + * $result["ips"][0]; // "189.51.60.9" + * $result["ips"][1]; // "138.97.124.129" + * $result["ips"][2]; // "177.71.136.66" + * ``` + * + * @link https://developers.openpix.com.br/api#tag/webhook/paths/~1api~1v1~1webhook~1ips/get + * + * @return array + */ + public function ips(): array + { + $request = (new Request()) + ->method("GET") + ->path("/api/v1/webhook/ips"); + + return $this->requestTransport->transport($request); + } + /** * Validate webhook signature. * diff --git a/tests/Resources/WebhooksTest.php b/tests/Resources/WebhooksTest.php index d9fe7f0..17d0199 100644 --- a/tests/Resources/WebhooksTest.php +++ b/tests/Resources/WebhooksTest.php @@ -73,6 +73,26 @@ public function testCreate(): void $this->assertSame(["webhook" => []], $result); } + public function testIps(): void + { + $requestTransportMock = $this->createMock(RequestTransport::class); + $requestTransportMock->expects($this->once()) + ->method("transport") + ->willReturnCallback(function (Request $request) { + $this->assertSame("GET", $request->getMethod()); + $this->assertSame("/api/v1/webhook/ips", $request->getPath()); + $this->assertSame(null, $request->getBody()); + $this->assertSame([], $request->getQueryParams()); + + return ["ips" => []]; + }); + + $webhooks = new Webhooks($requestTransportMock); + $result = $webhooks->ips(); + + $this->assertSame(["ips" => []], $result); + } + public function testIsWebhookValidReturnsTrueWithValidWebhook(): void { $webhooks = new Webhooks($this->createStub(RequestTransport::class));