From 824fe8265123b124ed12cd8962b30586c17c40e9 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Mon, 29 Jul 2024 14:47:38 +0200 Subject: [PATCH 001/175] hosted fields --- Controller/CredentialsChecker/GetToken.php | 142 +++++ Model/ConfigProvider/Account.php | 6 + etc/adminhtml/system/account.xml | 16 + etc/csp_whitelist.xml | 8 +- view/frontend/layout/checkout_index_index.xml | 1 + view/frontend/requirejs-config.js | 2 + .../payment/method-renderer/creditcards.js | 513 ++++++++---------- .../buckaroo_magento2_creditcards.html | 169 ++---- 8 files changed, 442 insertions(+), 415 deletions(-) create mode 100644 Controller/CredentialsChecker/GetToken.php diff --git a/Controller/CredentialsChecker/GetToken.php b/Controller/CredentialsChecker/GetToken.php new file mode 100644 index 000000000..10679c186 --- /dev/null +++ b/Controller/CredentialsChecker/GetToken.php @@ -0,0 +1,142 @@ +resultJsonFactory = $resultJsonFactory; + $this->logger = $logger; + $this->configProviderAccount = $configProviderAccount; + $this->encryptor = $encryptor; + $this->store = $storeManager->getStore(); + parent::__construct($context); + } + + private function sendPostRequest($url, $username, $password, $postData) { + // Initialize cURL + $ch = curl_init(); + + // Set the URL + curl_setopt($ch, CURLOPT_URL, $url); + + // Set the HTTP method to POST + curl_setopt($ch, CURLOPT_POST, true); + + // Set the username and password for Basic Auth + curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); + + // Set the Content-Type to application/x-www-form-urlencoded + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']); + + // Set the POST fields + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); + + // Return the response instead of printing it + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // Execute the request + $response = curl_exec($ch); + + // Check for cURL errors + if ($response === false) { + $error = 'Curl error: ' . curl_error($ch); + curl_close($ch); + throw new \Exception($error); + } + + // Close the cURL session + curl_close($ch); + return $response; + } + + protected function getHostedFieldsUsername() + { + try { + return $this->encryptor->decrypt( + $this->configProviderAccount->getHostedFieldsUsername($this->store) + ); + } catch (\Exception $e) { + $this->logger->error('Error decrypting Hosted Fields Username: ' . $e->getMessage()); + return null; + } + } + + protected function getHostedFieldsPassword() + { + try { + return $this->encryptor->decrypt( + $this->configProviderAccount->getHostedFieldsPassword($this->store) + ); + } catch (\Exception $e) { + $this->logger->error('Error decrypting Hosted Fields Password: ' . $e->getMessage()); + return null; + } + } + + public function execute() + { + $result = $this->resultJsonFactory->create(); + + $requestOrigin = $this->getRequest()->getHeader('X-Requested-From'); + + if ($requestOrigin !== 'MagentoFrontend') { + return $result->setHttpResponseCode(403)->setData(['error' => 'Unauthorized request']); + } + + $hostedFieldsUsername = $this->getHostedFieldsUsername(); + $hostedFieldsPassword = $this->getHostedFieldsPassword(); + + if (!empty($hostedFieldsUsername) && !empty($hostedFieldsPassword)) { + try { + $url = "https://auth.buckaroo.io/oauth/token"; + $postData = [ + 'scope' => 'hostedfields:save', + 'grant_type' => 'client_credentials' + ]; + + $response = $this->sendPostRequest($url, $hostedFieldsUsername, $hostedFieldsPassword, $postData); + $responseArray = json_decode($response, true); + + if (isset($responseArray['access_token'])) { + return $result->setData($responseArray); + } + + return $result->setHttpResponseCode(500)->setData([ + 'error' => 'Unable to fetch token', + 'response' => $response + ]); + } catch (\Exception $e) { + $this->logger->error('Error occurred while fetching token: ' . $e->getMessage()); + return $result->setHttpResponseCode(500)->setData([ + 'error' => 'An error occurred while fetching the token', + 'message' => $e->getMessage() + ]); + } + } else { + return $result->setHttpResponseCode(400)->setData([ + 'error' => 'Hosted Fields Username or Password is empty.' + ]); + } + } +} diff --git a/Model/ConfigProvider/Account.php b/Model/ConfigProvider/Account.php index b6cecaaa2..f2595f2b2 100644 --- a/Model/ConfigProvider/Account.php +++ b/Model/ConfigProvider/Account.php @@ -31,6 +31,8 @@ * @method mixed getActive() * @method mixed getSecretKey() * @method mixed getMerchantKey() + * @method mixed getHostedFieldsUsername() + * @method mixed getHostedFieldsPassword() * @method mixed getMerchantGuid() * @method mixed getTransactionLabel() * @method mixed getCertificateFile() @@ -58,6 +60,8 @@ class Account extends AbstractConfigProvider const XPATH_ACCOUNT_ACTIVE = 'buckaroo_magento2/account/active'; const XPATH_ACCOUNT_SECRET_KEY = 'buckaroo_magento2/account/secret_key'; const XPATH_ACCOUNT_MERCHANT_KEY = 'buckaroo_magento2/account/merchant_key'; + const XPATH_ACCOUNT_HOSTED_FIELDS_USERNAME = 'buckaroo_magento2/account/hosted_fields_username'; + const XPATH_ACCOUNT_HOSTED_FIELDS_PASSWORD = 'buckaroo_magento2/account/hosted_fields_password'; const XPATH_ACCOUNT_MERCHANT_GUID = 'buckaroo_magento2/account/merchant_guid'; const XPATH_ACCOUNT_TRANSACTION_LABEL = 'buckaroo_magento2/account/transaction_label'; const XPATH_ACCOUNT_INVOICE_HANDLING = 'buckaroo_magento2/account/invoice_handling'; @@ -121,6 +125,8 @@ public function getConfig($store = null) 'active' => $this->getActive($store), 'secret_key' => $this->getSecretKey($store), 'merchant_key' => $this->getMerchantKey($store), + 'hosted_fields_username' => $this->getHostedFieldsUsername($store), + 'hosted_fields_password' => $this->getHostedFieldsPassword($store), 'merchant_guid' => $this->getMerchantGuid($store), 'transaction_label' => $this->getTransactionLabel($store), 'certificate_file' => $this->getCertificateFile($store), diff --git a/etc/adminhtml/system/account.xml b/etc/adminhtml/system/account.xml index e8e36dcce..6c664d97c 100644 --- a/etc/adminhtml/system/account.xml +++ b/etc/adminhtml/system/account.xml @@ -56,6 +56,22 @@ + + + + The Secret Key can be retrieved in Payment Plaza under Configuration > Security > Secret Key. For support contact Buckaroo. + Magento\Config\Model\Config\Backend\Encrypted + buckaroo_magento2/account/hosted_fields_username + + + + + + The (Merchant) Key can be retrieved in Payment Plaza under My Buckaroo > Websites. For support contact Buckaroo. + Magento\Config\Model\Config\Backend\Encrypted + buckaroo_magento2/account/hosted_fields_password + + diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 35c36e996..3a311fc5b 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -1,6 +1,5 @@ - + @@ -8,6 +7,9 @@ list.xsd"> https://checkout.buckaroo.nl https://testcheckout.buckaroo.nl https://buckaroo.nl + https://hostedfields-externalapi.alpha.buckaroo.aws + https://hostedfields-externalapi.prod-pci.buckaroo.io + https://cdn.tailwindcss.com @@ -27,6 +29,8 @@ list.xsd"> wss://websockets.buckaroo.io/ https://checkout.buckaroo.nl https://testcheckout.buckaroo.nl + https://hostedfields-externalapi.alpha.buckaroo.aws + https://hostedfields-externalapi.prod-pci.buckaroo.io diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index e5ff51df4..bff197388 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -22,6 +22,7 @@ + - \ No newline at end of file + From cd051420f8acae6118613887e7e26dbfa6d69dd0 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Tue, 3 Sep 2024 11:14:13 +0200 Subject: [PATCH 005/175] remove credit card, and fix hosted fields --- Block/Info.php | 7 +- Block/Info/Creditcard.php | 4 +- Helper/Data.php | 3 +- Model/Config/Source/Creditcard.php | 6 +- Model/ConfigProvider/Method/Creditcard.php | 342 ------------------ Model/ConfigProvider/Method/Creditcards.php | 92 ++++- Model/Method/Creditcard.php | 207 ----------- Model/Service/Plugin/Mpi/Push.php | 109 ------ .../Model/Config/Source/CreditcardTest.php | 69 ---- .../ConfigProvider/Method/CreditcardTest.php | 76 ---- etc/adminhtml/system/account.xml | 16 - etc/adminhtml/system/payment_methods.xml | 2 - .../system/payment_methods/creditcard.xml | 312 ---------------- .../system/payment_methods/creditcards.xml | 22 +- etc/config.xml | 21 -- etc/csp_whitelist.xml | 6 + etc/di.xml | 7 +- etc/frontend/di.xml | 1 - i18n/de_DE.csv | 4 + i18n/nl_NL.csv | 4 + .../payment/method-renderer/creditcards.js | 199 +++++----- 21 files changed, 210 insertions(+), 1299 deletions(-) delete mode 100644 Model/ConfigProvider/Method/Creditcard.php delete mode 100644 Model/Method/Creditcard.php delete mode 100644 Model/Service/Plugin/Mpi/Push.php delete mode 100644 Test/Unit/Model/Config/Source/CreditcardTest.php delete mode 100644 Test/Unit/Model/ConfigProvider/Method/CreditcardTest.php delete mode 100644 etc/adminhtml/system/payment_methods/creditcard.xml diff --git a/Block/Info.php b/Block/Info.php index 5a2f0e08f..b76f5194e 100644 --- a/Block/Info.php +++ b/Block/Info.php @@ -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, @@ -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", @@ -115,7 +114,7 @@ public function getPaymentLogo(string $method): string ]; $name = "svg/{$method}.svg"; - + if(isset($mappings[$method])) { $name = $mappings[$method]; } @@ -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"); } } diff --git a/Block/Info/Creditcard.php b/Block/Info/Creditcard.php index 6eb551d95..27d484eb6 100644 --- a/Block/Info/Creditcard.php +++ b/Block/Info/Creditcard.php @@ -38,7 +38,7 @@ 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; @@ -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; diff --git a/Helper/Data.php b/Helper/Data.php index 06e5ace99..78ddac3d9 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -428,8 +428,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')], diff --git a/Model/Config/Source/Creditcard.php b/Model/Config/Source/Creditcard.php index 04a77c6c2..c7e877f2d 100644 --- a/Model/Config/Source/Creditcard.php +++ b/Model/Config/Source/Creditcard.php @@ -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; } diff --git a/Model/ConfigProvider/Method/Creditcard.php b/Model/ConfigProvider/Method/Creditcard.php deleted file mode 100644 index 57f40535c..000000000 --- a/Model/ConfigProvider/Method/Creditcard.php +++ /dev/null @@ -1,342 +0,0 @@ - 'American Express', - 'code' => self::CREDITCARD_SERVICE_CODE_AMEX, - 'sort' => 0 - ], - [ - 'name' => 'Carte Bancaire', - 'code' => self::CREDITCARD_SERVICE_CODE_CARTEBANCAIRE, - 'sort' => 0 - ], - [ - 'name' => 'Carte Bleue', - 'code' => self::CREDITCARD_SERVICE_CODE_CARTEBLEUE, - 'sort' => 0 - ], - [ - 'name' => 'Dankort', - 'code' => self::CREDITCARD_SERVICE_CODE_DANKORT, - 'sort' => 0 - ], - [ - 'name' => 'Maestro', - 'code' => self::CREDITCARD_SERVICE_CODE_MAESTRO, - 'sort' => 0 - ], - [ - 'name' => 'MasterCard', - 'code' => self::CREDITCARD_SERVICE_CODE_MASTERCARD, - 'sort' => 0 - ], - [ - 'name' => 'Nexi', - 'code' => self::CREDITCARD_SERVICE_CODE_NEXI, - 'sort' => 0 - ], - [ - 'name' => 'PostePay', - 'code' => self::CREDITCARD_SERVICE_CODE_POSTEPAY, - 'sort' => 0 - ], - [ - 'name' => 'VISA', - 'code' => self::CREDITCARD_SERVICE_CODE_VISA, - 'sort' => 0 - ], - [ - 'name' => 'VISA Electron', - 'code' => self::CREDITCARD_SERVICE_CODE_VISAELECTRON, - 'sort' => 0 - ], - [ - 'name' => 'VPay', - 'code' => self::CREDITCARD_SERVICE_CODE_VPAY, - 'sort' => 0 - ], - ]; - - /** - * Add the active flag to the creditcard list. This is used in the checkout process. - * - * @return array - */ - public function formatIssuers() - { - $sorted = $this->getSortedIssuers(); - $sorted = $sorted ? explode(',',$sorted) : []; - - if (!empty($sorted)) { - $sortedPosition = 1; - foreach ($sorted as $cardCode) { - $sorted_array[$cardCode] = $sortedPosition++; - } - } - - foreach ($this->getIssuers() as $item) { - $item['sort'] = isset($sorted_array[$item['code']]) ? - $sorted_array[$item['code']] : self::DEFAULT_SORT_VALUE; - $item['img'] = $this->getImageUrl($item['code']); - $allCreditcard[$item['code']] = $item; - } - - $allowed = explode(',', (string)$this->scopeConfig->getValue( - self::XPATH_CREDITCARD_ALLOWED_CREDITCARDS, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - )); - - $cards = []; - foreach ($allowed as $key => $value) { - if (isset($allCreditcard[$value])) { - $cards[] = $allCreditcard[$value]; - } - } - - usort($cards, function ($cardA, $cardB) { - return $cardA['sort'] - $cardB['sort']; - }); - - return $cards; - } - - /** - * @return array|void - */ - public function getConfig() - { - $issuers = $this->formatIssuers(); - $paymentFeeLabel = $this->getBuckarooPaymentFeeLabel( - \Buckaroo\Magento2\Model\Method\Creditcard::PAYMENT_METHOD_CODE - ); - - $selectionType = $this->scopeConfig->getValue( - self::XPATH_SELECTION_TYPE, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - $paymentFlow = $this->scopeConfig->getValue( - self::XPATH_PAYMENT_FLOW, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ); - - return [ - 'payment' => [ - 'buckaroo' => [ - 'creditcard' => [ - 'cards' => $issuers, - 'groupCreditcards' => $this->isGroupCreditcards(), - 'paymentFeeLabel' => $paymentFeeLabel, - 'subtext' => $this->getSubtext(), - 'subtext_style' => $this->getSubtextStyle(), - 'subtext_color' => $this->getSubtextColor(), - 'allowedCurrencies' => $this->getAllowedCurrencies(), - 'selectionType' => $selectionType, - 'paymentFlow' => $paymentFlow, - ], - ], - ], - ]; - } - - /** - * @param null|int $storeId - * - * @return float - */ - public function getPaymentFee($storeId = null) - { - $paymentFee = $this->scopeConfig->getValue( - self::XPATH_CREDITCARD_PAYMENT_FEE, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $storeId - ); - - return $paymentFee ? $paymentFee : false; - } - - /** - * @param string $cardType - * - * @return string - * - * @throws \InvalidArgumentException - */ - public function getCardName($cardType) - { - $config = $this->getConfig(); - - foreach ($config['payment']['buckaroo']['creditcard']['cards'] as $card) { - if ($card['code'] == $cardType) { - return $card['name']; - } - } - - throw new \InvalidArgumentException("No card found for card type: {$cardType}"); - } - - /** - * @param string $cardType - * - * @return string - * - * @throws \InvalidArgumentException - */ - public function getCardCode($cardType) - { - $config = $this->getConfig(); - foreach ($config['payment']['buckaroo']['creditcard']['cards'] as $card) { - if ($card['name'] == $cardType) { - return $card['code']; - } - } - - throw new \InvalidArgumentException("No card found for card type: {$cardType}"); - } - - 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; - } - - /** - * @param $storeId - * @return ?string - */ - public function getSortedIssuers($storeId = null): ?string - { - return $this->scopeConfig->getValue( - self::XPATH_SORTED_ISSUERS, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $storeId - ); - } - - /** - * Generate the url to the desired asset. - * - * @param string $imgName - * @param string $extension - * - * @return string - */ - public function getImageUrl($imgName, string $extension = 'png') - { - if($imgName === 'cartebleuevisa') { - $imgName = 'cartebleue'; - } - - return parent::getImageUrl("creditcards/{$imgName}", "svg"); - } - - /** - * Get all issuers not sorted - * - * @return array - */ - public function getAllIssuers(): array - { - $issuers = $this->getIssuers(); - $issuersPrepared = []; - foreach ($issuers as $issuer) { - $issuer['img'] = $this->getImageUrl($issuer['code']); - $issuersPrepared[$issuer['code']] = $issuer; - } - - return $issuersPrepared; - } - - /** - * Credit cards are displayed separately in the checkout. - * - * @param $storeId - * @return string - */ - public function isGroupCreditcards($storeId = null): string - { - return (bool)$this->scopeConfig->getValue( - self::XPATH_CREDITCARD_GROUP_CREDITCARD, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $storeId - ); - } -} diff --git a/Model/ConfigProvider/Method/Creditcards.php b/Model/ConfigProvider/Method/Creditcards.php index 638598061..55a2472d9 100644 --- a/Model/ConfigProvider/Method/Creditcards.php +++ b/Model/ConfigProvider/Method/Creditcards.php @@ -36,6 +36,21 @@ */ class Creditcards extends AbstractConfigProvider { + /**#@+ + * Creditcard service codes. + */ + const CREDITCARD_SERVICE_CODE_MASTERCARD = 'mastercard'; + const CREDITCARD_SERVICE_CODE_VISA = 'visa'; + const CREDITCARD_SERVICE_CODE_AMEX = 'amex'; + const CREDITCARD_SERVICE_CODE_MAESTRO = 'maestro'; + const CREDITCARD_SERVICE_CODE_VPAY = 'vpay'; + const CREDITCARD_SERVICE_CODE_VISAELECTRON = 'visaelectron'; + const CREDITCARD_SERVICE_CODE_CARTEBLEUE = 'cartebleuevisa'; + const CREDITCARD_SERVICE_CODE_CARTEBANCAIRE = 'cartebancaire'; + const CREDITCARD_SERVICE_CODE_DANKORT = 'dankort'; + const CREDITCARD_SERVICE_CODE_NEXI = 'nexi'; + const CREDITCARD_SERVICE_CODE_POSTEPAY = 'postepay'; + const XPATH_CREDITCARDS_PAYMENT_FEE = 'payment/buckaroo_magento2_creditcards/payment_fee'; const XPATH_CREDITCARDS_PAYMENT_FEE_LABEL = 'payment/buckaroo_magento2_creditcards/payment_fee_label'; const XPATH_CREDITCARDS_ACTIVE = 'payment/buckaroo_magento2_creditcards/active'; @@ -61,26 +76,63 @@ class Creditcards extends AbstractConfigProvider const XPATH_SPECIFIC_COUNTRY = 'payment/buckaroo_magento2_creditcards/specificcountry'; const XPATH_SPECIFIC_CUSTOMER_GROUP = 'payment/buckaroo_magento2_creditcards/specificcustomergroup'; - /** - * Creditcards constructor. - * - * @param Repository $assetRepo - * @param ScopeConfigInterface $scopeConfig - * @param AllowedCurrencies $allowedCurrencies - * @param PaymentFee $paymentFeeHelper - * @param Creditcard $creditcardConfigProvider - */ - public function __construct( - Repository $assetRepo, - ScopeConfigInterface $scopeConfig, - AllowedCurrencies $allowedCurrencies, - PaymentFee $paymentFeeHelper, - Creditcard $creditcardConfigProvider - ) { - parent::__construct($assetRepo, $scopeConfig, $allowedCurrencies, $paymentFeeHelper); - - $this->issuers = $creditcardConfigProvider->getIssuers(); - } + protected $issuers = [ + [ + 'name' => 'American Express', + 'code' => self::CREDITCARD_SERVICE_CODE_AMEX, + 'sort' => 0 + ], + [ + 'name' => 'Carte Bancaire', + 'code' => self::CREDITCARD_SERVICE_CODE_CARTEBANCAIRE, + 'sort' => 0 + ], + [ + 'name' => 'Carte Bleue', + 'code' => self::CREDITCARD_SERVICE_CODE_CARTEBLEUE, + 'sort' => 0 + ], + [ + 'name' => 'Dankort', + 'code' => self::CREDITCARD_SERVICE_CODE_DANKORT, + 'sort' => 0 + ], + [ + 'name' => 'Maestro', + 'code' => self::CREDITCARD_SERVICE_CODE_MAESTRO, + 'sort' => 0 + ], + [ + 'name' => 'MasterCard', + 'code' => self::CREDITCARD_SERVICE_CODE_MASTERCARD, + 'sort' => 0 + ], + [ + 'name' => 'Nexi', + 'code' => self::CREDITCARD_SERVICE_CODE_NEXI, + 'sort' => 0 + ], + [ + 'name' => 'PostePay', + 'code' => self::CREDITCARD_SERVICE_CODE_POSTEPAY, + 'sort' => 0 + ], + [ + 'name' => 'VISA', + 'code' => self::CREDITCARD_SERVICE_CODE_VISA, + 'sort' => 0 + ], + [ + 'name' => 'VISA Electron', + 'code' => self::CREDITCARD_SERVICE_CODE_VISAELECTRON, + 'sort' => 0 + ], + [ + 'name' => 'VPay', + 'code' => self::CREDITCARD_SERVICE_CODE_VPAY, + 'sort' => 0 + ], + ]; /** * @return array diff --git a/Model/Method/Creditcard.php b/Model/Method/Creditcard.php deleted file mode 100644 index a55665730..000000000 --- a/Model/Method/Creditcard.php +++ /dev/null @@ -1,207 +0,0 @@ -assignDataConvertToArray($data); - - if (isset($data['additional_data']['card_type'])) { - $this->getInfoInstance()->setAdditionalInformation( - 'card_type', - $data['additional_data']['card_type'] - ); - } - - return $this; - } - - /** - * Check capture availability - * - * @return bool - * @api - */ - public function canCapture() - { - if ($this->getConfigData('payment_action') == 'order') { - return false; - } - return $this->_canCapture; - } - - /** - * {@inheritdoc} - */ - public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) - { - /** - * If there are no credit cards chosen, we can't be available - */ - /** - * @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard $ccConfig - */ - $ccConfig = $this->configProviderMethodFactory->get('creditcard'); - if (null === $ccConfig->getAllowedCreditcards()) { - return false; - } - /** - * Return the regular isAvailable result - */ - return parent::isAvailable($quote); - } - - /** - * {@inheritdoc} - */ - public function getOrderTransactionBuilder($payment) - { - $transactionBuilder = $this->transactionBuilderFactory->get('order'); - - $services = [ - 'Name' => $payment->getAdditionalInformation('card_type'), - 'Action' => $this->getPayRemainder($payment, $transactionBuilder), - 'Version' => 1, - ]; - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $transactionBuilder->setOrder($payment->getOrder()) - ->setServices($services) - ->setMethod('TransactionRequest'); - - return $transactionBuilder; - } - - /** - * {@inheritdoc} - */ - public function getCaptureTransactionBuilder($payment) - { - $transactionBuilder = $this->transactionBuilderFactory->get('order'); - - $services = [ - 'Name' => $payment->getAdditionalInformation('card_type'), - 'Action' => 'Capture', - 'Version' => 1, - ]; - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $transactionBuilder->setOrder($payment->getOrder()) - ->setServices($services) - ->setMethod('TransactionRequest') - ->setChannel('CallCenter') - ->setOriginalTransactionKey( - $payment->getAdditionalInformation( - self::BUCKAROO_ORIGINAL_TRANSACTION_KEY_KEY - ) - ); - - return $transactionBuilder; - } - - /** - * {@inheritdoc} - */ - public function getAuthorizeTransactionBuilder($payment) - { - $transactionBuilder = $this->transactionBuilderFactory->get('order'); - - $services = [ - 'Name' => $payment->getAdditionalInformation('card_type'), - 'Action' => 'Authorize', - 'Version' => 1, - ]; - - /** - * @noinspection PhpUndefinedMethodInspection - */ - $transactionBuilder->setOrder($payment->getOrder()) - ->setServices($services) - ->setMethod('TransactionRequest'); - - return $transactionBuilder; - } - - /** - * {@inheritdoc} - */ - public function getVoidTransactionBuilder($payment) - { - return true; - } - - /** - * @param \Magento\Sales\Api\Data\OrderPaymentInterface|\Magento\Payment\Model\InfoInterface $payment - * - * @return bool|string - */ - public function getPaymentMethodName($payment) - { - return $payment->getAdditionalInformation('card_type'); - } -} diff --git a/Model/Service/Plugin/Mpi/Push.php b/Model/Service/Plugin/Mpi/Push.php deleted file mode 100644 index 4f361eaca..000000000 --- a/Model/Service/Plugin/Mpi/Push.php +++ /dev/null @@ -1,109 +0,0 @@ -configProviderCreditcard = $configProviderCreditcard; - } - - /** - * @param \Buckaroo\Magento2\Model\Push $push - * @param boolean $result - * - * @return boolean - */ - public function afterProcessSucceededPush( - \Buckaroo\Magento2\Model\Push $push, - $result - ) { - $payment = $push->order->getPayment(); - $method = $payment->getMethod(); - - if (strpos($method, 'buckaroo_magento2') === false) { - return $this; - } - - /** - * @var \Buckaroo\Magento2\Model\Method\AbstractMethod $paymentMethodInstance - */ - $paymentMethodInstance = $payment->getMethodInstance(); - $card = $paymentMethodInstance->getInfoInstance()->getAdditionalInformation('card_type'); - - if (empty($push->postData["brq_service_{$card}_authentication"]) - || empty($push->postData["brq_service_{$card}_enrolled"]) - ) { - return $result; - } - - $authentication = $push->postData["brq_service_{$card}_authentication"]; - - if ($authentication == 'U' || $authentication == 'N') { - switch ($card) { - case 'maestro': - $putOrderOnHold = (bool) $this->configProviderCreditcard->getMaestroUnsecureHold(); - break; - case 'visa': - $putOrderOnHold = (bool) $this->configProviderCreditcard->getVisaUnsecureHold(); - break; - case 'mastercard': - $putOrderOnHold = (bool) $this->configProviderCreditcard->getMastercardUnsecureHold(); - break; - default: - $putOrderOnHold = false; - break; - } - - if ($putOrderOnHold) { - $push->order - ->hold() - ->addStatusHistoryComment( - __('Order has been put on hold, because it is unsecure.') - ); - - $push->order->save(); - } - } - - $paymentMethodInstance->getInfoInstance()->setAdditionalInformation( - 'buckaroo_mpi_status', - [ - 'enrolled' => $push->postData["brq_service_{$card}_enrolled"], - 'authentication' => $push->postData["brq_service_{$card}_authentication"], - ] - ); - - return $result; - } -} diff --git a/Test/Unit/Model/Config/Source/CreditcardTest.php b/Test/Unit/Model/Config/Source/CreditcardTest.php deleted file mode 100644 index abc086f82..000000000 --- a/Test/Unit/Model/Config/Source/CreditcardTest.php +++ /dev/null @@ -1,69 +0,0 @@ - 'Test 1', - 'code' => 'code1', - ], - [ - 'name' => 'Test 2', - 'code' => 'code2', - ], - [ - 'name' => 'Test 3', - 'code' => 'code3', - ], - ]; - - $configProviderMock = $this->getFakeMock(CreditcardProvider::class)->setMethods(['getIssuers'])->getMock(); - $configProviderMock->expects($this->once())->method('getIssuers')->willReturn($issuers); - - $instance = $this->getInstance(['configProvider' => $configProviderMock]); - $result = $instance->toOptionArray(); - - $expected = [ - [ - 'value' => 'code1', - 'label' => 'Test 1', - ], - [ - 'value' => 'code2', - 'label' => 'Test 2', - ], - [ - 'value' => 'code3', - 'label' => 'Test 3', - ], - ]; - - $this->assertEquals($expected, $result); - } -} diff --git a/Test/Unit/Model/ConfigProvider/Method/CreditcardTest.php b/Test/Unit/Model/ConfigProvider/Method/CreditcardTest.php deleted file mode 100644 index 0b38f52bf..000000000 --- a/Test/Unit/Model/ConfigProvider/Method/CreditcardTest.php +++ /dev/null @@ -1,76 +0,0 @@ -markTestIncomplete( - 'This test needs to be reviewed.' - ); - $issuers = 'amex,visa'; - $allowedCurrencies = 'USD,EUR'; - - $scopeConfigMock = $this->getFakeMock(ScopeConfigInterface::class) - ->setMethods(['getValue']) - ->getMockForAbstractClass(); - $scopeConfigMock->method('getValue') - ->withConsecutive( - [Creditcard::XPATH_CREDITCARD_ALLOWED_CREDITCARDS, ScopeInterface::SCOPE_STORE], - [Creditcard::XPATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, null] - )->willReturnOnConsecutiveCalls($issuers, $allowedCurrencies); - - $instance = $this->getInstance(['scopeConfig' => $scopeConfigMock]); - $result = $instance->getConfig(); - - $this->assertInternalType('array', $result); - $this->assertArrayHasKey('payment', $result); - $this->assertArrayHasKey('buckaroo', $result['payment']); - $this->assertArrayHasKey('creditcard', $result['payment']['buckaroo']); - $this->assertArrayHasKey('cards', $result['payment']['buckaroo']['creditcard']); - $this->assertInternalType('array', $result['payment']['buckaroo']['creditcard']['cards']); - } - - /** - * Test if the getActive magic method returns the correct value. - */ - public function testGetActive() - { - $scopeConfigMock = $this->getFakeMock(ScopeConfigInterface::class) - ->setMethods(['getValue']) - ->getMockForAbstractClass(); - $scopeConfigMock->method('getValue') - ->with(Creditcard::XPATH_CREDITCARD_ACTIVE, ScopeInterface::SCOPE_STORE, null) - ->willReturn('1'); - - $instance = $this->getInstance(['scopeConfig' => $scopeConfigMock]); - $result = $instance->getActive(); - - $this->assertEquals(1, $result); - } -} diff --git a/etc/adminhtml/system/account.xml b/etc/adminhtml/system/account.xml index a433b58cd..5f243a4e9 100644 --- a/etc/adminhtml/system/account.xml +++ b/etc/adminhtml/system/account.xml @@ -56,22 +56,6 @@ - - - - The Secret Key can be retrieved in Payment Plaza under Configuration > Security > Secret Key. For support contact Buckaroo. - Magento\Config\Model\Config\Backend\Encrypted - buckaroo_magento2/account/hosted_fields_username - - - - - - The (Merchant) Key can be retrieved in Payment Plaza under My Buckaroo > Websites. For support contact Buckaroo. - Magento\Config\Model\Config\Backend\Encrypted - buckaroo_magento2/account/hosted_fields_password - - diff --git a/etc/adminhtml/system/payment_methods.xml b/etc/adminhtml/system/payment_methods.xml index 16022b639..c336e363e 100644 --- a/etc/adminhtml/system/payment_methods.xml +++ b/etc/adminhtml/system/payment_methods.xml @@ -52,8 +52,6 @@ - - diff --git a/etc/adminhtml/system/payment_methods/creditcard.xml b/etc/adminhtml/system/payment_methods/creditcard.xml deleted file mode 100644 index 92f2ff3c5..000000000 --- a/etc/adminhtml/system/payment_methods/creditcard.xml +++ /dev/null @@ -1,312 +0,0 @@ - - - - - - - Buckaroo\Magento2\Block\Config\Form\Field\Fieldset - - - - - Buckaroo\Magento2\Model\Config\Source\Enablemode - payment/buckaroo_magento2_creditcard/active - - - - - - payment/buckaroo_magento2_creditcard/title - - - - - - payment/buckaroo_magento2_creditcard/subtext - - - - - - Buckaroo\Magento2\Model\Config\Source\SubtextStyle - payment/buckaroo_magento2_creditcard/subtext_style - - - - - - payment/buckaroo_magento2_creditcard/subtext_color - Buckaroo\Magento2\Block\Config\Form\Field\ColorPicker - - - - - - - payment/buckaroo_magento2_creditcard/sort_order - - - - - Separate: Creditcards are show seperate in checkout. A frontend subtext is not supported when the separate option is chosen.
Grouped: Creditcards get redirected to the buckaroo checkout.]]>
- Buckaroo\Magento2\Model\Config\Source\SeparateOrGrouped - payment/buckaroo_magento2_creditcard/group_creditcards -
- - - - - payment/buckaroo_magento2_creditcard/allowed_issuers - Buckaroo\Magento2\Model\Config\Source\Creditcard - - - - - Buckaroo\Magento2\Block\Adminhtml\Form\Field\SortIssuers - - payment/buckaroo_magento2_creditcard/sorted_issuers - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/order_email - - - - - - payment/buckaroo_magento2_creditcard/payment_action - Buckaroo\Magento2\Model\Config\Source\PaymentFlow - - - - - - The payment method shows only for orders with an order amount greater than the minimum amount. - payment/buckaroo_magento2_creditcard/min_amount - Buckaroo\Magento2\Model\Config\Backend\Price - - - - - - The payment method shows only for orders with an order amount smaller than the maximum amount. - payment/buckaroo_magento2_creditcard/max_amount - Buckaroo\Magento2\Model\Config\Backend\Price - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/active_status - - - - - - To make a new status available it needs to be assigned to the correct state. See Magento documentation about state and status. - Buckaroo\Magento2\Model\Config\Source\StatusesSuccess - payment/buckaroo_magento2_creditcard/order_status_success - - 1 - - - - - - - To make a new status available it needs to be assigned to the correct state. See Magento documentation about state and status. - Buckaroo\Magento2\Model\Config\Source\StatusesFailed - payment/buckaroo_magento2_creditcard/order_status_failed - - 1 - - - - - - - Your contract with Buckaroo must allow for the selected currencies to be used with this payment method. - payment/buckaroo_magento2_creditcard/allowed_currencies - Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::creditcard - Buckaroo\Magento2\Model\Config\Backend\AllowedCurrencies - - - - - Buckaroo\Magento2\Model\Config\Source\AllOrSpecificCountries - payment/buckaroo_magento2_creditcard/allowspecific - - - - - - Magento\Config\Model\Config\Source\Locale\Country - payment/buckaroo_magento2_creditcard/specificcountry - - 1 - - - - - - - Magento developer client restrictions. - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/limit_by_ip - - - - - Buckaroo\Magento2\Model\Config\Source\SpecificCustomerGroups - 1 - payment/buckaroo_magento2_creditcard/specificcustomergroup - - - - - Configuration > Sales > Tax.]]> - payment/buckaroo_magento2_creditcard/payment_fee - Buckaroo\Magento2\Model\Config\Backend\PaymentFee - - - - - - payment/buckaroo_magento2_creditcard/payment_fee_label - - - - - - Magento\Config\Block\System\Config\Form\Field\Heading - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/limit_by_ip - - - - - - Magento\Config\Block\System\Config\Form\Field\Heading - - - - - - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/mastercard_unsecure_hold - - - - - - Magento\Config\Block\System\Config\Form\Field\Heading - - - - - - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/visa_unsecure_hold - - - - - - Magento\Config\Block\System\Config\Form\Field\Heading - - - - - - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/maestro_unsecure_hold - - - - - - - - Magento\Config\Block\System\Config\Form\Field\Heading - - - - - - - - - - - - - - - Magento\Config\Model\Config\Source\Yesno - payment/buckaroo_magento2_creditcard/dankort_unsecure_hold - - - - - - -
-
diff --git a/etc/adminhtml/system/payment_methods/creditcards.xml b/etc/adminhtml/system/payment_methods/creditcards.xml index 42ed09723..fd57032ae 100644 --- a/etc/adminhtml/system/payment_methods/creditcards.xml +++ b/etc/adminhtml/system/payment_methods/creditcards.xml @@ -22,11 +22,11 @@ - + Buckaroo\Magento2\Block\Config\Form\Field\Fieldset - + Buckaroo\Magento2\Model\Config\Source\Enablemode payment/buckaroo_magento2_creditcards/active @@ -35,6 +35,22 @@ + + + Token registration.]]> + Please enter your Buckaroo Hosted Fields Username. + Magento\Config\Model\Config\Backend\Encrypted + buckaroo_magento2/account/hosted_fields_username + + + + + Token registration.]]> + Please enter your Buckaroo Hosted Fields Password. + Magento\Config\Model\Config\Backend\Encrypted + buckaroo_magento2/account/hosted_fields_password + + @@ -46,7 +62,7 @@ payment/buckaroo_magento2_creditcards/subtext - + diff --git a/etc/config.xml b/etc/config.xml index 189cccd36..48dec449c 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -131,27 +131,6 @@ 0 - - 0 - Buckaroo\Magento2\Model\Method\Creditcard - pending - Buckaroo Creditcard and Debit Cards - 0 - 30 - 1 - Fee - Fee - Fee - Fee - - Fee - - buckaroo_magento2 - order - 0 - 1 - - 0 Buckaroo\Magento2\Model\Method\Creditcards diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 3a311fc5b..596b323df 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -33,5 +33,11 @@ https://hostedfields-externalapi.prod-pci.buckaroo.io + + + https://hostedfields-externalapi.alpha.buckaroo.aws + https://hostedfields-externalapi.prod-pci.buckaroo.io + + diff --git a/etc/di.xml b/etc/di.xml index ab7e0ea45..ded7ca7d4 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -124,7 +124,6 @@ - Magento\Framework\Filesystem\Driver\File @@ -241,10 +240,6 @@ idealprocessing Buckaroo\Magento2\Model\ConfigProvider\Method\IdealProcessing - - creditcard - Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard - creditcards Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards @@ -498,7 +493,7 @@ - Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard + Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 005d75f47..5d01b8a09 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -28,7 +28,6 @@ Buckaroo\Magento2\Model\ConfigProvider\Method\Ideal Buckaroo\Magento2\Model\ConfigProvider\Method\IdealProcessing Buckaroo\Magento2\Model\ConfigProvider\Method\Transfer - Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcard Buckaroo\Magento2\Model\ConfigProvider\Method\Creditcards Buckaroo\Magento2\Model\ConfigProvider\BuckarooFee Buckaroo\Magento2\Model\ConfigProvider\Method\Paypal diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 0659ba5ba..815fa2a4c 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -478,3 +478,7 @@ "Cannot create payment","Zahlung kann nicht erstellt werden" "Failed to create quote","Angebotserstellung fehlgeschlagen" "Failed to add address to quote","Adresse konnte dem Angebot nicht hinzugefügt werden" +"Buckaroo Hosted Fields Username:","Buckaroo Hosted Fields Benutzername." +"Buckaroo Hosted Fields Password:","Buckaroo Hosted Fields Passwort." +"Enter your Buckaroo Hosted Fields Username, obtainable from the Buckaroo Plaza at → Settings → Token registration.","Geben Sie hier Ihren Buckaroo Hosted Fields Benutzernamen ein, den Sie von der Buckaroo Plaza unter → Einstellungen → Tokenregistrierung." +"Enter your Buckaroo Hosted Fields Password, obtainable from the Buckaroo Plaza at → Settings → Token registration.","Geben Sie hier Ihr Buckaroo Hosted Fields Passwort ein, das Sie von der Buckaroo Plaza unter → Einstellungen → Tokenregistrierung." diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index a86c5002d..1c61f8b9d 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -488,3 +488,7 @@ "Cannot create payment","Betaling kan niet worden aangemaakt" "Failed to create quote","Offerte aanmaken mislukt" "Failed to add address to quote","Adres kan niet aan offerte worden toegevoegd" +"Buckaroo Hosted Fields Username:","Buckaroo Hosted Fields Gebruikersnaam." +"Buckaroo Hosted Fields Password:","Buckaroo Hosted Fields Wachtwoord." +"Enter your Buckaroo Hosted Fields Username, obtainable from the Buckaroo Plaza at → Settings → Token registration.","Voer hier uw Buckaroo Hosted Fields Gebruikersnaam in, die u kunt verkrijgen vanuit de Buckaroo Plaza bij → Instellingen → Tokenregistratie." +"Enter your Buckaroo Hosted Fields Password, obtainable from the Buckaroo Plaza at → Settings → Token registration.","Voer hier uw Buckaroo Hosted Fields wachtwoord in, die u kunt verkrijgen vanuit de Buckaroo Plaza bij → Instellingen → Tokenregistratie." diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcards.js b/view/frontend/web/js/view/payment/method-renderer/creditcards.js index 81d0e2b06..dc3bace94 100644 --- a/view/frontend/web/js/view/payment/method-renderer/creditcards.js +++ b/view/frontend/web/js/view/payment/method-renderer/creditcards.js @@ -104,127 +104,113 @@ define( return false; }, - getOAuthToken: function () { - var self = this; - - $.ajax({ - url: urlBuilder.build('/buckaroo/credentialschecker/gettoken'), - type: "GET", - headers: { - 'X-Requested-From': 'MagentoFrontend' - }, - success: function (response) { - if (response.access_token) { - setTimeout(function() { - self.initHostedFields(response.access_token); - }, 5000); // Wait 5 seconds before initializing to ensure elements are loaded - } else { - console.error("Error getting OAuth token:", response.error); + async getOAuthToken() { + try { + const response = await $.ajax({ + url: urlBuilder.build('/buckaroo/credentialschecker/gettoken'), + type: "GET", + headers: { + 'X-Requested-From': 'MagentoFrontend' } - }, - error: function (xhr, status, error) { - console.error("Error getting OAuth token:", error); + }); + + if (response.access_token) { + await this.initHostedFields(response.access_token); + } else { + console.error("Error getting OAuth token:", response.error); } - }); + } catch (error) { + console.error("Error getting OAuth token:", error); + } }, - initHostedFields: function (accessToken) { - var self = this; - const init = async function () { - try { - var sdkClient = new BuckarooHostedFieldsSdk.HFClient(accessToken); - let service = ""; - await sdkClient.startSession(function (event) { - sdkClient.handleValidation(event, 'cc-name-error', 'cc-number-error', 'cc-expiry-error', 'cc-cvc-error'); + async initHostedFields(accessToken) { + try { + const sdkClient = new BuckarooHostedFieldsSdk.HFClient(accessToken); + let service = ""; - let payButton = document.getElementById("pay"); + await sdkClient.startSession(event => { + sdkClient.handleValidation(event, 'cc-name-error', 'cc-number-error', 'cc-expiry-error', 'cc-cvc-error'); - if (payButton) { - let disabled = !sdkClient.formIsValid(); - payButton.disabled = disabled; - if (disabled) { - payButton.style.backgroundColor = "#ff5555"; - payButton.style.cursor = "not-allowed"; - payButton.style.opacity = "0.5"; - } else { - payButton.style.backgroundColor = ""; - payButton.style.cursor = ""; - payButton.style.opacity = ""; - } + let payButton = document.getElementById("pay"); + if (payButton) { + let disabled = !sdkClient.formIsValid(); + payButton.disabled = disabled; + if (disabled) { + payButton.style.backgroundColor = "#ff5555"; + payButton.style.cursor = "not-allowed"; + payButton.style.opacity = "0.5"; + } else { + payButton.style.backgroundColor = ""; + payButton.style.cursor = ""; + payButton.style.opacity = ""; } + } - service = sdkClient.getService(); - }); - - let styling = { - fontSize: "14px", - fontFamily: 'Consolas, Liberation Mono, Menlo, Courier, monospace', - textAlign: 'left', - background: 'inherit', - color: 'black', - placeholderColor: 'grey' - }; - - let chnameOptions = { - id: "ccname", - placeHolder: "John Doe", - labelSelector: "#cc-name-label", - baseStyling: styling - }; - - await sdkClient.mountCardHolderName("#cc-name-wrapper", chnameOptions) - .then(function (cardHolderNameField) { - cardHolderNameField.focus(); - }); - - let ccOptions = { - id: "cc", - placeHolder: "555x xxxx xxxx xxxx", - labelSelector: "#cc-number-label", - baseStyling: styling - }; + service = sdkClient.getService(); + }); - await sdkClient.mountCardNumber("#cc-number-wrapper", ccOptions); + // Define styling and mount hosted fields as needed... + let styling = { + fontSize: "14px", + fontFamily: 'Consolas, Liberation Mono, Menlo, Courier, monospace', + textAlign: 'left', + background: 'inherit', + color: 'black', + placeholderColor: 'grey' + }; - let cvcOptions = { - id: "cvc", - placeHolder: "1234", - labelSelector: "#cc-cvc-label", - baseStyling: styling - }; + await sdkClient.mountCardHolderName("#cc-name-wrapper", { + id: "ccname", + placeHolder: "John Doe", + labelSelector: "#cc-name-label", + baseStyling: styling + }).then(field => field.focus()); - await sdkClient.mountCvc("#cc-cvc-wrapper", cvcOptions); + await sdkClient.mountCardNumber("#cc-number-wrapper", { + id: "cc", + placeHolder: "555x xxxx xxxx xxxx", + labelSelector: "#cc-number-label", + baseStyling: styling + }); - let expiryDateOptions = { - id: "expiry", - placeHolder: "MM / YY", - labelSelector: "#cc-expiry-label", - baseStyling: styling - }; + await sdkClient.mountCvc("#cc-cvc-wrapper", { + id: "cvc", + placeHolder: "1234", + labelSelector: "#cc-cvc-label", + baseStyling: styling + }); - await sdkClient.mountExpiryDate("#cc-expiry-wrapper", expiryDateOptions); + await sdkClient.mountExpiryDate("#cc-expiry-wrapper", { + id: "expiry", + placeHolder: "MM / YY", + labelSelector: "#cc-expiry-label", + baseStyling: styling + }); - let payButton = document.getElementById("pay"); + let payButton = document.getElementById("pay"); + if (payButton) { + payButton.addEventListener("click", async function (event) { + event.preventDefault(); + payButton.disabled = true; // Disable button to prevent double submissions - if (payButton) { - payButton.addEventListener("click", async function (event) { - event.preventDefault(); - try { - let paymentToken = await sdkClient.submitSession(); - self.encryptedCardData = paymentToken; - self.service = service; - self.finalizePlaceOrder(event); - } catch (error) { - console.error("Error during payment submission:", error); + try { + let paymentToken = await sdkClient.submitSession(); + if (!paymentToken) { + throw new Error("Failed to get encrypted card data."); } - }); - } - } catch (error) { - console.error("Error initializing hosted fields:", error); + this.encryptedCardData = paymentToken; + this.service = service; + this.finalizePlaceOrder(event); + } catch (error) { + console.error("Error during payment submission:", error); + payButton.disabled = false; // Re-enable button if there's an error + } + }.bind(this)); } - }; - - init(); + } catch (error) { + console.error("Error initializing hosted fields:", error); + } }, /** @@ -241,6 +227,11 @@ define( event.preventDefault(); } + if (!this.encryptedCardData) { + console.error("Payment token is missing. Please try again."); + return; + } + if (this.validate() && additionalValidators.validate()) { this.isPlaceOrderActionAllowed(false); placeOrder = placeOrderAction(self.getData(), self.redirectAfterPlaceOrder, self.messageContainer); From ba510f7f7c1bcb3b5fa199e26ace0a0c2c6d0f6e Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Mon, 16 Sep 2024 09:56:58 +0200 Subject: [PATCH 006/175] remove credit card --- .../payment/method-renderer/creditcards.js | 39 +--- .../payment/buckaroo_magento2_creditcard.html | 168 ------------------ 2 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 view/frontend/web/template/payment/buckaroo_magento2_creditcard.html diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcards.js b/view/frontend/web/js/view/payment/method-renderer/creditcards.js index dc3bace94..2d25a8e50 100644 --- a/view/frontend/web/js/view/payment/method-renderer/creditcards.js +++ b/view/frontend/web/js/view/payment/method-renderer/creditcards.js @@ -66,44 +66,6 @@ define( return this; }, - /** Get the card issuer based on the creditcard number **/ - determineIssuer: function (cardNumber) { - var issuers = { - 'amex': { - 'regex': '^3[47][0-9]{13}$', - 'name': 'American Express' - }, - 'maestro': { - 'regex': '^(5018|5020|5038|6304|6759|6761|6763)[0-9]{8,15}$', - 'name': 'Maestro' - }, - 'dankort': { - 'regex': '^(5019|4571)[0-9]{12}$', - 'name': 'Dankort' - }, - 'mastercard': { - 'regex': '^(5[1-5]|2[2-7])[0-9]{14}$', - 'name': 'Mastercard' - }, - 'visaelectron': { - 'regex': '^(4026[0-9]{2}|417500|4508[0-9]{2}|4844[0-9]{2}|4913[0-9]{2}|4917[0-9]{2})[0-9]{10}$', - 'name': 'Visa Electron' - }, - 'visa': { - 'regex': '^4[0-9]{12}(?:[0-9]{3})?$', - 'name': 'Visa' - } - }; - - for (var key in issuers) { - if (cardNumber !== undefined && cardNumber.match(issuers[key].regex)) { - return issuers[key].name; - } - } - - return false; - }, - async getOAuthToken() { try { const response = await $.ajax({ @@ -252,6 +214,7 @@ define( }, getData: function() { + return { "method": this.item.method, "po_number": null, diff --git a/view/frontend/web/template/payment/buckaroo_magento2_creditcard.html b/view/frontend/web/template/payment/buckaroo_magento2_creditcard.html deleted file mode 100644 index 951818c1e..000000000 --- a/view/frontend/web/template/payment/buckaroo_magento2_creditcard.html +++ /dev/null @@ -1,168 +0,0 @@ - -
-
-
-
- - -
-
- -
-
-
- -
- - - - -
- - - -
- -
-
-
- -
- - - - - - - - - - - -
-
-
-
- -
- - - -
- -
-
- -
-
- - -
- -
- -
-
- - - - -
-
- -
-
-
- - -
-
- -
-
-
- -
- - - - -
- - - -
- -
- - - -
- -
-
- -
-
- - -
- -
- -
-
-
- - \ No newline at end of file From 192ab9d48b01625fd1ac31cacb4497b52bf5f7d2 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Thu, 26 Sep 2024 13:28:15 +0200 Subject: [PATCH 007/175] check for hosted fields username and password --- Model/Method/Creditcards.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Model/Method/Creditcards.php b/Model/Method/Creditcards.php index 4b6fb18d6..5713883de 100644 --- a/Model/Method/Creditcards.php +++ b/Model/Method/Creditcards.php @@ -116,6 +116,28 @@ public function __construct( $this->serviceParameters = $serviceParameters; } + /** + * {@inheritdoc} + */ + public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) + { + /** + * If there are no giftcards chosen, we can't be available + */ + /** + * @var \Buckaroo\Magento2\Model\ConfigProvider\Method\Giftcards $ccConfig + */ + $gcConfig = $this->configProviderMethodFactory->get('creditcards'); + + if ($gcConfig->getHostedFieldsUsername() === null || $gcConfig->getHostedFieldsPassword() === null) { + return false; + } + /** + * Return the regular isAvailable result + */ + return parent::isAvailable($quote); + } + public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); From e29eb757e44f8fd66ac4f46f81c632a77c9244c9 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Thu, 26 Sep 2024 13:36:19 +0200 Subject: [PATCH 008/175] check for hosted fields username and password --- Model/ConfigProvider/Method/Creditcards.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Model/ConfigProvider/Method/Creditcards.php b/Model/ConfigProvider/Method/Creditcards.php index 55a2472d9..8e59eb7c0 100644 --- a/Model/ConfigProvider/Method/Creditcards.php +++ b/Model/ConfigProvider/Method/Creditcards.php @@ -178,6 +178,22 @@ public function getPaymentFee($storeId = null) return $paymentFee ? $paymentFee : false; } + public function getHostedFieldsUsername() + { + return $this->scopeConfig->getValue( + 'buckaroo_magento2/account/hosted_fields_username', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + + public function getHostedFieldsPassword() + { + return $this->scopeConfig->getValue( + 'buckaroo_magento2/account/hosted_fields_password', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } + /** * Add the active flag to the creditcard list. This is used in the checkout process. * From 9925d057109812296ede1bbfb17004e7b3b09328 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Thu, 26 Sep 2024 14:20:40 +0200 Subject: [PATCH 009/175] update error handling --- Controller/CredentialsChecker/GetToken.php | 8 ++++++ .../payment/method-renderer/creditcards.js | 27 ++++++++++++------- .../buckaroo_magento2_creditcards.html | 12 +++++---- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Controller/CredentialsChecker/GetToken.php b/Controller/CredentialsChecker/GetToken.php index 10679c186..0abffcf37 100644 --- a/Controller/CredentialsChecker/GetToken.php +++ b/Controller/CredentialsChecker/GetToken.php @@ -122,6 +122,14 @@ public function execute() return $result->setData($responseArray); } + // Check if there's a message in the response + if (isset($responseArray['message'])) { + return $result->setHttpResponseCode(400)->setData([ + 'error' => 'Error fetching token', + 'response' => $responseArray['message'] + ]); + } + return $result->setHttpResponseCode(500)->setData([ 'error' => 'Unable to fetch token', 'response' => $response diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcards.js b/view/frontend/web/js/view/payment/method-renderer/creditcards.js index 2d25a8e50..c60ab36c6 100644 --- a/view/frontend/web/js/view/payment/method-renderer/creditcards.js +++ b/view/frontend/web/js/view/payment/method-renderer/creditcards.js @@ -55,17 +55,19 @@ define( subtext: window.checkoutConfig.payment.buckaroo.creditcards.subtext, subTextStyle: checkoutCommon.getSubtextStyle('creditcards'), + // Error message observables + cardholderNameError: ko.observable(''), + cardNumberError: ko.observable(''), + expiryError: ko.observable(''), + cvcError: ko.observable(''), + oauthTokenError: ko.observable(''), + initialize: function (options) { this._super(options); this.getOAuthToken(); return this; }, - initObservable: function () { - this._super(); - return this; - }, - async getOAuthToken() { try { const response = await $.ajax({ @@ -79,21 +81,26 @@ define( if (response.access_token) { await this.initHostedFields(response.access_token); } else { - console.error("Error getting OAuth token:", response.error); + this.oauthTokenError("Error getting OAuth token: " + response.error); } } catch (error) { - console.error("Error getting OAuth token:", error); + this.oauthTokenError("Error getting OAuth token: " + response.error); } }, async initHostedFields(accessToken) { try { const sdkClient = new BuckarooHostedFieldsSdk.HFClient(accessToken); - let service = ""; await sdkClient.startSession(event => { sdkClient.handleValidation(event, 'cc-name-error', 'cc-number-error', 'cc-expiry-error', 'cc-cvc-error'); + // Dynamically update the error messages using observables + this.cardholderNameError(event.errors['cc-name-error'] || ''); + this.cardNumberError(event.errors['cc-number-error'] || ''); + this.expiryError(event.errors['cc-expiry-error'] || ''); + this.cvcError(event.errors['cc-cvc-error'] || ''); + let payButton = document.getElementById("pay"); if (payButton) { let disabled = !sdkClient.formIsValid(); @@ -109,7 +116,7 @@ define( } } - service = sdkClient.getService(); + this.service = sdkClient.getService(); }); // Define styling and mount hosted fields as needed... @@ -162,7 +169,7 @@ define( throw new Error("Failed to get encrypted card data."); } this.encryptedCardData = paymentToken; - this.service = service; + this.service = sdkClient.getService(); this.finalizePlaceOrder(event); } catch (error) { console.error("Error during payment submission:", error); diff --git a/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html b/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html index 8d217e12e..5977c2967 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html @@ -19,6 +19,8 @@ +
+
@@ -36,7 +38,7 @@
-

+

@@ -46,7 +48,7 @@
-

+

@@ -58,7 +60,7 @@
-

+

@@ -105,4 +107,4 @@ - \ No newline at end of file + From 0ef018b895a298f2259b750761635d34a727bb4b Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Thu, 26 Sep 2024 14:26:23 +0200 Subject: [PATCH 010/175] update error handling --- .../frontend/web/js/view/payment/method-renderer/creditcards.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcards.js b/view/frontend/web/js/view/payment/method-renderer/creditcards.js index c60ab36c6..2589f8f22 100644 --- a/view/frontend/web/js/view/payment/method-renderer/creditcards.js +++ b/view/frontend/web/js/view/payment/method-renderer/creditcards.js @@ -84,7 +84,7 @@ define( this.oauthTokenError("Error getting OAuth token: " + response.error); } } catch (error) { - this.oauthTokenError("Error getting OAuth token: " + response.error); + this.oauthTokenError("Error getting OAuth token: " + error.message); } }, From 6cc351414c60f389c826d8c836ca7fb64d768ce0 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Thu, 26 Sep 2024 14:39:08 +0200 Subject: [PATCH 011/175] update error handling --- Controller/CredentialsChecker/GetToken.php | 85 ++++++++++--------- .../payment/method-renderer/creditcards.js | 10 ++- .../buckaroo_magento2_creditcards.html | 5 +- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Controller/CredentialsChecker/GetToken.php b/Controller/CredentialsChecker/GetToken.php index 0abffcf37..83de9bdd8 100644 --- a/Controller/CredentialsChecker/GetToken.php +++ b/Controller/CredentialsChecker/GetToken.php @@ -37,16 +37,12 @@ private function sendPostRequest($url, $username, $password, $postData) { // Initialize cURL $ch = curl_init(); - // Set the URL + // Set the URL and method curl_setopt($ch, CURLOPT_URL, $url); - - // Set the HTTP method to POST curl_setopt($ch, CURLOPT_POST, true); - // Set the username and password for Basic Auth + // Basic Auth and headers curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); - - // Set the Content-Type to application/x-www-form-urlencoded curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']); // Set the POST fields @@ -98,52 +94,57 @@ 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' => 'Unauthorized request']); + return $result->setHttpResponseCode(403)->setData([ + 'error' => true, + 'message' => 'Unauthorized request' + ]); } + // Get username and password $hostedFieldsUsername = $this->getHostedFieldsUsername(); $hostedFieldsPassword = $this->getHostedFieldsPassword(); - if (!empty($hostedFieldsUsername) && !empty($hostedFieldsPassword)) { - try { - $url = "https://auth.buckaroo.io/oauth/token"; - $postData = [ - 'scope' => 'hostedfields:save', - 'grant_type' => 'client_credentials' - ]; - - $response = $this->sendPostRequest($url, $hostedFieldsUsername, $hostedFieldsPassword, $postData); - $responseArray = json_decode($response, true); - - if (isset($responseArray['access_token'])) { - return $result->setData($responseArray); - } - - // Check if there's a message in the response - if (isset($responseArray['message'])) { - return $result->setHttpResponseCode(400)->setData([ - 'error' => 'Error fetching token', - 'response' => $responseArray['message'] - ]); - } - - return $result->setHttpResponseCode(500)->setData([ - 'error' => 'Unable to fetch token', - 'response' => $response - ]); - } catch (\Exception $e) { - $this->logger->error('Error occurred while fetching token: ' . $e->getMessage()); - return $result->setHttpResponseCode(500)->setData([ - 'error' => 'An error occurred while fetching the token', - 'message' => $e->getMessage() + if (empty($hostedFieldsUsername) || empty($hostedFieldsPassword)) { + return $result->setHttpResponseCode(400)->setData([ + 'error' => true, + 'message' => 'Hosted Fields Username or Password is empty.' + ]); + } + + // 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, $hostedFieldsUsername, $hostedFieldsPassword, $postData); + $responseArray = json_decode($response, true); + + // Check for successful response + if (isset($responseArray['access_token'])) { + return $result->setData([ + 'error' => false, + 'data' => $responseArray ]); } - } else { + + // Handle error response + $message = isset($responseArray['message']) ? $responseArray['message'] : 'Unknown error occurred'; return $result->setHttpResponseCode(400)->setData([ - 'error' => 'Hosted Fields Username or Password is empty.' + 'error' => true, + 'message' => 'Error fetching token: ' . $message + ]); + + } catch (\Exception $e) { + $this->logger->error('Error occurred while fetching token: ' . $e->getMessage()); + return $result->setHttpResponseCode(500)->setData([ + 'error' => true, + 'message' => 'An error occurred while fetching the token: ' . $e->getMessage() ]); } } diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcards.js b/view/frontend/web/js/view/payment/method-renderer/creditcards.js index 2589f8f22..a6cdf2785 100644 --- a/view/frontend/web/js/view/payment/method-renderer/creditcards.js +++ b/view/frontend/web/js/view/payment/method-renderer/creditcards.js @@ -78,12 +78,16 @@ define( } }); - if (response.access_token) { - await this.initHostedFields(response.access_token); + // Check for error field in response + if (response.error) { + // Display the error message in the observable + this.oauthTokenError("Error getting OAuth token: " + response.message); } else { - this.oauthTokenError("Error getting OAuth token: " + response.error); + // Success: Initialize hosted fields with access token + await this.initHostedFields(response.data.access_token); } } catch (error) { + // Catch any other errors (e.g., network issues) this.oauthTokenError("Error getting OAuth token: " + error.message); } }, diff --git a/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html b/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html index 5977c2967..aabc8b092 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html @@ -19,8 +19,6 @@ -
-
@@ -28,7 +26,6 @@
-
@@ -78,6 +75,8 @@
+
+
+
@@ -35,7 +36,7 @@
-

+

@@ -45,7 +46,7 @@
-

+

@@ -57,7 +58,7 @@
-

+

@@ -83,7 +84,7 @@ type="button"> Submit - + Cancel
From aee788eace86d6f267602c88a64fba4acb58ff30 Mon Sep 17 00:00:00 2001 From: "v.carkaxhija" Date: Fri, 27 Sep 2024 12:41:39 +0200 Subject: [PATCH 013/175] update error handling --- .../web/js/view/payment/method-renderer/creditcards.js | 9 ++++++--- .../template/payment/buckaroo_magento2_creditcards.html | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/creditcards.js b/view/frontend/web/js/view/payment/method-renderer/creditcards.js index 43d864fca..e299c4dc0 100644 --- a/view/frontend/web/js/view/payment/method-renderer/creditcards.js +++ b/view/frontend/web/js/view/payment/method-renderer/creditcards.js @@ -56,6 +56,7 @@ define( subTextStyle: checkoutCommon.getSubtextStyle('creditcards'), oauthTokenError: ko.observable(''), + paymentError: ko.observable(''), initialize: function (options) { this._super(options); @@ -93,6 +94,7 @@ define( // Re-fetch the OAuth token and reinitialize the hosted fields this.getOAuthToken(); + this.paymentError(''); // Re-enable the submit button let payButton = document.getElementById("pay"); @@ -190,8 +192,8 @@ define( this.service = sdkClient.getService(); this.finalizePlaceOrder(event); } catch (error) { - console.error("Error during payment submission:", error); - payButton.disabled = false; // Re-enable button if there's an error + this.paymentError("Payment processing failed. Please try again."); + payButton.disabled = false; } }.bind(this)); } @@ -215,7 +217,7 @@ define( } if (!this.encryptedCardData) { - console.error("Payment token is missing. Please try again."); + this.paymentError("Payment token is missing. Please try again."); return; } @@ -226,6 +228,7 @@ define( $.when(placeOrder).fail( function () { self.isPlaceOrderActionAllowed(true); + self.paymentError("Payment token is missing. Please try again."); } ).done(self.afterPlaceOrder.bind(self)); return true; diff --git a/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html b/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html index e3a1f46b0..da0d98b6d 100644 --- a/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html +++ b/view/frontend/web/template/payment/buckaroo_magento2_creditcards.html @@ -77,6 +77,7 @@
+