Skip to content

Commit 26ad12c

Browse files
authored
Feat: Adding support for adjustment type and VND currency (#108)
1 parent ba065b7 commit 26ad12c

File tree

15 files changed

+86
-10
lines changed

15 files changed

+86
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
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.
88

9+
## [1.7.0] - 2024-12-11
10+
11+
### Added
12+
13+
- 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)
14+
- 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)
15+
916
## [1.6.0] - 2024-12-05
1017

1118
### Added

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
class Client
6262
{
63-
private const SDK_VERSION = '1.6.0';
63+
private const SDK_VERSION = '1.7.0';
6464

6565
public readonly LoggerInterface $logger;
6666
public readonly Options $options;

src/Entities/Adjustment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Paddle\SDK\Entities\Adjustment\AdjustmentItem;
1515
use Paddle\SDK\Entities\Adjustment\AdjustmentTaxRatesUsed;
16+
use Paddle\SDK\Entities\Adjustment\AdjustmentType;
1617
use Paddle\SDK\Entities\Shared\Action;
1718
use Paddle\SDK\Entities\Shared\AdjustmentStatus;
1819
use Paddle\SDK\Entities\Shared\AdjustmentTotals;
@@ -41,6 +42,7 @@ private function __construct(
4142
public array $taxRatesUsed,
4243
public \DateTimeInterface $createdAt,
4344
public \DateTimeInterface|null $updatedAt,
45+
public AdjustmentType $type,
4446
) {
4547
}
4648

@@ -62,6 +64,7 @@ public static function from(array $data): self
6264
taxRatesUsed: array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []),
6365
createdAt: DateTime::from($data['created_at']),
6466
updatedAt: DateTime::from($data['updated_at']),
67+
type: AdjustmentType::from($data['type']),
6568
);
6669
}
6770
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Paddle\SDK\Entities\Adjustment;
6+
7+
use Paddle\SDK\PaddleEnum;
8+
9+
/**
10+
* @method static AdjustmentType Full()
11+
* @method static AdjustmentType Partial()
12+
*/
13+
final class AdjustmentType extends PaddleEnum
14+
{
15+
private const Full = 'full';
16+
private const Partial = 'partial';
17+
}

src/Entities/Shared/CurrencyCode.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* @method static CurrencyCode TRY()
4444
* @method static CurrencyCode TWD()
4545
* @method static CurrencyCode UAH()
46+
* @method static CurrencyCode VND()
4647
* @method static CurrencyCode ZAR()
4748
*/
4849
final class CurrencyCode extends PaddleEnum
@@ -76,5 +77,6 @@ final class CurrencyCode extends PaddleEnum
7677
private const TRY = 'TRY';
7778
private const TWD = 'TWD';
7879
private const UAH = 'UAH';
80+
private const VND = 'VND';
7981
private const ZAR = 'ZAR';
8082
}

src/Notifications/Entities/Adjustment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Paddle\SDK\Notifications\Entities\Adjustment\AdjustmentItem;
1515
use Paddle\SDK\Notifications\Entities\Adjustment\AdjustmentTaxRatesUsed;
16+
use Paddle\SDK\Notifications\Entities\Adjustment\AdjustmentType;
1617
use Paddle\SDK\Notifications\Entities\Shared\Action;
1718
use Paddle\SDK\Notifications\Entities\Shared\AdjustmentStatus;
1819
use Paddle\SDK\Notifications\Entities\Shared\AdjustmentTotals;
@@ -41,6 +42,7 @@ private function __construct(
4142
public array $taxRatesUsed,
4243
public \DateTimeInterface $createdAt,
4344
public \DateTimeInterface|null $updatedAt,
45+
public AdjustmentType|null $type,
4446
) {
4547
}
4648

