Rename type to action

This commit is contained in:
Francis Hilaire 2024-02-22 23:10:11 +01:00 committed by Grzegorz Sadowski
parent 3a6ad1dafd
commit 531a0c68ff
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
20 changed files with 42 additions and 42 deletions

View file

@ -167,9 +167,9 @@ final class PaypalContext implements Context
$request->setContent([
'paymentId' => $payment['@id'],
'paymentMethodCode' => $payment['method'],
'type' => $authorize
? PaymentRequestInterface::DATA_TYPE_AUTHORIZE
: PaymentRequestInterface::DATA_TYPE_CAPTURE,
'action' => $authorize
? PaymentRequestInterface::ACTION_AUTHORIZE
: PaymentRequestInterface::ACTION_CAPTURE,
'requestPayload' => [
'target_path' => 'https://myshop.tld/target-path',
'after_path' => 'https://myshop.tld/after-path',

View file

@ -21,8 +21,8 @@ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface
public function __construct(
private string $paymentId,
private string $paymentMethodCode,
private string $type,
private mixed $requestPayload = null,
private string $action,
private mixed $requestPayload = null,
) {
}
@ -36,9 +36,9 @@ class AddPaymentRequest implements IriToIdentifierConversionAwareInterface
return $this->paymentMethodCode;
}
public function getType(): string
public function getAction(): string
{
return $this->type;
return $this->action;
}
public function getRequestPayload(): mixed

View file

@ -62,7 +62,7 @@ final class AddPaymentRequestHandler implements MessageHandlerInterface
);
$paymentRequest = $this->paymentRequestFactory->createWithPaymentAndPaymentMethod($payment, $paymentMethod);
$paymentRequest->setType($addPaymentRequest->getType());
$paymentRequest->setAction($addPaymentRequest->getAction());
$paymentRequest->setRequestPayload($addPaymentRequest->getRequestPayload());
return $paymentRequest;

View file

@ -22,7 +22,7 @@
<attribute name="paymentMethodCode">
<group>sylius:shop:payment_request:create</group>
</attribute>
<attribute name="type">
<attribute name="action">
<group>sylius:shop:payment_request:create</group>
</attribute>
<attribute name="requestPayload">

View file

@ -34,7 +34,7 @@
<group>sylius:shop:payment_request:show</group>
<group>sylius:shop:payment_request:index</group>
</attribute>
<attribute name="type">
<attribute name="action">
<group>sylius:admin:payment_request:show</group>
<group>sylius:admin:payment_request:index</group>
<group>sylius:shop:payment_request:show</group>

View file

@ -27,7 +27,7 @@
</option>
</constraint>
</property>
<property name="type">
<property name="action">
<constraint name="NotBlank">
<option name="groups">
<value>sylius</value>

View file

@ -25,7 +25,7 @@ final class Version20231106190918 extends AbstractMigration
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE sylius_payment_request (hash BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, request_payload LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', response_data JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE sylius_payment_request (hash BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, action VARCHAR(255) NOT NULL, request_payload LONGTEXT NOT NULL COMMENT \'(DC2Type:object)\', response_data JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_86D904B19883967 (method_id), INDEX IDX_86D904B4C3A3BB (payment_id), PRIMARY KEY(hash)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B19883967 FOREIGN KEY (method_id) REFERENCES sylius_payment_method (id)');
$this->addSql('ALTER TABLE sylius_payment_request ADD CONSTRAINT FK_86D904B4C3A3BB FOREIGN KEY (payment_id) REFERENCES sylius_payment (id)');
}

View file

@ -25,7 +25,7 @@ final class Version20240203222417 extends AbstractPostgreSQLMigration
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE sylius_payment_request (hash UUID NOT NULL, method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, request_payload TEXT NOT NULL, response_data JSON NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(hash))');
$this->addSql('CREATE TABLE sylius_payment_request (hash UUID NOT NULL, method_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, state VARCHAR(255) NOT NULL, action VARCHAR(255) NOT NULL, request_payload TEXT NOT NULL, response_data JSON NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(hash))');
$this->addSql('CREATE INDEX IDX_86D904B19883967 ON sylius_payment_request (method_id)');
$this->addSql('CREATE INDEX IDX_86D904B4C3A3BB ON sylius_payment_request (payment_id)');
$this->addSql('COMMENT ON COLUMN sylius_payment_request.hash IS \'(DC2Type:uuid)\'');

View file

@ -21,7 +21,7 @@ final class CapturePaymentRequestCommandProvider implements PaymentRequestComman
{
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE;
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_CAPTURE;
}
public function provide(PaymentRequestInterface $paymentRequest): object

View file

@ -21,7 +21,7 @@ final class StatusPaymentRequestCommandProvider implements PaymentRequestCommand
{
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_STATUS;
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_STATUS;
}
public function provide(PaymentRequestInterface $paymentRequest): object

View file

@ -25,11 +25,11 @@ final class PaymentRequestTypeCommandProvider implements PaymentRequestCommandPr
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $this->locator->get($paymentRequest->getType())->supports($paymentRequest);
return $this->locator->get($paymentRequest->getAction())->supports($paymentRequest);
}
public function provide(PaymentRequestInterface $paymentRequest): object
{
return $this->locator->get($paymentRequest->getType())->provide($paymentRequest);
return $this->locator->get($paymentRequest->getAction())->provide($paymentRequest);
}
}

