diff --git a/src/Api/Transactions/CaptureRequest.php b/src/Api/Transactions/CaptureRequest.php index 8d6e674..c6e5a7e 100644 --- a/src/Api/Transactions/CaptureRequest.php +++ b/src/Api/Transactions/CaptureRequest.php @@ -7,21 +7,153 @@ namespace MultiSafepay\Api\Transactions; use MultiSafepay\Api\Base\RequestBody; -use MultiSafepay\Api\Base\RequestBodyInterface; +use MultiSafepay\ValueObject\Amount; /** - * Class UpdateRequest + * Class CaptureRequest * @package MultiSafepay\Api\Transactions */ class CaptureRequest extends RequestBody { public const CAPTURE_MANUAL_TYPE = 'manual'; + /** + * @var string + */ + private $newOrderId; + + /** + * @var Amount + */ + private $amount; + + /** + * @var string + */ + private $newOrderStatus; + + /** + * @var string + */ + private $invoiceId; + + /** + * @var string + */ + private $trackTraceCode; + + /** + * @var string + */ + private $carrier; + /** + * @var string + */ + private $reason; + + /** + * @var string + */ + private $description; /** * @return array */ public function getData(): array { - return $this->removeNullRecursive($this->data); + return $this->removeNullRecursive( + array_merge( + [ + 'amount' => $this->amount->get() ?? null, + 'new_order_id' => $this->newOrderId ?: null, + 'new_order_status' => $this->newOrderStatus ?: 'completed', + 'invoice_id' => $this->invoiceId ?: null, + 'tracktrace_code' => $this->trackTraceCode ?: null, + 'carrier' =>$this->carrier ?: null, + 'reason' => $this->reason ?: null, + 'description' => $this->description ?: null, + ], + $this->data + ) + ); + } + + /** + * @param Amount $amount + * @return CaptureRequest + */ + public function addAmount(Amount $amount): CaptureRequest + { + $this->amount = $amount; + return $this; + } + + /** + * @param string $newOrderId + * @return CaptureRequest + */ + public function addNewOrderId(string $newOrderId): CaptureRequest + { + $this->newOrderId = $newOrderId; + return $this; + } + + /** + * @param string $newOrderStatus + * @return CaptureRequest + */ + public function addNewOrderStatus(string $newOrderStatus): CaptureRequest + { + $this->newOrderStatus = $newOrderStatus; + return $this; + } + + /** + * @param string $invoiceId + * @return CaptureRequest + */ + public function addInvoiceId(string $invoiceId): CaptureRequest + { + $this->invoiceId = $invoiceId; + return $this; + } + + /** + * @param string $trackTraceCode + * @return CaptureRequest + */ + public function addTrackTraceCode(string $trackTraceCode): CaptureRequest + { + $this->trackTraceCode = $trackTraceCode; + return $this; + } + + /** + * @param string $carrier + * @return CaptureRequest + */ + public function addCarrier(string $carrier): CaptureRequest + { + $this->carrier = $carrier; + return $this; + } + + /** + * @param string $reason + * @return CaptureRequest + */ + public function addReason(string $reason): CaptureRequest + { + $this->reason = $reason; + return $this; + } + + /** + * @param string $description + * @return CaptureRequest + */ + public function addDescription(string $description): CaptureRequest + { + $this->description = $description; + return $this; } } diff --git a/tests/Unit/Api/Transactions/CaptureRequestTest.php b/tests/Unit/Api/Transactions/CaptureRequestTest.php new file mode 100644 index 0000000..b56534e --- /dev/null +++ b/tests/Unit/Api/Transactions/CaptureRequestTest.php @@ -0,0 +1,59 @@ +addAmount(new Amount(100)) + ->addNewOrderStatus('completed') + ->addInvoiceId('ORD-837243') + ->addReason('Verzonden'); + $data = $captureRequest->getData(); + $this->assertEquals(100, $data['amount']); + $this->assertEquals('completed', $data['new_order_status']); + $this->assertEquals('ORD-837243', $data['invoice_id']); + $this->assertEquals('Verzonden', $data['reason']); + } + + /** + * @covers \MultiSafepay\Api\Transactions\CaptureRequest::addMoney + */ + public function testAddAmount() + { + $captureRequest = new CaptureRequest(); + $captureRequest->addAmount(new Amount(42)); + $data = $captureRequest->getData(); + $this->assertSame(42, $data['amount']); + } + + /** + * `completed` is the only allowed `new_order_status` value for this request. So this value should be coerced. + * + * @covers \MultiSafepay\Api\Transactions\CaptureRequest::addMoney + */ + public function testAlwaysCompleted() + { + $captureRequest = new CaptureRequest(); + $captureRequest->addAmount(new Amount(42)); + $data = $captureRequest->getData(); + $this->assertSame('completed', $data['new_order_status']); + } +}