Skip to content

Commit f2c67bb

Browse files
rikterbeekattilakcyattilakiss
authoredJul 22, 2020
[PW-2087] Add Swish Payment Method and upgrade Component version to 3.4.0 This commit has the following changes: (Adyen#770)
* [PW-2087] This commit has the following changes: * With the added environment into the component is does not mather if we use the test or live component url. To remove complexity we will use the live endpoint on both environments. * Upgrade component version from 3.2.0 to 3.4.0. This requires a different way of loading in the component. This will change all payment method integration that is using checkout component. * Add swish payment method support with support for pending payment results and redering a QR code. * Environment and originKey is now as well needed for alternative payment methods so moved this into a genericConfigProvider. * The threeDS2processor is being used for 3DS2 and action payment methods. TODO we need to rename this to a generic name into the code this will mean a breaking change as interface will rename and PWA needs to adopt different API endpoint as this is a quick feature release I kept it out of scope. * Rename threeDS2PaymentData to generic adyenPaymentData as this will be used for alternative payent methods as well. * Remove unused ThreeDS2ResponseValidator file * fix phpcs warning * Remove duplicated getCheckoutEnvironment function * Update view/frontend/web/js/view/payment/method-renderer/adyen-hpp-method.js * remove debugger and add comment * Update view/frontend/web/js/view/payment/adyen-methods.js * Update Model/AdyenThreeDS2Process.php * revert hideCVC for recurring contracts needed to hide * Only for pending show back the component to the checkout form. For PresentToShopper redirect to success page to show action component. Co-authored-by: attilak <[email protected]> Co-authored-by: Attila Kiss <[email protected]>
1 parent b384b3c commit f2c67bb

16 files changed

+327
-312
lines changed
 

‎Gateway/Validator/CheckoutResponseValidator.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,23 @@ public function validate(array $validationSubject)
6868
$errorMessages = [];
6969
// validate result
7070
if (!empty($response['resultCode'])) {
71+
$payment->setAdditionalInformation('resultCode', $response['resultCode']);
7172
switch ($response['resultCode']) {
7273
case "IdentifyShopper":
7374
$payment->setAdditionalInformation('threeDSType', $response['resultCode']);
7475
$payment->setAdditionalInformation(
7576
'threeDS2Token',
7677
$response['authentication']['threeds2.fingerprintToken']
7778
);
78-
$payment->setAdditionalInformation('threeDS2PaymentData', $response['paymentData']);
79+
$payment->setAdditionalInformation('adyenPaymentData', $response['paymentData']);
7980
break;
8081
case "ChallengeShopper":
8182
$payment->setAdditionalInformation('threeDSType', $response['resultCode']);
8283
$payment->setAdditionalInformation(
8384
'threeDS2Token',
8485
$response['authentication']['threeds2.challengeToken']
8586
);
86-
$payment->setAdditionalInformation('threeDS2PaymentData', $response['paymentData']);
87+
$payment->setAdditionalInformation('adyenPaymentData', $response['paymentData']);
8788
break;
8889
case "Authorised":
8990
case "Received":
@@ -122,6 +123,12 @@ public function validate(array $validationSubject)
122123
$payment->setAdditionalInformation('pspReference', $response['pspReference']);
123124
}
124125
break;
126+
case 'Pending':
127+
$payment->setAdditionalInformation('adyenPaymentData', $response['paymentData']);
128+
if (!empty($response['action'])) {
129+
$payment->setAdditionalInformation('action', $response['action']);
130+
}
131+
break;
125132
case "RedirectShopper":
126133
$payment->setAdditionalInformation('threeDSType', $response['resultCode']);
127134

‎Gateway/Validator/ThreeDS2ResponseValidator.php

-90
This file was deleted.

‎Helper/Data.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Data extends AbstractHelper
3434
const MODULE_NAME = 'adyen-magento2';
3535
const TEST = 'test';
3636
const LIVE = 'live';
37+
// Only used for backend orders! Checkout in front-end is using different checkout version see web folder
3738
const CHECKOUT_COMPONENT_JS_LIVE = 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/3.2.0/adyen.js';
3839
const CHECKOUT_COMPONENT_JS_TEST = 'https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/3.2.0/adyen.js';
3940

@@ -680,12 +681,16 @@ public function isAdyenGooglePayEnabled($storeId = null)
680681
}
681682

682683
/**
683-
* @param null|int|string $storeId
684+
* @param string $storeId
684685
* @return mixed
685686
*/
686687
public function getAdyenGooglePayMerchantIdentifier($storeId = null)
687688
{
688-
return $this->getAdyenGooglePayConfigData('merchant_identifier', $storeId);
689+
$value = $this->getAdyenGooglePayConfigData('merchant_identifier', $storeId);
690+
if($value === null) {
691+
return '';
692+
}
693+
return $value;
689694
}
690695

691696
/**

‎Model/AdyenOrderPaymentStatus.php

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Adyen\Payment\Model;
2626

2727
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
28+
use Adyen\Payment\Model\Ui\AdyenHppConfigProvider;
2829
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;
2930

3031
class AdyenOrderPaymentStatus implements \Adyen\Payment\Api\AdyenOrderPaymentStatusInterface
@@ -87,6 +88,21 @@ public function getOrderPaymentStatus($orderId)
8788

8889
return $this->adyenHelper->buildThreeDS2ProcessResponseJson($type, $token);
8990
}
91+
92+
93+
/**
94+
* If payment method result is Pending and action is provided provide component action back to checkout
95+
*/
96+
if ($payment->getMethod() === AdyenHppConfigProvider::CODE) {
97+
$additionalInformation = $payment->getAdditionalInformation();
98+
if (
99+
!empty($additionalInformation['action']) &&
100+
$additionalInformation['resultCode'] == 'Pending'
101+
) {
102+
return json_encode(['action' => $additionalInformation['action']]);
103+
}
104+
}
105+
90106
return true;
91107
}
92108
}

