Skip to content
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

Criação de link de pagamento (#130) #3

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Api/Data/PaymentLinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ interface PaymentLinkInterface extends ExtensibleDataInterface
const LINK = 'link';
const ORDER_ID = 'order_id';
const VINDI_PAYMENT_METHOD = 'vindi_payment_method';
const CUSTOMER_ID = 'customer_id';
const CREATED_AT = 'created_at';
const STATUS = 'status';

/**
* @return int
Expand All @@ -35,7 +37,7 @@ public function getEntityId();
public function setEntityId(int $entityId);

/**
* @return int
* @return string
*/
public function getLink();

Expand All @@ -55,7 +57,6 @@ public function getOrderId();
public function setOrderId(int $orderId);

/**
*
* @return string
*/
public function getCreatedAt();
Expand All @@ -74,4 +75,24 @@ public function getVindiPaymentMethod();
* @param string $vindiPaymentMethod
*/
public function setVindiPaymentMethod(string $vindiPaymentMethod);

/**
* @return int
*/
public function getCustomerId();

/**
* @param int $customerId
*/
public function setCustomerId(int $customerId);

/**
* @return string
*/
public function getStatus();

/**
* @param string $status
*/
public function setStatus(string $status);
}
44 changes: 26 additions & 18 deletions Block/Adminhtml/Order/LinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@

declare(strict_types=1);

/**
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Vindi
* @package Vindi_Payment
*
*
*/

namespace Vindi\Payment\Block\Adminhtml\Order;

use \Magento\Backend\Block\Template;
Expand All @@ -23,7 +10,7 @@

class LinkField extends Template
{
const VINDI_PAYMENT_LINK = 'vindi_payment_link';
const VINDI_PAYMENT_LINK = 'vindi_vr_payment_link_';

/**
* @var PaymentLinkService
Expand All @@ -38,8 +25,8 @@ class LinkField extends Template
public function __construct(
Context $context,
PaymentLinkService $paymentLinkService,
array $data = [])
{
array $data = []
) {
$this->paymentLinkService = $paymentLinkService;
parent::__construct($context, $data);
}
Expand All @@ -49,8 +36,7 @@ public function __construct(
*/
public function getOrderId()
{
$orderId = $this->getRequest()->getParam('order_id');
return $orderId;
return $this->getRequest()->getParam('order_id');
}

/**
Expand All @@ -74,4 +60,26 @@ public function getPaymentMethod()
}
return null;
}

/**
* Check if the payment link status is "processed"
*
* @return bool
*/
public function isLinkPaid(): bool
{
$paymentLink = $this->paymentLinkService->getPaymentLink($this->getOrderId());
return $paymentLink->getStatus() === 'processed';
}

/**
* Check if the payment link is expired
*
* @return bool
*/
public function isLinkExpired(): bool
{
$paymentLink = $this->paymentLinkService->getPaymentLink($this->getOrderId());
return $paymentLink->getStatus() === 'expired';
}
}
2 changes: 1 addition & 1 deletion Block/Custom/PaymentLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function getFormattedPrice(float $price)
*/
public function getInstructions()
{
$method = str_replace('vindi_payment_link_','', $this->getPaymentLink()->getVindiPaymentMethod());
$method = str_replace('vindi_vr_payment_link_','', $this->getPaymentLink()->getVindiPaymentMethod());
return $this->helper->getConfig('checkout_instructions', $method);
}

Expand Down
54 changes: 54 additions & 0 deletions Block/Customer/Order/PaymentLinkColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Vindi\Payment\Block\Customer\Order;

use Magento\Framework\View\Element\Template;
use Vindi\Payment\Model\PaymentLinkService;
use Magento\Sales\Api\OrderRepositoryInterface;

