Skip to content
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
45 changes: 45 additions & 0 deletions Gateway/Request/CompanyDataBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/

namespace Adyen\Payment\Gateway\Request;

use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Sales\Model\Order;

class CompanyDataBuilder implements BuilderInterface
{
public function build(array $buildSubject): array
{
/** @var PaymentDataObject $paymentDataObject */
$paymentDataObject = SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
/** @var Order $order */
$order = $payment->getOrder();
$billingAddress = $order->getBillingAddress();
$company = [];

if (!empty($billingAddress->getVatId())) {
$company['taxId'] = $billingAddress->getVatId();
}

if (!empty($billingAddress->getCompany())) {
$company['name'] = $billingAddress->getCompany();
}

return [
'body' => [
'company' => $company
]
];
}
}
58 changes: 58 additions & 0 deletions Test/Unit/Gateway/Request/CompanyDataBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/

namespace Adyen\Payment\Test\Gateway\Request;

use Adyen\Payment\Gateway\Request\CompanyDataBuilder;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Sales\Api\Data\OrderAddressInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Payment;

class CompanyDataBuilderTest extends AbstractAdyenTestCase
{
/**
* @return void
*/
function testBuild()
{
$companyName = 'Adyen';
$vatId = 'NL-123456789';

$billingAddressMock = $this->createMock(OrderAddressInterface::class);
$billingAddressMock->expects($this->exactly(2))
->method('getCompany')
->willReturn('Adyen');
$billingAddressMock->expects($this->exactly(2))
->method('getVatId')
->willReturn($vatId);

$orderMock = $this->createMock(Order::class);
$orderMock->expects($this->once())
->method('getBillingAddress')
->willReturn($billingAddressMock);

$paymentMock = $this->createMock(Payment::class);
$paymentMock->method('getOrder')->willReturn($orderMock);

$buildSubject = [
'payment' => $this->createConfiguredMock(PaymentDataObject::class, [
'getPayment' => $paymentMock
])
];

$builder = new CompanyDataBuilder();
$result = $builder->build($buildSubject);

$this->assertEquals(['body' => ['company' => ['name' => $companyName, 'taxId' => $vatId]]], $result);
}
}
8 changes: 8 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@
<item name="origin" xsi:type="string">Adyen\Payment\Gateway\Request\OriginDataBuilder</item>
<item name="header" xsi:type="string">Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder</item>
<item name="giftcard" xsi:type="string">Adyen\Payment\Gateway\Request\GiftcardDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -1098,6 +1099,7 @@
<item name="shopperinteraction" xsi:type="string">Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder</item>
<item name="channel" xsi:type="string">Adyen\Payment\Gateway\Request\ChannelDataBuilder</item>
<item name="origin" xsi:type="string">Adyen\Payment\Gateway\Request\OriginDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -1114,6 +1116,7 @@
<item name="description" xsi:type="string">Adyen\Payment\Gateway\Request\DescriptionDataBuilder</item>
<item name="transaction" xsi:type="string">Adyen\Payment\Gateway\Request\CheckoutDataBuilder</item>
<item name="header" xsi:type="string">Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -1135,6 +1138,7 @@
<item name="shopperinteraction" xsi:type="string">Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder</item>
<item name="header" xsi:type="string">Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder</item>
<item name="giftcard" xsi:type="string">Adyen\Payment\Gateway\Request\GiftcardDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -1155,6 +1159,7 @@
<item name="shopperinteraction" xsi:type="string">Adyen\Payment\Gateway\Request\ShopperInteractionDataBuilder</item>
<item name="header" xsi:type="string">Adyen\Payment\Gateway\Request\Header\HeaderDataBuilder</item>
<item name="giftcard" xsi:type="string">Adyen\Payment\Gateway\Request\GiftcardDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand Down Expand Up @@ -1206,6 +1211,7 @@
<item name="channel" xsi:type="string">Adyen\Payment\Gateway\Request\ChannelDataBuilder</item>
<item name="origin" xsi:type="string">Adyen\Payment\Gateway\Request\OriginDataBuilder</item>
<item name="giftcard" xsi:type="string">Adyen\Payment\Gateway\Request\GiftcardDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -1226,6 +1232,7 @@
<item name="channel" xsi:type="string">Adyen\Payment\Gateway\Request\ChannelDataBuilder</item>
<item name="origin" xsi:type="string">Adyen\Payment\Gateway\Request\OriginDataBuilder</item>
<item name="giftcard" xsi:type="string">Adyen\Payment\Gateway\Request\GiftcardDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand Down Expand Up @@ -1254,6 +1261,7 @@
<item name="channel" xsi:type="string">Adyen\Payment\Gateway\Request\ChannelDataBuilder</item>
<item name="origin" xsi:type="string">Adyen\Payment\Gateway\Request\OriginDataBuilder</item>
<item name="giftcard" xsi:type="string">Adyen\Payment\Gateway\Request\GiftcardDataBuilder</item>
<item name="company" xsi:type="string">Adyen\Payment\Gateway\Request\CompanyDataBuilder</item>
</argument>
</arguments>
</virtualType>
Expand Down
Loading