Skip to content

Commit

Permalink
Release version 4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afterpayplugins committed Feb 1, 2024
1 parent a06e6e1 commit 85a5e00
Show file tree
Hide file tree
Showing 52 changed files with 381 additions and 219 deletions.
10 changes: 5 additions & 5 deletions Api/Data/CheckoutInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ interface CheckoutInterface
/**#@+
* Checkout result keys
*/
const AFTERPAY_TOKEN = 'afterpay_token';
const AFTERPAY_AUTH_TOKEN_EXPIRES = 'afterpay_expires';
const AFTERPAY_REDIRECT_CHECKOUT_URL = 'afterpay_redirectCheckoutUrl';
const AFTERPAY_IS_CBT_CURRENCY = 'afterpay_is_cbt_currency';
const AFTERPAY_CBT_CURRENCY = 'afterpay_cbt_currency';
public const AFTERPAY_TOKEN = 'afterpay_token';
public const AFTERPAY_AUTH_TOKEN_EXPIRES = 'afterpay_expires';
public const AFTERPAY_REDIRECT_CHECKOUT_URL = 'afterpay_redirectCheckoutUrl';
public const AFTERPAY_IS_CBT_CURRENCY = 'afterpay_is_cbt_currency';
public const AFTERPAY_CBT_CURRENCY = 'afterpay_cbt_currency';
/**#@-*/

