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
$payment = $paymentDataObject->getPayment();
$storeId = $payment->getOrder()->getStoreId();
$areaCode = $this->appState->getAreaCode();
$customerId = $payment->getOrder()->getCustomerId();
$additionalInformation = $payment->getAdditionalInformation();
$request['body'] = $this->adyenRequestsHelper->buildRecurringData(
$areaCode,
$storeId,
$additionalInformation,
$customerId,
[]
);
return $request;
......
......@@ -1041,6 +1041,11 @@ class Data extends AbstractHelper
return !$this->getAdyenOneclickConfigDataFlag('share_billing_agreement', $storeId);
}
public function isGuestTokenizationEnabled($storeId)
{
return $this->getAdyenOneclickConfigDataFlag('guest_checkout_tokenisation', $storeId);
}
/**
* @param $paymentMethod
* @return bool
......
......@@ -24,6 +24,7 @@
namespace Adyen\Payment\Helper;
use Adyen\Payment\Observer\AdyenOneclickDataAssignObserver;
use Adyen\Util\Uuid;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Vault\Model\Ui\VaultConfigProvider;
......@@ -37,12 +38,12 @@ class Requests extends AbstractHelper
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* Requests constructor.
*
* @param Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
) {
......@@ -86,6 +87,11 @@ class Requests extends AbstractHelper
if ($customerId > 0) {
$request['shopperReference'] = $customerId;
}
elseif ($this->adyenHelper->isGuestTokenizationEnabled($storeId)){
$uuid = Uuid::generateV4();
$guestCustomerId = $payment->getOrder()->getIncrementId() . $uuid;
$request['shopperReference'] = $guestCustomerId;
}
$paymentMethod = '';
if ($payment) {
......@@ -341,8 +347,13 @@ class Requests extends AbstractHelper
* @param $storeId
* @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 (!$this->adyenHelper->isCreditCardVaultEnabled()) {
if ($areaCode !== \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
......@@ -351,8 +362,7 @@ class Requests extends AbstractHelper
$enableOneclick = $this->adyenHelper->getAdyenAbstractConfigData('enable_oneclick', $storeId);
$enableRecurring = $this->adyenHelper->getAdyenAbstractConfigData('enable_recurring', $storeId);
if ($enableOneclick) {
if ($enableOneclick && !$isGuestUser) {
$request['enableOneClick'] = true;
} else {
$request['enableOneClick'] = false;
......@@ -365,7 +375,7 @@ class Requests extends AbstractHelper
}
// 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;
}
}
......
......@@ -58,5 +58,10 @@
<config_path>payment/adyen_oneclick/share_billing_agreement</config_path>
</field>
</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>
</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