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

PISHPS-253: MollieRefundConfigService now uses the refundable quantity #832

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function createConfigControllerResponse(string $orderId, MollieSettingStr

foreach ($mollieOrder->lines() as $line) {
$structs[] = OrderLineItemStruct::createWithId($line->metadata->orderLineItemId)
->setIsShipped($line->quantityShipped >= 1)
->setRefundableQuantity($line->refundableQuantity)
->setOrderedQuantity($line->quantity);
}

Expand Down Expand Up @@ -106,9 +106,13 @@ public function createResponse(OrderLineItemStructCollection $lineItems, MollieS
break;
}

// only shipped items can be refunded
// only items that have not been fully refunded can be refunded
if ($lineItem->isShipped() && $lineItem->getRefundedCount() < $lineItem->getOrderedQuantity()) {
if ($lineItem->getRefundedCount() < $lineItem->getOrderedQuantity()) {
$hasRefundableItems = true;
break;
}

if ($lineItem->getRefundableQuantity() > 0) {
$hasRefundableItems = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ public function getById(string $id): OrderLineItemStruct

throw LineItemNotPartOfCollectionConfigException::create($id);
}

public function getRefundableQuantity(): int
{
$refundableQuantity = 0;

foreach ($this as $item) {
$refundableQuantity += $item->getRefundableQuantity();
}

return $refundableQuantity;
}
}
32 changes: 16 additions & 16 deletions src/Controller/Api/PluginConfig/Structs/OrderLineItemStruct.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class OrderLineItemStruct extends Struct
*/
private $id;

/**
* @var bool
*/
private $isShipped = false;

/**
* @var int
*/
Expand All @@ -32,6 +27,11 @@ class OrderLineItemStruct extends Struct
*/
private $orderedQuantity = 0;

/**
* @var int
*/
private $refundableQuantity = 0;

final private function __construct(string $id)
{
$this->id = $id;
Expand All @@ -42,17 +42,6 @@ public static function createWithId(string $id): self
return new self($id);
}

public function isShipped(): bool
{
return $this->isShipped;
}

public function setIsShipped(bool $isShipped): OrderLineItemStruct
{
$this->isShipped = $isShipped;
return $this;
}

public function getId(): string
{
return $this->id;
Expand Down Expand Up @@ -90,4 +79,15 @@ public function setRefundedCount(int $refundedCount): OrderLineItemStruct
$this->refundedCount = $refundedCount;
return $this;
}

public function getRefundableQuantity(): int
{
return $this->refundableQuantity;
}

public function setRefundableQuantity(int $refundableQuantity): OrderLineItemStruct
{
$this->refundableQuantity = $refundableQuantity;
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testEnablesRefundManagerWhenPendingRefundExists(): void
->method('hasPendingRefund')
->willReturn(true);

$lineItem->expects($this->never())->method('isShipped');
$lineItem->expects($this->never())->method('getRefundableQuantity');
$lineItem->expects($this->never())->method('getRefundedCount');
$lineItem->expects($this->never())->method('getOrderedQuantity');

Expand All @@ -74,7 +74,7 @@ public function testEnablesRefundManagerWhenPendingRefundExists(): void
);
}

public function testRefundManagerIsDisabledWhenNoItemIsMarkedAsShipped(): void
public function testRefundManagerIsEnabledWhenRefundableQuantityForLineItemIsGreaterThanZero(): void
{
$lineItems = OrderLineItemStructCollection::create(
$lineItem = $this->createMock(OrderLineItemStruct::class)
Expand All @@ -85,16 +85,21 @@ public function testRefundManagerIsDisabledWhenNoItemIsMarkedAsShipped(): void
->willReturn(false);

$lineItem->expects($this->once())
->method('isShipped')
->willReturn(false);
->method('getRefundableQuantity')
->willReturn(1);

$lineItem->expects($this->never())->method('getRefundedCount');
$lineItem->expects($this->never())->method('getOrderedQuantity');
$lineItem->expects($this->once())
->method('getRefundedCount')
->willReturn(6);

$lineItem->expects($this->once())
->method('getOrderedQuantity')
->willReturn(5);

$result = $this->service->createResponse($lineItems, $this->config);

static::assertSame(
'{"enabled":false,"autoStockReset":true,"verifyRefund":true,"showInstructions":true}',
'{"enabled":true,"autoStockReset":true,"verifyRefund":true,"showInstructions":true}',
$result->getContent()
);
}
Expand All @@ -110,8 +115,8 @@ public function testRefundManagerIsDisabledWhenAllLineItemsHaveBeenRefunded(): v
->willReturn(false);

$lineItem->expects($this->once())
->method('isShipped')
->willReturn(true);
->method('getRefundableQuantity')
->willReturn(0);

$lineItem->expects($this->once())
->method('getRefundedCount')
Expand Down
Loading