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

Bp 3652 implement buckaroo hosted fields #1091

Merged
merged 25 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
824fe82
hosted fields
vegimcarkaxhija Jul 29, 2024
4708968
hosted fields
vegimcarkaxhija Jul 30, 2024
0c79bc1
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Aug 8, 2024
acdc420
credticard hosted fileds
vegimcarkaxhija Aug 9, 2024
be42232
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Aug 9, 2024
8f95fcf
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Sep 2, 2024
cd05142
remove credit card, and fix hosted fields
vegimcarkaxhija Sep 3, 2024
5970b0f
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Sep 12, 2024
ba510f7
remove credit card
vegimcarkaxhija Sep 16, 2024
192ab9d
check for hosted fields username and password
vegimcarkaxhija Sep 26, 2024
e29eb75
check for hosted fields username and password
vegimcarkaxhija Sep 26, 2024
9925d05
update error handling
vegimcarkaxhija Sep 26, 2024
0ef018b
update error handling
vegimcarkaxhija Sep 26, 2024
6cc3514
update error handling
vegimcarkaxhija Sep 26, 2024
1d5cc5e
remove credit card
vegimcarkaxhija Sep 27, 2024
aee788e
update error handling
vegimcarkaxhija Sep 27, 2024
4fabbcf
fix front end style
vegimcarkaxhija Sep 27, 2024
10f74bf
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Sep 27, 2024
1cd7046
remove payWithBaseCurrency
vegimcarkaxhija Sep 27, 2024
6f97368
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Oct 17, 2024
e9e6e4a
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Nov 6, 2024
6aa91a3
Merge branch 'refs/heads/develop' into BP-3652-Implement-Buckaroo-Hos…
vegimcarkaxhija Nov 6, 2024
671432f
update Buckaroo Hosted Fields
vegimcarkaxhija Nov 6, 2024
2622241
update Buckaroo Hosted Fields
vegimcarkaxhija Nov 6, 2024
9dd3da3
update Buckaroo Hosted Fields
vegimcarkaxhija Nov 6, 2024
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
7 changes: 3 additions & 4 deletions Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Info extends \Magento\Payment\Block\Info
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param array $data
* @param \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard $configProvider
* @param \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards $configProvider
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
Expand Down Expand Up @@ -98,7 +98,6 @@ public function getPaymentLogo(string $method): string
"afterpay20" => "svg/riverty.svg",
"capayablein3" => "svg/in3.svg",
"capayablepostpay" => "svg/in3.svg",
"creditcard" => "svg/creditcards.svg",
"creditcards" => "svg/creditcards.svg",
"giftcards" => "svg/giftcards.svg",
"idealprocessing" => "svg/ideal.svg",
Expand All @@ -115,7 +114,7 @@ public function getPaymentLogo(string $method): string
];

$name = "svg/{$method}.svg";

if(isset($mappings[$method])) {
$name = $mappings[$method];
}
Expand Down Expand Up @@ -164,7 +163,7 @@ public function getCreditcardLogo(string $code): string
if($code === 'cartebleuevisa') {
$code = 'cartebleue';
}

return $this->assetRepo->getUrl("Buckaroo_Magento2::images/creditcards/{$code}.svg");
}
}
6 changes: 3 additions & 3 deletions Block/Info/Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class Creditcard extends \Buckaroo\Magento2\Block\Info
protected $mpiStatus;

/**
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards
*/
protected $configProvider;

/**
* @var string
*/
protected $_template = 'Buckaroo_Magento2::info/creditcard.phtml';
protected $_template = 'Buckaroo_Magento2::info/creditcards.phtml';

