Skip to content

Commit

Permalink
Merge branch 'release/2.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadjer Chabane committed Sep 17, 2024
2 parents 7fff3ea + 4f66566 commit 0775c45
Show file tree
Hide file tree
Showing 29 changed files with 451 additions and 176 deletions.
54 changes: 0 additions & 54 deletions Block/Customer/Tab.php

This file was deleted.

66 changes: 58 additions & 8 deletions Block/Customer/Index.php → Block/Customer/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
namespace Lyranetwork\Payzen\Block\Customer;

class Index extends \Magento\Framework\View\Element\Template
class Wallet extends \Magento\Vault\Block\Customer\CreditCards
{
/**
* @var \Lyranetwork\Payzen\Helper\Data
Expand All @@ -21,29 +21,35 @@ class Index extends \Magento\Framework\View\Element\Template
*/
protected $customerSession;

protected $method;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Vault\Model\CustomerTokenManagement $customerTokenManagement,
* @param \Magento\Customer\Model\Session $customerSession
* @param \Lyranetwork\Payzen\Helper\Data $dataHelper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Vault\Model\CustomerTokenManagement $customerTokenManagement,
\Magento\Customer\Model\Session $customerSession,
\Lyranetwork\Payzen\Helper\Data $dataHelper,
array $data = []
) {
$this->customerSession = $customerSession;
$this->dataHelper = $dataHelper;
parent::__construct($context, $data);
parent::__construct($context, $customerTokenManagement);

$this->method = $this->dataHelper->getMethodInstance(\Lyranetwork\Payzen\Helper\Data::METHOD_STANDARD);
}

/**
* Get Form data by using ops payment api.
*
* @return array
*/
public function getStoredPaymentMeans()
public function getStoredPaymentMeans($identifier = null)
{
$means = [];

Expand All @@ -58,6 +64,11 @@ public function getStoredPaymentMeans()
'payzen_sepa_identifier' => 'payzen_sepa_iban_bic'
];

if ($identifier) {
$identifierToUnset = ($identifier == 'payzen_identifier') ? 'payzen_sepa_identifier' : 'payzen_identifier';
unset($aliasIds[$identifierToUnset]);
}

