-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbae1f2
commit 2dd4a65
Showing
47 changed files
with
926 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Block/Adminhtml/System/Config/Form/Field/CBTAvailableCurrencies.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Afterpay\Afterpay\Block\Adminhtml\System\Config\Form\Field; | ||
|
||
class CBTAvailableCurrencies extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); | ||
return parent::render($element); | ||
} | ||
|
||
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
/** @phpstan-ignore-next-line */ | ||
$element->setDisabled('disabled'); | ||
return $element->getElementHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Gateway/Response/MerchantConfiguration/CBTAvailableCurrenciesConfigurationHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Afterpay\Afterpay\Gateway\Response\MerchantConfiguration; | ||
|
||
class CBTAvailableCurrenciesConfigurationHandler implements \Magento\Payment\Gateway\Response\HandlerInterface | ||
{ | ||
private \Afterpay\Afterpay\Model\Config $config; | ||
|
||
public function __construct( | ||
\Afterpay\Afterpay\Model\Config $config | ||
) { | ||
$this->config = $config; | ||
} | ||
|
||
public function handle(array $handlingSubject, array $response): void | ||
{ | ||
$websiteId = (int)$handlingSubject['websiteId']; | ||
$cbtAvailableCurrencies = []; | ||
if (isset($response['CBT']['enabled']) && | ||
isset($response['CBT']['limits']) && | ||
is_array($response['CBT']['limits']) | ||
) { | ||
foreach ($response['CBT']['limits'] as $limit) { | ||
if (isset($limit['maximumAmount']['currency']) && isset($limit['maximumAmount']['amount'])) { | ||
$cbtAvailableCurrencies[] = $limit['maximumAmount']['currency'] . ':' . $limit['maximumAmount']['amount']; | ||
} | ||
} | ||
} | ||
$this->config->setCbtCurrencyLimits(implode(",", $cbtAvailableCurrencies), $websiteId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Afterpay\Afterpay\Gateway\Validator\Method; | ||
|
||
class CurrencyValidator extends \Magento\Payment\Gateway\Validator\AbstractValidator | ||
{ | ||
private \Afterpay\Afterpay\Model\Config $config; | ||
private \Magento\Checkout\Model\Session $checkoutSession; | ||
|
||
public function __construct( | ||
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory, | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Afterpay\Afterpay\Model\Config $config | ||
) { | ||
$this->config = $config; | ||
$this->checkoutSession = $checkoutSession; | ||
parent::__construct($resultFactory); | ||
} | ||
|
||
public function validate(array $validationSubject): \Magento\Payment\Gateway\Validator\ResultInterface | ||
{ | ||
$quote = $this->checkoutSession->getQuote(); | ||
$currentCurrency = $quote->getQuoteCurrencyCode(); | ||
$allowedCurrencies = $this->config->getAllowedCurrencies(); | ||
$cbtCurrencies = array_keys($this->config->getCbtCurrencyLimits()); | ||
|
||
if (in_array($currentCurrency, array_merge($allowedCurrencies, $cbtCurrencies))) { | ||
return $this->createResult(true); | ||
} | ||
|
||
return $this->createResult(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Afterpay\Afterpay\Model\CBT; | ||
|
||
interface CheckCBTCurrencyAvailabilityInterface | ||
{ | ||
public function check(string $currencyCode, float $amount = null): bool; | ||
|
||
public function checkByQuote(\Magento\Quote\Model\Quote $quote): bool; | ||
} |
Oops, something went wrong.