Skip to content

Commit

Permalink
PAYOSWXP-130: paymenthandler: add data-bag to getValidationDefinition
Browse files Browse the repository at this point in the history
… to allow easier conditional validations
  • Loading branch information
rommelfreddy committed Jun 17, 2024
1 parent 646955c commit f49952c
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/EventListener/OrderValidationEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function validateOrderData(BuildValidationEvent $event): void
$paymentHandler = $this->paymentHandlerRegistry->getPaymentMethodHandler($paymentMethodId);

if ($paymentHandler instanceof AbstractPayonePaymentHandler) {
$validationDefinitions = $paymentHandler->getValidationDefinitions($salesChannelContext);
$validationDefinitions = $paymentHandler->getValidationDefinitions($event->getData(), $salesChannelContext);

if ($validationDefinitions !== []) {
$this->addSubConstraints($event->getDefinition(), $validationDefinitions);
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/AbstractKlarnaPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PayonePayment\RequestConstants;
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -52,9 +53,9 @@ public function __construct(
);
}

public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
return array_merge(parent::getValidationDefinitions($salesChannelContext), [
return array_merge(parent::getValidationDefinitions($dataBag, $salesChannelContext), [
RequestConstants::WORK_ORDER_ID => [new NotBlank()],
RequestConstants::CART_HASH => [new NotBlank()],
]);
Expand Down
3 changes: 2 additions & 1 deletion src/PaymentHandler/AbstractPayonePaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -49,7 +50,7 @@ public function __construct(
) {
}

public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
return [
RequestConstants::WORK_ORDER_ID => [new Blank()], // workorder-id is mostly not required.
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneAmazonPayPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -60,9 +61,9 @@ public static function isCapturable(array $transactionData, array $payoneTransAc
return strtolower((string)$transactionData['txaction']) === TransactionStatusService::ACTION_PAID;
}

public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

if (empty($salesChannelContext->getCustomer()?->getActiveBillingAddress()?->getPhoneNumber())) {
$definitions[RequestConstants::PHONE] = [new NotBlank()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayonePayolutionDebitPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
namespace PayonePayment\PaymentHandler;

use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayonePayolutionDebitPaymentHandler extends AbstractSynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

$definitions['payolutionConsent'] = [new NotBlank()];
$definitions['payolutionMandate'] = [new NotBlank()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PayonePayment\RequestConstants;
use Shopware\Core\Checkout\Payment\Cart\SyncPaymentTransactionStruct;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -60,9 +61,9 @@ public function pay(
parent::pay($transaction, $dataBag, $salesChannelContext);
}

public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

$definitions[RequestConstants::WORK_ORDER_ID] = [new NotBlank()];
$definitions[RequestConstants::CART_HASH] = [new NotBlank()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
use PayonePayment\Components\Validator\Birthday;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayonePayolutionInvoicingPaymentHandler extends AbstractSynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

$definitions[RequestConstants::WORK_ORDER_ID] = [new NotBlank()];

Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneRatepayDebitPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
use PayonePayment\Components\Validator\Iban;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayoneRatepayDebitPaymentHandler extends AbstractSynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

$definitions['ratepayIban'] = [new NotBlank(), new Iban()];
$definitions[RequestConstants::BIRTHDAY] = [new NotBlank(), new Birthday()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneRatepayInstallmentPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
use PayonePayment\Components\Validator\Iban;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayoneRatepayInstallmentPaymentHandler extends AbstractSynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

if (empty($salesChannelContext->getCustomer()?->getActiveBillingAddress()?->getPhoneNumber())) {
$definitions[RequestConstants::PHONE] = [new NotBlank()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneRatepayInvoicingPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
use PayonePayment\Components\Validator\Birthday;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayoneRatepayInvoicingPaymentHandler extends AbstractSynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

$definitions[RequestConstants::BIRTHDAY] = [new NotBlank(), new Birthday()];

Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneSecureInvoicePaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use PayonePayment\Components\Validator\Birthday;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayoneSecureInvoicePaymentHandler extends AbstractPayoneInvoicePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

if (!$this->customerHasCompanyAddress($salesChannelContext)) {
$definitions[RequestConstants::BIRTHDAY] = [new NotBlank(), new Birthday()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneSecuredDirectDebitPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PayonePayment\Components\Validator\Iban;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;
Expand All @@ -32,9 +33,9 @@ public static function isRefundable(array $transactionData): bool
return static::matchesIsRefundableDefaults($transactionData);
}

public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

if (empty($salesChannelContext->getCustomer()?->getActiveBillingAddress()?->getPhoneNumber())) {
$definitions[RequestConstants::PHONE] = [new NotBlank()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneSecuredInstallmentPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
use PayonePayment\Components\Validator\Iban;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayoneSecuredInstallmentPaymentHandler extends AbstractSynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

if (empty($salesChannelContext->getCustomer()?->getActiveBillingAddress()?->getPhoneNumber())) {
$definitions[RequestConstants::PHONE] = [new NotBlank()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneSecuredInvoicePaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PayonePayment\Components\Validator\Birthday;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\RequestConstants;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;
Expand All @@ -31,9 +32,9 @@ public static function isRefundable(array $transactionData): bool
return static::matchesIsRefundableDefaults($transactionData);
}

public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

if (empty($salesChannelContext->getCustomer()?->getActiveBillingAddress()?->getPhoneNumber())) {
$definitions[RequestConstants::PHONE] = [new NotBlank()];
Expand Down
5 changes: 3 additions & 2 deletions src/PaymentHandler/PayoneTrustlyPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use PayonePayment\Components\TransactionStatus\TransactionStatusService;
use PayonePayment\Components\Validator\Iban;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Validator\Constraints\NotBlank;

class PayoneTrustlyPaymentHandler extends AbstractAsynchronousPayonePaymentHandler
{
public function getValidationDefinitions(SalesChannelContext $salesChannelContext): array
public function getValidationDefinitions(DataBag $dataBag, SalesChannelContext $salesChannelContext): array
{
$definitions = parent::getValidationDefinitions($salesChannelContext);
$definitions = parent::getValidationDefinitions($dataBag, $salesChannelContext);

$definitions['iban'] = [new NotBlank(), new Iban()];

Expand Down

0 comments on commit f49952c

Please sign in to comment.