Skip to content

Commit 61deb8b

Browse files
rikterbeekcyattilakissacampos1916msilvagarcia
authored
[PW-2390] Add action component on success page if presentToShopper an… (Adyen#775)
* [PW-2390] Add action component on success page if presentToShopper and Action result is provided. * Added a adyenCheckout3101 requireJS variable to use latest component version. This we can use for all new payment method integrations or upgrades. * Success block loads all values needed for the component * Success page renders the component * Layout renders the styles.css file for showing the component with the right styling * Update view/frontend/templates/checkout/success.phtml Co-authored-by: Attila Kiss <[email protected]> * Update view/frontend/templates/checkout/success.phtml Co-authored-by: Attila Kiss <[email protected]> * Update view/frontend/templates/checkout/success.phtml Co-authored-by: Attila Kiss <[email protected]> * remove empty lines * remove escapeHTML as it is json causing the JSON.parse to fail * Update view/frontend/templates/checkout/success.phtml * Update view/frontend/templates/checkout/success.phtml Co-authored-by: Attila Kiss <[email protected]> Co-authored-by: Attila Kiss <[email protected]> Co-authored-by: Ángel Campos <[email protected]> Co-authored-by: Marcos Garcia <[email protected]>
1 parent fb08cd3 commit 61deb8b

File tree

4 files changed

+107
-26
lines changed

4 files changed

+107
-26
lines changed

Block/Checkout/Success.php

+61-10
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,28 @@ class Success extends \Magento\Framework\View\Element\Template
3232
/**
3333
* @var \Magento\Sales\Model\Order $order
3434
*/
35-
protected $_order;
35+
protected $order;
3636

3737
/**
3838
* @var \Magento\Checkout\Model\Session
3939
*/
40-
protected $_checkoutSession;
40+
protected $checkoutSession;
4141

4242
/**
4343
* @var \Magento\Checkout\Model\OrderFactory
4444
*/
45-
protected $_orderFactory;
45+
protected $orderFactory;
46+
47+
48+
/**
49+
* @var \Adyen\Payment\Helper\Data
50+
*/
51+
protected $adyenHelper;
4652

4753
/**
48-
* @var \Magento\Framework\Pricing\Helper\Data
54+
* @var \Magento\Store\Model\StoreManagerInterface
4955
*/
50-
public $priceHelper;
56+
protected $storeManager;
5157

5258
/**
5359
* Success constructor.
@@ -63,11 +69,15 @@ public function __construct(
6369
\Magento\Checkout\Model\Session $checkoutSession,
6470
\Magento\Sales\Model\OrderFactory $orderFactory,
6571
\Magento\Framework\Pricing\Helper\Data $priceHelper,
72+
\Adyen\Payment\Helper\Data $adyenHelper,
73+
\Magento\Store\Model\StoreManagerInterface $storeManager,
6674
array $data = []
6775
) {
68-
$this->_checkoutSession = $checkoutSession;
69-
$this->_orderFactory = $orderFactory;
76+
$this->checkoutSession = $checkoutSession;
77+
$this->orderFactory = $orderFactory;
7078
$this->priceHelper = $priceHelper;
79+
$this->adyenHelper = $adyenHelper;
80+
$this->storeManager = $storeManager;
7181
parent::__construct($context, $data);
7282
}
7383

@@ -151,14 +161,55 @@ public function getMultibancoData()
151161
return $result;
152162
}
153163

164+
/**
165+
* If PresentToShopper resultCode and action has provided render this with the checkout component on the success page
166+
* @return bool
167+
*/
168+
public function renderAction()
169+
{
170+
if (
171+
!empty($this->getOrder()->getPayment()->getAdditionalInformation('resultCode')) &&
172+
$this->getOrder()->getPayment()->getAdditionalInformation('resultCode') == 'PresentToShopper' &&
173+
!empty($this->getOrder()->getPayment()->getAdditionalInformation('action'))
174+
) {
175+
return true;
176+
}
177+
return false;
178+
}
179+
180+
public function getAction()
181+
{
182+
return json_encode($this->getOrder()->getPayment()->getAdditionalInformation('action'));
183+
}
184+
185+
public function getLocale()
186+
{
187+
return $this->adyenHelper->getCurrentLocaleCode(
188+
$this->storeManager->getStore()->getId()
189+
);
190+
}
191+
192+
public function getOriginKey()
193+
{
194+
return $this->adyenHelper->getOriginKeyForBaseUrl();
195+
}
196+
197+
public function getEnvironment()
198+
{
199+
return $this->adyenHelper->getCheckoutEnvironment(
200+
$this->storeManager->getStore()->getId()
201+
);
202+
}
203+
204+
154205
/**
155206
* @return \Magento\Sales\Model\Order
156207
*/
157208
public function getOrder()
158209
{
159-
if ($this->_order == null) {
160-
$this->_order = $this->_orderFactory->create()->load($this->_checkoutSession->getLastOrderId());
210+
if ($this->order == null) {
211+
$this->order = $this->orderFactory->create()->load($this->checkoutSession->getLastOrderId());
161212
}
162-
return $this->_order;
213+
return $this->order;
163214
}
164215
}

view/frontend/layout/checkout_onepage_success.xml

+11-6
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@
2222
* Author: Adyen <[email protected]>
2323
*/
2424
-->
25-
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
26-
<body>
27-
<referenceContainer name="order.success.additional.info">
28-
<block class="Adyen\Payment\Block\Checkout\Success" name="onepage.success.adyen_payment" template="checkout/success.phtml" cacheable="false"/>
29-
</referenceContainer>
30-
</body>
25+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
27+
<head>
28+
<css src="Adyen_Payment::css/styles.css"/>
29+
</head>
30+
<body>
31+
<referenceContainer name="order.success.additional.info">
32+
<block class="Adyen\Payment\Block\Checkout\Success" name="onepage.success.adyen_payment"
33+
template="checkout/success.phtml" cacheable="false"/>
34+
</referenceContainer>
35+
</body>
3136
</page>

view/frontend/requirejs-config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var config = {
1414
},
1515
map: {
1616
'*': {
17-
'adyenCheckout': 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/3.4.0/adyen.js'
17+
'adyenCheckout': 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/3.4.0/adyen.js',
18+
'adyenCheckout3101': 'https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/3.10.1/adyen.js'
1819
}
1920
}
2021
};