/**
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Button/LimitUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class LimitUpdate extends \Magento\Config\Block\System\Config\Form\Field
{
const TEMPLATE = 'Afterpay_Afterpay::system/config/button/update.phtml';
public const TEMPLATE = 'Afterpay_Afterpay::system/config/button/update.phtml';

public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ protected function _renderValue(\Magento\Framework\Data\Form\Element\AbstractEle
}

foreach ($CbtAvailableCurrencies as $currencyCode => $currency) {
$newValue .= $currencyCode . '(min:' . $currency['minimumAmount']['amount']
. ',max:' . $currency['maximumAmount']['amount'] . ') ';
$min = $currency['minimumAmount']['amount'] ?? '0';
$newValue .= $currencyCode . '(min:' . $min . ',max:' . $currency['maximumAmount']['amount'] . ') ';
}
$element->setValue($newValue);
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/Field/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Version extends \Magento\Config\Block\System\Config\Form\Field
{
const MODULE_NAME = "Afterpay_Afterpay";
public const MODULE_NAME = "Afterpay_Afterpay";

private $resource;

Expand Down
2 changes: 1 addition & 1 deletion Controller/Express/CreateCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function execute(): \Magento\Framework\Controller\ResultInterface
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Throwable $e) {
$this->logger->error($e->getMessage());
$this->messageManager->addErrorMessage((string)__('Afterpay payment declined. Please select an alternative payment method.'));
$this->messageManager->addErrorMessage((string)__('Afterpay payment is declined. Please select an alternative payment method.'));
}
return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/Express/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public function execute()

$this->messageManager->addSuccessMessage((string)__('Afterpay Transaction Completed.'));

return $jsonResult->setData(['redirectUrl' => $this->storeManager->getStore()->getUrl('checkout/onepage/success')]);
return $jsonResult->setData(['redirectUrl' => $this->storeManager->getStore()->getUrl('checkout/onepage/success')]);// @codingStandardsIgnoreLine
}
}
4 changes: 2 additions & 2 deletions Controller/Payment/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class Capture implements HttpGetActionInterface
{
const CHECKOUT_STATUS_CANCELLED = 'CANCELLED';
const CHECKOUT_STATUS_SUCCESS = 'SUCCESS';
public const CHECKOUT_STATUS_CANCELLED = 'CANCELLED';
public const CHECKOUT_STATUS_SUCCESS = 'SUCCESS';
private $request;
private $session;
private $redirectFactory;
Expand Down
6 changes: 5 additions & 1 deletion Gateway/Command/GetMerchantConfigurationCommandWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class GetMerchantConfigurationCommandWrapper implements \Magento\Payment\Gateway\CommandInterface
{
const DEFAULT_WEBSITE_ID = 0;
public const DEFAULT_WEBSITE_ID = 0;

private $merchantConfigurationCommand;
private $afterpayConfig;
Expand Down Expand Up @@ -48,6 +48,10 @@ public function execute(array $commandSubject)
}
$this->checkCountry($scope, $websiteId);
$this->checkCurrency($scope, $websiteId);
// Disable Cash App Pay if Afterpay is disabled
if($this->afterpayConfig->getIsPaymentActive($websiteId)===false){
$this->afterpayConfig->setCashAppPayActive(0,$websiteId);
}
$this->debugLogger->setForceDebug($this->afterpayConfig->getIsDebug($websiteId));
return $this->merchantConfigurationCommand->execute($commandSubject);
} catch (\Magento\Payment\Gateway\Command\CommandException $e) {
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Config extends \Magento\Payment\Gateway\Config\Config
{
const CODE = 'afterpay';
public const CODE = 'afterpay';

public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
Expand Down
5 changes: 3 additions & 2 deletions Gateway/ErrorMessageMapper/CaptureErrorMessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

class CaptureErrorMessageMapper implements ErrorMessageMapperInterface
{
public const STATUS_DECLINED_ERROR_MESSAGE = 'Aftepay payment declined. Please select an alternative payment method.';
public const STATUS_DECLINED_ERROR_MESSAGE = 'Aftepay payment declined. Please select an alternative payment method.'; // @codingStandardsIgnoreLine

public function getMessage(string $code)
{
$message = (string)self::STATUS_DECLINED_ERROR_MESSAGE;
switch ($code) {
case CaptureResponseValidator::STATUS_DECLINED:
return __(self::STATUS_DECLINED_ERROR_MESSAGE);
return __($message);
default:
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions Gateway/Http/TransferFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class TransferFactory implements \Magento\Payment\Gateway\Http\TransferFactoryInterface
{
const METHOD_POST = "post";
const METHOD_GET = "get";
public const METHOD_POST = "post";
public const METHOD_GET = "get";

const ARGS = [
public const ARGS = [
'orderId',
'websiteId',
'storeId',
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(
$this->method = $method;
}

public function create(array $request): \Magento\Payment\Gateway\Http\TransferInterface
public function create(array $request): \Magento\Payment\Gateway\Http\TransferInterface // @codingStandardsIgnoreLine
{
$args = $this->removeAndReturnArgs($request);

Expand Down
1 change: 1 addition & 0 deletions Gateway/Http/TransferFactory/UserAgentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public function provide(?int $websiteId = null): string

return "AfterpayMagento2Plugin $moduleVersion ($magentoProductName $magentoProductEdition $magentoVersion) " .
"PHPVersion: PHP/$phpVersion MerchantID: $afterpayMerchantId; MPID/$afterpayMPId; CAPAvailable/$CashAppPayAvailable; CAPEnabled/$CashAppPayEnabled; URL: $websiteDomain";

}
}
2 changes: 1 addition & 1 deletion Gateway/Request/Checkout/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function getItemsImages(array $items): array
{
$itemsImages = [];
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('entity_id', array_map(static function ($item) {return $item->getProduct()->getId();}, $items), 'in')
->addFilter('entity_id', array_map(static function ($item) {return $item->getProduct()->getId();}, $items), 'in') // @codingStandardsIgnoreLine
->create();
$products = $this->productRepository->getList($searchCriteria)->getItems();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function handle(array $handlingSubject, array $response)
$payment = $paymentDO->getPayment();
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $payment->getQuote();
$isCBTCurrency = $payment->getAdditionalInformation(\Afterpay\Afterpay\Api\Data\CheckoutInterface::AFTERPAY_IS_CBT_CURRENCY);
$isCBTCurrency = $payment->getAdditionalInformation(\Afterpay\Afterpay\Api\Data\CheckoutInterface::AFTERPAY_IS_CBT_CURRENCY); // @codingStandardsIgnoreLine
$grandTotal = $isCBTCurrency ? $quote->getGrandTotal() : $quote->getBaseGrandTotal();

if (round(1 * $grandTotal, 2) != round(1 * $response['amount']['amount'], 2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
class ChannelsConfigurationHandler implements HandlerInterface
{
private $config;
private $logger;

public function __construct(
Config $config
)
{
Config $config,
\Psr\Log\LoggerInterface $logger
) {
$this->config = $config;
$this->logger = $logger;
}

public function handle(array $handlingSubject, array $response): void
Expand All @@ -23,18 +25,26 @@ public function handle(array $handlingSubject, array $response): void

$getCashAppConfig = array_search("CASH_APP", array_column($response['channels'], 'name'));
$isCashAppEnabled = 0;
if (isset($response['channels'][$getCashAppConfig])) {

if ( isset($response['channels'][$getCashAppConfig]) &&
isset($response['channels'][$getCashAppConfig]['name']) &&
strtoupper($response['channels'][$getCashAppConfig]['name'])== "CASH_APP") {
$cashappData=$response['channels'][$getCashAppConfig];

if (isset($cashappData['enabled']) && $cashappData['enabled']==true &&
isset($cashappData['integrationCompleted']) && $cashappData['integrationCompleted']==true &&
isset($cashappData['enabledForOrders']) && $cashappData['enabledForOrders']==true) {
$isCashAppEnabled = (int)$cashappData['enabled'];
}

$this->config->setCashAppPayAvailable($isCashAppEnabled, $websiteId);
}else{
if( $this->config->getCashAppPayActive($websiteId)==true) {
//Disable the Cash App Pay if it's not available for the Merchant
$this->config->setCashAppPayActive($isCashAppEnabled, $websiteId);
$this->logger->notice("Disable the Cash App Pay as it's not available for the Merchant");
}
}
$this->config->setCashAppPayAvailable($isCashAppEnabled, $websiteId);
}
}


}
4 changes: 2 additions & 2 deletions Gateway/Validator/CaptureResponseValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class CaptureResponseValidator extends \Magento\Payment\Gateway\Validator\AbstractValidator
{
const STATUS_DECLINED = 'DECLINED';
const STATUS_APPROVED = 'APPROVED';
public const STATUS_DECLINED = 'DECLINED';
public const STATUS_APPROVED = 'APPROVED';

public function validate(array $validationSubject): \Magento\Payment\Gateway\Validator\ResultInterface
{
Expand Down
1 change: 1 addition & 0 deletions Model/CheckoutConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function getConfig(): array
'isCBTCurrency' => $this->checkCBTCurrencyAvailability->checkByQuote($quote),
'consumerLendingEnabled' => $this->config->getConsumerLendingEnabled(),
'consumerLendingMinimumAmount' => $this->config->getConsumerLendingMinAmount(),
'mpid' => $this->config->getPublicId(),
]
]
];
Expand Down
104 changes: 71 additions & 33 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,40 @@

class Config
{
const XML_PATH_PAYMENT_ACTIVE = 'payment/afterpay/active';
const XML_PATH_API_MODE = 'payment/afterpay/api_mode';
const XML_PATH_DEBUG = 'payment/afterpay/debug';
const XML_PATH_ENABLE_CTA_PRODUCT = 'payment/afterpay/enable_cta_product_page';
const XML_PATH_ENABLE_CTA_MINI_CART = 'payment/afterpay/enable_cta_mini_cart';
const XML_PATH_ENABLE_CTA_CART_PAGE = 'payment/afterpay/enable_cta_cart_page';
const XML_PATH_ENABLE_EXPRESS_CHECKOUT_ACTION_PRODUCT = 'payment/afterpay/enable_express_checkout_product_page';
const XML_PATH_ENABLE_EXPRESS_CHECKOUT_ACTION_MINI_CART = 'payment/afterpay/enable_express_checkout_mini_cart';
const XML_PATH_ENABLE_EXPRESS_CHECKOUT_ACTION_CART_PAGE = 'payment/afterpay/enable_express_checkout_cart_page';
const XML_PATH_MERCHANT_ID = 'payment/afterpay/merchant_id';
const XML_PATH_MERCHANT_KEY = 'payment/afterpay/merchant_key';
const XML_PATH_PAYMENT_FLOW = 'payment/afterpay/payment_flow';
const XML_PATH_MIN_LIMIT = 'payment/afterpay/min_order_total';
const XML_PATH_MAX_LIMIT = 'payment/afterpay/max_order_total';
const XML_PATH_CBT_CURRENCY_LIMITS = 'payment/afterpay/cbt_currency_limits';
const XML_PATH_EXCLUDE_CATEGORIES = 'payment/afterpay/exclude_categories';
const XML_PATH_ALLOW_SPECIFIC_COUNTRIES = 'payment/afterpay/allowspecific';
const XML_PATH_SPECIFIC_COUNTRIES = 'payment/afterpay/specificcountry';
const XML_PATH_ALLOWED_MERCHANT_COUNTRIES = 'payment/afterpay/allowed_merchant_countries';
const XML_PATH_ALLOWED_MERCHANT_CURRENCIES = 'payment/afterpay/allowed_merchant_currencies';
const XML_PATH_PAYPAL_MERCHANT_COUNTRY = 'paypal/general/merchant_country';
const XML_PATH_ENABLE_REVERSAL = 'payment/afterpay/enable_reversal';
const XML_PATH_MPID = 'payment/afterpay/public_id';
const XML_PATH_CASHAPP_PAY_AVAILABLE = 'payment/afterpay/cash_app_pay_available';
const XML_PATH_CASHAPP_PAY_ENABLE = 'payment/cashapp/active';
const XML_PATH_CONSUMER_LENDING_ENABLED = 'payment/afterpay/consumer_lending_enabled';
const XML_PATH_CONSUMER_LENDING_MIN_AMOUNT = 'payment/afterpay/consumer_lending_min_amount';

private $scopeConfig;
private $writer;
private $resourceConnection;
private $serializer;

public const XML_PATH_PAYMENT_ACTIVE = 'payment/afterpay/active';
public const XML_PATH_API_MODE = 'payment/afterpay/api_mode';
public const XML_PATH_DEBUG = 'payment/afterpay/debug';
public const XML_PATH_ENABLE_CTA_PRODUCT = 'payment/afterpay/enable_cta_product_page';
public const XML_PATH_ENABLE_CTA_MINI_CART = 'payment/afterpay/enable_cta_mini_cart';
public const XML_PATH_ENABLE_CTA_CART_PAGE = 'payment/afterpay/enable_cta_cart_page';
public const XML_PATH_ENABLE_EXPRESS_CHECKOUT_ACTION_PRODUCT = 'payment/afterpay/enable_express_checkout_product_page'; // @codingStandardsIgnoreLine
public const XML_PATH_ENABLE_EXPRESS_CHECKOUT_ACTION_MINI_CART = 'payment/afterpay/enable_express_checkout_mini_cart'; // @codingStandardsIgnoreLine
public const XML_PATH_ENABLE_EXPRESS_CHECKOUT_ACTION_CART_PAGE = 'payment/afterpay/enable_express_checkout_cart_page'; // @codingStandardsIgnoreLine
public const XML_PATH_ADD_LAST_SELECTED_SHIP_RATE = 'payment/afterpay/add_last_selected_ship_rate';
public const XML_PATH_MERCHANT_ID = 'payment/afterpay/merchant_id';
public const XML_PATH_MERCHANT_KEY = 'payment/afterpay/merchant_key';
public const XML_PATH_PAYMENT_FLOW = 'payment/afterpay/payment_flow';
public const XML_PATH_MIN_LIMIT = 'payment/afterpay/min_order_total';
public const XML_PATH_MAX_LIMIT = 'payment/afterpay/max_order_total';
public const XML_PATH_CBT_CURRENCY_LIMITS = 'payment/afterpay/cbt_currency_limits';
public const XML_PATH_EXCLUDE_CATEGORIES = 'payment/afterpay/exclude_categories';
public const XML_PATH_ALLOW_SPECIFIC_COUNTRIES = 'payment/afterpay/allowspecific';
public const XML_PATH_SPECIFIC_COUNTRIES = 'payment/afterpay/specificcountry';
public const XML_PATH_ALLOWED_MERCHANT_COUNTRIES = 'payment/afterpay/allowed_merchant_countries';
public const XML_PATH_ALLOWED_MERCHANT_CURRENCIES = 'payment/afterpay/allowed_merchant_currencies';
public const XML_PATH_PAYPAL_MERCHANT_COUNTRY = 'paypal/general/merchant_country';
public const XML_PATH_ENABLE_REVERSAL = 'payment/afterpay/enable_reversal';
public const XML_PATH_MPID = 'payment/afterpay/public_id';
public const XML_PATH_CASHAPP_PAY_AVAILABLE = 'payment/afterpay/cash_app_pay_available';
public const XML_PATH_CASHAPP_PAY_ACTIVE = 'payment/cashapp/active';
public const XML_PATH_CONSUMER_LENDING_ENABLED = 'payment/afterpay/consumer_lending_enabled';
public const XML_PATH_CONSUMER_LENDING_MIN_AMOUNT = 'payment/afterpay/consumer_lending_min_amount';

private $scopeConfig;
private $writer;
private $resourceConnection;
private $serializer;

public function __construct(
ScopeConfigInterface $scopeConfig,
Expand Down Expand Up @@ -501,7 +503,7 @@ public function getCashAppPayAvailable(?int $scopeCode = null): bool
public function getCashAppPayEnabled(?int $scopeCode = null): bool
{
return (bool)$this->scopeConfig->getValue(
self::XML_PATH_CASHAPP_PAY_ENABLE,
self::XML_PATH_CASHAPP_PAY_ACTIVE,
ScopeInterface::SCOPE_WEBSITE,
$scopeCode
);
Expand Down Expand Up @@ -564,4 +566,40 @@ public function getConsumerLendingMinAmount(?int $scopeCode = null): float
$scopeCode
);
}

public function getAddLastSelectedShipRate(?int $scopeCode = null): bool
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_ADD_LAST_SELECTED_SHIP_RATE,
ScopeInterface::SCOPE_WEBSITE,
$scopeCode
);
}

public function setCashAppPayActive(int $value, int $scopeId = 0): self
{
if ($scopeId) {
$this->writer->save(
self::XML_PATH_CASHAPP_PAY_ACTIVE,
$value,
ScopeInterface::SCOPE_WEBSITES,
$scopeId
);
return $this;
}
$this->writer->save(
self::XML_PATH_CASHAPP_PAY_ACTIVE,
$value
);
return $this;
}

public function getCashAppPayActive(?int $scopeCode = null): bool
{
return (bool)$this->scopeConfig->isSetFlag(
self::XML_PATH_CASHAPP_PAY_ACTIVE,
ScopeInterface::SCOPE_WEBSITE,
$scopeCode
);
}
}
4 changes: 2 additions & 2 deletions Model/Config/Source/ApiMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class ApiMode implements \Magento\Framework\Data\OptionSourceInterface
{
const SANDBOX = 'sandbox';
const PRODUCTION = 'production';
public const SANDBOX = 'sandbox';
public const PRODUCTION = 'production';

public function toOptionArray(): array
{
Expand Down
4 changes: 2 additions & 2 deletions Model/Config/Source/PaymentFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class PaymentFlow implements \Magento\Framework\Data\OptionSourceInterface
{
const IMMEDIATE = 'immediate';
const DEFERRED = 'deferred';
public const IMMEDIATE = 'immediate';
public const DEFERRED = 'deferred';

public function toOptionArray(): array
{
Expand Down
Loading

0 comments on commit 85a5e00

Please sign in to comment.