Skip to content

Commit

Permalink
Merge branch 'release/v3.1.0' into 'master'
Browse files Browse the repository at this point in the history
release/v3.1.0 into master

See merge request agence-dnd/marketplace/magento-2/external/module-checkout-magento2-plugin!27
  • Loading branch information
Rémi V committed Mar 31, 2022
2 parents c9518e8 + 5a5fb3a commit 9ae2ea6
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 121 deletions.
75 changes: 40 additions & 35 deletions Model/Methods/GooglePayMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Checkout\Library\Exceptions\CheckoutHttpException;
use Checkout\Models\Payments\BillingDescriptor;
use Checkout\Models\Payments\Payment;
use Checkout\Models\Payments\ThreeDs;
use Checkout\Models\Payments\TokenSource;
use Checkout\Models\Tokens\GooglePay;
use CheckoutCom\Magento2\Gateway\Config\Config;
Expand All @@ -39,7 +40,6 @@
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
Expand Down Expand Up @@ -160,25 +160,25 @@ class GooglePayMethod extends AbstractMethod
/**
* GooglePayMethod constructor
*
* @param Context $context
* @param Registry $registry
* @param Context $context
* @param Registry $registry
* @param ExtensionAttributesFactory $extensionFactory
* @param AttributeValueFactory $customAttributeFactory
* @param Data $paymentData
* @param ScopeConfigInterface $scopeConfig
* @param Logger $logger
* @param Config $config
* @param ApiHandlerService $apiHandler
* @param Utilities $utilities
* @param StoreManagerInterface $storeManager
* @param QuoteHandlerService $quoteHandler
* @param LoggerHelper $ckoLogger
* @param Session $backendAuthSession
* @param DirectoryHelper $directoryHelper
* @param DataObjectFactory $dataObjectFactory
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param AttributeValueFactory $customAttributeFactory
* @param Data $paymentData
* @param ScopeConfigInterface $scopeConfig
* @param Logger $logger
* @param Config $config
* @param ApiHandlerService $apiHandler
* @param Utilities $utilities
* @param StoreManagerInterface $storeManager
* @param QuoteHandlerService $quoteHandler
* @param LoggerHelper $ckoLogger
* @param Session $backendAuthSession
* @param DirectoryHelper $directoryHelper
* @param DataObjectFactory $dataObjectFactory
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
Context $context,
Expand Down Expand Up @@ -217,22 +217,22 @@ public function __construct(
$data
);

$this->config = $config;
$this->apiHandler = $apiHandler;
$this->utilities = $utilities;
$this->storeManager = $storeManager;
$this->quoteHandler = $quoteHandler;
$this->ckoLogger = $ckoLogger;
$this->config = $config;
$this->apiHandler = $apiHandler;
$this->utilities = $utilities;
$this->storeManager = $storeManager;
$this->quoteHandler = $quoteHandler;
$this->ckoLogger = $ckoLogger;
$this->backendAuthSession = $backendAuthSession;
}

/**
* Send a charge request
*
* @param string[] $data
* @param float $amount
* @param string $currency
* @param string $reference
* @param float $amount
* @param string $currency
* @param string $reference
*
* @return mixed|void
* @throws FileSystemException
Expand Down Expand Up @@ -263,6 +263,7 @@ public function sendPaymentRequest(array $data, float $amount, string $currency,
$tokenSource = new TokenSource($tokenData->getId());

// Set the payment
/** @var Payment $request */
$request = new Payment(
$tokenSource, $currency
);
Expand All @@ -278,15 +279,19 @@ public function sendPaymentRequest(array $data, float $amount, string $currency,
}