foreach ($aliasIds as $aliasId => $maskedId) {
// Check if there is a saved alias.
if (! $customer->getCustomAttribute($aliasId)) {
Expand All @@ -69,11 +80,16 @@ public function getStoredPaymentMeans()
$card['pm'] = $maskedId;

$maskedPan = $customer->getCustomAttribute($maskedId)->getValue();
$pos = strpos($maskedPan, '|');

if ($pos !== false) {
if ($pos = strpos($maskedPan, '|')) {
$card['brand'] = substr($maskedPan, 0, $pos);
$card['number'] = substr($maskedPan, $pos + 1);
$number = substr($maskedPan, $pos + 1);

if ($pos = strpos($number, '-')) {
$card['expiry'] = substr($number, $pos + 2);
$number = substr($number, 0, $pos);
}

$card['number'] = $number;
} else {
$card['brand'] = '';
$card['number'] = $maskedPan;
Expand All @@ -96,6 +112,40 @@ public function getCcTypeImageSrc($card)
return $this->dataHelper->getCcTypeImageSrc($card);
}

public function getAccountToken()
{
if (! $this->useCustomerWallet()) {
return null;
}

return $this->method->getAccountToken();
}

public function getLanguage()
{
return $this->method->getPaymentLanguage();
}

public function hideWalletElements()
{
return $this->dataHelper->onVaultTab() && ! $this->method->isRestMode();
}

public function hasIdentifiers()
{
return ! empty($this->getStoredPaymentMeans());
}

private function useCustomerWallet()
{
$customer = $this->method->getCurrentCustomer();
if (! $customer || ! $this->method->isOneClickActive()) {
return false;
}

return true;
}

/**
* Render block HTML.
*
Expand All @@ -109,4 +159,4 @@ protected function _toHtml()

return parent::_toHtml();
}
}
}
2 changes: 1 addition & 1 deletion Block/Payment/Rest/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getCardLabel()
*/
protected function _toHtml()
{
if (! $this->method->isRestMode()) {
if (! $this->method->isRestMode() && ! $this->dataHelper->onVaultTab()) {
return '';
}

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.10.0, 2024-09-17:
- [embedded] Use customer wallet functionality to manage payment by alias on buyer account.
- [alias] Improve alias validity check.

2.9.2, 2024-07-30:
- Bug fix: Do not override CSP module configured mode.
- Some fixes by plugin variant.
Expand Down
6 changes: 4 additions & 2 deletions Controller/Customer/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public function execute()
$customerId = $this->customerSession->getCustomer()->getId();
$attribute = $this->getRequest()->getPost('alias_attr', false);
$maskedAttribute = $this->getRequest()->getPost('pm_attr', false);
$alias = $this->getRequest()->getPost('alias', false);

if ($customerId && $attribute && $maskedAttribute) {
if ($this->paymentHelper->deleteIdentifier($customerId, $attribute, $maskedAttribute)) {
if ($this->paymentHelper->deleteIdentifier($customerId, $attribute, $maskedAttribute, $alias)) {
$this->messageManager->addSuccessMessage(__('The stored means of payment was successfully deleted.'));
} else {
$this->messageManager->addErrorMessage(__('The stored means of payment could not be deleted.'));
Expand All @@ -53,7 +54,8 @@ public function execute()

/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/*/index', ['_secure' => true]);
$resultRedirect->setPath('vault/cards/listaction', ['_secure' => true]);

return $resultRedirect;
}
}
42 changes: 0 additions & 42 deletions Controller/Customer/Index.php

This file was deleted.

18 changes: 18 additions & 0 deletions Controller/Payment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function execute()
$params = $this->getRequest()->getParams();
$data = $this->prepareResponse($params);

if (isset($data['from_account'])) {
return $this->redirectToAccount($data['response']);
}

$order = $data['order'];
$response = $data['response'];
$result = $this->responseProcessor->execute($order, $response);
Expand Down Expand Up @@ -179,6 +183,20 @@ protected function redirectResponse($order, $case, $checkUrlWarn = false)
return $resultRedirect;
}

protected function redirectToAccount($response)
{
// Clear all messages in session.
$this->messageManager->getMessages(true);

if ($response->get('identifier') || ($response->get('identifier_status') == 'CREATED')) {
$this->messageManager->addSuccessMessage(__('Payment means successfully added.'));
} else {
$this->messageManager->addErrorMessage(__('Unable to add payment means to your account.'));
}

return $this->createResult('vault/cards/listaction', ['_scope' => '1']);
}

private function createResult($path, $params)
{
if ($this->getRequest()->getParam('iframe', false)) {
Expand Down
27 changes: 22 additions & 5 deletions Controller/Payment/Rest/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ protected function prepareResponse($params)
]
);

if ($response->getExtInfo('from_account')) {
$storeId = $response->getExtInfo('store_id');

// Check the authenticity of the request.
$this->checkResponseHash($params, $storeId);

return [
'response' => $response,
'from_account' => true
];
}

$orderId = (int) $response->get('order_id');
if (! $orderId) {
$this->dataHelper->log("Received empty Order ID.", \Psr\Log\LogLevel::ERROR);
Expand All @@ -127,16 +139,21 @@ protected function prepareResponse($params)
$storeId = $order->getStore()->getId();

// Check the authenticity of the request.
$this->checkResponseHash($params, $storeId);

return [
'response' => $response,
'order' => $order
];
}

private function checkResponseHash($params, $storeId)
{
if (! $this->restHelper->checkResponseHash($params, $this->restHelper->getReturnKey($storeId))) {
// Authentication failed.
throw new ResponseException(
"{$this->dataHelper->getIpAddress()} tries to access payzen/payment_rest/response page without valid signature with parameters: " . json_encode($params)
);
}

return [
'response' => $response,
'order' => $order
];
}
}
19 changes: 18 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public function getCheckoutStoreId()
return $session->getStoreId();
}

public function getCurrentStore()
{
return $this->storeManager->getStore();
}

/**
* Return store obeject by ID.
*
Expand Down Expand Up @@ -360,6 +365,17 @@ public function isPublishFileImageExists($fileName)
return $this->fileExists($filePath);
}

/**
* Check if image file is published to pub/static directory.
*
* @param string $fileName
* @return string
*/
public function onVaultTab()
{
return (strpos($this->storeManager->getStore()->getCurrentUrl(), 'vault/cards/listaction') !== false);
}

/**
* Returns a configuration parameter from XML files.
*
Expand Down Expand Up @@ -607,7 +623,8 @@ public function isOneClickActive()
$standardMethod = $this->getMethodInstance(\Lyranetwork\Payzen\Helper\Data::METHOD_STANDARD);
$sepaMethod = $this->getMethodInstance(\Lyranetwork\Payzen\Helper\Data::METHOD_SEPA);

return $standardMethod->isOneClickActive() || $sepaMethod->isOneClickActive();
return ($standardMethod->isAvailable() && $standardMethod->isOneClickActive()) ||
($sepaMethod->isAvailable() && $sepaMethod->isOneClickActive());
}

private function convertCardDataEntryMode($code) {
Expand Down
Loading

0 comments on commit 0775c45

Please sign in to comment.