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 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
{
/**
* Trigger sync call on terminal
* @param string $payload
* @return mixed
*/
public function initiate();
public function initiate($payload);
}
......@@ -92,7 +92,7 @@ class TransactionPosCloudSync implements ClientInterface
//always do status call and return the response of the status call
$service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$poiId = $this->adyenHelper->getPoiId($this->storeId);
$poiId = $request['terminalID'];
$newServiceID = date("dHis");
$statusDate = date("U");
......
......@@ -41,7 +41,8 @@ class PosCloudBuilder implements BuilderInterface
return [
"response" => $payment->getAdditionalInformation("terminalResponse"),
"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
}
/**
* Return the Terminal ID for the current store/mode
* Return the Store ID for the current store/mode
*
* @param int|null $storeId
* @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
{
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
* @return mixed
* @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();
$payment = $quote->getPayment();
$payment->setMethod(AdyenPosCloudConfigProvider::CODE);
......@@ -102,7 +116,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
$service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$transactionType = \Adyen\TransactionType::NORMAL;
$poiId = $this->adyenHelper->getPoiId($this->storeId);
$serviceID = date("dHis");
$initiateDate = date("U");
$timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00");
......
......@@ -43,6 +43,11 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
*/
protected $urlBuilder;
/**
* @var \Adyen\Payment\Helper\PaymentMethods
*/
protected $paymentMethodsHelper;
/**
* AdyenHppConfigProvider constructor.
*
......@@ -51,10 +56,12 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder
\Magento\Framework\UrlInterface $urlBuilder,
\Adyen\Payment\Helper\PaymentMethods $paymentMethodsHelper
) {
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->paymentMethodsHelper = $paymentMethodsHelper;
}
/**
......@@ -77,6 +84,8 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
]
];
$config['payment']['adyenPos']['connectedTerminals'] = $this->getConnectedTerminals();
return $config;
}
......@@ -89,4 +98,19 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
{
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 @@
}
],
"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/module-vault": "101.*"
},
......
......@@ -41,24 +41,25 @@
<frontend_class>validate-number</frontend_class>
<config_path>payment/adyen_pos_cloud/sort_order</config_path>
</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">
<label>Merchant Account for Cloud API</label>
<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>
<config_path>payment/adyen_pos_cloud/pos_merchant_account</config_path>
</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>
<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>
<config_path>payment/adyen_pos_cloud/api_key_test</config_path>
</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>
<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>
......
......@@ -32,6 +32,9 @@
<event name="payment_method_assign_data_adyen_hpp">
<observer name="adyen_hpp_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenHppDataAssignObserver" />
</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">
<observer name="adyen_boleto_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
</event>
......
......@@ -57,12 +57,26 @@ define(
agreementsAssigner(paymentData);
serviceUrl = urlBuilder.createUrl('/adyen/initiate', {});
fullScreenLoader.startLoader();
let payload = {
"payload": JSON.stringify({terminal_id: self.terminalId()})
}
return storage.post(
serviceUrl
serviceUrl,
JSON.stringify(payload)
).always(function(){
self.placeOrderPos()});
return false;
},
initObservable: function () {
this._super()
.observe([
'terminalId'
]);
return this;
},
posComplete: function () {
this.afterPlaceOrder();
if (this.redirectAfterPlaceOrder) {
......@@ -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 () {
return window.checkoutConfig.payment.adyen.showLogo;
},
......
......@@ -50,6 +50,25 @@
<!--/ko-->
</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">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
......@@ -62,8 +81,7 @@
data-bind="
click: initiate,
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
css: {disabled: !isPlaceOrderActionAllowed()}
enable: getConnectedTerminals().length > 0
"
disabled>
<span data-bind="text: $t('Place Order')"></span>
......@@ -72,4 +90,3 @@
</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