-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #65 Update order address if changed during completion (SirDom…
…in, Zales0123) This PR was merged into the 1.0-dev branch. Discussion ---------- As webhooks arent working yet, it changes address when completing the order Commits ------- 2ae1fff provder + spec e824c24 code standards 147e04c webhook removed, address is changed while completing order 9a04e78 removed unused service 592f05c Improve PayPalAddressProcessor specs ddfc5fc Fix typo in javascript resulting failing payment-page payment functionality
- Loading branch information
Showing
9 changed files
with
170 additions
and
2 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
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,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\PayPalPlugin\Processor; | ||
|
||
use Doctrine\Persistence\ObjectManager; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\PayPalPlugin\Processor\PayPalAddressProcessorInterface; | ||
|
||
final class PayPalAddressProcessorSpec extends ObjectBehavior | ||
{ | ||
function let(ObjectManager $objectManager): void | ||
{ | ||
$this->beConstructedWith($objectManager); | ||
} | ||
|
||
function it_implements_pay_pal_address_processor_interface(): void | ||
{ | ||
$this->shouldImplement(PayPalAddressProcessorInterface::class); | ||
} | ||
|
||
function it_updates_order_address( | ||
OrderInterface $order, | ||
AddressInterface $orderAddress, | ||
ObjectManager $objectManager | ||
): void { | ||
$order->getShippingAddress()->willReturn($orderAddress); | ||
|
||
$orderAddress->setCity('New York')->shouldBeCalled(); | ||
$orderAddress->setStreet('Main St. 123')->shouldBeCalled(); | ||
$orderAddress->setPostcode('10001')->shouldBeCalled(); | ||
$orderAddress->setCountryCode('US')->shouldBeCalled(); | ||
|
||
$objectManager->flush()->shouldBeCalled(); | ||
|
||
$this->process( | ||
[ | ||
'address_line_1' => 'Main St. 123', | ||
'admin_area_2' => 'New York', | ||
'postal_code' => '10001', | ||
'country_code' => 'US', | ||
], | ||
$order | ||
); | ||
} | ||
|
||
function it_updates_order_address_with_two_address_lines( | ||
OrderInterface $order, | ||
AddressInterface $orderAddress, | ||
ObjectManager $objectManager | ||
): void { | ||
$order->getShippingAddress()->willReturn($orderAddress); | ||
|
||
$orderAddress->setCity('New York')->shouldBeCalled(); | ||
$orderAddress->setStreet('Main St. 123')->shouldBeCalled(); | ||
$orderAddress->setPostcode('10001')->shouldBeCalled(); | ||
$orderAddress->setCountryCode('US')->shouldBeCalled(); | ||
|
||
$objectManager->flush()->shouldBeCalled(); | ||
|
||
$this->process( | ||
[ | ||
'address_line_1' => 'Main St.', | ||
'address_line_2' => '123', | ||
'admin_area_2' => 'New York', | ||
'postal_code' => '10001', | ||
'country_code' => 'US', | ||
], | ||
$order | ||
); | ||
} | ||
|
||
function it_throws_an_exception_if_address_data_is_missing( | ||
OrderInterface $order, | ||
AddressInterface $orderAddress, | ||
ObjectManager $objectManager | ||
): void { | ||
$order->getShippingAddress()->willReturn($orderAddress); | ||
|
||
$objectManager->flush()->shouldNotBeCalled(); | ||
$this->shouldThrow(\InvalidArgumentException::class)->during('process', [[], $order]); | ||
} | ||
} |
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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\PayPalPlugin\Processor; | ||
|
||
use Doctrine\Persistence\ObjectManager; | ||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class PayPalAddressProcessor implements PayPalAddressProcessorInterface | ||
{ | ||
/** @var ObjectManager */ | ||
private $objectManager; | ||
|
||
public function __construct(ObjectManager $objectManager) | ||
{ | ||
$this->objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* @param array<string, string> $address | ||
*/ | ||
public function process(array $address, OrderInterface $order): void | ||
{ | ||
/** @var AddressInterface $orderAddress */ | ||
$orderAddress = $order->getShippingAddress(); | ||
|
||
Assert::keyExists($address, 'admin_area_2'); | ||
Assert::keyExists($address, 'address_line_1'); | ||
Assert::keyExists($address, 'postal_code'); | ||
Assert::keyExists($address, 'country_code'); | ||
|
||
$street = $address['address_line_1'] . (isset($address['address_line_2']) ? ' ' . $address['address_line_2'] : ''); | ||
|
||
$orderAddress->setCity($address['admin_area_2']); | ||
$orderAddress->setStreet($street); | ||
$orderAddress->setPostcode($address['postal_code']); | ||
$orderAddress->setCountryCode($address['country_code']); | ||
|
||
$this->objectManager->flush(); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\PayPalPlugin\Processor; | ||
|
||
use Sylius\Component\Core\Model\OrderInterface; | ||
|
||
interface PayPalAddressProcessorInterface | ||
{ | ||
/** | ||
* @param array<string, string> $address | ||
*/ | ||
public function process(array $address, OrderInterface $order): void; | ||
} |
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
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
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
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