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 @@ + $this->disposition?->getValue(), + ]); + } +} diff --git a/src/Resources/Transactions/TransactionsClient.php b/src/Resources/Transactions/TransactionsClient.php index c7bb398..5b9e588 100644 --- a/src/Resources/Transactions/TransactionsClient.php +++ b/src/Resources/Transactions/TransactionsClient.php @@ -21,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; @@ -128,10 +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): TransactionData + public function getInvoicePDF(string $id, GetTransactionInvoice $getOperation = new GetTransactionInvoice()): TransactionData { $parser = new ResponseParser( - $this->client->getRaw("/transactions/{$id}/invoice"), + $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 2f04d16..64802b4 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; @@ -29,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; @@ -529,11 +531,13 @@ public static function previewOperationsProvider(): \Generator * @dataProvider getInvoicePDFOperationsProvider */ public function get_invoice_pdf_hits_expected_uri( + string $id, + GetTransactionInvoice $getOperation, ResponseInterface $response, string $expectedUri, ): void { $this->mockClient->addResponse($response); - $this->client->transactions->getInvoicePDF('txn_01hen7bxc1p8ep4yk7n5jbzk9r'); + $this->client->transactions->getInvoicePDF($id, $getOperation); $request = $this->mockClient->getLastRequest(); self::assertInstanceOf(RequestInterface::class, $request); @@ -544,8 +548,24 @@ public function get_invoice_pdf_hits_expected_uri( public static function getInvoicePDFOperationsProvider(): \Generator { yield 'Default' => [ + 'txn_01hen7bxc1p8ep4yk7n5jbzk9r', + 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', + 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', + 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()), + ]; } }