Skip to content

Commit

Permalink
PAA-238 Fix should not use static method
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-zhang-awx committed May 9, 2024
1 parent c056f40 commit b5ffda8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 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
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.4.5",
"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.4.5">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit b5ffda8

Please sign in to comment.