From c5580a55b1b8901bf469b0f6cc06d475ad804a67 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Thu, 12 Sep 2024 14:32:48 +0100 Subject: [PATCH 1/2] Feature: Support disposition query parameter --- CHANGELOG.md | 1 + src/Entities/Shared/Disposition.php | 24 +++++++++++++++++++ .../Transactions/TransactionsClient.php | 7 ++++-- .../Transactions/TransactionsClientTest.php | 21 +++++++++++++++- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/Entities/Shared/Disposition.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f33e6ea..8df9c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx - Added `product` to `subscription.items[]`, see [related changelog](https://developer.paddle.com/changelog/2024/subscription-items-product?utm_source=dx&utm_medium=paddle-php-sdk) - Added `import_meta` to `transaction` - Support for `createdAt` and `updatedAt` on Subscription notification prices +- `TransactionsClient::getInvoicePDF` now supports `disposition` parameter, see [related changelog](https://developer.paddle.com/changelog/2024/invoice-pdf-open-in-browser) ## [1.1.2] - 2024-08-23 diff --git a/src/Entities/Shared/Disposition.php b/src/Entities/Shared/Disposition.php new file mode 100644 index 0000000..0f97155 --- /dev/null +++ b/src/Entities/Shared/Disposition.php @@ -0,0 +1,24 @@ + $disposition->getValue()]; + $parser = new ResponseParser( - $this->client->getRaw("/transactions/{$id}/invoice"), + $this->client->getRaw("/transactions/{$id}/invoice", $params), ); return TransactionData::from($parser->getData()); diff --git a/tests/Functional/Resources/Transactions/TransactionsClientTest.php b/tests/Functional/Resources/Transactions/TransactionsClientTest.php index 2f04d16..75f0896 100644 --- a/tests/Functional/Resources/Transactions/TransactionsClientTest.php +++ b/tests/Functional/Resources/Transactions/TransactionsClientTest.php @@ -11,6 +11,7 @@ use Paddle\SDK\Entities\Shared\CollectionMode; use Paddle\SDK\Entities\Shared\CurrencyCode; use Paddle\SDK\Entities\Shared\CustomData; +use Paddle\SDK\Entities\Shared\Disposition; use Paddle\SDK\Entities\Shared\Interval; use Paddle\SDK\Entities\Shared\Money; use Paddle\SDK\Entities\Shared\PriceQuantity; @@ -529,11 +530,13 @@ public static function previewOperationsProvider(): \Generator * @dataProvider getInvoicePDFOperationsProvider */ public function get_invoice_pdf_hits_expected_uri( + string $id, + Disposition|null $disposition, ResponseInterface $response, string $expectedUri, ): void { $this->mockClient->addResponse($response); - $this->client->transactions->getInvoicePDF('txn_01hen7bxc1p8ep4yk7n5jbzk9r'); + $this->client->transactions->getInvoicePDF($id, $disposition); $request = $this->mockClient->getLastRequest(); self::assertInstanceOf(RequestInterface::class, $request); @@ -544,8 +547,24 @@ public function get_invoice_pdf_hits_expected_uri( public static function getInvoicePDFOperationsProvider(): \Generator { yield 'Default' => [ + 'txn_01hen7bxc1p8ep4yk7n5jbzk9r', + null, new Response(200, body: self::readRawJsonFixture('response/get_invoice_pdf_default')), sprintf('%s/transactions/txn_01hen7bxc1p8ep4yk7n5jbzk9r/invoice', Environment::SANDBOX->baseUrl()), ]; + + yield 'Disposition Inline' => [ + 'txn_02hen7bxc1p8ep4yk7n5jbzk9r', + Disposition::Inline(), + new Response(200, body: self::readRawJsonFixture('response/get_invoice_pdf_default')), + sprintf('%s/transactions/txn_02hen7bxc1p8ep4yk7n5jbzk9r/invoice?disposition=inline', Environment::SANDBOX->baseUrl()), + ]; + + yield 'Disposition Attachment' => [ + 'txn_03hen7bxc1p8ep4yk7n5jbzk9r', + Disposition::Attachment(), + new Response(200, body: self::readRawJsonFixture('response/get_invoice_pdf_default')), + sprintf('%s/transactions/txn_03hen7bxc1p8ep4yk7n5jbzk9r/invoice?disposition=attachment', Environment::SANDBOX->baseUrl()), + ]; } } From d73db213409d138f00337541dae1bc97034922c6 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 13 Sep 2024 16:06:47 +0100 Subject: [PATCH 2/2] Move transaction invoice query param to get operation --- .../Operations/GetTransactionInvoice.php | 23 +++++++++++++++++++ .../Transactions/TransactionsClient.php | 8 +++---- .../Transactions/TransactionsClientTest.php | 11 +++++---- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/Resources/Transactions/Operations/GetTransactionInvoice.php diff --git a/src/Resources/Transactions/Operations/GetTransactionInvoice.php b/src/Resources/Transactions/Operations/GetTransactionInvoice.php new file mode 100644 index 0000000..2041484 --- /dev/null +++ b/src/Resources/Transactions/Operations/GetTransactionInvoice.php @@ -0,0 +1,23 @@ + $this->disposition?->getValue(), + ]); + } +} diff --git a/src/Resources/Transactions/TransactionsClient.php b/src/Resources/Transactions/TransactionsClient.php index a252fb2..5b9e588 100644 --- a/src/Resources/Transactions/TransactionsClient.php +++ b/src/Resources/Transactions/TransactionsClient.php @@ -14,7 +14,6 @@ use Paddle\SDK\Client; use Paddle\SDK\Entities\Collections\Paginator; use Paddle\SDK\Entities\Collections\TransactionCollection; -use Paddle\SDK\Entities\Shared\Disposition; use Paddle\SDK\Entities\Transaction; use Paddle\SDK\Entities\TransactionData; use Paddle\SDK\Entities\TransactionPreview; @@ -22,6 +21,7 @@ use Paddle\SDK\Exceptions\SdkExceptions\InvalidArgumentException; use Paddle\SDK\Exceptions\SdkExceptions\MalformedResponse; use Paddle\SDK\Resources\Transactions\Operations\CreateTransaction; +use Paddle\SDK\Resources\Transactions\Operations\GetTransactionInvoice; use Paddle\SDK\Resources\Transactions\Operations\List\Includes; use Paddle\SDK\Resources\Transactions\Operations\ListTransactions; use Paddle\SDK\Resources\Transactions\Operations\PreviewTransaction; @@ -129,12 +129,10 @@ public function preview(PreviewTransaction $operation): TransactionPreview * @throws ApiError\TransactionApiError On a transaction specific API error * @throws MalformedResponse If the API response was not parsable */ - public function getInvoicePDF(string $id, Disposition|null $disposition = null): TransactionData + public function getInvoicePDF(string $id, GetTransactionInvoice $getOperation = new GetTransactionInvoice()): TransactionData { - $params = $disposition === null ? [] : ['disposition' => $disposition->getValue()]; - $parser = new ResponseParser( - $this->client->getRaw("/transactions/{$id}/invoice", $params), + $this->client->getRaw("/transactions/{$id}/invoice", $getOperation), ); return TransactionData::from($parser->getData()); diff --git a/tests/Functional/Resources/Transactions/TransactionsClientTest.php b/tests/Functional/Resources/Transactions/TransactionsClientTest.php index 75f0896..64802b4 100644 --- a/tests/Functional/Resources/Transactions/TransactionsClientTest.php +++ b/tests/Functional/Resources/Transactions/TransactionsClientTest.php @@ -30,6 +30,7 @@ use Paddle\SDK\Resources\Shared\Operations\List\DateComparison; use Paddle\SDK\Resources\Shared\Operations\List\Pager; use Paddle\SDK\Resources\Transactions\Operations\CreateTransaction; +use Paddle\SDK\Resources\Transactions\Operations\GetTransactionInvoice; use Paddle\SDK\Resources\Transactions\Operations\List\Includes; use Paddle\SDK\Resources\Transactions\Operations\List\Origin; use Paddle\SDK\Resources\Transactions\Operations\ListTransactions; @@ -531,12 +532,12 @@ public static function previewOperationsProvider(): \Generator */ public function get_invoice_pdf_hits_expected_uri( string $id, - Disposition|null $disposition, + GetTransactionInvoice $getOperation, ResponseInterface $response, string $expectedUri, ): void { $this->mockClient->addResponse($response); - $this->client->transactions->getInvoicePDF($id, $disposition); + $this->client->transactions->getInvoicePDF($id, $getOperation); $request = $this->mockClient->getLastRequest(); self::assertInstanceOf(RequestInterface::class, $request); @@ -548,21 +549,21 @@ public static function getInvoicePDFOperationsProvider(): \Generator { yield 'Default' => [ 'txn_01hen7bxc1p8ep4yk7n5jbzk9r', - null, + new GetTransactionInvoice(), new Response(200, body: self::readRawJsonFixture('response/get_invoice_pdf_default')), sprintf('%s/transactions/txn_01hen7bxc1p8ep4yk7n5jbzk9r/invoice', Environment::SANDBOX->baseUrl()), ]; yield 'Disposition Inline' => [ 'txn_02hen7bxc1p8ep4yk7n5jbzk9r', - Disposition::Inline(), + new GetTransactionInvoice(Disposition::Inline()), new Response(200, body: self::readRawJsonFixture('response/get_invoice_pdf_default')), sprintf('%s/transactions/txn_02hen7bxc1p8ep4yk7n5jbzk9r/invoice?disposition=inline', Environment::SANDBOX->baseUrl()), ]; yield 'Disposition Attachment' => [ 'txn_03hen7bxc1p8ep4yk7n5jbzk9r', - Disposition::Attachment(), + new GetTransactionInvoice(Disposition::Attachment()), new Response(200, body: self::readRawJsonFixture('response/get_invoice_pdf_default')), sprintf('%s/transactions/txn_03hen7bxc1p8ep4yk7n5jbzk9r/invoice?disposition=attachment', Environment::SANDBOX->baseUrl()), ];