// Set the request parameters
$request->amount = $this->quoteHandler->amountToGateway(
$request->amount = $this->quoteHandler->amountToGateway(
$this->utilities->formatDecimals($amount),
$quote
);
$request->reference = $reference;
$request->description = __('Payment request from %1', $this->config->getStoreName())->render();
$request->customer = $api->createCustomer($quote);

$request->reference = $reference;
$request->success_url = $this->config->getStoreUrl() . 'checkout_com/payment/verify';
$request->failure_url = $this->config->getStoreUrl() . 'checkout_com/payment/fail';
$request->threeDs = new ThreeDs($this->config->needs3ds($this->_code));
$request->description = __('Payment request from %1', $this->config->getStoreName())->render();
$request->customer = $api->createCustomer($quote);
$request->payment_type = 'Regular';
$request->shipping = $api->createShippingAddress($quote);
$request->shipping = $api->createShippingAddress($quote);

// Billing descriptor
if ($this->config->needsDynamicDescriptor()) {
Expand Down Expand Up @@ -318,7 +323,7 @@ public function sendPaymentRequest(array $data, float $amount, string $currency,
* Perform a capture request
*
* @param InfoInterface $payment
* @param float $amount
* @param float $amount
*
* @return $this|GooglePayMethod
* @throws LocalizedException
Expand Down Expand Up @@ -442,7 +447,7 @@ public function cancel(InfoInterface $payment): AbstractMethod
* Perform a refund request
*
* @param InfoInterface $payment
* @param float $amount
* @param float $amount
*
* @return $this|GooglePayMethod
* @throws LocalizedException
Expand Down
37 changes: 25 additions & 12 deletions Setup/Patch/Data/EncryptOldApiKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ class EncryptOldApiKeys implements DataPatchInterface
* EncryptOldApiKeys constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EncryptorInterface $encryptor
* @param WriterInterface $writer
* @param EncryptorInterface $encryptor
* @param WriterInterface $writer
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EncryptorInterface $encryptor,
WriterInterface $writer
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->encryptor = $encryptor;
$this->writer = $writer;
$this->encryptor = $encryptor;
$this->writer = $writer;
}

/**
Expand Down Expand Up @@ -116,17 +116,30 @@ public function apply()
/** @var string $coreConfigDataTable */
$coreConfigDataTable = $setup->getTableName('core_config_data');
/** @var Select $query */
$query = $setup->select()->from($coreConfigDataTable, ['value'])->where('path = ?', $configPath);
/** @var mixed $oldKey */
$oldKey = $setup->fetchRow($query);
$query = $setup->select()->from($coreConfigDataTable, ['scope', 'scope_id', 'value'])->where('path = ?', $configPath);
/** @var mixed[] $oldKeys */
$oldKeys = $setup->fetchAll($query);

if ($oldKey) {
$oldKey = $oldKey['value'];
/** @var string $encryptedKey */
$encryptedKey = $this->encryptor->encrypt($oldKey);
$this->writer->save($configPath, $encryptedKey);
/** @var mixed[] $oldKey */
foreach ($oldKeys as $oldKey) {
$this->encryptKey($oldKey, $configPath);
}
}
$this->moduleDataSetup->getConnection()->endSetup();
}

/**
* @param mixed[] $oldKey
* @param string $configPath
*
* @return void
*/
public function encryptKey(array $oldKey, string $configPath): void
{
if ($oldKey) {
/** @var string $encryptedKey */
$encryptedKey = $this->encryptor->encrypt($oldKey['value']);
$this->writer->save($configPath, $encryptedKey, $oldKey['scope'], (int)$oldKey['scope_id']);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"magento/framework": ">=100.0.1"
},
"type": "magento2-module",
"version": "3.0.1",
"version": "3.1.0",
"autoload": {
"files": [
"registration.php"
Expand Down
9 changes: 7 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<label>Enable Webhook Table</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>settings/checkoutcom_configuration/webhooks_table_enabled</config_path>
<comment>This enables webhooks to be logged to a dedicated table to improve traceability for when webhook events are received. </comment>
<comment>This enables webhooks to be logged to a dedicated table to improve traceability for when webhook events are received.</comment>
</field>

<field id="webhooks_table_clean_enabled" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -420,7 +420,6 @@
<comment>The Apple Pay merchant id (e.g. merchant.example.com.sandbox). Make sure you validated this domain in the mercahnt id settings.</comment>
</field>


<field id="merchant_id_certificate" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Merchant Identity Certificate*</label>
<config_path>payment/checkoutcom_apple_pay/merchant_id_certificate</config_path>
Expand Down Expand Up @@ -477,6 +476,12 @@
</requires>
</field>

<field id="three_ds" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use 3D Secure</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/checkoutcom_google_pay/three_ds</config_path>
</field>

<field id="sort_order" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sort Order</label>
<validate>validate-number</validate>
Expand Down
Loading

0 comments on commit 9ae2ea6

Please sign in to comment.