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 7c6eec15 authored by cyattilakiss's avatar cyattilakiss Committed by GitHub

Merge pull request #466 from Adyen/PW-1269

PW-1269 Possibility for multiple terminals in Magento
parents f6da96d4 092904d0
...@@ -28,7 +28,8 @@ interface AdyenInitiateTerminalApiInterface ...@@ -28,7 +28,8 @@ interface AdyenInitiateTerminalApiInterface
{ {
/** /**
* Trigger sync call on terminal * Trigger sync call on terminal
* @param string $payload
* @return mixed * @return mixed
*/ */
public function initiate(); public function initiate($payload);
} }
...@@ -92,7 +92,7 @@ class TransactionPosCloudSync implements ClientInterface ...@@ -92,7 +92,7 @@ class TransactionPosCloudSync implements ClientInterface
//always do status call and return the response of the status call //always do status call and return the response of the status call
$service = $this->adyenHelper->createAdyenPosPaymentService($this->client); $service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$poiId = $this->adyenHelper->getPoiId($this->storeId); $poiId = $request['terminalID'];
$newServiceID = date("dHis"); $newServiceID = date("dHis");
$statusDate = date("U"); $statusDate = date("U");
......
...@@ -41,7 +41,8 @@ class PosCloudBuilder implements BuilderInterface ...@@ -41,7 +41,8 @@ class PosCloudBuilder implements BuilderInterface
return [ return [
"response" => $payment->getAdditionalInformation("terminalResponse"), "response" => $payment->getAdditionalInformation("terminalResponse"),
"serviceID" => $payment->getAdditionalInformation("serviceID"), "serviceID" => $payment->getAdditionalInformation("serviceID"),
"initiateDate" => $payment->getAdditionalInformation("initiateDate") "initiateDate" => $payment->getAdditionalInformation("initiateDate"),
"terminalID" => $payment->getAdditionalInformation("terminal_id")
]; ];
} }
} }
...@@ -1353,14 +1353,14 @@ class Data extends AbstractHelper ...@@ -1353,14 +1353,14 @@ class Data extends AbstractHelper
} }
/** /**
* Return the Terminal ID for the current store/mode * Return the Store ID for the current store/mode
* *
* @param int|null $storeId * @param int|null $storeId
* @return mixed * @return mixed
*/ */
public function getPoiId($storeId = null) public function getPosStoreId($storeId = null)
{ {
return $this->getAdyenPosCloudConfigData('pos_terminal_id', $storeId); return $this->getAdyenPosCloudConfigData('pos_store_id', $storeId);
} }
/** /**
......
...@@ -390,4 +390,41 @@ class PaymentMethods extends AbstractHelper ...@@ -390,4 +390,41 @@ class PaymentMethods extends AbstractHelper
{ {
return $this->getQuote()->getCustomerId(); return $this->getQuote()->getCustomerId();
} }
/**
* @return array|mixed
* @throws \Adyen\AdyenException
*/
public function getConnectedTerminals()
{
$storeId = $this->getQuote()->getStoreId();
// initialize the adyen client
$client = $this->adyenHelper->initializeAdyenClient($storeId, $this->adyenHelper->getPosApiKey($storeId));
// initialize service
$service = $this->adyenHelper->createAdyenPosPaymentService($client);
$requestParams = [
"merchantAccount" => $this->adyenHelper->getAdyenMerchantAccount('adyen_pos_cloud', $storeId),
];
// In case the POS store id is set, provide in the request
if (!empty($this->adyenHelper->getPosStoreId($storeId))) {
$requestParams['store'] = $this->adyenHelper->getPosStoreId($storeId);
}
try {
$responseData = $service->getConnectedTerminals($requestParams);
} catch (\Adyen\AdyenException $e) {
$this->adyenLogger->error(
"The getConnectedTerminals response is empty check your Adyen configuration in Magento."
);
// return empty result
return [];
}
return $responseData;
}
} }
\ No newline at end of file
...@@ -93,8 +93,22 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface ...@@ -93,8 +93,22 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
* @return mixed * @return mixed
* @throws \Exception * @throws \Exception
*/ */
public function initiate() public function initiate($payload)
{ {
// Decode payload from frontend
$payload = json_decode($payload, true);
// Validate JSON that has just been parsed if it was in a valid format
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Magento\Framework\Exception\LocalizedException(__('Terminal API initiate request was not a valid JSON'));
}
if (empty($payload['terminal_id'])) {
throw new \Adyen\AdyenException("Terminal ID is empty in initiate request");
}
$poiId = $payload['terminal_id'];
$quote = $this->checkoutSession->getQuote(); $quote = $this->checkoutSession->getQuote();
$payment = $quote->getPayment(); $payment = $quote->getPayment();
$payment->setMethod(AdyenPosCloudConfigProvider::CODE); $payment->setMethod(AdyenPosCloudConfigProvider::CODE);
...@@ -102,7 +116,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface ...@@ -102,7 +116,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
$service = $this->adyenHelper->createAdyenPosPaymentService($this->client); $service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$transactionType = \Adyen\TransactionType::NORMAL; $transactionType = \Adyen\TransactionType::NORMAL;
$poiId = $this->adyenHelper->getPoiId($this->storeId);
$serviceID = date("dHis"); $serviceID = date("dHis");
$initiateDate = date("U"); $initiateDate = date("U");
$timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00");
......
...@@ -43,6 +43,11 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface ...@@ -43,6 +43,11 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
*/ */
protected $urlBuilder; protected $urlBuilder;
/**
* @var \Adyen\Payment\Helper\PaymentMethods
*/
protected $paymentMethodsHelper;
/** /**
* AdyenHppConfigProvider constructor. * AdyenHppConfigProvider constructor.
* *
...@@ -51,10 +56,12 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface ...@@ -51,10 +56,12 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\RequestInterface $request, \Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder \Magento\Framework\UrlInterface $urlBuilder,
\Adyen\Payment\Helper\PaymentMethods $paymentMethodsHelper
) { ) {
$this->request = $request; $this->request = $request;
$this->urlBuilder = $urlBuilder; $this->urlBuilder = $urlBuilder;
$this->paymentMethodsHelper = $paymentMethodsHelper;
} }
/** /**
...@@ -77,6 +84,8 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface ...@@ -77,6 +84,8 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
] ]
]; ];
$config['payment']['adyenPos']['connectedTerminals'] = $this->getConnectedTerminals();
return $config; return $config;
} }
...@@ -89,4 +98,19 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface ...@@ -89,4 +98,19 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
{ {
return $this->request; return $this->request;
} }
/**
* @return array|mixed
* @throws \Adyen\AdyenException
*/
protected function getConnectedTerminals()
{
$connectedTerminals = $this->paymentMethodsHelper->getConnectedTerminals();
if (!empty($connectedTerminals['uniqueTerminalIds'])) {
return $connectedTerminals['uniqueTerminalIds'];
}
return [];
}
} }
<?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\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/**
* Class DataAssignObserver
*/
class AdyenPosCloudDataAssignObserver extends AbstractDataAssignObserver
{
const TERMINAL_ID = 'terminal_id';
/**
* @var array
*/
protected $additionalInformationList = [
self::TERMINAL_ID
];
/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
$data = $this->readDataArgument($observer);
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
$paymentInfo = $this->readPaymentModelArgument($observer);
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (!empty($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
} }
], ],
"require": { "require": {
"adyen/php-api-library": ">=2.0.0", "adyen/php-api-library": ">=2.1.0",
"magento/framework": ">=101.0.8 <102 || >=102.0.1", "magento/framework": ">=101.0.8 <102 || >=102.0.1",
"magento/module-vault": "101.*" "magento/module-vault": "101.*"
}, },
......
...@@ -41,24 +41,25 @@ ...@@ -41,24 +41,25 @@
<frontend_class>validate-number</frontend_class> <frontend_class>validate-number</frontend_class>
<config_path>payment/adyen_pos_cloud/sort_order</config_path> <config_path>payment/adyen_pos_cloud/sort_order</config_path>
</field> </field>
<field id="pos_terminal_id" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Unique Terminal ID for Cloud API</label>
<tooltip>Copy this from the Adyen Customer Area => Point of sale => Terminal Fleet Manager => Unique Terminal Id </tooltip>
<config_path>payment/adyen_pos_cloud/pos_terminal_id</config_path>
</field>
<field id="pos_merchant_account" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0"> <field id="pos_merchant_account" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Merchant Account for Cloud API</label> <label>Merchant Account for Cloud API</label>
<can_be_empty>1</can_be_empty> <can_be_empty>1</can_be_empty>
<tooltip>Please insert your Merchant Account name used by the Cloud API. Please leave it blank if the Merchant Account is the same as the one configured in the Required Settings</tooltip> <tooltip>Please insert your Merchant Account name used by the Cloud API. Please leave it blank if the Merchant Account is the same as the one configured in the Required Settings</tooltip>
<config_path>payment/adyen_pos_cloud/pos_merchant_account</config_path> <config_path>payment/adyen_pos_cloud/pos_merchant_account</config_path>
</field> </field>
<field id="api_key_test" translate="label" type="obscure" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0"> <field id="pos_store_id" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Store ID for Cloud API</label>
<can_be_empty>1</can_be_empty>
<tooltip>Please insert your store ID used by the Cloud API. Please leave it blank if you want to retrieve all the terminals connected to your merchant account</tooltip>
<config_path>payment/adyen_pos_cloud/pos_store_id</config_path>
</field>
<field id="api_key_test" translate="label" type="obscure" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API key for Cloud API TEST</label> <label>API key for Cloud API TEST</label>
<tooltip>Copy this from the Test Adyen Customer Area => Settings => Users => System => [web service user]=> Checkout API Key.</tooltip> <tooltip>Copy this from the Test Adyen Customer Area => Settings => Users => System => [web service user]=> Checkout API Key.</tooltip>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model> <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<config_path>payment/adyen_pos_cloud/api_key_test</config_path> <config_path>payment/adyen_pos_cloud/api_key_test</config_path>
</field> </field>
<field id="api_key_live" translate="label" type="obscure" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0"> <field id="api_key_live" translate="label" type="obscure" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>API key for Cloud API LIVE</label> <label>API key for Cloud API LIVE</label>
<tooltip>Copy this from the Live Adyen Customer Area => Settings => Users => System => [web service user]=> Checkout API Key.</tooltip> <tooltip>Copy this from the Live Adyen Customer Area => Settings => Users => System => [web service user]=> Checkout API Key.</tooltip>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model> <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
<event name="payment_method_assign_data_adyen_hpp"> <event name="payment_method_assign_data_adyen_hpp">
<observer name="adyen_hpp_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenHppDataAssignObserver" /> <observer name="adyen_hpp_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenHppDataAssignObserver" />
</event> </event>
<event name="payment_method_assign_data_adyen_pos_cloud">
<observer name="adyen_pos_cloud_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenPosCloudDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_boleto"> <event name="payment_method_assign_data_adyen_boleto">
<observer name="adyen_boleto_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" /> <observer name="adyen_boleto_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
</event> </event>
......
...@@ -57,12 +57,26 @@ define( ...@@ -57,12 +57,26 @@ define(
agreementsAssigner(paymentData); agreementsAssigner(paymentData);
serviceUrl = urlBuilder.createUrl('/adyen/initiate', {}); serviceUrl = urlBuilder.createUrl('/adyen/initiate', {});
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
let payload = {
"payload": JSON.stringify({terminal_id: self.terminalId()})
}
return storage.post( return storage.post(
serviceUrl serviceUrl,
JSON.stringify(payload)
).always(function(){ ).always(function(){
self.placeOrderPos()}); self.placeOrderPos()});
return false; return false;
}, },
initObservable: function () {
this._super()
.observe([
'terminalId'
]);
return this;
},
posComplete: function () { posComplete: function () {
this.afterPlaceOrder(); this.afterPlaceOrder();
if (this.redirectAfterPlaceOrder) { if (this.redirectAfterPlaceOrder) {
...@@ -91,6 +105,33 @@ define( ...@@ -91,6 +105,33 @@ define(
} }
) )
}, },
getConnectedTerminals: function() {
let connectedTerminals = [];
const connectedTerminalsList = window.checkoutConfig.payment.adyenPos.connectedTerminals;
for (let i = 0; i < connectedTerminalsList.length; i++) {
connectedTerminals.push(
{
key: connectedTerminalsList[i],
value: connectedTerminalsList[i]
}
);
}
return connectedTerminals;
},
/**
* Get data for place order
* @returns {{method: *}}
*/
getData: function () {
return {
'method': this.item.method,
additional_data: {
'terminal_id': this.terminalId()
}
};
},
showLogo: function () { showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo; return window.checkoutConfig.payment.adyen.showLogo;
}, },
......
...@@ -50,6 +50,25 @@ ...@@ -50,6 +50,25 @@
<!--/ko--> <!--/ko-->
</div> </div>
<div class="field required"
data-bind="attr: {id: getCode() + '_connected_terminals_div'}, visible: getConnectedTerminals().length > 0">
<label data-bind="attr: {for: getCode() + '_connected_terminals'}" class="label">
<span><!-- ko text: $t('Connected terminals')--><!-- /ko --></span>
</label>
<div class="control">
<select class="select"
name="paymentMethod[connected_terminals]"
data-bind="attr: {id: getCode() + '_connected_terminals', 'data-container': getCode() + '-connected-terminals', 'data-validate': JSON.stringify({required:true})},
options: getConnectedTerminals(),
optionsValue: 'value',
optionsText: 'key',
value: terminalId"
>
</select>
</div>
</div>
<div class="checkout-agreements-block"> <div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') --> <!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko --> <!-- ko template: getTemplate() --><!-- /ko -->
...@@ -62,8 +81,7 @@ ...@@ -62,8 +81,7 @@
data-bind=" data-bind="
click: initiate, click: initiate,
attr: {title: $t('Place Order')}, attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()), enable: getConnectedTerminals().length > 0
css: {disabled: !isPlaceOrderActionAllowed()}
" "
disabled> disabled>
<span data-bind="text: $t('Place Order')"></span> <span data-bind="text: $t('Place Order')"></span>
...@@ -72,4 +90,3 @@ ...@@ -72,4 +90,3 @@
</div> </div>
</div> </div>
</div> </div>
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