Skip to content

Commit

Permalink
Add and map pec info
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaGallinari committed Sep 5, 2024
1 parent 58366f5 commit cdfd969
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Client/ValueObject/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(
private string $buyerInfoName,
private string $buyerInfoVatNumber,
private string $buyerInfoEmail,
private string $buyerInfoPec,
private array $purchasedItems,
) {
}
Expand Down Expand Up @@ -76,6 +77,11 @@ public function getBuyerInfoEmail(): string
return $this->buyerInfoEmail;
}

public function getBuyerInfoPec(): string
{
return $this->buyerInfoPec;
}

/**
* @return OrderItem[]
*/
Expand Down Expand Up @@ -104,6 +110,7 @@ public function toArray(): array
'name' => $this->buyerInfoName,
'vatCode' => $this->buyerInfoVatNumber,
'email' => $this->buyerInfoEmail,
'pec' => $this->buyerInfoPec,
],
'items' => $items,
'allowSCTPayment' => true, // if PausePay is not available, allow to pay by classic instant Wire Bank?
Expand Down
1 change: 1 addition & 0 deletions src/Mapper/OrderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function mapFromSyliusPayment(PaymentInterface $payment, string $captureU
$companyInfo->getName(),
$companyInfo->getVatNumber(),
$companyInfo->getEmail(),
$companyInfo->getPec(),
$items,
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/ValueObject/CompanyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function __construct(
private string $name,
private string $vatNumber,
private string $email,
private string $pec,
) {
}

Expand All @@ -27,4 +28,9 @@ public function getEmail(): string
{
return $this->email;
}

public function getPec(): string
{
return $this->pec;
}
}
3 changes: 2 additions & 1 deletion tests/Application/src/Resolver/CompanyInfoResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public function resolveFromOrder(OrderInterface $order): CompanyInfo
return new CompanyInfo(
'Azienda A',
'IT73228252614',
'[email protected]'
'[email protected]',
'[email protected]',
);
}
}
2 changes: 1 addition & 1 deletion tests/Service/Resolver/DummyCompanyInfoResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ final class DummyCompanyInfoResolver implements CompanyInfoResolverInterface
{
public function resolveFromOrder(OrderInterface $order): CompanyInfo
{
return new CompanyInfo('Webgriffe SRL', '02277170359', '[email protected]');
return new CompanyInfo('Webgriffe SRL', '02277170359', '[email protected]', '[email protected]');
}
}
66 changes: 66 additions & 0 deletions tests/Unit/Client/ValueObject/OrderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Tests\Webgriffe\SyliusPausePayPlugin\Unit\Client\ValueObject;

use PHPUnit\Framework\TestCase;
use Webgriffe\SyliusPausePayPlugin\Client\ValueObject\Order;
use Webgriffe\SyliusPausePayPlugin\Client\ValueObject\OrderItem;

final class OrderTest extends TestCase
{
public function test_to_array(): void
{
$order = new Order(
100.0,
'123',
new \DateTimeImmutable('2024-09-01 12:23:56'),
'Description',
'Remittance',
'http://ok.com',
'http://ko.com',
'Buyer Name',
'VAT123',
'[email protected]',
'[email protected]',
[
new OrderItem('Product 1', 1, 10.0),
new OrderItem('Product 2', 2, 20.0),
]
);

self::assertSame(
[
'amount' => 100.0,
'number' => '123',
'issueDate' => '01/09/2024 12:23',
'description' => 'Description',
'remittance' => 'Remittance',
'okRedirect' => 'http://ok.com',
'koRedirect' => 'http://ko.com',
'allowToEditRemittance' => false,
'buyerInfo' => [
'name' => 'Buyer Name',
'vatCode' => 'VAT123',
'email' => '[email protected]',
'pec' => '[email protected]',
],
'items' => [
[
'description' => 'Product 1',
'quantity' => 1,
'amount' => 10.0,
],
[
'description' => 'Product 2',
'quantity' => 2,
'amount' => 20.0,
],
],
'allowSCTPayment' => true,
],
$order->toArray()
);
}
}
1 change: 1 addition & 0 deletions tests/Unit/Mapper/OrderMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function test_it_maps_sylius_payment_to_pausepay_order(): void
self::assertSame('Webgriffe SRL', $pausePayOrder->getBuyerInfoName());
self::assertSame('02277170359', $pausePayOrder->getBuyerInfoVatNumber());
self::assertSame('[email protected]', $pausePayOrder->getBuyerInfoEmail());
self::assertSame('[email protected]', $pausePayOrder->getBuyerInfoPec());

$items = $pausePayOrder->getPurchasedItems();
self::assertCount(3, $items);
Expand Down

0 comments on commit cdfd969

Please sign in to comment.