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 0efb78c7 authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

PW-1190 add magento info into request (#605)

* PW-1190 add magento info into request

* PW-1190 add unit tests and fix current ones. Add codesniffer and magento/magento-coding-standard to easy validate code within the repo. Add paypal reference as we have a depencency to paypal module as we need it for billing agreements.

* [WIP] Feature/pw 1190 travis (#606)

* add travis file

* add credentials encrypted will only work for local branches

* fix commands

* add ruleset

* update travis to execute all plugin code

* remove params as it is declared into the ruleset. and update version codesniffer

* only fail and show errors not warnings

* added arguments p and n for better visibility and ignoring warning in ruleset xml

* use relative path to fix local check
parent f57578c5
language: php
sudo: false
php:
- 7.1
- 7.2
- 7.3
install:
- echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json
- composer install --prefer-dist
script:
- php vendor/bin/phpcs
- vendor/bin/phpunit -c Test/phpunit.xml
\ No newline at end of file
......@@ -56,23 +56,34 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
*/
protected $checkoutSession;
/**
* @var \Magento\Framework\App\ProductMetadataInterface
*/
protected $productMetadata;
/**
* AdyenInitiateTerminalApi constructor.
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Magento\Checkout\Model\Session $_checkoutSession
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param array $data
* @throws \Adyen\AdyenException
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
array $data = []
) {
$this->adyenHelper = $adyenHelper;
$this->adyenLogger = $adyenLogger;
$this->checkoutSession = $checkoutSession;
$this->productMetadata = $productMetadata;
$this->storeId = $storeManager->getStore()->getId();
// initialize client
......@@ -132,7 +143,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
'SaleID' => 'Magento2Cloud',
'POIID' => $poiId,
'ProtocolVersion' => '3.0',
'ServiceID' => $serviceID,
'ServiceID' => $serviceID
],
'PaymentRequest' =>
[
......@@ -142,19 +153,19 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
'SaleTransactionID' =>
[
'TransactionID' => $reference,
'TimeStamp' => $timeStamper,
],
'TimeStamp' => $timeStamper
]
],
'PaymentTransaction' =>
[
'AmountsReq' =>
[
'Currency' => $quote->getCurrency()->getQuoteCurrencyCode(),
'RequestedAmount' => doubleval($quote->getGrandTotal()),
],
],
],
],
'RequestedAmount' => doubleval($quote->getGrandTotal())
]
]
]
]
];
if (!empty($payload['number_of_installments'])) {
......@@ -179,22 +190,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
}
$customerId = $this->getCustomerId($quote);
// If customer exists add it into the request to store request
if (!empty($customerId)) {
$shopperEmail = $quote->getCustomerEmail();
$recurringContract = $this->adyenHelper->getAdyenPosCloudConfigData('recurring_type', $this->storeId);
if (!empty($recurringContract) && !empty($shopperEmail)) {
$recurringDetails = [
'shopperEmail' => $shopperEmail,
'shopperReference' => strval($customerId),
'recurringContract' => $recurringContract
];
$request['SaleToPOIRequest']['PaymentRequest']['SaleData']['SaleToAcquirerData'] = http_build_query($recurringDetails);
}
}
$request = $this->addSaleToAquirerData($request, $quote);
$quote->getPayment()->getMethodInstance()->getInfoInstance()->setAdditionalInformation(
'serviceID',
......@@ -231,9 +227,9 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
}
/**
* This getter makes it possible to overwrite the customer id from other plugins
* Use this function to get the customer id so we can keep using this plugin in the UCD
*
* This getter makes it possible to overwrite the customer id from other plugins
* Use this function to get the customer id so we can keep using this plugin in the UCD
*
* @param Quote $quote
* @return mixed
*/
......@@ -241,4 +237,38 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
{
return $quote->getCustomerId();
}
/**
* Add SaleToAquirerData for storing for recurring transactions and able to track platform and version
* When upgrading to new version of library we can use the client methods
* @param $request
* @param $quote
* @return mixed
*/
public function addSaleToAquirerData($request, $quote)
{
$customerId = $this->getCustomerId($quote);
$saleToAcquirerData = [];
// If customer exists add it into the request to store request
if (!empty($customerId)) {
$shopperEmail = $quote->getCustomerEmail();
$recurringContract = $this->adyenHelper->getAdyenPosCloudConfigData('recurring_type', $this->storeId);
if (!empty($recurringContract) && !empty($shopperEmail)) {
$saleToAcquirerData['shopperEmail'] = $shopperEmail;
$saleToAcquirerData['shopperReference'] = (string)$customerId;
$saleToAcquirerData['recurringContract'] = $recurringContract;
}
}
$saleToAcquirerData['applicationInfo']['merchantApplication']['version'] = $this->adyenHelper->getModuleVersion();
$saleToAcquirerData['applicationInfo']['merchantApplication']['name'] = $this->adyenHelper->getModuleName();
$saleToAcquirerData['applicationInfo']['externalPlatform']['version'] = $this->productMetadata->getVersion();
$saleToAcquirerData['applicationInfo']['externalPlatform']['name'] = $this->productMetadata->getName();
$saleToAcquirerDataBase64 = base64_encode(json_encode($saleToAcquirerData));
$request['SaleToPOIRequest']['PaymentRequest']['SaleData']['SaleToAcquirerData'] = $saleToAcquirerDataBase64;
return $request;
}
}
......@@ -59,6 +59,8 @@ class DataTest extends \PHPUnit\Framework\TestCase
$localeResolver = $this->getSimpleMock(\Magento\Framework\Locale\ResolverInterface::class);
$config = $this->getSimpleMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
$helperBackend = $this->getSimpleMock(\Magento\Backend\Helper\Data::class);
$serializer = $this->getSimpleMock( \Magento\Framework\Serialize\SerializerInterface::class);
$componentRegistrar = $this->getSimpleMock(\Magento\Framework\Component\ComponentRegistrarInterface::class);
$this->dataHelper = new \Adyen\Payment\Helper\Data(
$context,
......@@ -80,7 +82,9 @@ class DataTest extends \PHPUnit\Framework\TestCase
$agreementResourceModel,
$localeResolver,
$config,
$helperBackend
$helperBackend,
$serializer,
$componentRegistrar
);
}
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2019 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
class AdyenInitiateTerminalApiTest extends \PHPUnit\Framework\TestCase
{
/**
* @var
*/
private $adyenInitiateTerminalApi;
private const MODULE_VERSION = '1.0.0';
private const MODULE_NAME = 'ModuleVersion';
private const PLATFORM_VERSION = '2.0.0';
private const PLATFORM_NAME = 'PlatformName';
private const CUSTOMER_ID = '1';
private const CUSTOMER_EMAIL = 'customer@example.com';
private const RECURRING_TYPE = 'ONECLICK,RECURRING';
private function getSimpleMock($originalClassName)
{
return $this->getMockBuilder($originalClassName)
->disableOriginalConstructor()
->getMock();
}
public function setUp()
{
$adyenHelper = $this->getSimpleMock(\Adyen\Payment\Helper\Data::class);
$adyenLogger = $this->getSimpleMock(\Adyen\Payment\Logger\AdyenLogger::class);
$checkoutSession = $this->getSimpleMock(\Magento\Checkout\Model\Session::class);
$storeManager = $this->getSimpleMock(\Magento\Store\Model\StoreManagerInterface::class);
$productMetadata = $this->getSimpleMock(\Magento\Framework\App\ProductMetadataInterface::class);
$store = $this->getSimpleMock(\Magento\Store\Api\Data\StoreInterface::class);
$storeManager->method('getStore')
->will($this->returnValue($store));
$adyenHelper->method('getModuleVersion')
->will($this->returnValue(self::MODULE_VERSION));
// Create a map of arguments to return values.
$map = [
['pos_timeout', null, ''],
['recurring_type', null, self::RECURRING_TYPE]
];
// Configure the stub.
$adyenHelper->method('getAdyenPosCloudConfigData')
->will($this->returnValueMap($map));
$adyenHelper->method('getModuleName')
->will($this->returnValue(self::MODULE_NAME));
$productMetadata->method('getVersion')
->will($this->returnValue(self::PLATFORM_VERSION));
$productMetadata->method('getName')
->will($this->returnValue(self::PLATFORM_NAME));
$this->adyenInitiateTerminalApi = new \Adyen\Payment\Model\AdyenInitiateTerminalApi(
$adyenHelper,
$adyenLogger,
$checkoutSession,
$storeManager,
$productMetadata
);
}
/** @throws \Exception */
public function testAddSaleToAquirerData()
{
$quote = $this->getSimpleMock(\Magento\Quote\Model\Quote::class);
$request = [];
$result = $this->adyenInitiateTerminalApi->addSaleToAquirerData($request, $quote);
$appInfo = [
'applicationInfo' => [
'merchantApplication' => [
'version' => self::MODULE_VERSION,
'name' => self::MODULE_NAME
],
'externalPlatform' => [
'version' => self::PLATFORM_VERSION,
'name' => self::PLATFORM_NAME
]
]
];
$saleToAcquirerData = base64_encode(json_encode($appInfo));
$resultArrayExpected = [
'SaleToPOIRequest' => [
'PaymentRequest' => [
'SaleData' => [
'SaleToAcquirerData' => $saleToAcquirerData
]
]
]
];
$this->assertEquals($resultArrayExpected, $result);
}
public function testAddSaleToAquirerDataLoggedInCustomer()
{
$quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote')
->disableOriginalConstructor()
->setMethods(
[
'getId',
'getCustomerEmail',
'getCustomerId'
]
)
->getMock();
$quoteMock->expects($this->any())
->method('getCustomerId')
->willReturn(self::CUSTOMER_ID);
$quoteMock->expects($this->atLeastOnce())
->method('getCustomerEmail')
->willReturn(self::CUSTOMER_EMAIL);
$request = [];
$result = $this->adyenInitiateTerminalApi->addSaleToAquirerData($request, $quoteMock);
$appInfo = [
'shopperEmail' => self::CUSTOMER_EMAIL,
'shopperReference' => self::CUSTOMER_ID,
'recurringContract' => self::RECURRING_TYPE,
'applicationInfo' => [
'merchantApplication' => [
'version' => self::MODULE_VERSION,
'name' => self::MODULE_NAME
],
'externalPlatform' => [
'version' => self::PLATFORM_VERSION,
'name' => self::PLATFORM_NAME
]
]
];
$saleToAcquirerData = base64_encode(json_encode($appInfo));
$resultArrayExpected = [
'SaleToPOIRequest' => [
'PaymentRequest' => [
'SaleData' => [
'SaleToAcquirerData' => $saleToAcquirerData
]
]
]
];
$this->assertEquals($resultArrayExpected, $result);
}
}
\ No newline at end of file
......@@ -23,4 +23,3 @@
*/
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../../../../vendor/autoload.php';
......@@ -16,10 +16,13 @@
"require": {
"adyen/php-api-library": "~4.1",
"magento/framework": ">=101.0.8 <102 || >=102.0.1",
"magento/module-vault": "101.*"
"magento/module-vault": "101.*",
"magento/module-paypal": "*"
},
"require-dev": {
"phpunit/phpunit": "~6.5.0"
"phpunit/phpunit": "~6.5.0",
"magento/magento-coding-standard": "*",
"squizlabs/php_codesniffer": "~3.5.3"
},
"autoload": {
"files": [
......@@ -38,6 +41,12 @@
"test": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpunit -c Test/phpunit.xml"
],
"post-install-cmd": [
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
],
"post-update-cmd": [
"([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
]
}
}
<?xml version="1.0"?>
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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>
*/
-->
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<exclude-pattern type="relative">vendor/*</exclude-pattern>
<file>.</file>
<arg value="p"/>
<arg value="n"/>
<rule ref="Magento2"/>
</ruleset>
\ No newline at end of file
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