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

[WIP]

Add json response builder processing 3DS2
Don't send the card details 2 times from the frontend
Show popup only for challenge shopper and not for identify shopper
parent 245987bd
...@@ -1767,4 +1767,30 @@ class Data extends AbstractHelper ...@@ -1767,4 +1767,30 @@ class Data extends AbstractHelper
$timeStamp = new \DateTime($date); $timeStamp = new \DateTime($date);
return $timeStamp->format($format); return $timeStamp->format($format);
} }
/**
* @param string|null $type
* @param string|null $token
* @return string
*/
public function buildThreeDS2ProcessResponseJson($type = null, $token = null)
{
$response = json_encode(
array(
'threeDS2' => false
)
);
if ($type && $token) {
$response = json_encode(
array(
"threeDS2" => true,
"type" => $type,
"token" => $token
)
);
}
return $response;
}
} }
...@@ -107,13 +107,7 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -107,13 +107,7 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
$result['resultCode'] === 'ChallengeShopper' && $result['resultCode'] === 'ChallengeShopper' &&
!empty($result['authentication']['threeds2.challengeToken']) !empty($result['authentication']['threeds2.challengeToken'])
) { ) {
return json_encode( return $this->adyenHelper->buildThreeDS2ProcessResponseJson($result['resultCode'], $result['authentication']['threeds2.challengeToken']);
array(
'threeDS2' => true,
'type' => $result['resultCode'],
'token' => $result['authentication']['threeds2.challengeToken']
)
);
} }
// Payment can get back to the original flow // Payment can get back to the original flow
...@@ -129,10 +123,6 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -129,10 +123,6 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
$quote->save(); $quote->save();
// 3DS2 flow is done, original place order flow can continue from frontend // 3DS2 flow is done, original place order flow can continue from frontend
return json_encode( return $this->adyenHelper->buildThreeDS2ProcessResponseJson();
array(
'threeDS2' => false
)
);
} }
} }
...@@ -90,8 +90,7 @@ class PaymentInformationManagement ...@@ -90,8 +90,7 @@ class PaymentInformationManagement
\Adyen\Payment\Gateway\Http\Client\TransactionPayment $transactionPayment, \Adyen\Payment\Gateway\Http\Client\TransactionPayment $transactionPayment,
\Adyen\Payment\Gateway\Validator\CheckoutResponseValidator $checkoutResponseValidator, \Adyen\Payment\Gateway\Validator\CheckoutResponseValidator $checkoutResponseValidator,
\Adyen\Payment\Gateway\Validator\ThreeDS2ResponseValidator $threeDS2ResponseValidator \Adyen\Payment\Gateway\Validator\ThreeDS2ResponseValidator $threeDS2ResponseValidator
) ) {
{
$this->checkoutSession = $checkoutSession; $this->checkoutSession = $checkoutSession;
$this->adyenHelper = $adyenHelper; $this->adyenHelper = $adyenHelper;
$this->adyenRequestHelper = $adyenRequestHelper; $this->adyenRequestHelper = $adyenRequestHelper;
...@@ -109,8 +108,7 @@ class PaymentInformationManagement ...@@ -109,8 +108,7 @@ class PaymentInformationManagement
public function afterSavePaymentInformation( public function afterSavePaymentInformation(
\Magento\Checkout\Model\PaymentInformationManagement $subject, \Magento\Checkout\Model\PaymentInformationManagement $subject,
$response $response
) ) {
{
// Get payment and cart information from session // Get payment and cart information from session
$quote = $this->checkoutSession->getQuote(); $quote = $this->checkoutSession->getQuote();
$payment = $quote->getPayment(); $payment = $quote->getPayment();
...@@ -121,11 +119,7 @@ class PaymentInformationManagement ...@@ -121,11 +119,7 @@ class PaymentInformationManagement
$payment->unsAdditionalInformation('placeOrder'); $payment->unsAdditionalInformation('placeOrder');
$quote->save(); $quote->save();
return json_encode( return $this->adyenHelper->buildThreeDS2ProcessResponseJson();
array(
'threeDS2' => false
)
);
} }
// Init request array // Init request array
...@@ -181,21 +175,17 @@ class PaymentInformationManagement ...@@ -181,21 +175,17 @@ class PaymentInformationManagement
// Check if 3DS2.0 validation is needed or not // Check if 3DS2.0 validation is needed or not
// In case 3DS2.0 validation is necessary send the type and token back to the frontend // In case 3DS2.0 validation is necessary send the type and token back to the frontend
if (!empty($paymentsResponse['resultCode']) && if (!empty($paymentsResponse['resultCode']) &&
( ($paymentsResponse['resultCode'] == 'IdentifyShopper' ||
$paymentsResponse['resultCode'] == 'IdentifyShopper' || $paymentsResponse['resultCode'] == 'ChallengeShopper')
$paymentsResponse['resultCode'] == 'ChallengeShopper'
)
) { ) {
if ($this->threeDS2ResponseValidator->validate(array("response" => $paymentsResponse, "payment" => $payment))->isValid()) { if ($this->threeDS2ResponseValidator->validate(array(
"response" => $paymentsResponse,
"payment" => $payment
))->isValid()) {
$quote->save(); $quote->save();
return json_encode( return $this->adyenHelper->buildThreeDS2ProcessResponseJson($payment->getAdditionalInformation('threeDS2Type'),
array( $payment->getAdditionalInformation('threeDS2Token'));
"threeDS2" => true,
"type" => $payment->getAdditionalInformation('threeDS2Type'),
"token" => $payment->getAdditionalInformation('threeDS2Token')
)
);
} }
} }
...@@ -210,10 +200,6 @@ class PaymentInformationManagement ...@@ -210,10 +200,6 @@ class PaymentInformationManagement
$quote->save(); $quote->save();
// Original flow can continue, return to frontend and place the order // Original flow can continue, return to frontend and place the order
return json_encode( return $this->adyenHelper->buildThreeDS2ProcessResponseJson();
array(
'threeDS2' => false
)
);
} }
} }
...@@ -206,23 +206,24 @@ define( ...@@ -206,23 +206,24 @@ define(
var threeDS2Node = document.getElementById('threeDS2Container'); var threeDS2Node = document.getElementById('threeDS2Container');
if (type == "IdentifyShopper") { if (type == "IdentifyShopper") {
fullScreenLoader.startLoader();
self.threeDS2Component = self.checkout self.threeDS2Component = self.checkout
.create('threeDS2DeviceFingerprint', { .create('threeDS2DeviceFingerprint', {
fingerprintToken: token, fingerprintToken: token,
onComplete: function(result) { onComplete: function(result) {
fullScreenLoader.stopLoader();
self.processThreeDS2(result.data); self.processThreeDS2(result.data);
$('#threeDS2Modal').modal("closeModal");
},
onError: function(result) {
// TODO error handling show error message
console.log(result);
} }
}); });
} else if (type == "ChallengeShopper") { } else if (type == "ChallengeShopper") {
self.threeDS2Component.unmount(threeDS2Node); $('#threeDS2Modal').modal({
if (self.threeDS2Component) { // disable user to hide popup
self.threeDS2Component.unmount(cardNode); clickableOverlay: false,
} // empty buttons, we don't need that
buttons: []
});
$('#threeDS2Modal').modal("openModal");
self.threeDS2Component = self.checkout self.threeDS2Component = self.checkout
.create('threeDS2Challenge', { .create('threeDS2Challenge', {
...@@ -230,10 +231,6 @@ define( ...@@ -230,10 +231,6 @@ define(
onComplete: function(result) { onComplete: function(result) {
self.processThreeDS2(result.data); self.processThreeDS2(result.data);
$('#threeDS2Modal').modal("closeModal"); $('#threeDS2Modal').modal("closeModal");
},
onError: function(result) {
// TODO error handling show error message
console.log(result);
} }
}); });
} }
...@@ -269,9 +266,9 @@ define( ...@@ -269,9 +266,9 @@ define(
/** /**
* Builds the payment details part of the payment information reqeust * Builds the payment details part of the payment information reqeust
* *
* @returns {{method: *, additional_data: {cc_type: *, number: *, cvc, expiryMonth: *, expiryYear: *, holderName: *, store_cc: *, number_of_installments: *}}} * @returns {{method: *, additional_data: {card_brand: *, cc_type: *, number: *, cvc: *, expiryMonth: *, expiryYear: *, holderName: *, store_cc: (boolean|*), number_of_installments: *, java_enabled: boolean, screen_color_depth: number, screen_width, screen_height, timezone_offset: *}}}
*/ */
getData: function () { getCcData: function () {
var browserInfo = threeDS2Utils.getBrowserInfo(); var browserInfo = threeDS2Utils.getBrowserInfo();
var data = { var data = {
...@@ -296,6 +293,16 @@ define( ...@@ -296,6 +293,16 @@ define(
this.vaultEnabler.visitAdditionalData(data); this.vaultEnabler.visitAdditionalData(data);
return data; return data;
}, },
/**
* Get data for place order
* @returns {{method: *}}
*/
getData: function() {
var data = {
'method': this.item.method
};
return data;
},
/** /**
* Returns state of place order button * Returns state of place order button
* @returns {boolean} * @returns {boolean}
...@@ -324,12 +331,7 @@ define( ...@@ -324,12 +331,7 @@ define(
self.isPlaceOrderActionAllowed(false); self.isPlaceOrderActionAllowed(false);
//update payment method information if additional data was changed //update payment method information if additional data was changed
selectPaymentMethodAction(this.getData()); selectPaymentMethodAction(this.getCcData());
// here I can remove all the data collected from the card component
// OR I should create a new getData function which just retrieves the data necessary for the 3ds2 flow
setPaymentMethodAction(this.messageContainer).done( setPaymentMethodAction(this.messageContainer).done(
function (responseJSON) { function (responseJSON) {
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
...@@ -351,16 +353,6 @@ define( ...@@ -351,16 +353,6 @@ define(
var response = JSON.parse(responseJSON); var response = JSON.parse(responseJSON);
if (!!response.threeDS2) { if (!!response.threeDS2) {
$('#threeDS2Modal').modal({
// disable user to hide popup
clickableOverlay: false,
// empty buttons, we don't need that
buttons: []
});
$('#threeDS2Modal').modal("openModal");
// render component // render component
self.renderThreeDS2Component(response.type, response.token); self.renderThreeDS2Component(response.type, response.token);
} else { } else {
......
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