Skip to content

Commit de511be

Browse files
fix: Notification replay now calls correct endpoint (#104)
1 parent d3807a1 commit de511be

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-php-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.
88

9+
## [Unreleased]
10+
11+
### Fixed
12+
13+
- `Client->notifications->replay()` now calls the correct endpoint
14+
915
## [1.5.0] - 2024-11-18
1016

1117
### Added

examples/notification_replay.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Paddle\SDK\Exceptions\ApiError;
6+
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;
7+
8+
require __DIR__ . '/../vendor/autoload.php';
9+
10+
$environment = Paddle\SDK\Environment::tryFrom(getenv('PADDLE_ENVIRONMENT') ?: '') ?? Paddle\SDK\Environment::SANDBOX;
11+
$apiKey = getenv('PADDLE_API_KEY') ?: null;
12+
$notificationId = getenv('PADDLE_NOTIFICATION_ID') ?: null;
13+
14+
if (is_null($apiKey)) {
15+
echo "You must provide the PADDLE_API_KEY in the environment:\n";
16+
echo "PADDLE_API_KEY=your-key php examples/basic_usage.php\n";
17+
exit(1);
18+
}
19+
20+
$paddle = new Paddle\SDK\Client($apiKey, options: new Paddle\SDK\Options($environment));
21+
22+
// ┌───
23+
// │ Replay Notification │
24+
// └─────────────────────┘
25+
try {
26+
$replayedNotificationId = $paddle->notifications->replay($notificationId);
27+
} catch (ApiError|MalformedResponse $e) {
28+
var_dump($e);
29+
exit;
30+
}
31+
32+
echo sprintf("Replayed Notification ID: %s\n", $replayedNotificationId);

src/Resources/Notifications/NotificationsClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function get(string $id): Notification
6363
public function replay(string $id): string
6464
{
6565
$parser = new ResponseParser(
66-
$this->client->postRaw("/notifications/{$id}"),
66+
$this->client->postRaw("/notifications/{$id}/replay"),
6767
);
6868

6969
$data = $parser->getData();

tests/Functional/Resources/Notifications/NotificationsClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function replay_hits_expected_uri(): void
170170
self::assertInstanceOf(RequestInterface::class, $request);
171171
self::assertEquals('POST', $request->getMethod());
172172
self::assertEquals(
173-
sprintf('%s/notifications/nft_01h8441jn5pcwrfhwh78jqt8hk', Environment::SANDBOX->baseUrl()),
173+
sprintf('%s/notifications/nft_01h8441jn5pcwrfhwh78jqt8hk/replay', Environment::SANDBOX->baseUrl()),
174174
urldecode((string) $request->getUri()),
175175
);
176176
self::assertSame('ntf_01h46h1s2zabpkdks7yt4vkgkc', $replayId);

0 commit comments

Comments
 (0)