Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/Api/Transactions/OrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class OrderRequest extends RequestBody implements OrderRequestInterface
*/
private $currency;

/**
* @var string
*/
private $capture;

/**
* @var ?OrderRequest\Arguments\Affiliate
*/
Expand Down Expand Up @@ -588,6 +593,16 @@ public function addAffiliate(?OrderRequest\Arguments\Affiliate $affiliate): Orde
return $this;
}

/**
* @param string $capture
* @return OrderRequest
*/
public function addCapture(string $capture = 'manual'): OrderRequest
{
$this->capture = $capture;
return $this;
}

/**
* @return Affiliate|null
*/
Expand Down Expand Up @@ -627,6 +642,7 @@ public function getData(): array
'var1' => $this->getVar1(),
'var2' => $this->getVar2(),
'var3' => $this->getVar3(),
'capture' => $this->capture ?? null,
'affiliate' => $this->affiliate ? $this->affiliate->getData() : null,
];

Expand Down
55 changes: 55 additions & 0 deletions tests/Unit/Api/Transactions/OrderRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,59 @@ public function testOrderWithAffiliate()
$this->assertArrayHasKey('affiliate', $data);
$this->assertArrayHasKey('split_payments', $data['affiliate']);
}

/**
* Test if we can get the manual capture flag, with an expliticly set correct value
* @throws InvalidArgumentException
* @throws InvalidTotalAmountException
*/
public function testOrderWithManualCapture()
{
$orderRequest = $this->createOrderIdealDirectRequestFixture();
$orderRequest->addCapture('manual');
$data = $orderRequest->getData();

$this->assertEquals('manual', $data['capture'] ?? '');
}

/**
* Test if we can get the manual capture flag, with an explicitly set value
* @throws InvalidArgumentException
* @throws InvalidTotalAmountException
*/
public function testOrderWithFreestyleManualCapture()
{
$orderRequest = $this->createOrderIdealDirectRequestFixture();
$orderRequest->addCapture('example');
$data = $orderRequest->getData();

$this->assertEquals('example', $data['capture'] ?? '');
}

/**
* Test if we can set the manual capture flag by using the default
* @throws InvalidArgumentException
* @throws InvalidTotalAmountException
*/
public function testOrderWithDefaultManualCapture()
{
$orderRequest = $this->createOrderIdealDirectRequestFixture();
$orderRequest->addCapture();
$data = $orderRequest->getData();

$this->assertEquals('manual', $data['capture'] ?? '');
}

/**
* Test if the capture flag is truly missing when the order is created without setting it
* @throws InvalidArgumentException
* @throws InvalidTotalAmountException
*/
public function testOrderWithoutManualCapture()
{
$orderRequest = $this->createOrderIdealDirectRequestFixture();
$data = $orderRequest->getData();

$this->assertArrayNotHasKey('capture', $data);
}
}