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 2ac407f2 authored by Rik ter Beek's avatar Rik ter Beek Committed by Aleffio

store card on adyen side for pos payments

diff --git a/Model/AdyenInitiateTerminalApi.php b/Model/AdyenInitiateTerminalApi.php
index 464ae2e..a21c9c9 100644
--- a/Model/AdyenInitiateTerminalApi.php
+++ b/Model/AdyenInitiateTerminalApi.php
@@ -22,11 +22,14 @@
  * Author: Adyen <magento@adyen.com>
  */

+
 namespace Adyen\Payment\Model;

+
 use Adyen\Payment\Api\AdyenInitiateTerminalApiInterface;
 use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider;
 use Adyen\Util\Util;
+use Magento\Payment\Gateway\Http\ClientInterface;

 class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
 {
@@ -90,9 +93,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface

     /**
      * Trigger sync call on terminal
-     *
      * @return mixed
-     * @throws \Magento\Framework\Exception\LocalizedException
      */
     public function initiate()
     {
@@ -106,69 +107,71 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
         $poiId = $this->_adyenHelper->getPoiId();
         $serviceID = date("dHis");
         $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00");
+
+        // if custom is logged in send data accross
         $customerId = $quote->getCustomerId();

-        $request = [
-            'SaleToPOIRequest' =>
-                [
-                    'MessageHeader' =>
-                        [
-                            'MessageType' => 'Request',
-                            'MessageClass' => 'Service',
-                            'MessageCategory' => 'Payment',
-                            'SaleID' => 'Magento2Cloud',
-                            'POIID' => $poiId,
-                            'ProtocolVersion' => '3.0',
-                            'ServiceID' => $serviceID,
-                        ],
-                    'PaymentRequest' =>
-                        [
-                            'SaleData' =>
-                                [
-                                    'TokenRequestedType' => 'Customer',
-                                    'SaleTransactionID' =>
-                                        [
-                                            'TransactionID' => $reference,
-                                            'TimeStamp' => $timeStamper,
-                                        ],
-                                ],
-                            'PaymentTransaction' =>
-                                [
-                                    'AmountsReq' =>
-                                        [
-                                            'Currency' => $quote->getCurrency()->getQuoteCurrencyCode(),
-                                            'RequestedAmount' => $quote->getGrandTotal(),
-                                        ],
-                                ],
-                            'PaymentData' =>
-                                [
-                                    'PaymentType' => $transactionType,
-                                ],
-                        ],
-                ],
-        ];
-
-        // If customer exists add it into the request to store request
+
+        $newStructureValue = "";
+//        $oldValueStructure = "";
         if (!empty($customerId)) {
             $shopperEmail = $quote->getCustomerEmail();
             $recurringContract = $this->_adyenHelper->getAdyenPosCloudConfigData('recurring_type');

-            if (!empty($recurringContract)) {
-                $jsonValue = '{
+            $jsonValue = '{
                 "shopperEmail": "' . $shopperEmail . '",
                 "shopperReference": "' . $customerId . '",
                 "recurringContract": "' . $recurringContract . '"
              }';

-                $request['SaleToPOIRequest']['PaymentRequest']['SaleData']['SaleToAcquirerData'] = base64_encode($jsonValue);
-            }
+            $jsonValueBase64 = base64_encode($jsonValue);
+
+            $newStructureValue = '"SaleToAcquirerData":"' . $jsonValueBase64 . '",';
+//            $oldValueStructure = '"SaleToAcquirerData":"shopperEmail=' . $shopperEmail . '&shopperReference=' . $customerId . '&recurringContract=' . $recurringContract . '",';
         }

+        $json = '{
+                    "SaleToPOIRequest": {
+                        "MessageHeader": {
+                            "MessageType": "Request",
+                            "MessageClass": "Service",
+                            "MessageCategory": "Payment",
+                            "SaleID": "Magento2Cloud",
+                            "POIID": "' . $poiId . '",
+                            "ProtocolVersion": "3.0",
+                            "ServiceID": "' . $serviceID . '"
+                        },
+                        "PaymentRequest": {
+                            "SaleData": {
+                                ' . $newStructureValue . '
+                                "TokenRequestedType":"Customer",
+                                "SaleTransactionID": {
+                                    "TransactionID": "' . $reference . '",
+                                    "TimeStamp": "' . $timeStamper . '"
+                                },
+                                "TokenRequestedType": "Customer"
+                            },
+                            "PaymentTransaction": {
+                                "AmountsReq": {
+                                    "Currency": "' . $quote->getCurrency()->getQuoteCurrencyCode() . '",
+                                    "RequestedAmount": ' . $quote->getGrandTotal() . '
+                                }
+                            },
+                            "PaymentData": {
+                                "PaymentType": "' . $transactionType . '"
+                            }
+                        }
+                    }
+                }
+            ';
+
+        $params = json_decode($json, true); //Create associative array for passing along
+
         $quote->getPayment()->getMethodInstance()->getInfoInstance()->setAdditionalInformation('serviceID',
             $serviceID);

         try {
-            $response = $service->runTenderSync($request);
+            $response = $service->runTenderSync($params);
         } catch (\Adyen\AdyenException $e) {
             //Not able to perform a payment
             $this->_adyenLogger->addAdyenDebug("adyenexception");
parent c202c694
...@@ -22,11 +22,14 @@ ...@@ -22,11 +22,14 @@
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Model; namespace Adyen\Payment\Model;
use Adyen\Payment\Api\AdyenInitiateTerminalApiInterface; use Adyen\Payment\Api\AdyenInitiateTerminalApiInterface;
use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider; use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider;
use Adyen\Util\Util; use Adyen\Util\Util;
use Magento\Payment\Gateway\Http\ClientInterface;
class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
{ {
...@@ -90,9 +93,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface ...@@ -90,9 +93,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
/** /**
* Trigger sync call on terminal * Trigger sync call on terminal
*
* @return mixed * @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/ */
public function initiate() public function initiate()
{ {
...@@ -106,69 +107,71 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface ...@@ -106,69 +107,71 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
$poiId = $this->_adyenHelper->getPoiId(); $poiId = $this->_adyenHelper->getPoiId();
$serviceID = date("dHis"); $serviceID = date("dHis");
$timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00"); $timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00");
// if custom is logged in send data accross
$customerId = $quote->getCustomerId(); $customerId = $quote->getCustomerId();
$request = [
'SaleToPOIRequest' => $newStructureValue = "";
[ // $oldValueStructure = "";
'MessageHeader' =>
[
'MessageType' => 'Request',
'MessageClass' => 'Service',
'MessageCategory' => 'Payment',
'SaleID' => 'Magento2Cloud',
'POIID' => $poiId,
'ProtocolVersion' => '3.0',
'ServiceID' => $serviceID,
],
'PaymentRequest' =>
[
'SaleData' =>
[
'TokenRequestedType' => 'Customer',
'SaleTransactionID' =>
[
'TransactionID' => $reference,
'TimeStamp' => $timeStamper,
],
],
'PaymentTransaction' =>
[
'AmountsReq' =>
[
'Currency' => $quote->getCurrency()->getQuoteCurrencyCode(),
'RequestedAmount' => $quote->getGrandTotal(),
],
],
'PaymentData' =>
[
'PaymentType' => $transactionType,
],
],
],
];
// If customer exists add it into the request to store request
if (!empty($customerId)) { if (!empty($customerId)) {
$shopperEmail = $quote->getCustomerEmail(); $shopperEmail = $quote->getCustomerEmail();
$recurringContract = $this->_adyenHelper->getAdyenPosCloudConfigData('recurring_type'); $recurringContract = $this->_adyenHelper->getAdyenPosCloudConfigData('recurring_type');
if (!empty($recurringContract)) { $jsonValue = '{
$jsonValue = '{
"shopperEmail": "' . $shopperEmail . '", "shopperEmail": "' . $shopperEmail . '",
"shopperReference": "' . $customerId . '", "shopperReference": "' . $customerId . '",
"recurringContract": "' . $recurringContract . '" "recurringContract": "' . $recurringContract . '"
}'; }';
$request['SaleToPOIRequest']['PaymentRequest']['SaleData']['SaleToAcquirerData'] = base64_encode($jsonValue); $jsonValueBase64 = base64_encode($jsonValue);
}
$newStructureValue = '"SaleToAcquirerData":"' . $jsonValueBase64 . '",';
// $oldValueStructure = '"SaleToAcquirerData":"shopperEmail=' . $shopperEmail . '&shopperReference=' . $customerId . '&recurringContract=' . $recurringContract . '",';
} }
$json = '{
"SaleToPOIRequest": {
"MessageHeader": {
"MessageType": "Request",
"MessageClass": "Service",
"MessageCategory": "Payment",
"SaleID": "Magento2Cloud",
"POIID": "' . $poiId . '",
"ProtocolVersion": "3.0",
"ServiceID": "' . $serviceID . '"
},
"PaymentRequest": {
"SaleData": {
' . $newStructureValue . '
"TokenRequestedType":"Customer",
"SaleTransactionID": {
"TransactionID": "' . $reference . '",
"TimeStamp": "' . $timeStamper . '"
},
"TokenRequestedType": "Customer"
},
"PaymentTransaction": {
"AmountsReq": {
"Currency": "' . $quote->getCurrency()->getQuoteCurrencyCode() . '",
"RequestedAmount": ' . $quote->getGrandTotal() . '
}
},
"PaymentData": {
"PaymentType": "' . $transactionType . '"
}
}
}
}
';
$params = json_decode($json, true); //Create associative array for passing along
$quote->getPayment()->getMethodInstance()->getInfoInstance()->setAdditionalInformation('serviceID', $quote->getPayment()->getMethodInstance()->getInfoInstance()->setAdditionalInformation('serviceID',
$serviceID); $serviceID);
try { try {
$response = $service->runTenderSync($request); $response = $service->runTenderSync($params);
} catch (\Adyen\AdyenException $e) { } catch (\Adyen\AdyenException $e) {
//Not able to perform a payment //Not able to perform a payment
$this->_adyenLogger->addAdyenDebug("adyenexception"); $this->_adyenLogger->addAdyenDebug("adyenexception");
......
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