-
Notifications
You must be signed in to change notification settings - Fork 10
BLIK payment confirmation and retry screen #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
88bd26b
BLIK payment confirmation and retry screen
KamilBalwierz 4fc9782
Code style fixes
KamilBalwierz 7d027bd
PHP 7.1 compatybility fix
KamilBalwierz 64c4740
Code style fixes
KamilBalwierz ebbd299
DX-1255: missing translations, moved blik retry counter from session …
KamilBalwierz c2480c2
Code style compliance
KamilBalwierz ffc340a
prevent from sending phone number for vm
KamilBalwierz 784517d
Version 2.4.0 Changelog
KamilBalwierz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.3.2 | ||
| 2.4.0 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tpay\Magento2\Controller\Tpay; | ||
|
|
||
| use Magento\Checkout\Model\Session; | ||
| use Magento\Framework\App\Action\HttpPostActionInterface; | ||
| use Magento\Framework\App\ActionInterface; | ||
| use Magento\Framework\App\Request\Http; | ||
| use Magento\Framework\App\Request\InvalidRequestException; | ||
| use Magento\Framework\Controller\Result\JsonFactory; | ||
| use Magento\Framework\Controller\ResultInterface; | ||
| use Magento\Sales\Api\OrderRepositoryInterface; | ||
| use Tpay\Magento2\Model\ApiFacade\Transaction\TransactionApiFacade; | ||
| use Tpay\Magento2\Model\TpayPayment; | ||
| use Tpay\Magento2\Service\TpayService; | ||
|
|
||
| class Retry implements ActionInterface, HttpPostActionInterface | ||
| { | ||
| /** @var JsonFactory */ | ||
| private $resultJsonFactory; | ||
|
|
||
| /** @var OrderRepositoryInterface */ | ||
| private $orderRepository; | ||
|
|
||
| /** @var TransactionApiFacade */ | ||
| private $transactionApi; | ||
|
|
||
| /** @var Http */ | ||
| private $request; | ||
|
|
||
| /** @var TpayPayment */ | ||
| private $tpay; | ||
|
|
||
| /** @var TpayService */ | ||
| private $service; | ||
|
|
||
| /** @var Session */ | ||
| private $checkoutSession; | ||
|
|
||
| public function __construct(JsonFactory $resultJsonFactory, OrderRepositoryInterface $orderRepository, TransactionApiFacade $transactionApi, Http $request, TpayPayment $tpay, TpayService $service, Session $checkoutSession) | ||
| { | ||
| $this->resultJsonFactory = $resultJsonFactory; | ||
| $this->orderRepository = $orderRepository; | ||
| $this->transactionApi = $transactionApi; | ||
| $this->request = $request; | ||
| $this->tpay = $tpay; | ||
| $this->service = $service; | ||
| $this->checkoutSession = $checkoutSession; | ||
| } | ||
|
|
||
| public function execute(): ResultInterface | ||
| { | ||
| $orderId = $this->request->getParam('order_id'); | ||
| $transactionId = $this->request->getParam('transaction_id'); | ||
| $order = $this->orderRepository->get($orderId); | ||
| $payment = $order->getPayment(); | ||
| $response = $this->resultJsonFactory->create(); | ||
|
|
||
| $orderTransactionId = $payment->getAdditionalInformation('transaction_id'); | ||
| if ($transactionId !== $orderTransactionId) { | ||
| throw new InvalidRequestException($response->setData(['error' => true])); | ||
| } | ||
|
|
||
| $paymentAttemptsCount = (int) ($payment->getAdditionalInformation('payment_attempts_count') ?? 1); | ||
|
|
||
| $status = $this->transactionApi->getStatus($transactionId); | ||
|
|
||
| if (in_array($status['status'], ['paid', 'correct', 'success'])) { | ||
| return $response->setData(['status' => 'success']); | ||
| } | ||
|
|
||
| if (null !== $payment->getAdditionalInformation('old_transaction_id')) { | ||
| return $response->setData(['status' => 'error']); | ||
| } | ||
|
|
||
| $disableBlik = $paymentAttemptsCount >= 3; | ||
|
|
||
| $blikCode = $this->request->getParam('blikCode'); | ||
|
|
||
| if (!empty($blikCode) && preg_match('/^\d{6}$/', $blikCode) && $paymentAttemptsCount <= 3) { | ||
| $result = $this->transactionApi->blik($transactionId, $blikCode, null); | ||
|
|
||
| $payment->setAdditionalInformation('payment_attempts_count', $paymentAttemptsCount + 1); | ||
| $this->service->saveOrderPayment($payment); | ||
|
|
||
| if (!empty($result['payments']['errors'])) { | ||
| return $response->setData(['status' => 'failed', 'errorMessage' => $result['payments']['errors'][0]['errorMessage'], 'disableBlik' => $disableBlik]); | ||
| } | ||
|
|
||
| return $response->setData(['status' => 'wait', 'disableBlik' => $disableBlik]); | ||
| } | ||
|
|
||
| $this->transactionApi->cancel($transactionId); | ||
|
|
||
| $data = $this->tpay->getTpayFormData($order->getIncrementId()); | ||
| $data = $this->transactionApi->originApiFieldCorrect($data); | ||
| $transaction = $this->transactionApi->createTransaction($data); | ||
|
|
||
| $payment->setAdditionalInformation('transaction_id', $transaction['transactionId']); | ||
| $payment->setAdditionalInformation('old_transaction_id', $transactionId); | ||
| $this->service->saveOrderPayment($payment); | ||
| $this->service->addCommentToHistory($order->getIncrementId(), __('Retrying payment with redirect to paywall and new transaction %1, link: %2', $transaction['title'], $transaction['transactionPaymentUrl'])); | ||
|
|
||
| $this->checkoutSession->setLastRealOrderId($order->getIncrementId()); | ||
| $this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId()); | ||
| $this->checkoutSession->setLastQuoteId($order->getQuoteId()); | ||
| $this->checkoutSession->setLastOrderId($order->getIncrementId()); | ||
|
|
||
| return $response->setData(['redirect' => $transaction['transactionPaymentUrl']]); | ||
| } | ||
| } |
This file contains hidden or 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,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tpay\Magento2\Controller\Tpay; | ||
|
|
||
| use Magento\Framework\App\Action\HttpGetActionInterface; | ||
| use Magento\Framework\App\ActionInterface; | ||
| use Magento\Framework\App\Request\InvalidRequestException; | ||
| use Magento\Framework\App\RequestInterface; | ||
| use Magento\Framework\Controller\Result\JsonFactory; | ||
| use Magento\Framework\Controller\ResultInterface; | ||
| use Magento\Sales\Api\OrderRepositoryInterface; | ||
| use Tpay\Magento2\Model\ApiFacade\Transaction\TransactionApiFacade; | ||
|
|
||
| class Status implements ActionInterface, HttpGetActionInterface | ||
| { | ||
| /** @var JsonFactory */ | ||
| private $resultJsonFactory; | ||
|
|
||
| /** @var OrderRepositoryInterface */ | ||
| private $orderRepository; | ||
|
|
||
| /** @var TransactionApiFacade */ | ||
| private $transactionApi; | ||
|
|
||
| /** @var RequestInterface */ | ||
| private $request; | ||
|
|
||
| public function __construct(JsonFactory $resultJsonFactory, OrderRepositoryInterface $orderRepository, TransactionApiFacade $transactionApi, RequestInterface $request) | ||
| { | ||
| $this->resultJsonFactory = $resultJsonFactory; | ||
| $this->orderRepository = $orderRepository; | ||
| $this->transactionApi = $transactionApi; | ||
| $this->request = $request; | ||
| } | ||
|
|
||
| public function execute(): ResultInterface | ||
| { | ||
| $orderId = $this->request->getParam('order_id'); | ||
| $transactionId = $this->request->getParam('transaction_id'); | ||
| $order = $this->orderRepository->get($orderId); | ||
| $payment = $order->getPayment(); | ||
| $response = $this->resultJsonFactory->create(); | ||
|
|
||
| $orderTransactionId = $payment->getAdditionalInformation('transaction_id'); | ||
| if ($transactionId !== $orderTransactionId) { | ||
| throw new InvalidRequestException($response->setData(['error' => true])); | ||
| } | ||
|
|
||
| $status = $this->transactionApi->getStatus($transactionId); | ||
|
|
||
| if (in_array($status['status'], ['paid', 'correct', 'success'])) { | ||
| return $response->setData(['status' => 'success']); | ||
| } | ||
|
|
||
| $previousAttempts = (int) ($payment->getAdditionalInformation('payment_attempts_count') ?? 1); | ||
| if (count($status['payments']['attempts']) >= $previousAttempts) { | ||
| return $response->setData(['status' => 'failed', 'errorMessage' => __('Payment failed. Try again.')]); | ||
| } | ||
|
|
||
| return $response->setData(['status' => 'wait']); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gdzie ta metoda była użyta?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nie była, IDE wskazało martwy kod