Skip to content

Commit

Permalink
fix: Add convenience static factory methods for adjustment create
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Dec 17, 2024
1 parent ce4c7d1 commit fc69012
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/Resources/Adjustments/Operations/CreateAdjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public function __construct(
}
}

public static function full(Action $action, string $reason, string $transactionId): self
{
return new self($action, new Undefined(), $reason, $transactionId, AdjustmentType::Full());
}

public static function partial(Action $action, array $items, string $reason, string $transactionId): self
{
return new self($action, $items, $reason, $transactionId, AdjustmentType::Partial());
}

public function jsonSerialize(): array
{
if (is_array($this->items)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Paddle\SDK\Resources\Adjustments\Operations\ListAdjustments;
use Paddle\SDK\Resources\Shared\Operations\List\Pager;
use Paddle\SDK\Tests\Utils\ReadsFixtures;
use Paddle\SDK\Undefined;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -103,7 +102,7 @@ public static function createOperationsProvider(): \Generator
];

yield 'Partial type with items' => [
new CreateAdjustment(
CreateAdjustment::partial(
Action::Refund(),
[new AdjustmentItem(
'txnitm_01h8bxryv3065dyh6103p3yg28',
Expand All @@ -112,19 +111,16 @@ public static function createOperationsProvider(): \Generator
)],
'error',
'txn_01h8bxpvx398a7zbawb77y0kp5',
\Paddle\SDK\Entities\Adjustment\AdjustmentType::Partial(),
),
new Response(200, body: self::readRawJsonFixture('response/minimal_entity')),
self::readRawJsonFixture('request/create_type_partial_with_items'),
];

yield 'Full type with no items' => [
new CreateAdjustment(
CreateAdjustment::full(
Action::Refund(),
new Undefined(),
'error',
'txn_01h8bxpvx398a7zbawb77y0kp5',
\Paddle\SDK\Entities\Adjustment\AdjustmentType::Full(),
),
new Response(200, body: self::readRawJsonFixture('response/minimal_entity')),
self::readRawJsonFixture('request/create_type_full_with_no_items'),
Expand Down

0 comments on commit fc69012

Please sign in to comment.