public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
Expand All @@ -54,7 +54,7 @@ public function __construct(
Repository $assetRepo,
UrlInterface $baseUrl,
array $data = [],
\Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard $configProvider = null
\Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards $configProvider = null
) {
parent::__construct($context, $groupTransaction, $giftcardCollection, $assetRepo, $baseUrl, $data);
$this->configProvider = $configProvider;
Expand Down
1 change: 0 additions & 1 deletion Block/Widget/Button/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Toolbar
'buckaroo_magento2_billink',
'buckaroo_magento2_payperemail',
'buckaroo_magento2_paylink',
'buckaroo_magento2_creditcard',
'buckaroo_magento2_creditcards',
'buckaroo_magento2_ideal',
'buckaroo_magento2_idealprocessing',
Expand Down
164 changes: 164 additions & 0 deletions Controller/CredentialsChecker/GetToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
namespace Buckaroo\Magento2\Controller\CredentialsChecker;

use Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Psr\Log\LoggerInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\HTTP\Client\Curl;

class GetToken extends Action
{
protected $resultJsonFactory;
protected $logger;
protected $configProviderCreditcard;
protected $encryptor;
protected $store;
protected $curlClient;

public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
LoggerInterface $logger,
Creditcards $configProviderCreditcard,
EncryptorInterface $encryptor,
StoreManagerInterface $storeManager,
Curl $curlClient
) {
$this->resultJsonFactory = $resultJsonFactory;
$this->logger = $logger;
$this->configProviderCreditcard = $configProviderCreditcard;
$this->encryptor = $encryptor;
$this->store = $storeManager->getStore();
$this->curlClient = $curlClient;
parent::__construct($context);
}

/**
* Send POST request using Magento's Curl client.
*/
private function sendPostRequest($url, $username, $password, $postData) {
try {
// Set Basic Auth credentials without base64_encode()
$this->curlClient->setCredentials($username, $password);

// Set the headers and post fields
$this->curlClient->addHeader("Content-Type", "application/x-www-form-urlencoded");

// Send the POST request
$this->curlClient->post($url, http_build_query($postData));

// Get the response body
return $this->curlClient->getBody();
} catch (\Exception $e) {
$this->logger->error('Curl request error: ' . $e->getMessage());
throw new \Exception('Error occurred during cURL request: ' . $e->getMessage());
}
}

protected function getHostedFieldsClientId()
{
try {
return $this->encryptor->decrypt(
$this->configProviderCreditcard->getHostedFieldsClientId($this->store)
);
} catch (\Exception $e) {
$this->logger->error('Error decrypting Hosted Fields Username: ' . $e->getMessage());
return null;
}
}

protected function getHostedFieldsClientSecret()
{
try {
return $this->encryptor->decrypt(
$this->configProviderCreditcard->getHostedFieldsClientSecret($this->store)
);
} catch (\Exception $e) {
$this->logger->error('Error decrypting Hosted Fields Password: ' . $e->getMessage());
return null;
}
}

protected function getAllowedIssuers()
{
try {
return $this->configProviderCreditcard->getSupportedServices();
} catch (\Exception $e) {
$this->logger->error('Error getting Allowed Issuers: ' . $e->getMessage());
return null;
}
}

public function execute()
{
$result = $this->resultJsonFactory->create();

// Validate the request origin
$requestOrigin = $this->getRequest()->getHeader('X-Requested-From');
if ($requestOrigin !== 'MagentoFrontend') {
return $result->setHttpResponseCode(403)->setData([
'error' => true,
'message' => 'Unauthorized request'
]);
}

// Get username and password
$hostedFieldsClientId = $this->getHostedFieldsClientId();
$hostedFieldsClientSecret = $this->getHostedFieldsClientSecret();
$issuers = $this->getAllowedIssuers();

if (empty($hostedFieldsClientId) || empty($hostedFieldsClientSecret)) {
return $result->setHttpResponseCode(400)->setData([
'error' => true,
'message' => 'Hosted Fields Username or Password is empty.'
]);
}
if (empty($issuers)) {
return $result->setHttpResponseCode(400)->setData([
'error' => true,
'message' => 'There is no Allowed Issuers for Hosted Fields.'
]);
}

// Try to fetch the token
try {
$url = "https://auth.buckaroo.io/oauth/token";
$postData = [
'scope' => 'hostedfields:save',
'grant_type' => 'client_credentials'
];

$response = $this->sendPostRequest($url, $hostedFieldsClientId, $hostedFieldsClientSecret, $postData);
$responseArray = json_decode($response, true);

// Check for successful response
if (isset($responseArray['access_token'])) {
return $result->setData([
'error' => false,
'data' => [
'access_token' => $responseArray['access_token'],
'issuers' => $issuers
]
]);
}

// Handle error response
$message = isset($responseArray['message']) ? $responseArray['message'] : 'Unknown error occurred';
return $result->setHttpResponseCode(400)->setData([
'error' => true,
'message' => 'Error fetching token.'
]);

} catch (\Exception $e) {
$this->logger->error('Error occurred while fetching token.');
return $result->setHttpResponseCode(500)->setData([
'error' => true,
'message' => 'An error occurred while fetching the token.'
]);
}
}
}
14 changes: 1 addition & 13 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,6 @@ public function getStore()
}
}

public function getConfigCardSort()
{
$configValue = $this->scopeConfig->getValue(
'payment/buckaroo_magento2_creditcard/sorted_issuers',
$this->scopeDefiner->getScope(),
($this->scopeDefiner->getScope() == ScopeInterface::SCOPE_WEBSITES) ? $this->storeManager->getStore() : null
);

return $configValue;
}

public function getConfigGiftCardsSort()
{
$configValue = $this->scopeConfig->getValue(
Expand Down Expand Up @@ -428,8 +417,7 @@ public function getPaymentMethodsList()
['value' => 'applepay', 'label' => __('Apple Pay')],
['value' => 'billink', 'label' => __('Billink')],
['value' => 'capayablein3', 'label' => __('In3')],
['value' => 'creditcard', 'label' => __('Credit and debit cards')],
['value' => 'creditcards', 'label' => __('Credit and debit cards (Client sided)')],
['value' => 'creditcards', 'label' => __('Credit and debit cards')],
['value' => 'emandate', 'label' => __('Digital Debit Authorization')],
['value' => 'eps', 'label' => __('EPS')],
['value' => 'giftcards', 'label' => __('Giftcards')],
Expand Down
6 changes: 3 additions & 3 deletions Model/Config/Source/Creditcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
class Creditcard implements \Magento\Framework\Option\ArrayInterface
{
/**
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard
* @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards
*/
protected $configProvider;

/**
* Use the constructor to get the requested config provider.
*
* @param \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard $configProvider
* @param \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards $configProvider
*/
public function __construct(
\Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard $configProvider
\Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards $configProvider
) {
$this->configProvider = $configProvider;
}
Expand Down
2 changes: 1 addition & 1 deletion Model/ConfigProvider/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function getParsedLabel(Store $store, OrderInterface $order)
if ($label === null) {
return $store->getName();
}

$label = preg_replace('/\{order_number\}/', $order->getIncrementId(), $label);
$label = preg_replace('/\{shop_name\}/', $store->getName(), $label);

Expand Down
Loading
Loading