‎Model/AdyenThreeDS2Process.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace Adyen\Payment\Model;
2525

26-
use \Adyen\Payment\Api\AdyenThreeDS2ProcessInterface;
26+
use Adyen\Payment\Api\AdyenThreeDS2ProcessInterface;
2727

2828
class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
2929
{
@@ -92,21 +92,23 @@ public function initiate($payload)
9292
} else {
9393
// Create order by order id
9494
$order = $this->orderFactory->create()->load($payload['orderId']);
95+
// don't send orderId to adyen. Improve that orderId and state.data are separated in payload
96+
unset($payload['orderId']);
9597
}
9698

9799
$payment = $order->getPayment();
98100

99101
// Init payments/details request
100102
$result = [];
101103

102-
if ($paymentData = $payment->getAdditionalInformation("threeDS2PaymentData")) {
104+
if ($paymentData = $payment->getAdditionalInformation("adyenPaymentData")) {
103105
// Add payment data into the request object
104106
$request = [
105-
"paymentData" => $payment->getAdditionalInformation("threeDS2PaymentData")
107+
"paymentData" => $paymentData
106108
];
107109

108110
// unset payment data from additional information
109-
$payment->unsAdditionalInformation("threeDS2PaymentData");
111+
$payment->unsAdditionalInformation("adyenPaymentData");
110112
} else {
111113
$this->adyenLogger->error("3D secure 2.0 failed, payment data not found");
112114
throw new \Magento\Framework\Exception\LocalizedException(
@@ -119,8 +121,11 @@ public function initiate($payload)
119121
$request['details']['threeds2.fingerprint'] = $payload['details']['threeds2.fingerprint'];
120122
} elseif (!empty($payload['details']['threeds2.challengeResult'])) {
121123
$request['details']['threeds2.challengeResult'] = $payload['details']['threeds2.challengeResult'];
124+
} elseif (!empty($payload)) {
125+
$request = $payload;
122126
}
123127

128+
124129
// Send the request
125130
try {
126131
$client = $this->adyenHelper->initializeAdyenClient($order->getStoreId());
@@ -161,6 +166,12 @@ public function initiate($payload)
161166

162167
$order->cancel()->save();
163168

169+
$this->adyenLogger->error(
170+
sprintf("Payment details call failed for action or 3ds2 payment method, resultcode is %s Raw API responds: %s",
171+
$result['resultCode'],
172+
print_r($result, true)
173+
));
174+
164175
throw new \Magento\Framework\Exception\LocalizedException(__('The payment is REFUSED.'));
165176
}
166177

‎Model/Ui/AdyenCcConfigProvider.php

-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ public function getConfig()
157157
$config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
158158
$config['payment']['adyenCc']['icons'] = $this->getIcons();
159159

160-
$config['payment']['adyenCc']['originKey'] = $this->_adyenHelper->getOriginKeyForBaseUrl();
161-
$config['payment']['adyenCc']['checkoutEnvironment'] = $this->_adyenHelper->getCheckoutEnvironment(
162-
$this->storeManager->getStore()->getId()
163-
);
164160

165161
// has installments by default false
166162
$config['payment']['adyenCc']['hasInstallments'] = false;

‎Model/Ui/AdyenGenericConfigProvider.php

+7-17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
3232
/**
3333
* @var \Adyen\Payment\Helper\Data
3434
*/
35-
protected $_adyenHelper;
35+
protected $adyenHelper;
3636

3737
/**
3838
* @var \Magento\Store\Model\StoreManagerInterface
@@ -48,7 +48,7 @@ public function __construct(
4848
\Adyen\Payment\Helper\Data $adyenHelper,
4949
\Magento\Store\Model\StoreManagerInterface $storeManager
5050
) {
51-
$this->_adyenHelper = $adyenHelper;
51+
$this->adyenHelper = $adyenHelper;
5252
$this->storeManager = $storeManager;
5353
}
5454

@@ -63,36 +63,26 @@ public function getConfig()
6363
'payment' => []
6464
];
6565
// show logos turned on by default
66-
if ($this->_showLogos()) {
66+
if ($this->showLogos()) {
6767
$config['payment']['adyen']['showLogo'] = true;
6868
} else {
6969
$config['payment']['adyen']['showLogo'] = false;
7070
}
7171

72-
$config['payment']['checkoutCardComponentSource'] = $this->_adyenHelper->getCheckoutCardComponentJs(
72+
$config['payment']['adyen']['originKey'] = $this->adyenHelper->getOriginKeyForBaseUrl();
73+
$config['payment']['adyen']['checkoutEnvironment'] = $this->adyenHelper->getCheckoutEnvironment(
7374
$this->storeManager->getStore()->getId()
7475
);
7576

7677
return $config;
7778
}
7879

79-
/**
80-
* Return redirect URL for method
81-
*
82-
* @param string $code
83-
* @return mixed
84-
*/
85-
protected function getMethodRedirectUrl($code)
86-
{
87-
return $this->_methods[$code]->getCheckoutRedirectUrl();
88-
}
89-
9080
/**
9181
* @return bool
9282
*/
93-
protected function _showLogos()
83+
protected function showLogos()
9484
{
95-
$showLogos = $this->_adyenHelper->getAdyenAbstractConfigData('title_renderer');
85+
$showLogos = $this->adyenHelper->getAdyenAbstractConfigData('title_renderer');
9686
if ($showLogos == \Adyen\Payment\Model\Config\Source\RenderMode::MODE_TITLE_IMAGE) {
9787
return true;
9888
}

‎Model/Ui/AdyenOneclickConfigProvider.php

-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ public function getConfig()
144144
);
145145

146146
$config['payment']['adyenOneclick']['methodCode'] = self::CODE;
147-
$config['payment']['adyenOneclick']['originKey'] = $this->_adyenHelper->getOriginKeyForBaseUrl();
148-
$config['payment']['adyenOneclick']['checkoutEnvironment'] = $this->_adyenHelper->getCheckoutEnvironment(
149-
$this->_storeManager->getStore()->getId()
150-
);
151147
$config['payment']['adyenOneclick']['locale'] = $this->_adyenHelper->getStoreLocale(
152148
$this->_storeManager->getStore()->getId()
153149
);

‎view/base/web/images/logos/swish.png

967 Bytes
Loading

‎view/frontend/requirejs-config.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ var config = {
1111
'Magento_CheckoutAgreements/js/model/place-order-mixin': true
1212
}
1313
}
14+
},
15+
map: {
16+
'*': {
17+
'adyenCheckout': 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/3.4.0/adyen.js'
18+
}
1419
}
1520
};

