-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa303d0
commit e332d7c
Showing
8 changed files
with
92 additions
and
3 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,10 @@ | ||
<?php | ||
|
||
namespace Locastic\SyliusHTPayWayPlugin; | ||
|
||
interface HTPayWayFactoryInterface | ||
{ | ||
public const LOCALES_AVAILABLE = ['en_US', 'hr_HR', 'de_CH', 'de_DE', 'fr_BE', 'fr_FR', 'it_IT', 'ru_RU']; | ||
|
||
public const CURRENCIES_AVAILABLE = ['HRK']; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Sylius\Component\Core\Model\PaymentMethod: | ||
constraints: | ||
- Locastic\SyliusHTPayWayPlugin\Validator\Constraints\Currency: | ||
groups: ['sylius'] | ||
message: 'locastic.sylius_ht_payway_plugin.channel.required_currency' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Locastic\SyliusHTPayWayPlugin\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
final class Currency extends Constraint | ||
{ | ||
public $message; | ||
|
||
public function validatedBy(): string | ||
{ | ||
return 'locastic_sylius_ht_payway_plugin_currency'; | ||
} | ||
|
||
public function getTargets(): string | ||
{ | ||
return self::CLASS_CONSTRAINT; | ||
} | ||
} |
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 | ||
|
||
namespace Locastic\SyliusHTPayWayPlugin\Validator\Constraints; | ||
|
||
use Locastic\SyliusHTPayWayPlugin\HTPayWayFactoryInterface; | ||
use Locastic\SyliusHTPayWayPlugin\HTPayWayOffsiteGatewayFactory; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\PaymentMethodInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Webmozart\Assert\Assert; | ||
|
||
|
||
final class CurrencyValidator extends ConstraintValidator | ||
{ | ||
public function validate($paymentMethod, Constraint $constraint): void | ||
{ | ||
Assert::isInstanceOf($paymentMethod, PaymentMethodInterface::class); | ||
Assert::isInstanceOf($constraint, Currency::class); | ||
|
||
$gatewayConfig = $paymentMethod->getGatewayConfig(); | ||
|
||
if (null === $gatewayConfig || $gatewayConfig->getFactoryName( | ||
) !== HTPayWayOffsiteGatewayFactory::FACTORY_NAME) { | ||
return; | ||
} | ||
|
||
/** @var ChannelInterface $channel */ | ||
foreach ($paymentMethod->getChannels() as $channel) { | ||
if ( | ||
null === $channel->getBaseCurrency() || | ||
false === in_array( | ||
strtoupper($channel->getBaseCurrency()->getCode()), | ||
HTPayWayFactoryInterface::CURRENCIES_AVAILABLE | ||
) | ||
) { | ||
$message = isset($constraint->message) ? $constraint->message : null; | ||
|
||
$this->context->buildViolation($message)->atPath('channels')->addViolation(); | ||
|
||
return; | ||
} | ||
} | ||
} | ||
} |