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

fix: Adjustment items can be omitted when adjustment type is full #110

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

davidgrayston-paddle
Copy link
Contributor

Fixed

  • Adjustment items can be omitted for when adjustment type is full

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))) {
$typeIsFull = AdjustmentType::Full()->equals($this->type);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->type === AdjustmentType::Partial() strict comparison can't be used here

throw InvalidArgumentException::arrayIsEmpty('items');
}

if ($typeIsFull && is_array($this->items)) {
throw new InvalidArgumentException('items are not allowed when the adjustment type is full');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API returns error "Array must have at least 1 items" when an empty array is sent in request, and "items are not allowed when the adjustment type is full" when items are provided with full type

}

public function jsonSerialize(): array
{
$items = [];
if (is_array($this->items)) {
$items = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved $items = [] inside is_array($this->items) check so that Undefined value is omitted from request

vifer
vifer previously approved these changes Dec 17, 2024
@davidgrayston-paddle davidgrayston-paddle merged commit 31b5cc0 into main Dec 17, 2024
4 checks passed
@davidgrayston-paddle davidgrayston-paddle deleted the fix/adjustment-type-items branch December 17, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants