diff --git a/src/Api/Transactions/OrderRequest.php b/src/Api/Transactions/OrderRequest.php index aaffe53..a801daa 100644 --- a/src/Api/Transactions/OrderRequest.php +++ b/src/Api/Transactions/OrderRequest.php @@ -166,6 +166,11 @@ class OrderRequest extends RequestBody implements OrderRequestInterface */ private $currency; + /** + * @var string + */ + private $capture; + /** * @var ?OrderRequest\Arguments\Affiliate */ @@ -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 */ @@ -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, ]; diff --git a/tests/Unit/Api/Transactions/OrderRequestTest.php b/tests/Unit/Api/Transactions/OrderRequestTest.php index f472176..ba7415c 100644 --- a/tests/Unit/Api/Transactions/OrderRequestTest.php +++ b/tests/Unit/Api/Transactions/OrderRequestTest.php @@ -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); + } }