Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to meet the Magento 2 code standard #43

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Helper/AvailablePaymentMethodsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Model/Adminhtml/Notifications/ExpressDisabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.');
}
}
}
3 changes: 1 addition & 2 deletions Model/Methods/RedirectMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Model/PaymentIntents.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public function __construct(
CacheInterface $cache,
UrlInterface $urlInterface,
Logger $logger
)
{
) {
$this->paymentIntentsCancel = $paymentIntentsCancel;
$this->paymentIntentsCreate = $paymentIntentsCreate;
$this->checkoutSession = $checkoutSession;
Expand Down
28 changes: 17 additions & 11 deletions Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Service implements ServiceInterface
private Postcode $postcodeValidator;
private ShippingAddressValidationRule $shippingAddressValidationRule;
private BillingAddressValidationRule $billingAddressValidationRule;
private ReCaptchaValidationPlugin $reCaptchaValidationPlugin;

/**
* Index constructor.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -184,6 +187,7 @@ public function __construct(
$this->postcodeValidator = $postcodeValidator;
$this->shippingAddressValidationRule = $shippingAddressValidationRule;
$this->billingAddressValidationRule = $billingAddressValidationRule;
$this->reCaptchaValidationPlugin = $reCaptchaValidationPlugin;
}
/**
* Return URL
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -471,7 +475,8 @@ public function addToCart(): string
}
}

private function error($message) {
private function error($message)
{
return json_encode([
'type' => 'error',
'message' => $message
Expand Down Expand Up @@ -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([
Expand All @@ -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"}';
Expand Down Expand Up @@ -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));
}
}
}
6 changes: 3 additions & 3 deletions Plugin/ReCaptchaValidationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Airwallex_Payments" setup_version="1.5.0">
<module name="Airwallex_Payments" setup_version="1.5.1">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
7 changes: 3 additions & 4 deletions view/frontend/templates/express.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div data-bind="scope: 'airwallex-express'">
<?php
require __DIR__ . '/../web/template/payment/express-checkout.html';
?>
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
<script type="text/x-magento-init">
{
Expand All @@ -10,7 +8,8 @@ require __DIR__ . '/../web/template/payment/express-checkout.html';
"components": {
"airwallex-express": {
"component": "Airwallex_Payments/js/view/payment/method-renderer/express-checkout",
"from": "<?=$block->getData('from')?>"
"from": "<?= $block->escapeHtml($block->getData('from')) ?>",
"template": "Airwallex_Payments/payment/express-checkout"
}
}
}
Expand Down
Loading