diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e3456e..67e8456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. +## [1.3.0] - 2024-09-30 + +### Added + +- Added `AdjustmentsClient::getCreditNote`, see [related changelog](https://developer.paddle.com/changelog/2024/generate-adjustments-credit-notes) + ## [1.2.0] - 2024-09-18 ### Added diff --git a/src/Entities/AdjustmentCreditNote.php b/src/Entities/AdjustmentCreditNote.php new file mode 100644 index 0000000..89be0bb --- /dev/null +++ b/src/Entities/AdjustmentCreditNote.php @@ -0,0 +1,25 @@ +getData()); } + + /** + * @throws ApiError On a generic API error + * @throws ApiError\AdjustmentApiError On an adjustment specific API error + * @throws MalformedResponse If the API response was not parsable + */ + public function getCreditNote(string $id, GetAdjustmentCreditNote $getOperation = new GetAdjustmentCreditNote()): AdjustmentCreditNote + { + $parser = new ResponseParser( + $this->client->getRaw("/adjustments/{$id}/credit-note", $getOperation), + ); + + return AdjustmentCreditNote::from($parser->getData()); + } } diff --git a/src/Resources/Adjustments/Operations/GetAdjustmentCreditNote.php b/src/Resources/Adjustments/Operations/GetAdjustmentCreditNote.php new file mode 100644 index 0000000..f8d490d --- /dev/null +++ b/src/Resources/Adjustments/Operations/GetAdjustmentCreditNote.php @@ -0,0 +1,23 @@ + $this->disposition?->getValue(), + ]); + } +} diff --git a/tests/Functional/Resources/Adjustments/AdjustmentsClientTest.php b/tests/Functional/Resources/Adjustments/AdjustmentsClientTest.php index 4c3cad3..e154311 100644 --- a/tests/Functional/Resources/Adjustments/AdjustmentsClientTest.php +++ b/tests/Functional/Resources/Adjustments/AdjustmentsClientTest.php @@ -10,10 +10,12 @@ use Paddle\SDK\Entities\Shared\Action; use Paddle\SDK\Entities\Shared\AdjustmentStatus; use Paddle\SDK\Entities\Shared\AdjustmentType; +use Paddle\SDK\Entities\Shared\Disposition; use Paddle\SDK\Environment; use Paddle\SDK\Options; use Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem; use Paddle\SDK\Resources\Adjustments\Operations\CreateAdjustment; +use Paddle\SDK\Resources\Adjustments\Operations\GetAdjustmentCreditNote; use Paddle\SDK\Resources\Adjustments\Operations\ListAdjustments; use Paddle\SDK\Resources\Shared\Operations\List\Pager; use Paddle\SDK\Tests\Utils\ReadsFixtures; @@ -208,4 +210,66 @@ public static function listOperationsProvider(): \Generator sprintf('%s/adjustments?action=refund', Environment::SANDBOX->baseUrl()), ]; } + + /** + * @test + */ + public function get_credit_note_has_correct_url(): void + { + $fixture = self::readRawJsonFixture('response/get_credit_note_default'); + $this->mockClient->addResponse(new Response(200, body: $fixture)); + + $creditNote = $this->client->adjustments->getCreditNote( + 'adj_01h8c65c2ggq5nxswnnwv78e75', + new GetAdjustmentCreditNote(), + ); + + $expectedCreditNoteUrl = 'https://paddle-production-invoice-service-pdfs.s3.amazonaws.com/credit_notes/15839/crdnt_01j4scmgpbtbxap16573dtck9n/credit_notes_296-10016_Paddle-com.pdf'; + + self::assertSame($expectedCreditNoteUrl, $creditNote->url); + } + + /** + * @test + * + * @dataProvider getCreditNoteOperationsProvider + */ + public function get_credit_note_hits_expected_uri( + string $id, + GetAdjustmentCreditNote $getOperation, + ResponseInterface $response, + string $expectedUri, + ): void { + $this->mockClient->addResponse($response); + $this->client->adjustments->getCreditNote($id, $getOperation); + $request = $this->mockClient->getLastRequest(); + + self::assertInstanceOf(RequestInterface::class, $request); + self::assertEquals('GET', $request->getMethod()); + self::assertEquals($expectedUri, urldecode((string) $request->getUri())); + } + + public static function getCreditNoteOperationsProvider(): \Generator + { + yield 'Default' => [ + 'adj_01h8c65c2ggq5nxswnnwv78e75', + new GetAdjustmentCreditNote(), + new Response(200, body: self::readRawJsonFixture('response/get_credit_note_default')), + sprintf('%s/adjustments/adj_01h8c65c2ggq5nxswnnwv78e75/credit-note', Environment::SANDBOX->baseUrl()), + ]; + + yield 'Disposition Inline' => [ + 'adj_01h8c65c2ggq5nxswnnwv78e75', + new GetAdjustmentCreditNote(Disposition::Inline()), + new Response(200, body: self::readRawJsonFixture('response/get_credit_note_default')), + sprintf('%s/adjustments/adj_01h8c65c2ggq5nxswnnwv78e75/credit-note?disposition=inline', Environment::SANDBOX->baseUrl()), + ]; + + yield 'Disposition Attachment' => [ + 'adj_01h8c65c2ggq5nxswnnwv78e75', + new GetAdjustmentCreditNote(Disposition::Attachment()), + new Response(200, body: self::readRawJsonFixture('response/get_credit_note_default')), + sprintf('%s/adjustments/adj_01h8c65c2ggq5nxswnnwv78e75/credit-note?disposition=attachment', Environment::SANDBOX->baseUrl()), + ]; + } } diff --git a/tests/Functional/Resources/Adjustments/_fixtures/response/get_credit_note_default.json b/tests/Functional/Resources/Adjustments/_fixtures/response/get_credit_note_default.json new file mode 100644 index 0000000..e788309 --- /dev/null +++ b/tests/Functional/Resources/Adjustments/_fixtures/response/get_credit_note_default.json @@ -0,0 +1,8 @@ +{ + "data": { + "url": "https://paddle-production-invoice-service-pdfs.s3.amazonaws.com/credit_notes/15839/crdnt_01j4scmgpbtbxap16573dtck9n/credit_notes_296-10016_Paddle-com.pdf" + }, + "meta": { + "request_id": "e34d4a9c-2088-447d-a3a1-1da5ce74f507" + } +}