@@ -62,6 +64,7 @@ public static function from(array $data): self
6264
taxRatesUsed: array_map(fn (array $taxRateUsed): AdjustmentTaxRatesUsed => AdjustmentTaxRatesUsed::from($taxRateUsed), $data['tax_rates_used'] ?? []),
6365
createdAt: DateTime::from($data['created_at']),
6466
updatedAt: isset($data['updated_at']) ? DateTime::from($data['updated_at']) : null,
67+
type: isset($data['type']) ? AdjustmentType::from($data['type']) : null,
6568
);
6669
}
6770
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Paddle\SDK\Notifications\Entities\Adjustment;
6+
7+
use Paddle\SDK\PaddleEnum;
8+
9+
/**
10+
* @method static AdjustmentType Full()
11+
* @method static AdjustmentType Partial()
12+
*/
13+
final class AdjustmentType extends PaddleEnum
14+
{
15+
private const Full = 'full';
16+
private const Partial = 'partial';
17+
}

src/Notifications/Entities/Shared/CurrencyCode.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* @method static CurrencyCode TRY()
4444
* @method static CurrencyCode TWD()
4545
* @method static CurrencyCode UAH()
46+
* @method static CurrencyCode VND()
4647
* @method static CurrencyCode ZAR()
4748
*/
4849
final class CurrencyCode extends PaddleEnum
@@ -76,5 +77,6 @@ final class CurrencyCode extends PaddleEnum
7677
private const TRY = 'TRY';
7778
private const TWD = 'TWD';
7879
private const UAH = 'UAH';
80+
private const VND = 'VND';
7981
private const ZAR = 'ZAR';
8082
}

src/Resources/Adjustments/Operations/CreateAdjustment.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,54 @@
44

55
namespace Paddle\SDK\Resources\Adjustments\Operations;
66

7+
use Paddle\SDK\Entities\Adjustment\AdjustmentType;
78
use Paddle\SDK\Entities\Shared\Action;
9+
use Paddle\SDK\Exceptions\SdkExceptions\InvalidArgumentException;
10+
use Paddle\SDK\FiltersUndefined;
811
use Paddle\SDK\Resources\Adjustments\Operations\Create\AdjustmentItem;
12+
use Paddle\SDK\Undefined;
913

1014
class CreateAdjustment implements \JsonSerializable
1115
{
16+
use FiltersUndefined;
17+
1218
/**
1319
* @param array<AdjustmentItem> $items
20+
*
21+
* @throws InvalidArgumentException
1422
*/
1523
public function __construct(
1624
public readonly Action $action,
17-
public readonly array $items,
25+
public readonly array|Undefined $items,
1826
public readonly string $reason,
1927
public readonly string $transactionId,
28+
public readonly AdjustmentType|Undefined $type = new Undefined(),
2029
) {
30+
if ($this->type === AdjustmentType::Partial() && ($this->items instanceof Undefined || empty($this->items))) {
31+
throw InvalidArgumentException::arrayIsEmpty('items');
32+
}
2133
}
2234

2335
public function jsonSerialize(): array
2436
{
2537
$items = [];
2638

27-
foreach ($this->items as $item) {
28-
$items[] = [
29-
'item_id' => $item->itemId,
30-
'type' => $item->type->getValue(),
31-
'amount' => $item->amount,
32-
];
39+
if (! $this->items instanceof Undefined) {
40+
foreach ($this->items as $item) {
41+
$items[] = [
42+
'item_id' => $item->itemId,
43+
'type' => $item->type->getValue(),
44+
'amount' => $item->amount,
45+
];
46+
}
3347
}
3448

35-
return [
49+
return $this->filterUndefined([
3650
'action' => $this->action,
3751
'items' => $items,
3852
'reason' => $this->reason,
3953
'transaction_id' => $this->transactionId,
40-
];
54+
'type' => $this->type,
55+
]);
4156
}
4257
}

tests/Functional/Resources/Adjustments/_fixtures/response/full_entity.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"data": {
33
"id": "adj_01h8c65c2ggq5nxswnnwv78e75",
44
"action": "refund",
5+
"type": "partial",
56
"transaction_id": "txn_01h8bxpvx398a7zbawb77y0kp5",
67
"subscription_id": "sub_01h8bxswamxysj44zt5n48njwh",
78
"customer_id": "ctm_01h8441jn5pcwrfhwh78jqt8hk",

0 commit comments

Comments
 (0)