View file

@ -21,7 +21,7 @@ final class AuthorizeCommandProvider implements PaymentRequestCommandProviderInt
{
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_AUTHORIZE;
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_AUTHORIZE;
}
public function provide(PaymentRequestInterface $paymentRequest): object

View file

@ -21,7 +21,7 @@ final class CaptureCommandProvider implements PaymentRequestCommandProviderInter
{
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_CAPTURE;
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_CAPTURE;
}
public function provide(PaymentRequestInterface $paymentRequest): object

View file

@ -21,7 +21,7 @@ final class StatusCommandProvider implements PaymentRequestCommandProviderInterf
{
public function supports(PaymentRequestInterface $paymentRequest): bool
{
return $paymentRequest->getType() === PaymentRequestInterface::DATA_TYPE_STATUS;
return $paymentRequest->getAction() === PaymentRequestInterface::ACTION_STATUS;
}
public function provide(PaymentRequestInterface $paymentRequest): object

View file

@ -39,7 +39,7 @@ final class AfterTokenRequestProcessor implements AfterTokenRequestProcessorInte
$paymentRequest->setResponseData($details);
$newPaymentRequest = $this->paymentRequestFactory->createFromPaymentRequest($paymentRequest);
$newPaymentRequest->setType(PaymentRequestInterface::DATA_TYPE_STATUS);
$newPaymentRequest->setAction(PaymentRequestInterface::ACTION_STATUS);
$this->paymentRequestCommandDispatcher->add($newPaymentRequest);
}

View file

@ -30,13 +30,13 @@ class PaymentRequestRepository extends EntityRepository implements PaymentReques
->innerJoin('o.payment', 'payment')
->innerJoin('o.method', 'method')
->where('o != :paymentRequest')
->andWhere('o.type = :type')
->andWhere('o.action = :action')
->andWhere('o.payment = :payment')
->andWhere('o.method = :method')
// Symfony\Bridge\Doctrine\Types\UuidType has signature changes between sf 5.4 and 6.4
// We are forced to use type: "uuid" to use both Sf versions
->setParameter('paymentRequest', $paymentRequest->getHash(), 'uuid')
->setParameter('type', $paymentRequest->getType())
->setParameter('action', $paymentRequest->getAction())
->setParameter('method', $paymentRequest->getMethod())
->setParameter('payment', $paymentRequest->getPayment())
->getQuery()

View file

@ -29,7 +29,7 @@
</many-to-one>
<field name="state" column="state" type="string" />
<field name="type" column="type" type="string" />
<field name="action" column="action" type="string" />
<field name="requestPayload" column="request_payload" type="object" />
<field name="responseData" column="response_data" type="json" />

View file

@ -28,7 +28,7 @@ class PaymentRequest implements PaymentRequestInterface
protected string $state = PaymentRequestInterface::STATE_NEW;
protected string $type = PaymentRequestInterface::DATA_TYPE_CAPTURE;
protected string $action = PaymentRequestInterface::ACTION_CAPTURE;
protected mixed $requestPayload = null;
@ -79,14 +79,14 @@ class PaymentRequest implements PaymentRequestInterface
$this->state = $state;
}
public function getType(): string
public function getAction(): string
{
return $this->type;
return $this->action;
}
public function setType(string $type): void
public function setAction(string $action): void
{
$this->type = $type;
$this->action = $action;
}
public function getRequestPayload(): mixed

View file

@ -29,17 +29,17 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf
public const STATE_COMPLETED = 'completed';
public const DATA_TYPE_CAPTURE = 'capture';
public const ACTION_CAPTURE = 'capture';
public const DATA_TYPE_AUTHORIZE = 'authorize';
public const ACTION_AUTHORIZE = 'authorize';
public const DATA_TYPE_REFUND = 'refund';
public const ACTION_REFUND = 'refund';
public const DATA_TYPE_STATUS = 'status';
public const ACTION_STATUS = 'status';
public const DATA_TYPE_SYNC = 'sync';
public const ACTION_SYNC = 'sync';
public const DATA_TYPE_PAYOUT = 'payout';
public const ACTION_PAYOUT = 'payout';
public function getHash(): ?Uuid;
@ -55,9 +55,9 @@ interface PaymentRequestInterface extends TimestampableInterface, ResourceInterf
public function setState(string $state): void;
public function getType(): string;
public function getAction(): string;
public function setType(string $type): void;
public function setAction(string $action): void;
public function getRequestPayload(): mixed;

View file

@ -64,15 +64,15 @@ final class PaymentRequestSpec extends ObjectBehavior
$this->getState()->shouldReturn('test_state');
}
function it_has_capture_type_by_default(): void
function it_has_capture_action_by_default(): void
{
$this->getType()->shouldReturn(PaymentRequestInterface::DATA_TYPE_CAPTURE);
$this->getAction()->shouldReturn(PaymentRequestInterface::ACTION_CAPTURE);
}
function its_type_is_mutable(): void
function its_action_is_mutable(): void
{
$this->setType('test_type');
$this->getType()->shouldReturn('test_type');
$this->setAction('test_action');
$this->getAction()->shouldReturn('test_action');
}
function it_has_null_data_by_default(): void