view/frontend/templates/checkout/success.phtml

+33-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,28 @@
2525
* @var \Adyen\Payment\Block\Checkout\Success $block
2626
*/
2727
?>
28-
<?php if ($block->isBoletoPayment()): ?>
28+
<?php if ($block->renderAction()): ?>
29+
<script type="text/javascript">
30+
require([
31+
'jquery',
32+
'adyenCheckout3101'
33+
], function ($, AdyenCheckout) {
34+
var action = JSON.parse('<?= /* @noEscape */ $block->getAction(); ?>');
35+
var checkoutComponent = new AdyenCheckout({
36+
locale: '<?= $block->escapeHtml($block->getLocale()); ?>',
37+
environment: '<?= $block->escapeHtml($block->getEnvironment()); ?>',
38+
originKey: '<?= $block->escapeHtml($block->getOriginKey()); ?>'
39+
});
40+
try {
41+
checkoutComponent.createFromAction(action).mount('#ActionContainer');
42+
} catch(err) {
43+
// Action component cannot be created
44+
}
45+
});
46+
</script>
47+
<div id="ActionContainer"></div>
48+
<?php else: ?>
49+
<?php if ($block->isBoletoPayment()): ?>
2950
<?php
3051
$boletoData = $block->getBoletoData();
3152
?>
@@ -37,21 +58,22 @@
3758
</p>
3859
<?php endif; ?>
3960

40-
<?php if (!empty($block->getBankTransferData())): ?>
61+
<?php if (!empty($block->getBankTransferData())): ?>
4162
<?php
4263
$banktranferData = $block->getBankTransferData();
4364
$order = $block->getOrder();
4465
?>
4566
<h2><?= $block->escapeHtml(__('Pay using Bank transfer')); ?></h2>
4667
<p><?= $block->escapeHtml(
47-
__('Please transfer the amount using the reference below to the following bank account')
68+
__('Please transfer the amount using the reference below to the following bank account')
4869
); ?></p>
4970
<table>
5071
<tbody>
5172
<?php if (!empty($order->getGrandTotal())): ?>
5273
<tr>
5374
<th scope="row"><?= $block->escapeHtml(__('Amount')); ?></th>
54-
<td><?= /* @noEscape */ $order->formatPrice($order->getGrandTotal()); ?></td>
75+
<td><?= /* @noEscape */
76+
$order->formatPrice($order->getGrandTotal()); ?></td>
5577
</tr>
5678
<?php endif; ?>
5779

@@ -97,10 +119,10 @@
97119
?>
98120
<h2><?= $block->escapeHtml(__('Pay using Multibanco')); ?></h2>
99121
<p><?= $block->escapeHtml(
100-
__(
101-
'Please pay with the provided Multibanco reference and entity before payment deadline in order to ' .
102-
'complete our payment'
103-
)
122+
__(
123+
'Please pay with the provided Multibanco reference and entity before payment deadline in order to ' .
124+
'complete our payment'
125+
)
104126
); ?></p>
105127
<table>
106128
<tbody>
@@ -122,7 +144,8 @@
122144
<?php if (!empty($multibancoData['totalAmount'])): ?>
123145
<tr>
124146
<th scope="row"><?= $block->escapeHtml(__('Amount')); ?></th>
125-
<td><?= /* @noEscape */ $block->priceHelper->currency($multibancoData['totalAmount']['value']);?>
147+
<td><?= /* @noEscape */
148+
$block->priceHelper->currency($multibancoData['totalAmount']['value']); ?>
126149
</td>
127150
</tr>
128151
<?php endif; ?>
@@ -135,4 +158,5 @@
135158
<?php endif; ?>
136159
</tbody>
137160
</table>
161+
<?php endif; ?>
138162
<?php endif; ?>

0 commit comments

Comments
 (0)