Skip to content

Commit f37c002

Browse files
contardiThiago ContardiGabrielAntalcarolineestevesAntal
authored
v1.4.1 - Correção endereço e fingerprint (#13)
* feat: added new credit card form * feat: added setup for old settings and minor bugfixes * fix: error with 1i18n on setting's page * fix: allow all countris by default * i18n: add new terms for language file * feat: added max installments and minum installment value * feat: added reseller token to transactions * feat: added reseller token to transactions * feat: send tracking code to Vindi * fix: mask also reseller token and token account * fix: when the card number comes with 4 digits, don't add 20 before it * fix: when the card number comes with 4 digits, don't add 20 before it * doc: added pull request template * fix: observer to bankslippix * fix: cancel unapproved orders without config * feat: adjust with phpstan * fix: error monitoring transactions * fix: worng price additional * fix: update terms to ask for a CPF on checkout * feat: don't auto select TaxVat when is not a CPF number * feat: don't auto select TaxVat when is not a CPF number * Payment link functionality created * Vindi payment method verification to send the payment link has been added * The payment link email template changed and made an email configuration to set the template * Template Id changed * Email path and list fixed * feat/VINDI-143: estilo da pagina de link de pagamento com boleto, pix, bolepix e cartao * feat/VINDI-143: estilizacao pagina link de pagamento * Use strict added to js file * ko library added * float cast removed * Applying the requested changes on payment link files * adding the vindi_customer_taxvat to additionalInformation * Fixing the bugs about payment link * VP module version has been updated * payment link email template has been changed * Deleting the payment link when it is expired * Fixing the payment link summary details * Adding a discount verification * Making the discount value positive * fix: change fingerprint loader * VINDI-143: pagina de sucesso * VINDI-143: mensagem de desconto no link de pagamento * Remove linha comentada * The payment link delete has been removed from the payment link page * fix: add fingerprint method in define * fix: customer without taxvat * fix: preventing conflict with the vindi recurrence module * feat: adding security validations and better payment link management * fix: phpstan fix * feat: creating mass sending of payment link * fix: remove await vindi fingerprint * feat: add translate * feat: automatically cancels orders whose payment link has expired more than 30 days ago * feat: custom email template * fix: remove await vindi fingerprint * fix: remove await vindi fingerprint * refactor: adding validation on payment methods and payment link success page * fix: change form with get status * feat: implementing single view system on success page * feat: translate * fix: remove await vindi fingerprint * fix: remove await vindi fingerprint * feat: expire_at field * update * update * update * update * fix: processing payment link when canceling * fix: Adjust payment data displays if the order has already been invoiced * fix: address saving repeated * fix: call fingerprint script in all pages * v1.4.1 --------- Co-authored-by: Thiago Contardi <thiago@bizcommerce.com.br> Co-authored-by: Gabriel Antal <gabrielantalsilva@gmail.com> Co-authored-by: Caroline Esteves <carol@bizcommerce.com.br> Co-authored-by: Antal <gabriel.antal@bizcommerce.com.br> Co-authored-by: Antal <44688111+GabrielAntal@users.noreply.github.com> Co-authored-by: carolineesteves <131886821+carolineesteves@users.noreply.github.com> Co-authored-by: Iago Cedran <iago@bizcommerce.com.br>
1 parent 7ee3b67 commit f37c002

File tree

30 files changed

+1012
-394
lines changed

30 files changed

+1012
-394
lines changed

Api/Data/PaymentLinkInterface.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface PaymentLinkInterface extends ExtensibleDataInterface
2626
const CREATED_AT = 'created_at';
2727

2828
const STATUS = 'status';
29+
const SUCCESS_PAGE_ACCESSED = 'success_page_accessed';
30+
const EXPIRED_AT = 'expired_at';
2931

3032
/**
3133
* @return int
@@ -97,5 +99,33 @@ public function getStatus();
9799
* @param string $status
98100
*/
99101
public function setStatus(string $status);
102+
103+
/**
104+
* Check if the success page has been accessed
105+
*
106+
* @return bool
107+
*/
108+
public function getSuccessPageAccessed();
109+
110+
/**
111+
* Set the success page accessed flag
112+
*
113+
* @param bool $successPageAccessed
114+
*/
115+
public function setSuccessPageAccessed(bool $successPageAccessed);
116+
117+
/**
118+
* Get the expiration date of the payment link
119+
*
120+
* @return string|null
121+
*/
122+
public function getExpiredAt();
123+
124+
/**
125+
* Set the expiration date of the payment link
126+
*
127+
* @param string|null $expiredAt
128+
*/
129+
public function setExpiredAt($expiredAt);
100130
}
101131

