diff --git a/Helper/AvailablePaymentMethodsHelper.php b/Helper/AvailablePaymentMethodsHelper.php index a3ac082..c00d8e5 100644 --- a/Helper/AvailablePaymentMethodsHelper.php +++ b/Helper/AvailablePaymentMethodsHelper.php @@ -93,8 +93,7 @@ public function __construct( */ public function canInitialize(): bool { - return !is_null($this->configuration->getApiKey()) && - !is_null($this->configuration->getClientId()); + return $this->configuration->getApiKey() && $this->configuration->getClientId(); } /** diff --git a/Model/Adminhtml/Notifications/ExpressDisabled.php b/Model/Adminhtml/Notifications/ExpressDisabled.php index a797d9a..ff21042 100644 --- a/Model/Adminhtml/Notifications/ExpressDisabled.php +++ b/Model/Adminhtml/Notifications/ExpressDisabled.php @@ -22,9 +22,8 @@ class ExpressDisabled implements MessageInterface * * @param Configuration $configuration */ - public function __construct( - Configuration $configuration - ){ + public function __construct(Configuration $configuration) + { $this->configuration = $configuration; $this->expressDisabled(); } @@ -64,9 +63,11 @@ public function getSeverity(): int /** * @return void */ - private function expressDisabled(): void { + private function expressDisabled(): void + { if (!$this->configuration->isCardActive()) { - $this->displayedText = __('Airwallex Express Checkout is also disabled. To use Express Checkout, you must first enable Credit Card payments.'); + $this->displayedText = __('Airwallex Express Checkout is also disabled.' + . ' To use Express Checkout, you must first enable Credit Card payments.'); } } } diff --git a/Model/Methods/RedirectMethod.php b/Model/Methods/RedirectMethod.php index a2a1e94..c9e5548 100644 --- a/Model/Methods/RedirectMethod.php +++ b/Model/Methods/RedirectMethod.php @@ -32,8 +32,7 @@ class RedirectMethod extends AbstractMethod public const KAKAO_CODE = 'airwallex_payments_kakaopay'; public const TOUCH_N_GO_CODE = 'airwallex_payments_tng'; public const WECHAT_CODE = 'airwallex_payments_wechatpay'; - - + /** * @param InfoInterface $payment * @param float $amount diff --git a/Model/PaymentIntents.php b/Model/PaymentIntents.php index ce3d632..4811d4b 100644 --- a/Model/PaymentIntents.php +++ b/Model/PaymentIntents.php @@ -87,8 +87,7 @@ public function __construct( CacheInterface $cache, UrlInterface $urlInterface, Logger $logger - ) - { + ) { $this->paymentIntentsCancel = $paymentIntentsCancel; $this->paymentIntentsCreate = $paymentIntentsCreate; $this->checkoutSession = $checkoutSession; diff --git a/Model/Service.php b/Model/Service.php index a83a786..b3835c0 100644 --- a/Model/Service.php +++ b/Model/Service.php @@ -90,6 +90,7 @@ class Service implements ServiceInterface private Postcode $postcodeValidator; private ShippingAddressValidationRule $shippingAddressValidationRule; private BillingAddressValidationRule $billingAddressValidationRule; + private ReCaptchaValidationPlugin $reCaptchaValidationPlugin; /** * Index constructor. @@ -123,6 +124,7 @@ class Service implements ServiceInterface * @param Postcode $postcodeValidator * @param ShippingAddressValidationRule $shippingAddressValidationRule * @param BillingAddressValidationRule $billingAddressValidationRule + * @param ReCaptchaValidationPlugin $reCaptchaValidationPlugin */ public function __construct( PaymentIntents $paymentIntents, @@ -153,7 +155,8 @@ public function __construct( Country $countryValidator, Postcode $postcodeValidator, ShippingAddressValidationRule $shippingAddressValidationRule, - BillingAddressValidationRule $billingAddressValidationRule + BillingAddressValidationRule $billingAddressValidationRule, + ReCaptchaValidationPlugin $reCaptchaValidationPlugin ) { $this->paymentIntents = $paymentIntents; $this->configuration = $configuration; @@ -184,6 +187,7 @@ public function __construct( $this->postcodeValidator = $postcodeValidator; $this->shippingAddressValidationRule = $shippingAddressValidationRule; $this->billingAddressValidationRule = $billingAddressValidationRule; + $this->reCaptchaValidationPlugin = $reCaptchaValidationPlugin; } /** * Return URL @@ -222,7 +226,7 @@ public function airwallexGuestPlaceOrder( $response = $this->placeOrderResponseFactory->create(); if ($intentId === null) { $intent = $this->paymentIntents->getIntents(); - $this->cache->save(1, ReCaptchaValidationPlugin::getCacheKey($intent['id']), [], 3600); + $this->cache->save(1, $this->reCaptchaValidationPlugin->getCacheKey($intent['id']), [], 3600); $response->setData([ 'response_type' => 'confirmation_required', @@ -270,7 +274,7 @@ public function airwallexPlaceOrder( if ($intentId === null) { $intent = $this->paymentIntents->getIntents(); - $this->cache->save(1, ReCaptchaValidationPlugin::getCacheKey($intent['id']), [], 3600); + $this->cache->save(1, $this->reCaptchaValidationPlugin->getCacheKey($intent['id']), [], 3600); $response->setData([ 'response_type' => 'confirmation_required', @@ -471,7 +475,8 @@ public function addToCart(): string } } - private function error($message) { + private function error($message) + { return json_encode([ 'type' => 'error', 'message' => $message @@ -565,13 +570,13 @@ public function postAddress(): string public function validateMerchant() { $validationUrl = $this->request->getParam('validationUrl'); - if ( empty( $validationUrl ) ) { - throw new Exception( 'Validation URL is empty.' ); + if (empty($validationUrl)) { + return $this->error('Validation URL is empty.'); } $initiativeContext = $this->request->getParam('origin'); - if ( empty( $initiativeContext ) ) { - throw new Exception( 'Initiative Context is empty.' ); + if (empty($initiativeContext)) { + return $this->error('Initiative Context is empty.'); } return $this->validateMerchant->setInitiativeParams([ @@ -590,11 +595,11 @@ public function validateAddresses() { $quote = $this->checkoutHelper->getQuote(); $errors = $this->shippingAddressValidationRule->validate($quote); - if ($errors and $errors[0]->getErrors()) { + if ($errors && $errors[0]->getErrors()) { return $this->error(__(implode(' ', $errors[0]->getErrors()))); } $errors = $this->billingAddressValidationRule->validate($quote); - if ($errors and $errors[0]->getErrors()) { + if ($errors && $errors[0]->getErrors()) { return $this->error(__(implode(' ', $errors[0]->getErrors()))); } return '{"type": "success"}'; @@ -629,7 +634,8 @@ protected function checkIntent($id) $respArr = json_decode($resp, true); $okStatus = [$this->intentGet::INTENT_STATUS_SUCCESS, $this->intentGet::INTENT_STATUS_REQUIRES_CAPTURE]; if (!in_array($respArr['status'], $okStatus, true)) { - throw new Exception(__('Something went wrong while processing your request. Please try again later.')); + $msg = 'Something went wrong while processing your request. Please try again later.'; + throw new GuzzleException(__($msg)); } } } diff --git a/Plugin/ReCaptchaValidationPlugin.php b/Plugin/ReCaptchaValidationPlugin.php index d2dcd4a..61cdcdf 100644 --- a/Plugin/ReCaptchaValidationPlugin.php +++ b/Plugin/ReCaptchaValidationPlugin.php @@ -71,15 +71,15 @@ protected function validateBypassReCaptcha(): bool return false; } - if ($this->cache->load(self::getCacheKey($intentId))) { - $this->cache->remove(self::getCacheKey($intentId)); + if ($this->cache->load($this->getCacheKey($intentId))) { + $this->cache->remove($this->getCacheKey($intentId)); return true; } return false; } - public static function getCacheKey(string $intentId): string + public function getCacheKey(string $intentId): string { return implode('_', [self::CACHE_PREFIX, $intentId]); } diff --git a/composer.json b/composer.json index e6c7681..7ff0b2e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "airwallex/payments-plugin-magento", "type": "magento2-module", "description": "", - "version": "1.5.0", + "version": "1.5.1", "require": { "ext-json": "*", "php": "^7.4|^8.0", diff --git a/etc/module.xml b/etc/module.xml index 6a7aee3..3616c04 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -16,7 +16,7 @@ */ --> - + diff --git a/view/frontend/templates/express.phtml b/view/frontend/templates/express.phtml index 97af11a..62329fe 100644 --- a/view/frontend/templates/express.phtml +++ b/view/frontend/templates/express.phtml @@ -1,7 +1,5 @@
- +