We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 6ed050b3 authored by attilak's avatar attilak

[WIP]

works with challenge shopper
parent 5727c8d0
......@@ -60,7 +60,6 @@ class ThreeDS2ResponseValidator extends AbstractValidator
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
}
$payment->setAdditionalInformation('3ds2Active', false);
$isValid = true;
$errorMessages = [];
......
......@@ -250,7 +250,7 @@ class Requests extends AbstractHelper
{
$request['amount'] = [
'currency' => $currencyCode,
'value' =>$this->adyenHelper->formatAmount($amount, $currencyCode)
'value' => $this->adyenHelper->formatAmount($amount, $currencyCode)
];
......@@ -292,6 +292,13 @@ class Requests extends AbstractHelper
$request['browserInfo']['language'] = $this->adyenHelper->getCurrentLocaleCode($store);
$request['browserInfo']['javaEnabled'] = true; //$payment->getAdditionalInformation(AdyenCcDataAssignObserver::JAVA_ENABLED);
// uset browser related data from additional information
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::SCREEN_WIDTH);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::SCREEN_HEIGHT);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::SCREEN_COLOR_DEPTH);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::TIMEZONE_OFFSET);
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::JAVA_ENABLED);
return $request;
}
......
......@@ -75,10 +75,13 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
"paymentData" => $payment->getAdditionalInformation("threeDS2PaymentData")
];
// unset payment data from additional information
$payment->unsAdditionalInformation("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'])) {
} elseif (!empty($payload['details']['threeds2.challengeResult'])) {
$request['details']['threeds2.challengeResult'] = $payload['details']['threeds2.challengeResult'];
}
......@@ -94,19 +97,20 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
// Check if result is challenge shopper, if yes return the token
if (!empty($result['resultCode']) &&
$result['resultCode'] === 'ChallengeShopper' &&
!empty(result['authentication']['threeds2.fingerprintToken'])
!empty($result['authentication']['threeds2.challengeToken'])
) {
return json_encode(
array(
'threeDS2' => true,
'type' => 'ChallengeShopper',
'token' => $result['authentication']['threeds2.challengeResult']
'type' => $result['resultCode'],
'token' => $result['authentication']['threeds2.challengeToken']
)
);
}
// Payment can get back to the original flow
$payment->setAdditionalInformation("paymentsResponse", $result);
$payment->setAdditionalInformation('3ds2Active', false);
$quote->save();
// 3DS2 flow is done, original place order flow can continue from frontend
......
......@@ -72,6 +72,11 @@ class PaymentInformationManagement
$quote = $this->checkoutSession->getQuote();
$payment = $quote->getPayment();
// in case payments response is already there we don't need to perform another payments call
if ($payment->getAdditionalInformation('paymentsResponse')) {
return true;
}
// Init request array
$request = [];
......@@ -132,6 +137,7 @@ class PaymentInformationManagement
) {
if ($this->threeDS2ResponseValidator->validate(array("response" => $paymentsResponse, "payment" => $payment))->isValid()) {
$payment->setAdditionalInformation('3ds2Active', true);
$quote->save();
return json_encode(
array(
......@@ -140,6 +146,8 @@ class PaymentInformationManagement
"token" => $payment->getAdditionalInformation('threeDS2Token')
)
);
} else {
// TODO Handle error
}
} else {
$payment->setAdditionalInformation('paymentsResponse', $paymentsResponse);
......
......@@ -61,6 +61,7 @@ define(
this.vaultEnabler.setPaymentCode(this.getVaultCode());
this.vaultEnabler.isActivePaymentTokenEnabler(false);
// initialize adyen component for general use
this.checkout = new AdyenCheckout({
locale: this.getLocale()
});
......@@ -104,7 +105,7 @@ define(
var allInstallments = self.getAllInstallments();
var cardNode = document.getElementById('cardContainer');
var card = self.checkout.create('card', {
self.cardComponent = self.checkout.create('card', {
originKey: self.getOriginKey(),
loadingContext: self.getLoadingContext(),
type: 'card',
......@@ -178,9 +179,7 @@ define(
installments.setInstallments(0);
}
}
});
card.mount(cardNode);
}).mount(cardNode);
},
/**
* Rendering the 3DS2.0 components
......@@ -189,17 +188,12 @@ define(
* @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
self.threeDS2Component = self.checkout
.create('threeDS2DeviceFingerprint', {
fingerprintToken: token,
onComplete: function(result) {
......@@ -211,12 +205,16 @@ define(
}
});
} else if (type == "ChallengeShopper") {
var threeDS2Component = self.checkout
self.cardComponent.unmount(cardNode);
if (self.threeDS2Component) {
self.threeDS2Component.unmount(cardNode);
}
self.threeDS2Component = self.checkout
.create('threeDS2Challenge', {
challengeToken: token,
onComplete: function(result) {
console.log(result);
//self.processThreeDS2(result);
self.processThreeDS2(result.data);
},
onError: function(result) {
// TODO error handling show error message
......@@ -225,7 +223,7 @@ define(
});
}
threeDS2Component.mount(threeDS2Node);
self.threeDS2Component.mount(cardNode);
},
/**
*
......@@ -267,7 +265,7 @@ define(
'holderName': this.creditCardOwner(),
'store_cc': this.setStoreCc(),
'number_of_installments': this.installment(),
'java_enabled': navigator.javaEnabled(),
'java_enabled': navigator.javaEnabled().toString(),
'screen_color_depth': screen.colorDepth,
'screen_width': screen.width,
'screen_height': screen.height,
......@@ -330,6 +328,7 @@ define(
if (!!response.threeDS2) {
// render component
self.cardComponent.unmount();
self.renderThreeDS2Component(response.type, response.token);
} else {
self.getPlaceOrderDeferredObject()
......
......@@ -77,8 +77,6 @@
<div afterRender="renderSecureFields()" data-bind="attr: { id: 'cardContainer'}"></div>
</div>
<div id="threeDS2Container"></div>
<!-- ko if: (hasInstallments())-->
<div class="field required"
......
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