Block/Adminhtml/Order/LinkField.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,26 @@ public function getPaymentMethod()
7676
}
7777
return null;
7878
}
79+
80+
/**
81+
* Check if the payment link status is "processed"
82+
*
83+
* @return bool
84+
*/
85+
public function isLinkPaid(): bool
86+
{
87+
$paymentLink = $this->paymentLinkService->getPaymentLink($this->getOrderId());
88+
return $paymentLink->getStatus() === 'processed';
89+
}
90+
91+
/**
92+
* Check if the payment link is expired
93+
*
94+
* @return bool
95+
*/
96+
public function isLinkExpired(): bool
97+
{
98+
$paymentLink = $this->paymentLinkService->getPaymentLink($this->getOrderId());
99+
return $paymentLink->getStatus() === 'expired';
100+
}
79101
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Vindi\VP\Console\Command;
6+
7+
use Vindi\VP\Cron\CancelOrdersWithExpiredLinks;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Psr\Log\LoggerInterface;
12+
13+
class RunCancelOrdersWithExpiredLinks extends Command
14+
{
15+
/**
16+
* @var CancelOrdersWithExpiredLinks
17+
*/
18+
private CancelOrdersWithExpiredLinks $cancelOrdersWithExpiredLinks;
19+
20+
/**
21+
* @var LoggerInterface
22+
*/
23+
private LoggerInterface $logger;
24+
25+
/**
26+
* @param CancelOrdersWithExpiredLinks $cancelOrdersWithExpiredLinks
27+
* @param LoggerInterface $logger
28+
*/
29+
public function __construct(
30+
CancelOrdersWithExpiredLinks $cancelOrdersWithExpiredLinks,
31+
LoggerInterface $logger
32+
) {
33+
$this->cancelOrdersWithExpiredLinks = $cancelOrdersWithExpiredLinks;
34+
$this->logger = $logger;
35+
parent::__construct();
36+
}
37+
38+
/**
39+
* Configure the command
40+
*/
41+
protected function configure()
42+
{
43+
$this->setName('vindi:vp:cancel-orders-with-expired-links');
44+
$this->setDescription('Manually run the cron to cancel orders with expired payment links');
45+
parent::configure();
46+
}
47+
48+
/**
49+
* Execute the command
50+
*
51+
* @param InputInterface $input
52+
* @param OutputInterface $output
53+
* @return int
54+
*/
55+
protected function execute(InputInterface $input, OutputInterface $output): int
56+
{
57+
try {
58+
$this->cancelOrdersWithExpiredLinks->execute();
59+
$output->writeln('<info>Orders with expired payment links have been canceled successfully.</info>');
60+
return Command::SUCCESS;
61+
} catch (\Exception $e) {
62+
$this->logger->error('Error while canceling orders with expired payment links: ' . $e->getMessage());
63+
$output->writeln('<error>An error occurred while canceling orders with expired payment links.</error>');
64+
return Command::FAILURE;
65+
}
66+
}
67+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Vindi\VP\Controller\Adminhtml\PaymentLink;
6+
7+
use Magento\Backend\App\Action;
8+
use Magento\Backend\App\Action\Context;
9+
use Magento\Framework\Controller\Result\JsonFactory;
10+
use Magento\Framework\Controller\Result\Redirect;
11+
use Magento\Framework\Data\Form\FormKey\Validator;
12+
use Magento\Framework\Message\ManagerInterface;
13+
use Psr\Log\LoggerInterface;
14+
use Vindi\VP\Model\PaymentLinkService;
15+
use Magento\Sales\Api\OrderRepositoryInterface;
16+
use Vindi\VP\Block\Adminhtml\Order\LinkField;
17+
18+
class MassSend extends Action
19+
{
20+
/**
21+
* @var JsonFactory
22+
*/
23+
private JsonFactory $resultJsonFactory;
24+
25+
/**
26+
* @var PaymentLinkService
27+
*/
28+
private PaymentLinkService $paymentLinkService;
29+
30+
/**
31+
* @var LoggerInterface
32+
*/
33+
private LoggerInterface $logger;
34+
35+
/**
36+
* @var Validator
37+
*/
38+
private Validator $formKeyValidator;
39+
40+
/**
41+
* @var OrderRepositoryInterface
42+
*/
43+
private OrderRepositoryInterface $orderRepository;
44+
45+
/**
46+
* Maximum number of orders allowed for processing at once.
47+
*/
48+
private const MAX_ORDERS = 50;
49+
50+
/**
51+
* @param Context $context
52+
* @param JsonFactory $resultJsonFactory
53+
* @param PaymentLinkService $paymentLinkService
54+
* @param LoggerInterface $logger
55+
* @param Validator $formKeyValidator
56+
* @param ManagerInterface $messageManager
57+
* @param OrderRepositoryInterface $orderRepository
58+
*/
59+
public function __construct(
60+
Context $context,
61+
JsonFactory $resultJsonFactory,
62+
PaymentLinkService $paymentLinkService,
63+
LoggerInterface $logger,
64+
Validator $formKeyValidator,
65+
ManagerInterface $messageManager,
66+
OrderRepositoryInterface $orderRepository
67+
) {
68+
parent::__construct($context);
69+
$this->resultJsonFactory = $resultJsonFactory;
70+
$this->paymentLinkService = $paymentLinkService;
71+
$this->logger = $logger;
72+
$this->formKeyValidator = $formKeyValidator;
73+
$this->messageManager = $messageManager;
74+
$this->orderRepository = $orderRepository;
75+
}
76+
77+
/**
78+
* Execute mass action for sending payment link
79+
*
80+
* @return \Magento\Framework\Controller\Result\Redirect
81+
*/
82+
public function execute()
83+
{
84+
$resultRedirect = $this->resultRedirectFactory->create();
85+
$orderIds = $this->getRequest()->getParam('selected', []);
86+
87+
if (count($orderIds) > self::MAX_ORDERS) {
88+
$this->messageManager->addErrorMessage(__('You can only select up to %1 orders at a time.', self::MAX_ORDERS));
89+
return $resultRedirect->setPath('sales/order/index');
90+
}
91+
92+
if (!$this->formKeyValidator->validate($this->getRequest())) {
93+
$this->messageManager->addErrorMessage(__('Invalid Form Key'));
94+
return $resultRedirect->setPath('sales/order/index');
95+
}
96+
97+
try {
98+
$errors = 0;
99+
$successes = 0;
100+
101+
foreach ($orderIds as $orderId) {
102+
try {
103+
$order = $this->orderRepository->get($orderId);
104+
$paymentMethod = $order->getPayment()->getMethod();
105+
106+
if (!str_contains($paymentMethod, LinkField::VINDI_PAYMENT_LINK)) {
107+
$this->messageManager->addWarningMessage(__('Order ID %1 is not an order with a payment link or has already been processed.', $order->getIncrementId()));
108+
continue;
109+
}
110+
111+
$paymentLink = $this->paymentLinkService->getPaymentLink($orderId);
112+
113+
if (!$paymentLink || !$paymentLink->getId()) {
114+
$this->messageManager->addWarningMessage(__('No payment link found for order ID %1.', $order->getIncrementId()));
115+
continue;
116+
}
117+
118+
if ($paymentLink->getStatus() === 'processed') {
119+
$this->messageManager->addWarningMessage(__('Payment link for order ID %1 has already been processed and will not be sent.', $order->getIncrementId()));
120+
continue;
121+
}
122+
123+
$success = $this->paymentLinkService->sendPaymentLinkEmail($order->getEntityId());
124+
if ($success) {
125+
$successes++;
126+
} else {
127+
$errors++;
128+
}
129+
} catch (\Exception $e) {
130+
$this->logger->critical($e);
131+
$errors++;
132+
}
133+
}
134+
135+
if ($errors === 0 && $successes > 0) {
136+
$this->messageManager->addSuccessMessage(__('%1 orders were successfully sent the payment link.', $successes));
137+
} elseif ($errors > 0 && $successes > 0) {
138+
$this->messageManager->addSuccessMessage(__('%1 orders were successfully sent the payment link.', $successes));
139+
$this->messageManager->addWarningMessage(__('%1 orders failed to send the payment link.', $errors));
140+
} elseif ($errors > 0 && $successes === 0) {
141+
$this->messageManager->addErrorMessage(__('No orders were successfully sent. %1 orders failed to send the payment link.', $errors));
142+
}
143+
} catch (\Exception $e) {
144+
$this->logger->critical($e);
145+
$this->messageManager->addErrorMessage(__('Error sending the payment link.'));
146+
}
147+
148+
return $resultRedirect->setPath('sales/order/index');
149+
}
150+
}

Controller/Checkout/Success.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @category Vindi
1313
* @package Vindi_VP
1414
*
15-
*
1615
*/
1716

1817
namespace Vindi\VP\Controller\Checkout;
@@ -21,6 +20,7 @@
2120
use Magento\Framework\App\RequestInterface;
2221
use Magento\Framework\View\Result\PageFactory;
2322
use Magento\Framework\Controller\Result\RedirectFactory;
23+
use Magento\Framework\Message\ManagerInterface;
2424
use Vindi\VP\Helper\Data;
2525
use Vindi\VP\Model\PaymentLinkService;
2626

@@ -51,26 +51,34 @@ class Success implements HttpGetActionInterface
5151
*/
5252
private Data $helperData;
5353

54+
/**
55+
* @var ManagerInterface
56+
*/
57+
private ManagerInterface $messageManager;
58+
5459
/**
5560
* @param PageFactory $resultPageFactory
5661
* @param PaymentLinkService $paymentLinkService
5762
* @param RequestInterface $request
5863
* @param RedirectFactory $redirectFactory
5964
* @param Data $helperData
65+
* @param ManagerInterface $messageManager
6066
*/
6167
public function __construct(
6268
PageFactory $resultPageFactory,
6369
PaymentLinkService $paymentLinkService,
6470
RequestInterface $request,
6571
RedirectFactory $redirectFactory,
66-
Data $helperData
72+
Data $helperData,
73+
ManagerInterface $messageManager
6774
)
6875
{
6976
$this->resultPageFactory = $resultPageFactory;
7077
$this->paymentLinkService = $paymentLinkService;
7178
$this->request = $request;
7279
$this->redirectFactory = $redirectFactory;
7380
$this->helperData = $helperData;
81+
$this->messageManager = $messageManager;
7482
}
7583

7684
/**
@@ -80,17 +88,41 @@ public function execute()
8088
{
8189
$result = $this->resultPageFactory->create();
8290
$orderId = $this->request->getParam('order_id');
83-
$order = $this->paymentLinkService->getOrderByOrderId($orderId);
84-
$orderStatus = $order->getStatus();
85-
$configStatus = $this->helperData->getConfig('order_status', $order->getPayment()->getMethod());
86-
$isCcMethod = str_contains($order->getPayment()->getMethod(), 'cc');
8791

8892
try {
89-
if (!$orderId || (!$isCcMethod && $orderStatus !== $configStatus)) {
90-
return $this->redirectFactory->create()->setPath('noroute');
93+
if (!$orderId) {
94+
$this->messageManager->addWarningMessage(
95+
__('The order ID is missing or invalid. Please contact support or try again.')
96+
);
97+
return $this->redirectFactory->create()->setPath('/');
98+
}
99+
100+
$paymentLink = $this->paymentLinkService->getPaymentLinkByOrderId($orderId);
101+
102+
if ($paymentLink && $paymentLink->getSuccessPageAccessed()) {
103+
$this->messageManager->addWarningMessage(
104+
__('The payment success page has already been accessed.')
105+
);
106+
return $this->redirectFactory->create()->setPath('/');
107+
}
108+
109+
$order = $this->paymentLinkService->getOrderByOrderId($orderId);
110+
$orderStatus = $order->getStatus();
111+
$configStatus = $this->helperData->getConfig('order_status', $order->getPayment()->getMethod());
112+
$isCcMethod = str_contains($order->getPayment()->getMethod(), 'cc');
113+
114+
if (!$isCcMethod && $orderStatus !== $configStatus) {
115+
return $this->redirectFactory->create()->setPath('/');
91116
}
117+
118+
$paymentLink->setSuccessPageAccessed(true);
119+
$this->paymentLinkService->savePaymentLink($paymentLink);
120+
92121
} catch (\Exception $e) {
93-
return $this->redirectFactory->create()->setPath('noroute');
122+
$this->messageManager->addErrorMessage(
123+
__('An error occurred while processing your request. Please try again later.')
124+
);
125+
return $this->redirectFactory->create()->setPath('/');
94126
}
95127

96128
return $result;

0 commit comments

Comments
 (0)