-
Notifications
You must be signed in to change notification settings - Fork 9
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
Adam Wysocki
committed
Nov 7, 2024
1 parent
527616d
commit 3bb10ba
Showing
12 changed files
with
205 additions
and
8 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,13 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Model; | ||
|
||
use Magento\Framework\Model\AbstractModel; | ||
|
||
class Alias extends AbstractModel | ||
{ | ||
public function __construct() | ||
{ | ||
$this->_init(ResourceModel\Alias::class); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Model\ResourceModel; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
|
||
class Alias extends AbstractDb | ||
{ | ||
protected function _construct(): void | ||
{ | ||
$this->_init('tpay_blik_aliases', 'id'); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Notification; | ||
|
||
use Tpay\Magento2\Notification\Strategy\Factory\NotificationProcessorFactoryInterface; | ||
|
||
class NotificationProcessor | ||
{ | ||
/** @var NotificationProcessorFactoryInterface */ | ||
protected $factory; | ||
|
||
public function __construct(NotificationProcessorFactoryInterface $factory) | ||
{ | ||
$this->factory = $factory; | ||
} | ||
|
||
public function process() | ||
{ | ||
$strategy = $this->factory->create(); | ||
|
||
return $strategy->process(); | ||
} | ||
} |
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 Tpay\Magento2\Notification\Strategy; | ||
|
||
class BlikAliasNotificationProcessor implements NotificationProcessorInterface | ||
{ | ||
public function process(?int $storeId) | ||
{ | ||
} | ||
} |
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 Tpay\Magento2\Notification\Strategy; | ||
|
||
class CardNotificationProcessor implements NotificationProcessorInterface | ||
{ | ||
public function process(?int $storeId) | ||
{ | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Notification\Strategy; | ||
|
||
use Laminas\Http\Response; | ||
use Tpay\Magento2\Api\TpayConfigInterface; | ||
use Tpay\Magento2\Service\TpayService; | ||
use Tpay\OpenApi\Webhook\JWSVerifiedPaymentNotification; | ||
|
||
class DefaultNotificationProcessor implements NotificationProcessorInterface | ||
{ | ||
/** @var TpayConfigInterface */ | ||
protected $tpayConfig; | ||
|
||
/** @var TpayService */ | ||
protected $tpayService; | ||
|
||
public function __construct(TpayConfigInterface $tpayConfig, TpayService $tpayService) | ||
{ | ||
$this->tpayConfig = $tpayConfig; | ||
$this->tpayService = $tpayService; | ||
} | ||
|
||
public function process(?int $storeId) | ||
{ | ||
$notification = (new JWSVerifiedPaymentNotification( | ||
$this->tpayConfig->getSecurityCode($storeId), | ||
!$this->tpayConfig->useSandboxMode($storeId) | ||
))->getNotification(); | ||
|
||
$notification = $notification->getNotificationAssociative(); | ||
$orderId = base64_decode($notification['tr_crc']); | ||
|
||
if ('PAID' === $notification['tr_status']) { | ||
$response = $this->getPaidTransactionResponse($orderId); | ||
|
||
return $this->response->setStatusCode(Response::STATUS_CODE_200)->setContent($response); | ||
} | ||
|
||
$this->saveCard($notification, $orderId); | ||
$this->tpayService->setOrderStatus($orderId, $notification, $this->tpayConfig); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Notification/Strategy/Factory/NotificationProcessorFactory.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,29 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Notification\Strategy\Factory; | ||
|
||
use Tpay\Magento2\Notification\Strategy\NotificationProcessorInterface; | ||
|
||
class NotificationProcessorFactory implements NotificationProcessorFactoryInterface | ||
{ | ||
/** @var NotificationProcessorInterface[] */ | ||
protected $strategies; | ||
|
||
public function __construct(array $strategies = []) | ||
{ | ||
$this->strategies = $strategies; | ||
} | ||
|
||
public function create(array $data): NotificationProcessorInterface | ||
{ | ||
if (isset($_POST['card'])) { | ||
return $this->strategies['card']; | ||
} | ||
|
||
if (isset($_POST['event'])) { | ||
return $this->strategies['blikAlias']; | ||
} | ||
|
||
return $this->strategies['default']; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Notification/Strategy/Factory/NotificationProcessorFactoryInterface.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,10 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Notification\Strategy\Factory; | ||
|
||
use Tpay\Magento2\Notification\Strategy\NotificationProcessorInterface; | ||
|
||
interface NotificationProcessorFactoryInterface | ||
{ | ||
public function create(array $data): NotificationProcessorInterface; | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Tpay\Magento2\Notification\Strategy; | ||
|
||
interface NotificationProcessorInterface | ||
{ | ||
public function process(?int $storeId); | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tpay\Magento2\Service; | ||
|
||
class TpayAliasesService | ||
{ | ||
|
||
} |
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