-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAYOSWXP-105: Add order action log and webhook log
- Loading branch information
Moritz Müller
committed
Nov 15, 2023
1 parent
e38e3aa
commit 2420543
Showing
71 changed files
with
1,545 additions
and
131 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandler.php
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\DataHandler\OrderActionLog; | ||
|
||
use Shopware\Core\Checkout\Order\OrderEntity; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; | ||
|
||
class OrderActionLogDataHandler implements OrderActionLogDataHandlerInterface | ||
{ | ||
public function __construct( | ||
protected readonly EntityRepository $orderActionLogRepository | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $request | ||
* @param array<string, mixed> $response | ||
*/ | ||
public function createOrderActionLog( | ||
OrderEntity $order, | ||
array $request, | ||
array $response, | ||
Context $context | ||
): void { | ||
$orderActionLog = [ | ||
'orderId' => $order->getId(), | ||
'transactionId' => $response['txid'], | ||
'referenceNumber' => $order->getOrderNumber(), | ||
'request' => $request['request'], | ||
'response' => $response['status'], | ||
'amount' => $request['amount'], | ||
'mode' => $request['mode'], | ||
'merchantId' => $request['mid'], | ||
'portalId' => $request['portalid'], | ||
'requestDetails' => $request, | ||
'responseDetails' => $response, | ||
'requestDateTime' => new \DateTime(), | ||
]; | ||
|
||
$this->orderActionLogRepository->create([$orderActionLog], $context); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Components/DataHandler/OrderActionLog/OrderActionLogDataHandlerInterface.php
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\DataHandler\OrderActionLog; | ||
|
||
use Shopware\Core\Checkout\Order\OrderEntity; | ||
use Shopware\Core\Framework\Context; | ||
|
||
interface OrderActionLogDataHandlerInterface | ||
{ | ||
/** | ||
* @param array<string, mixed> $request | ||
* @param array<string, mixed> $response | ||
*/ | ||
public function createOrderActionLog( | ||
OrderEntity $order, | ||
array $request, | ||
array $response, | ||
Context $context | ||
): void; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Components/DataHandler/WebhookLog/WebhookLogDataHandler.php
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\DataHandler\WebhookLog; | ||
|
||
use Shopware\Core\Checkout\Order\OrderEntity; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; | ||
|
||
class WebhookLogDataHandler implements WebhookLogDataHandlerInterface | ||
{ | ||
public function __construct( | ||
protected readonly EntityRepository $webhookLogRepository | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $webhookData | ||
*/ | ||
public function createWebhookLog( | ||
OrderEntity $order, | ||
array $webhookData, | ||
Context $context | ||
): void { | ||
$webhookLog = [ | ||
'orderId' => $order->getId(), | ||
'transactionId' => $webhookData['txid'], | ||
'transactionState' => $webhookData['txaction'], | ||
'sequenceNumber' => (int) $webhookData['sequencenumber'], | ||
'clearingType' => $webhookData['clearingtype'], | ||
'webhookDetails' => $webhookData, | ||
'webhookDateTime' => new \DateTime(), | ||
]; | ||
|
||
$this->webhookLogRepository->create([$webhookLog], $context); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Components/DataHandler/WebhookLog/WebhookLogDataHandlerInterface.php
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\DataHandler\WebhookLog; | ||
|
||
use Shopware\Core\Checkout\Order\OrderEntity; | ||
use Shopware\Core\Framework\Context; | ||
|
||
interface WebhookLogDataHandlerInterface | ||
{ | ||
/** | ||
* @param array<string, mixed> $webhookData | ||
*/ | ||
public function createWebhookLog( | ||
OrderEntity $order, | ||
array $webhookData, | ||
Context $context | ||
): 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
18 changes: 18 additions & 0 deletions
18
src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogCollection.php
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\DataAbstractionLayer\Entity\OrderActionLog; | ||
|
||
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection; | ||
|
||
/** | ||
* @extends EntityCollection<PayonePaymentOrderActionLogEntity> | ||
*/ | ||
class PayonePaymentOrderActionLogCollection extends EntityCollection | ||
{ | ||
protected function getExpectedClass(): string | ||
{ | ||
return PayonePaymentOrderActionLogEntity::class; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/DataAbstractionLayer/Entity/OrderActionLog/PayonePaymentOrderActionLogDefinition.php
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\DataAbstractionLayer\Entity\OrderActionLog; | ||
|
||
use Shopware\Core\Checkout\Order\OrderDefinition; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\CreatedAtField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\JsonField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Field\UpdatedAtField; | ||
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; | ||
|
||
class PayonePaymentOrderActionLogDefinition extends EntityDefinition | ||
{ | ||
final public const ENTITY_NAME = 'payone_payment_order_action_log'; | ||
|
||
public function getEntityName(): string | ||
{ | ||
return self::ENTITY_NAME; | ||
} | ||
|
||
public function getCollectionClass(): string | ||
{ | ||
return PayonePaymentOrderActionLogCollection::class; | ||
} | ||
|
||
public function getEntityClass(): string | ||
{ | ||
return PayonePaymentOrderActionLogEntity::class; | ||
} | ||
|
||
protected function defineFields(): FieldCollection | ||
{ | ||
return new FieldCollection([ | ||
(new IdField('id', 'id'))->setFlags(new PrimaryKey(), new Required()), | ||
|
||
(new FkField('order_id', 'orderId', OrderDefinition::class))->addFlags(new Required()), | ||
(new ReferenceVersionField(OrderDefinition::class, 'order_version_id'))->addFlags(new Required()), | ||
new ManyToOneAssociationField('order', 'order_id', OrderDefinition::class, 'id', false), | ||
|
||
(new StringField('transaction_id', 'transactionId'))->setFlags(new Required()), | ||
(new StringField('reference_number', 'referenceNumber'))->setFlags(new Required()), | ||
(new StringField('request', 'request'))->setFlags(new Required()), | ||
(new StringField('response', 'response'))->setFlags(new Required()), | ||
(new IntField('amount', 'amount'))->setFlags(new Required()), | ||
(new StringField('mode', 'mode'))->setFlags(new Required()), | ||
(new StringField('merchant_id', 'merchantId'))->setFlags(new Required()), | ||
(new StringField('portal_id', 'portalId'))->setFlags(new Required()), | ||
(new JsonField('request_details', 'requestDetails'))->setFlags(new Required()), | ||
(new JsonField('response_details', 'responseDetails'))->setFlags(new Required()), | ||
(new DateTimeField('request_date_time', 'requestDateTime'))->setFlags(new Required()), | ||
|
||
new CreatedAtField(), | ||
new UpdatedAtField(), | ||
]); | ||
} | ||
} |
Oops, something went wrong.