-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EPC-9597] Generate a new builder and pass company information (#2889)
Co-authored-by: Can Demiralp <can.demiralp@adyen.com>
- Loading branch information
1 parent
ec8477e
commit 253c5dd
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters