Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support disposition query parameter #68

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions src/Entities/Shared/Disposition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/**
* |------
* | ! Generated code !
* | Altering this code will result in changes being overwritten |
* |-------------------------------------------------------------|.
*/

namespace Paddle\SDK\Entities\Shared;

use Paddle\SDK\PaddleEnum;

/**
* @method static Disposition Attachment()
* @method static Disposition Inline()
*/
final class Disposition extends PaddleEnum
{
private const Attachment = 'attachment';
private const Inline = 'inline';
}
23 changes: 23 additions & 0 deletions src/Resources/Transactions/Operations/GetTransactionInvoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Resources\Transactions\Operations;

use Paddle\SDK\Entities\Shared\Disposition;
use Paddle\SDK\HasParameters;

class GetTransactionInvoice implements HasParameters
{
public function __construct(
private readonly Disposition|null $disposition = null,
) {
}

public function getParameters(): array
{
return array_filter([
'disposition' => $this->disposition?->getValue(),
]);
}
}
5 changes: 3 additions & 2 deletions src/Resources/Transactions/TransactionsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()),
];
}
}
Loading