‎view/frontend/web/js/view/payment/adyen-methods.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,18 @@ define(
6464
/** Add view logic here if needed */
6565
return Component.extend({
6666
initialize: function () {
67-
var self = this;
6867
this._super();
6968

70-
// include checkout card component javascript
71-
var checkoutCardComponentScriptTag = document.createElement('script');
72-
checkoutCardComponentScriptTag.id = "AdyenCheckoutCardComponentScript";
73-
checkoutCardComponentScriptTag.src = self.getCheckoutCardComponentSource();
74-
checkoutCardComponentScriptTag.type = "text/javascript";
75-
document.head.appendChild(checkoutCardComponentScriptTag);
76-
7769
if (this.isGooglePayEnabled()) {
7870
var googlepayscript = document.createElement('script');
7971
googlepayscript.src = "https://pay.google.com/gp/p/js/pay.js";
8072
googlepayscript.type = "text/javascript";
8173
document.head.appendChild(googlepayscript);
8274
}
8375
},
84-
getCheckoutCardComponentSource: function () {
85-
return window.checkoutConfig.payment.checkoutCardComponentSource;
86-
},
8776
isGooglePayEnabled: function () {
8877
return window.checkoutConfig.payment.adyenGooglePay.active;
8978
}
9079
});
9180
}
92-
);
81+
);

0 commit comments

Comments
 (0)
Please sign in to comment.