Skip to content

Commit

Permalink
fix: Notification replay now calls correct endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Dec 3, 2024
1 parent d3807a1 commit 7397f33
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

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.

## [Unreleased]

### Fixed

- `Client->notifications->replay()` now calls the correct endpoint

## [1.5.0] - 2024-11-18

### Added
Expand Down
32 changes: 32 additions & 0 deletions examples/notification_replay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

use Paddle\SDK\Exceptions\ApiError;
use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse;

require __DIR__ . '/../vendor/autoload.php';

$environment = Paddle\SDK\Environment::tryFrom(getenv('PADDLE_ENVIRONMENT') ?: '') ?? Paddle\SDK\Environment::SANDBOX;
$apiKey = getenv('PADDLE_API_KEY') ?: null;
$notificationId = getenv('PADDLE_NOTIFICATION_ID') ?: null;

if (is_null($apiKey)) {
echo "You must provide the PADDLE_API_KEY in the environment:\n";
echo "PADDLE_API_KEY=your-key php examples/basic_usage.php\n";
exit(1);
}

$paddle = new Paddle\SDK\Client($apiKey, options: new Paddle\SDK\Options($environment));

// ┌───
// │ Replay Notification │
// └─────────────────────┘
try {
$replayedNotificationId = $paddle->notifications->replay($notificationId);
} catch (ApiError|MalformedResponse $e) {
var_dump($e);
exit;
}

echo sprintf("Replayed Notification ID: %s\n", $replayedNotificationId);
2 changes: 1 addition & 1 deletion src/Resources/Notifications/NotificationsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function get(string $id): Notification
public function replay(string $id): string
{
$parser = new ResponseParser(
$this->client->postRaw("/notifications/{$id}"),
$this->client->postRaw("/notifications/{$id}/replay"),
);

$data = $parser->getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function replay_hits_expected_uri(): void
self::assertInstanceOf(RequestInterface::class, $request);
self::assertEquals('POST', $request->getMethod());
self::assertEquals(
sprintf('%s/notifications/nft_01h8441jn5pcwrfhwh78jqt8hk', Environment::SANDBOX->baseUrl()),
sprintf('%s/notifications/nft_01h8441jn5pcwrfhwh78jqt8hk/replay', Environment::SANDBOX->baseUrl()),
urldecode((string) $request->getUri()),
);
self::assertSame('ntf_01h46h1s2zabpkdks7yt4vkgkc', $replayId);
Expand Down

0 comments on commit 7397f33

Please sign in to comment.