Skip to content

Commit

Permalink
Merge branch 'feat/disposition-query' into 'feat/api-sync'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Sep 13, 2024
2 parents a66ff32 + d73db21 commit dd827a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
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(),
]);
}
}
8 changes: 3 additions & 5 deletions src/Resources/Transactions/TransactionsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
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;
use Paddle\SDK\Exceptions\ApiError;
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 @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()),
];
Expand Down

0 comments on commit dd827a8

Please sign in to comment.