We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 02fbadca authored by Alexandros Moraitis's avatar Alexandros Moraitis Committed by GitHub

[PW-2567] Guest checkout tokenisation (#788)

* Add check to guest user

* Create the uuid with orderId

* Update Helper/Requests.php
Co-authored-by: default avatarAttila Kiss <42297201+cyattilakiss@users.noreply.github.com>

* remove the guest_checkout_tokenize from config.xml
Co-authored-by: default avatarAttila Kiss <42297201+cyattilakiss@users.noreply.github.com>
parent 5f7221e8
...@@ -63,11 +63,13 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -63,11 +63,13 @@ class RecurringDataBuilder implements BuilderInterface
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$storeId = $payment->getOrder()->getStoreId(); $storeId = $payment->getOrder()->getStoreId();
$areaCode = $this->appState->getAreaCode(); $areaCode = $this->appState->getAreaCode();
$customerId = $payment->getOrder()->getCustomerId();
$additionalInformation = $payment->getAdditionalInformation(); $additionalInformation = $payment->getAdditionalInformation();
$request['body'] = $this->adyenRequestsHelper->buildRecurringData( $request['body'] = $this->adyenRequestsHelper->buildRecurringData(
$areaCode, $areaCode,
$storeId, $storeId,
$additionalInformation, $additionalInformation,
$customerId,
[] []
); );
return $request; return $request;
......
...@@ -1041,6 +1041,11 @@ class Data extends AbstractHelper ...@@ -1041,6 +1041,11 @@ class Data extends AbstractHelper
return !$this->getAdyenOneclickConfigDataFlag('share_billing_agreement', $storeId); return !$this->getAdyenOneclickConfigDataFlag('share_billing_agreement', $storeId);
} }
public function isGuestTokenizationEnabled($storeId)
{
return $this->getAdyenOneclickConfigDataFlag('guest_checkout_tokenisation', $storeId);
}
/** /**
* @param $paymentMethod * @param $paymentMethod
* @return bool * @return bool
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
namespace Adyen\Payment\Helper; namespace Adyen\Payment\Helper;
use Adyen\Payment\Observer\AdyenOneclickDataAssignObserver; use Adyen\Payment\Observer\AdyenOneclickDataAssignObserver;
use Adyen\Util\Uuid;
use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Vault\Model\Ui\VaultConfigProvider; use Magento\Vault\Model\Ui\VaultConfigProvider;
...@@ -37,12 +38,12 @@ class Requests extends AbstractHelper ...@@ -37,12 +38,12 @@ class Requests extends AbstractHelper
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
*/ */
private $adyenHelper; private $adyenHelper;
/** /**
* Requests constructor. * Requests constructor.
* *
* @param Data $adyenHelper * @param Data $adyenHelper
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper \Adyen\Payment\Helper\Data $adyenHelper
) { ) {
...@@ -86,6 +87,11 @@ class Requests extends AbstractHelper ...@@ -86,6 +87,11 @@ class Requests extends AbstractHelper
if ($customerId > 0) { if ($customerId > 0) {
$request['shopperReference'] = $customerId; $request['shopperReference'] = $customerId;
} }
elseif ($this->adyenHelper->isGuestTokenizationEnabled($storeId)){
$uuid = Uuid::generateV4();
$guestCustomerId = $payment->getOrder()->getIncrementId() . $uuid;
$request['shopperReference'] = $guestCustomerId;
}
$paymentMethod = ''; $paymentMethod = '';
if ($payment) { if ($payment) {
...@@ -341,8 +347,13 @@ class Requests extends AbstractHelper ...@@ -341,8 +347,13 @@ class Requests extends AbstractHelper
* @param $storeId * @param $storeId
* @param $payment * @param $payment
*/ */
public function buildRecurringData($areaCode, int $storeId, $additionalData, $request = []) public function buildRecurringData($areaCode, int $storeId, $additionalData, $customerId, $request = [])
{ {
$isGuestUser = true;
if ($customerId > 0) {
$isGuestUser = false;
}
// If the vault feature is on this logic is handled in the VaultDataBuilder // If the vault feature is on this logic is handled in the VaultDataBuilder
if (!$this->adyenHelper->isCreditCardVaultEnabled()) { if (!$this->adyenHelper->isCreditCardVaultEnabled()) {
if ($areaCode !== \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { if ($areaCode !== \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
...@@ -351,8 +362,7 @@ class Requests extends AbstractHelper ...@@ -351,8 +362,7 @@ class Requests extends AbstractHelper
$enableOneclick = $this->adyenHelper->getAdyenAbstractConfigData('enable_oneclick', $storeId); $enableOneclick = $this->adyenHelper->getAdyenAbstractConfigData('enable_oneclick', $storeId);
$enableRecurring = $this->adyenHelper->getAdyenAbstractConfigData('enable_recurring', $storeId); $enableRecurring = $this->adyenHelper->getAdyenAbstractConfigData('enable_recurring', $storeId);
if ($enableOneclick && !$isGuestUser) {
if ($enableOneclick) {
$request['enableOneClick'] = true; $request['enableOneClick'] = true;
} else { } else {
$request['enableOneClick'] = false; $request['enableOneClick'] = false;
...@@ -365,7 +375,7 @@ class Requests extends AbstractHelper ...@@ -365,7 +375,7 @@ class Requests extends AbstractHelper
} }
// value can be 0,1 or true // value can be 0,1 or true
if (!empty($additionalData[AdyenCcDataAssignObserver::STORE_CC])) { if (!empty($additionalData[AdyenCcDataAssignObserver::STORE_CC]) || ($isGuestUser && $this->adyenHelper->isGuestTokenizationEnabled($storeId))) {
$request['paymentMethod']['storeDetails'] = true; $request['paymentMethod']['storeDetails'] = true;
} }
} }
......
...@@ -58,5 +58,10 @@ ...@@ -58,5 +58,10 @@
<config_path>payment/adyen_oneclick/share_billing_agreement</config_path> <config_path>payment/adyen_oneclick/share_billing_agreement</config_path>
</field> </field>
</group> </group>
<field id="guest_checkout_tokenisation" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable guest checkout tokenisation</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_oneclick/guest_checkout_tokenisation</config_path>
</field>
</group> </group>
</include> </include>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment