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 6694b94f authored by attilak's avatar attilak

[WIP]

PW-1103 new controller implemented, new di logic also.
Oneclick payments are not working - a new builder needs to be created
for that separately
PW-1104 components are rendered, challengeShopper was not tested
PW-1105 separate controller to handle the 3DS2.0 process created
PW-1106 feature toggle implemented

TODO:
challengeShopper flow test and fix
Oneclick fix
checkout component 2.0 was updated therefore needs to be tested
e.g. "save card data" checkout is rendered by the component now
data builders need to use the Requests helper functions or should be
deleted if never used
Code review and refactor where needed
parent 0ea49d3c
...@@ -24,14 +24,11 @@ ...@@ -24,14 +24,11 @@
namespace Adyen\Payment\Api; namespace Adyen\Payment\Api;
interface Adyen3DS2ProcessInterface interface AdyenThreeDS2ProcessInterface
{ {
/** /**
* Returns string * @param mixed $payload
* * @return mixed
* @api
* @param string $payload
* @return string
*/ */
public function initiate($payload); public function initiate($payload);
} }
\ No newline at end of file
...@@ -55,6 +55,13 @@ class TransactionPayment implements ClientInterface ...@@ -55,6 +55,13 @@ class TransactionPayment implements ClientInterface
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject) public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{ {
$request = $transferObject->getBody(); $request = $transferObject->getBody();
// If the payments call is already done return the
if (!empty($request['resultCode'])) {
//Initiate has already a response
return $request;
}
$client = $this->adyenHelper->initializeAdyenClient(); $client = $this->adyenHelper->initializeAdyenClient();
$service = new \Adyen\Service\Checkout($client); $service = new \Adyen\Service\Checkout($client);
......
...@@ -35,16 +35,23 @@ class AddressDataBuilder implements BuilderInterface ...@@ -35,16 +35,23 @@ class AddressDataBuilder implements BuilderInterface
*/ */
private $adyenHelper; private $adyenHelper;
/**
* @var \Adyen\Payment\Helper\Requests
*/
private $adyenRequestsHelper;
/** /**
* AddressDataBuilder constructor. * AddressDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Helper\Requests $adyenRequestsHelper
) )
{ {
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->adyenRequestsHelper = $adyenRequestsHelper;
} }
/** /**
...@@ -59,75 +66,10 @@ class AddressDataBuilder implements BuilderInterface ...@@ -59,75 +66,10 @@ class AddressDataBuilder implements BuilderInterface
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder(); $order = $paymentDataObject->getOrder();
$billingAddress = $order->getBillingAddress(); $billingAddress = $order->getBillingAddress();
$result = [];
if ($billingAddress) {
$requestBilling = [
"street" => "N/A",
"postalCode" => '',
"city" => "N/A",
"houseNumberOrName" => '',
"stateOrProvince" => '',
"country" => "ZZ"
];
$address = $this->adyenHelper->getStreetFromString($billingAddress->getStreetLine1());
if ($address) {
$requestBilling["street"] = $address["name"];
$requestBilling["houseNumberOrName"] = $address["house_number"];
}
if ($billingAddress->getPostcode()) {
$requestBilling["postalCode"] = $billingAddress->getPostcode();
}
if ($billingAddress->getCity()) {
$requestBilling["city"] = $billingAddress->getCity();
}
if ($billingAddress->getRegionCode()) {
$requestBilling["stateOrProvince"] = $billingAddress->getRegionCode();
}
if ($billingAddress->getCountryId()) {
$requestBilling["country"] = $billingAddress->getCountryId();
}
$result['billingAddress'] = $requestBilling;
}
$shippingAddress = $order->getShippingAddress(); $shippingAddress = $order->getShippingAddress();
if ($shippingAddress) { $result = [];
$result = $this->adyenRequestsHelper->buildAddressData($result, $billingAddress, $shippingAddress);
$address = $this->adyenHelper->getStreetFromString($shippingAddress->getStreetLine1());
if ($address) {
$requestDelivery["street"] = $address["name"];
$requestDelivery["houseNumberOrName"] = $address["house_number"];
}
if ($shippingAddress->getPostcode()) {
$requestDelivery["postalCode"] = $shippingAddress->getPostcode();
}
if ($shippingAddress->getCity()) {
$requestDelivery["city"] = $shippingAddress->getCity();
}
if ($shippingAddress->getRegionCode()) {
$requestDelivery["stateOrProvince"] = $shippingAddress->getRegionCode();
}
if ($shippingAddress->getCountryId()) {
$requestDelivery["country"] = $shippingAddress->getCountryId();
}
$result['deliveryAddress'] = $requestDelivery;
}
return $result; return $result;
} }
......
...@@ -29,18 +29,30 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -29,18 +29,30 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
*/ */
class BrowserInfoDataBuilder implements BuilderInterface class BrowserInfoDataBuilder implements BuilderInterface
{ {
/**
* @var \Adyen\Payment\Helper\Requests
*/
private $adyenRequestsHelper;
/**
* BrowserInfoDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/
public function __construct(
\Adyen\Payment\Helper\Requests $adyenRequestsHelper
)
{
$this->adyenRequestsHelper = $adyenRequestsHelper;
}
/** /**
* @param array $buildSubject * @param array $buildSubject
* @return array * @return array
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
return [ $result = $this->adyenRequestsHelper->buildBrowserData();
'browserInfo' => return $result;
[
'userAgent' => $_SERVER['HTTP_USER_AGENT'],
'acceptHeader' => $_SERVER['HTTP_ACCEPT']
]
];
} }
} }
...@@ -33,23 +33,15 @@ class CcAuthorizationDataBuilder implements BuilderInterface ...@@ -33,23 +33,15 @@ class CcAuthorizationDataBuilder implements BuilderInterface
*/ */
private $adyenHelper; private $adyenHelper;
/**
* @var \Magento\Framework\App\State
*/
private $appState;
/** /**
* CcAuthorizationDataBuilder constructor. * CcAuthorizationDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\Model\Context $context
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper
\Magento\Framework\Model\Context $context
) { ) {
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->appState = $context->getAppState();
} }
/** /**
...@@ -61,54 +53,16 @@ class CcAuthorizationDataBuilder implements BuilderInterface ...@@ -61,54 +53,16 @@ class CcAuthorizationDataBuilder implements BuilderInterface
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$order = $paymentDataObject->getOrder();
$storeId = $order->getStoreId();
$request = [];
// If ccType is set use this. For bcmc you need bcmc otherwise it will fail
$request['paymentMethod']['type'] = "scheme";
if ($cardNumber = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER)) {
$request['paymentMethod']['encryptedCardNumber'] = $cardNumber;
}
if ($expiryMonth = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_MONTH)) {
$request['paymentMethod']['encryptedExpiryMonth'] = $expiryMonth;
}
if ($expiryYear = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_YEAR)) { // retrieve payments response which we already got and saved in the
$request['paymentMethod']['encryptedExpiryYear'] = $expiryYear; // Adyen\Payment\Plugin\PaymentInformationManagement::afterSavePaymentInformation
} if ($response = $payment->getAdditionalInformation("paymentsResponse")) {
$request = $response;
if ($holderName = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::HOLDER_NAME)) { // Remove from additional data
$request['paymentMethod']['holderName'] = $holderName; $payment->unsAdditionalInformation("paymentsResponse");
} } else {
$errorMsg = __('Error with payment method please select different payment method.');
if ($securityCode = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_SECURITY_CODE)) { throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
$request['paymentMethod']['encryptedSecurityCode'] = $securityCode;
}
// Remove from additional data
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_MONTH);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_YEAR);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_SECURITY_CODE);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::HOLDER_NAME);
/**
* if MOTO for backend is enabled use MOTO as shopper interaction type
*/
$enableMoto = $this->adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE &&
$enableMoto
) {
$request['shopperInteraction'] = "Moto";
}
// if installments is set add it into the request
if ($payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) &&
$payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) > 0
) {
$request['installments']['value'] = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS);
} }
return $request; return $request;
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Validator;
use Magento\Payment\Gateway\Validator\AbstractValidator;
class ThreeDS2ResponseValidator extends AbstractValidator
{
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
private $adyenLogger;
/**
* GeneralResponseValidator constructor.
*
* @param \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/
public function __construct(
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
$this->adyenLogger = $adyenLogger;
parent::__construct($resultFactory);
}
/**
* @param array $validationSubject
* @return \Magento\Payment\Gateway\Validator\ResultInterface
*/
public function validate(array $validationSubject)
{
$response = \Magento\Payment\Gateway\Helper\SubjectReader::readResponse($validationSubject);
if (!empty($validationSubject['payment'])) {
$payment = $validationSubject['payment'];
} else {
$errorMsg = __('Error with payment method during validation please select different payment method.');
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
}
$payment->setAdditionalInformation('3ds2Active', false);
$isValid = true;
$errorMessages = [];
// validate result
if (!empty($response['resultCode'])) {
// 3DS2.0 should have IdentifyShopper or ChallengeShopper as a resultCode
switch ($response['resultCode']) {
case "IdentifyShopper":
if (!empty($response['authentication']['threeds2.fingerprintToken'])) {
$payment->setAdditionalInformation('threeDS2Type', $response['resultCode']);
$payment->setAdditionalInformation('threeDS2Token', $response['authentication']['threeds2.fingerprintToken']);
$payment->setAdditionalInformation('threeDS2PaymentData', $response['paymentData']);
}
break;
case "ChallengeShopper":
if (!empty($response['authentication']['threeds2.challengeToken'])) {
$payment->setAdditionalInformation('threeDS2Type', $response['resultCode']);
$payment->setAdditionalInformation('threeDS2Token', $response['authentication']['threeds2.challengeToken']);
$payment->setAdditionalInformation('threeDS2PaymentData', $response['paymentData']);
}
break;
default:
$errorMsg = __('Error with payment method please select different payment method.');
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
break;
}
} else {
$errorMsg = __('Error with payment method please select different payment method.');
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
}
return $this->createResult($isValid, $errorMessages);
}
}
\ No newline at end of file
...@@ -35,8 +35,8 @@ class Data extends AbstractHelper ...@@ -35,8 +35,8 @@ class Data extends AbstractHelper
const LIVE = 'live'; const LIVE = 'live';
const CHECKOUT_CONTEXT_URL_LIVE = 'https://checkoutshopper-live.adyen.com/checkoutshopper/'; const CHECKOUT_CONTEXT_URL_LIVE = 'https://checkoutshopper-live.adyen.com/checkoutshopper/';
const CHECKOUT_CONTEXT_URL_TEST = 'https://checkoutshopper-test.adyen.com/checkoutshopper/'; const CHECKOUT_CONTEXT_URL_TEST = 'https://checkoutshopper-test.adyen.com/checkoutshopper/';
const CHECKOUT_COMPONENT_JS_LIVE = 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/2.1.0/adyen.js'; const CHECKOUT_COMPONENT_JS_LIVE = 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/2.2.0/adyen.js';
const CHECKOUT_COMPONENT_JS_TEST = 'https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/2.1.0/adyen.js'; const CHECKOUT_COMPONENT_JS_TEST = 'https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/2.2.0/adyen.js';
/** /**
* @var \Magento\Framework\Encryption\EncryptorInterface * @var \Magento\Framework\Encryption\EncryptorInterface
...@@ -439,7 +439,7 @@ class Data extends AbstractHelper ...@@ -439,7 +439,7 @@ class Data extends AbstractHelper
} }
/** /**
* Gives back adyen_cc configuration values as flag * Gives back adyen_cc_vault configuration values as flag
* *
* @param $field * @param $field
* @param null $storeId * @param null $storeId
...@@ -450,6 +450,18 @@ class Data extends AbstractHelper ...@@ -450,6 +450,18 @@ class Data extends AbstractHelper
return $this->getConfigData($field, 'adyen_cc_vault', $storeId, true); return $this->getConfigData($field, 'adyen_cc_vault', $storeId, true);
} }
/**
* Gives back adyen_cc_threeds2 configuration values as flag
*
* @param $field
* @param null $storeId
* @return mixed
*/
public function getAdyenCcThreeDS2ConfigDataFlag($field, $storeId = null)
{
return $this->getConfigData($field, 'adyen_cc_threeds2', $storeId, true);
}
/** /**
* Gives back adyen_hpp configuration values * Gives back adyen_hpp configuration values
* *
...@@ -1515,7 +1527,7 @@ class Data extends AbstractHelper ...@@ -1515,7 +1527,7 @@ class Data extends AbstractHelper
{ {
$params = array( $params = array(
"originDomains" => array( "originDomains" => array(
$url $origin
) )
); );
...@@ -1530,8 +1542,8 @@ class Data extends AbstractHelper ...@@ -1530,8 +1542,8 @@ class Data extends AbstractHelper
$originKey = ""; $originKey = "";
if (!empty($response['originKeys'][$url])) { if (!empty($response['originKeys'][$origin])) {
$originKey = $response['originKeys'][$url]; $originKey = $response['originKeys'][$origin];
} }
return $originKey; return $originKey;
...@@ -1686,7 +1698,6 @@ class Data extends AbstractHelper ...@@ -1686,7 +1698,6 @@ class Data extends AbstractHelper
return $icon; return $icon;
} }
/** /**
* Check if CreditCard vault is enabled * Check if CreditCard vault is enabled
* *
...@@ -1710,6 +1721,16 @@ class Data extends AbstractHelper ...@@ -1710,6 +1721,16 @@ class Data extends AbstractHelper
return in_array(strtolower($country), $countryList); return in_array(strtolower($country), $countryList);
} }
/**
* Check if 3DS2.0 is enabled for credit cards
*
* @param int|null $storeId
* @return mixed
*/
public function isCreditCardThreeDS2Enabled($storeId = null)
{
return $this->getAdyenCcThreeDS2ConfigDataFlag('active', $storeId);
}
/** /**
* @param $client * @param $client
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
class Payments extends AbstractHelper
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
)
{
$this->adyenHelper = $adyenHelper;
}
}
This diff is collapsed.
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
use Adyen\Payment\Api\Adyen3DS2ProcessInterface;
class Adyen3DS2Process implements Adyen3DS2ProcessInterface
{
public function __construct()
{
}
public function initiate($payload)
{
$payload = json_decode($payload);
$paymentMethod = $payload;
return $payload;
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
use \Adyen\Payment\Api\AdyenThreeDS2ProcessInterface;
class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
{
/**
* @var \Magento\Checkout\Model\Session
*/
private $checkoutSession;
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* AdyenThreeDS2Process constructor.
*
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Helper\Data $adyenHelper
)
{
$this->checkoutSession = $checkoutSession;
$this->adyenHelper = $adyenHelper;
}
/**
* @api
* @param mixed $payload
* @return mixed
*/
public function initiate($payload)
{
// Decode payload from frontend
$payload = json_decode($payload, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Magento\Framework\Exception\LocalizedException(__('3D secure 2.0 failed because the request was not a valid JSON'));
}
// Get payment and cart information from session
$quote = $this->checkoutSession->getQuote();
$payment = $quote->getPayment();
// Init payments/details request
$request = [
"paymentData" => $payment->getAdditionalInformation("threeDS2PaymentData")
];
// Depends on the component's response we send a fingerprint or the challenge result
if (!empty($payload['details']['threeds2.fingerprint'])) {
$request['details']['threeds2.fingerprint'] = $payload['details']['threeds2.fingerprint'];
} elseif (!empty($payload['threeds2.challengeResult'])) {
$request['details']['threeds2.challengeResult'] = $payload['details']['threeds2.challengeResult'];
}
// Send the request
try {
$client = $this->adyenHelper->initializeAdyenClient($quote->getStoreId());
$service = $this->adyenHelper->createAdyenCheckoutService($client);
$result = $service->paymentsDetails($request);
} catch (\Adyen\AdyenException $e) {
throw new \Magento\Framework\Exception\LocalizedException(__('3D secure 2.0 failed'));
}
// Check if result is challenge shopper, if yes return the token
if (!empty($result['resultCode']) &&
$result['resultCode'] === 'ChallengeShopper' &&
!empty(result['authentication']['threeds2.fingerprintToken'])
) {
return json_encode(
array(
'threeDS2' => true,
'type' => 'ChallengeShopper',
'token' => $result['authentication']['threeds2.challengeResult']
)
);
}
// Payment can get back to the original flow
$payment->setAdditionalInformation("paymentsResponse", $result);
$quote->save();
// 3DS2 flow is done, original place order flow can continue from frontend
return json_encode(
array(
'threeDS2' => false
)
);
}
}
This diff is collapsed.
...@@ -59,6 +59,12 @@ ...@@ -59,6 +59,12 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_cc_vault/active</config_path> <config_path>payment/adyen_cc_vault/active</config_path>
</field> </field>
<field id="adyen_cc_threeds2" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>3DS2.0 Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_cc_threeds2/active</config_path>
</field>
<group id="adyen_cc_advanced_settings" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" <group id="adyen_cc_advanced_settings" translate="label" showInDefault="1" showInWebsite="1" showInStore="1"
sortOrder="150"> sortOrder="150">
......
...@@ -396,6 +396,8 @@ ...@@ -396,6 +396,8 @@
<!-- Authorization command --> <!-- Authorization command -->
<virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand"> <virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments> <arguments>
<argument name="requestBuilder" xsi:type="object">AdyenPaymentCcAuthorizeRequest</argument>
<argument name="transferFactory" xsi:type="object">Adyen\Payment\Gateway\Http\TransferFactory</argument>
<argument name="client" xsi:type="object">Adyen\Payment\Gateway\Http\Client\TransactionPayment</argument> <argument name="client" xsi:type="object">Adyen\Payment\Gateway\Http\Client\TransactionPayment</argument>
<argument name="validator" xsi:type="object">CheckoutResponseValidator</argument> <argument name="validator" xsi:type="object">CheckoutResponseValidator</argument>
<argument name="handler" xsi:type="object">AdyenPaymentCcResponseHandlerComposite</argument> <argument name="handler" xsi:type="object">AdyenPaymentCcResponseHandlerComposite</argument>
...@@ -487,16 +489,8 @@ ...@@ -487,16 +489,8 @@
<virtualType name="AdyenPaymentCcAuthorizeRequest" type="Magento\Payment\Gateway\Request\BuilderComposite"> <virtualType name="AdyenPaymentCcAuthorizeRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments> <arguments>
<argument name="builders" xsi:type="array"> <argument name="builders" xsi:type="array">
<item name="merchantaccount" xsi:type="string">Adyen\Payment\Gateway\Request\MerchantAccountDataBuilder</item>
<item name="customer" xsi:type="string">Adyen\Payment\Gateway\Request\CustomerDataBuilder</item>
<item name="customerip" xsi:type="string">Adyen\Payment\Gateway\Request\CustomerIpDataBuilder</item>
<item name="address" xsi:type="string">Adyen\Payment\Gateway\Request\AddressDataBuilder</item>
<item name="payment" xsi:type="string">Adyen\Payment\Gateway\Request\PaymentDataBuilder</item>
<item name="browserinfo" xsi:type="string">Adyen\Payment\Gateway\Request\BrowserInfoDataBuilder</item>
<item name="recurring" xsi:type="string">Adyen\Payment\Gateway\Request\RecurringDataBuilder</item>
<item name="transaction" xsi:type="string">Adyen\Payment\Gateway\Request\CcAuthorizationDataBuilder <item name="transaction" xsi:type="string">Adyen\Payment\Gateway\Request\CcAuthorizationDataBuilder
</item> </item>
<item name="vault" xsi:type="string">Adyen\Payment\Gateway\Request\VaultDataBuilder</item>
</argument> </argument>
</arguments> </arguments>
</virtualType> </virtualType>
...@@ -883,8 +877,8 @@ ...@@ -883,8 +877,8 @@
type="Adyen\Payment\Model\AdyenRequestMerchantSession"/> type="Adyen\Payment\Model\AdyenRequestMerchantSession"/>
<preference for="Adyen\Payment\Api\AdyenInitiateTerminalApiInterface" <preference for="Adyen\Payment\Api\AdyenInitiateTerminalApiInterface"
type="Adyen\Payment\Model\AdyenInitiateTerminalApi"/> type="Adyen\Payment\Model\AdyenInitiateTerminalApi"/>
<preference for="Adyen\Payment\Api\Adyen3DS2ProcessInterface" <preference for="Adyen\Payment\Api\AdyenThreeDS2ProcessInterface"
type="Adyen\Payment\Model\Adyen3DS2Process"/> type="Adyen\Payment\Model\AdyenThreeDS2Process"/>
<preference for="Magento\Checkout\Api\PaymentInformationManagementInterface" <preference for="Magento\Checkout\Api\PaymentInformationManagementInterface"
type="Adyen\Payment\Model\AdyenPaymentInformationManagement"/> type="Adyen\Payment\Model\AdyenPaymentInformationManagement"/>
<type name="Magento\Vault\Api\PaymentTokenRepositoryInterface"> <type name="Magento\Vault\Api\PaymentTokenRepositoryInterface">
......
...@@ -58,8 +58,8 @@ ...@@ -58,8 +58,8 @@
</resources> </resources>
</route> </route>
<route url="/V1/adyen/3ds2Process" method="POST"> <route url="/V1/adyen/threeDS2Process" method="POST">
<service class="Adyen\Payment\Api\Adyen3DS2ProcessInterface" method="initiate"/> <service class="Adyen\Payment\Api\AdyenThreeDS2ProcessInterface" method="initiate"/>
<resources> <resources>
<resource ref="anonymous"/> <resource ref="anonymous"/>
</resources> </resources>
......
...@@ -35,8 +35,9 @@ define( ...@@ -35,8 +35,9 @@ define(
'mage/storage', 'mage/storage',
'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/model/full-screen-loader',
'Magento_Paypal/js/action/set-payment-method', 'Magento_Paypal/js/action/set-payment-method',
'Magento_Checkout/js/action/select-payment-method'
], ],
function ($, ko, Component, customer, creditCardData, additionalValidators, quote, installments, url, VaultEnabler, urlBuilder, storage, fullScreenLoader, setPaymentMethodAction) { function ($, ko, Component, customer, creditCardData, additionalValidators, quote, installments, url, VaultEnabler, urlBuilder, storage, fullScreenLoader, setPaymentMethodAction, selectPaymentMethodAction) {
'use strict'; 'use strict';
...@@ -60,6 +61,10 @@ define( ...@@ -60,6 +61,10 @@ define(
this.vaultEnabler.setPaymentCode(this.getVaultCode()); this.vaultEnabler.setPaymentCode(this.getVaultCode());
this.vaultEnabler.isActivePaymentTokenEnabler(false); this.vaultEnabler.isActivePaymentTokenEnabler(false);
this.checkout = new AdyenCheckout({
locale: this.getLocale()
});
return this; return this;
}, },
initObservable: function () { initObservable: function () {
...@@ -99,11 +104,7 @@ define( ...@@ -99,11 +104,7 @@ define(
var allInstallments = self.getAllInstallments(); var allInstallments = self.getAllInstallments();
var cardNode = document.getElementById('cardContainer'); var cardNode = document.getElementById('cardContainer');
var checkout = new AdyenCheckout({ var card = self.checkout.create('card', {
locale: self.getLocale()
});
var card = checkout.create('card', {
originKey: self.getOriginKey(), originKey: self.getOriginKey(),
loadingContext: self.getLoadingContext(), loadingContext: self.getLoadingContext(),
type: 'card', type: 'card',
...@@ -181,6 +182,73 @@ define( ...@@ -181,6 +182,73 @@ define(
card.mount(cardNode); card.mount(cardNode);
}, },
/**
* Rendering the 3DS2.0 components
*
* @param type
* @param token
*/
renderThreeDS2Component: function(type, token) {
console.log("ati 2");
var self = this;
// hide card component
var cardNode = document.getElementById('cardContainer');
$(cardNode).slideUp();
var threeDS2Node = document.getElementById('threeDS2Container');
if (type == "IdentifyShopper") {
var threeDS2Component = self.checkout
.create('threeDS2DeviceFingerprint', {
fingerprintToken: token,
onComplete: function(result) {
self.processThreeDS2(result.data);
},
onError: function(result) {
// TODO error handling show error message
console.log(result);
}
});
} else if (type == "ChallengeShopper") {
var threeDS2Component = self.checkout
.create('threeDS2Challenge', {
challengeToken: token,
onComplete: function(result) {
console.log(result);
//self.processThreeDS2(result);
},
onError: function(result) {
// TODO error handling show error message
console.log(result);
}
});
}
threeDS2Component.mount(threeDS2Node);
},
/**
*
* @param response
*/
processThreeDS2: function(data) {
var self = this;
var payload = {
"payload": JSON.stringify(data)
};
var serviceUrl = urlBuilder.createUrl('/adyen/threeDS2Process', {});
storage.post(
serviceUrl,
JSON.stringify(payload),
true
).done(function(responseJSON) {
fullScreenLoader.stopLoader();
self.validateThreeDS2OrPlaceOrder(responseJSON)
});
},
/** /**
* Builds the payment details part of the payment information reqeust * Builds the payment details part of the payment information reqeust
* *
...@@ -237,35 +305,34 @@ define( ...@@ -237,35 +305,34 @@ define(
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
var serviceUrl = urlBuilder.createUrl('/adyen/3ds2Process', {});
var payload = {
"payload": JSON.stringify(self.getData()),
};
//update payment method information if additional data was changed //update payment method information if additional data was changed
self.selectPaymentMethod(); selectPaymentMethodAction(this.getData());
setPaymentMethodAction(this.messageContainer).done( setPaymentMethodAction(this.messageContainer).done(
function (response) { function (responseJSON) {
console.log(response);
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
} self.validateThreeDS2OrPlaceOrder(responseJSON);
); });
return false; return false;
}
return false;
},
/**
*
* @param responseJSON
*/
validateThreeDS2OrPlaceOrder: function(responseJSON) {
var self = this;
/*storage.post( console.log(responseJSON);
serviceUrl,
JSON.stringify(payload),
true
).done(function(response) {
console.log(response);
fullScreenLoader.stopLoader();
//this.isPlaceOrderActionAllowed(true);
});*/
/*this.getPlaceOrderDeferredObject() var response = JSON.parse(responseJSON);
if (!!response.threeDS2) {
// render component
self.renderThreeDS2Component(response.type, response.token);
} else {
self.getPlaceOrderDeferredObject()
.fail( .fail(
function () { function () {
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
...@@ -279,12 +346,8 @@ define( ...@@ -279,12 +346,8 @@ define(
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl)); window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
} }
} }
);*/ );
return true;
} }
return false;
}, },
/** /**
* Validates the payment date when clicking the pay button * Validates the payment date when clicking the pay button
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
<div afterRender="renderSecureFields()" data-bind="attr: { id: 'cardContainer'}"></div> <div afterRender="renderSecureFields()" data-bind="attr: { id: 'cardContainer'}"></div>
</div> </div>
<div id="threeDS2Container"></div>
<!-- ko if: (hasInstallments())--> <!-- ko if: (hasInstallments())-->
......
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