class PaymentLinkColumn extends Template
{
/**
* @var PaymentLinkService
*/
private $paymentLinkService;

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* @param Template\Context $context
* @param PaymentLinkService $paymentLinkService
* @param OrderRepositoryInterface $orderRepository
* @param array $data
*/
public function __construct(
Template\Context $context,
PaymentLinkService $paymentLinkService,
OrderRepositoryInterface $orderRepository,
array $data = []
) {
$this->paymentLinkService = $paymentLinkService;
$this->orderRepository = $orderRepository;
parent::__construct($context, $data);
}

/**
* Get pending payment link by order ID.
*
* @param int $orderId
* @return bool|string
*/
public function getPaymentLink($orderId)
{
$paymentLink = $this->paymentLinkService->getPaymentLinkByOrderId($orderId);
if ($paymentLink && $paymentLink->getStatus() === 'pending') {
return $paymentLink->getLink();
}
return false;
}
}
75 changes: 75 additions & 0 deletions Block/Customer/PaymentLinkNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace Vindi\Payment\Block\Customer;

use Magento\Customer\Model\Session as CustomerSession;
use Vindi\Payment\Model\PaymentLinkService;
use Magento\Framework\View\Element\Template;
use Magento\Framework\App\Request\Http as HttpRequest;

class PaymentLinkNotification extends Template
{
/**
* @var PaymentLinkService
*/
private $paymentLinkService;

/**
* @var CustomerSession
*/
private $customerSession;

/**
* @var HttpRequest
*/
private $request;

/**
* @param Template\Context $context
* @param PaymentLinkService $paymentLinkService
* @param CustomerSession $customerSession
* @param HttpRequest $request
* @param array $data
*/
public function __construct(
Template\Context $context,
PaymentLinkService $paymentLinkService,
CustomerSession $customerSession,
HttpRequest $request,
array $data = []
) {
$this->paymentLinkService = $paymentLinkService;
$this->customerSession = $customerSession;
$this->request = $request;
parent::__construct($context, $data);
}

/**
* Check if there is a pending payment link for the logged-in customer.
*
* @return string|false
*/
public function getPaymentLink()
{
if (!$this->customerSession->isLoggedIn()) {
return false;
}

$fullActionName = $this->request->getFullActionName();

if ($fullActionName !== 'customer_account_index') {
return false;
}

$customerId = $this->customerSession->getCustomerId();
$paymentLink = $this->paymentLinkService->getMostRecentPendingPaymentLinkByCustomerId($customerId);

if ($paymentLink && $paymentLink->getStatus() === 'pending') {
return true;
}

return false;
}
}
34 changes: 33 additions & 1 deletion Block/InfoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,53 @@

trait InfoTrait
{
/**
* Check if credit card information can be shown
*
* @return bool
*/
public function canShowCcInfo()
{
return $this->getOrder()->getPayment()->getMethod() === 'vindi';
}

/**
* Get credit card owner
*
* @return string|null
*/
public function getCcOwner()
{
return $this->getOrder()->getPayment()->getCcOwner();
}

/**
* Get number of credit card installments
*
* @return string|null
*/
public function getCcInstallments()
{
return $this->getOrder()->getPayment()->getAdditionalInformation('installments');
}

/**
* Get last four digits of credit card
*
* @return string|null
*/
public function getCcNumber()
{
return $this->getOrder()->getPayment()->getCcLast4();
}

/**
* Get credit card value
*
* @param int $totalQtyCard
* @param int $cardPosition
* @return string
*/
public function getCcValue($totalQtyCard = 1, $cardPosition = 1)
{
return $this->currency->currency(
Expand All @@ -35,11 +62,16 @@ public function getCcValue($totalQtyCard = 1, $cardPosition = 1)
);
}

/**
* Get credit card brand
*
* @return string|null
*/
public function getCcBrand()
{
$brands = $this->paymentMethod->getCreditCardTypes();
$CardCode = $this->getOrder()->getPayment()->getCcType();

return $brands[$CardCode];
return isset($brands[$CardCode]) ? $brands[$CardCode] : null;
}
}
Loading