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

Feat: Adding support for adjustment type and VND currency #108

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-php-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.

## [1.7.0] - 2024-12-09

### Added

- Support for adjustment type, see [related changelog](https://developer.paddle.com/changelog/2024/refund-credit-full-total?utm_source=dx&utm_medium=paddle-php-sdk)
- Added Vietnamese Dong (`VND`) as a supported currency for payments [related changelog](https://developer.paddle.com/changelog/2024/vietnamese-dong-vnd-supported-currency?utm_source=dx&utm_medium=paddle-php-sdk)

## [1.6.0] - 2024-12-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

class Client
{
private const SDK_VERSION = '1.6.0';
private const SDK_VERSION = '1.7.0';

public readonly LoggerInterface $logger;
public readonly Options $options;
Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
use Paddle\SDK\Entities\Adjustment\AdjustmentTaxRatesUsed;
use Paddle\SDK\Entities\Adjustment\AdjustmentType;
use Paddle\SDK\Entities\Shared\Action;
use Paddle\SDK\Entities\Shared\AdjustmentStatus;
use Paddle\SDK\Entities\Shared\AdjustmentTotals;
Expand Down Expand Up @@ -41,6 +42,7 @@ private function __construct(
public array $taxRatesUsed,
public \DateTimeInterface $createdAt,
public \DateTimeInterface|null $updatedAt,
public AdjustmentType|null $type,
davidgrayston-paddle marked this conversation as resolved.
Show resolved Hide resolved
) {
}

Expand All @@ -62,6 +64,7 @@ public static function from(array $data): self
taxRatesUsed: array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []),
createdAt: DateTime::from($data['created_at']),
updatedAt: DateTime::from($data['updated_at']),
type: isset($data['type']) ? AdjustmentType::from($data['type']) : null,
);
}
}
17 changes: 17 additions & 0 deletions src/Entities/Adjustment/AdjustmentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Entities\Adjustment;

use Paddle\SDK\PaddleEnum;

/**
* @method static AdjustmentType Full()
* @method static AdjustmentType Partial()
*/
final class AdjustmentType extends PaddleEnum
{
private const Full = 'full';
private const Partial = 'partial';
}
2 changes: 2 additions & 0 deletions src/Entities/Shared/CurrencyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* @method static CurrencyCode TRY()
* @method static CurrencyCode TWD()
* @method static CurrencyCode UAH()
* @method static CurrencyCode VND()
* @method static CurrencyCode ZAR()
*/
final class CurrencyCode extends PaddleEnum
Expand Down Expand Up @@ -76,5 +77,6 @@ final class CurrencyCode extends PaddleEnum
private const TRY = 'TRY';
private const TWD = 'TWD';
private const UAH = 'UAH';
private const VND = 'VND';
private const ZAR = 'ZAR';
}
3 changes: 3 additions & 0 deletions src/Notifications/Entities/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Paddle\SDK\Notifications\Entities\Adjustment\AdjustmentItem;
use Paddle\SDK\Notifications\Entities\Adjustment\AdjustmentTaxRatesUsed;
use Paddle\SDK\Notifications\Entities\Adjustment\AdjustmentType;
use Paddle\SDK\Notifications\Entities\Shared\Action;
use Paddle\SDK\Notifications\Entities\Shared\AdjustmentStatus;
use Paddle\SDK\Notifications\Entities\Shared\AdjustmentTotals;
Expand Down Expand Up @@ -41,6 +42,7 @@ private function __construct(
public array $taxRatesUsed,
public \DateTimeInterface $createdAt,
public \DateTimeInterface|null $updatedAt,
public AdjustmentType|null $type,
) {
}

Expand All @@ -62,6 +64,7 @@ public static function from(array $data): self
taxRatesUsed: array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []),
createdAt: DateTime::from($data['created_at']),
updatedAt: isset($data['updated_at']) ? DateTime::from($data['updated_at']) : null,
type: isset($data['type']) ? AdjustmentType::from($data['type']) : null,
);
}
}
17 changes: 17 additions & 0 deletions src/Notifications/Entities/Adjustment/AdjustmentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Notifications\Entities\Adjustment;

use Paddle\SDK\PaddleEnum;

/**
* @method static AdjustmentType Full()
* @method static AdjustmentType Partial()
*/
final class AdjustmentType extends PaddleEnum
{
private const Full = 'full';
private const Partial = 'partial';
}
2 changes: 2 additions & 0 deletions src/Notifications/Entities/Shared/CurrencyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
* @method static CurrencyCode TRY()
* @method static CurrencyCode TWD()
* @method static CurrencyCode UAH()
* @method static CurrencyCode VND()
* @method static CurrencyCode ZAR()
*/
final class CurrencyCode extends PaddleEnum
Expand Down Expand Up @@ -76,5 +77,6 @@ final class CurrencyCode extends PaddleEnum
private const TRY = 'TRY';
private const TWD = 'TWD';
private const UAH = 'UAH';
private const VND = 'VND';
private const ZAR = 'ZAR';
}
33 changes: 24 additions & 9 deletions src/Resources/Adjustments/Operations/CreateAdjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,54 @@

namespace Paddle\SDK\Resources\Adjustments\Operations;

use Paddle\SDK\Entities\Adjustment\AdjustmentType;
use Paddle\SDK\Entities\Shared\Action;
use Paddle\SDK\Exceptions\SdkExceptions\InvalidArgumentException;
use Paddle\SDK\FiltersUndefined;
use Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem;
use Paddle\SDK\Undefined;

class CreateAdjustment implements \JsonSerializable
{
use FiltersUndefined;

/**
* @param array<AdjustmentItem> $items
*
* @throws InvalidArgumentException
*/
public function __construct(
public readonly Action $action,
public readonly array $items,
public readonly array|Undefined $items,
public readonly string $reason,
public readonly string $transactionId,
public readonly AdjustmentType|Undefined $type = new Undefined(),
) {
if ($this->type === AdjustmentType::Partial() && ($this->items instanceof Undefined || empty($this->items))) {
throw InvalidArgumentException::arrayIsEmpty('items');
}
}

public function jsonSerialize(): array
{
$items = [];

foreach ($this->items as $item) {
$items[] = [
'item_id' => $item->itemId,
'type' => $item->type->getValue(),
'amount' => $item->amount,
];
if (! $this->items instanceof Undefined) {
foreach ($this->items as $item) {
$items[] = [
'item_id' => $item->itemId,
'type' => $item->type->getValue(),
'amount' => $item->amount,
];
}
}

return [
return $this->filterUndefined([
'action' => $this->action,
'items' => $items,
'reason' => $this->reason,
'transaction_id' => $this->transactionId,
];
'type' => $this->type,
]);
}
}
Loading