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 42c7908f authored by Alessio Zampatti's avatar Alessio Zampatti Committed by cyattilakiss

PW-390 Pay with Google for Web (#496)

* PW-390 Added Google Pay skeleton/configuration

* PW-390 Added Google Pay method on frontend + authorizationdatabuilder, config provider/logo

* PW-390 Save BillingAgreements for googlepay

* PW-390 Save vault token for GooglePay, fix button issue on css, fix isavailable promise

* remove comments

* Set token invisible for shopper if payment method is Google Pay

* split formatAmount into formatAmount and decimalNumbers

* PW-390 use only one merchant identifier for test/live, reformat comment in configuration
parent 1cff4df9
<?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\Block\Form;
class GooglePay extends \Magento\Payment\Block\Form
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
/**
* GooglePay constructor.
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Adyen\Payment\Helper\Data $adyenHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->adyenHelper = $adyenHelper;
}
}
<?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\Block\Info;
class GooglePay extends Cc
{
}
<?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\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Setup\Exception;
class GooglePayAuthorizationDataBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
private $adyenLogger;
/**
* GooglePayAuthorizationDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
$this->adyenHelper = $adyenHelper;
$this->adyenLogger = $adyenLogger;
}
public function build(array $buildSubject)
{
$request = [];
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
$token = $payment->getAdditionalInformation('token');
$request['paymentMethod']['type'] = 'paywithgoogle';
// get payment data
if ($token) {
$parsedToken = json_decode($token);
try {
$request['paymentMethod']['paywithgoogle.token'] = $parsedToken;
} catch (\Exception $exception) {
$this->adyenLogger->addAdyenDebug("exception: " . $exception->getMessage());
}
} else {
$this->adyenLogger->addAdyenDebug("PaymentToken is empty");
}
return $request;
}
}
...@@ -140,6 +140,11 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -140,6 +140,11 @@ class VaultDetailsHandler implements HandlerInterface
$paymentToken = $this->paymentTokenFactory->create( $paymentToken = $this->paymentTokenFactory->create(
PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
); );
if (strpos($cardType, "paywithgoogle") !== false && !empty($additionalData['paymentMethodVariant'])) {
$cardType = $additionalData['paymentMethodVariant'];
$paymentToken->setIsVisible(false);
}
$paymentToken->setGatewayToken($token); $paymentToken->setGatewayToken($token);
$paymentToken->setExpiresAt($this->getExpirationDate($expirationDate)); $paymentToken->setExpiresAt($this->getExpirationDate($expirationDate));
......
...@@ -248,14 +248,12 @@ class Data extends AbstractHelper ...@@ -248,14 +248,12 @@ class Data extends AbstractHelper
]; ];
} }
/** /**
* Return the formatted currency. Adyen accepts the currency in multiple formats. * Return the number of decimals for the specified currency
* @param $amount
* @param $currency * @param $currency
* @return string * @return int
*/ */
public function formatAmount($amount, $currency) public function decimalNumbers($currency)
{ {
switch ($currency) { switch ($currency) {
case "CVE": case "CVE":
...@@ -287,10 +285,21 @@ class Data extends AbstractHelper ...@@ -287,10 +285,21 @@ class Data extends AbstractHelper
default: default:
$format = 2; $format = 2;
} }
return $format;
}
return (int)number_format($amount, $format, '', ''); /**
* Return the formatted amount. Adyen accepts the currency in multiple formats.
* @param $amount
* @param $currency
* @return int
*/
public function formatAmount($amount, $currency)
{
return (int)number_format($amount, $this->decimalNumbers($currency), '', '');
} }
/** /**
* Tax Percentage needs to be in minor units for Adyen * Tax Percentage needs to be in minor units for Adyen
* *
...@@ -623,6 +632,39 @@ class Data extends AbstractHelper ...@@ -623,6 +632,39 @@ class Data extends AbstractHelper
} }
} }
/**
* Gives back adyen_google_pay configuration values
*
* @param $field
* @param null $storeId
* @return mixed
*/
public function getAdyenGooglePayConfigData($field, $storeId = null)
{
return $this->getConfigData($field, 'adyen_google_pay', $storeId);
}
/**
* Gives back adyen_google_pay configuration values
*
* @param $field
* @param null $storeId
* @return mixed
*/
public function isAdyenGooglePayEnabled($storeId = null)
{
return $this->getAdyenGooglePayConfigData('active', $storeId);
}
/**
* @param null $storeId
* @return mixed
*/
public function getAdyenGooglePayMerchantIdentifier($storeId = null)
{
return $this->getAdyenGooglePayConfigData('merchant_identifier', $storeId);
}
/** /**
* Retrieve decrypted hmac key * Retrieve decrypted hmac key
* *
......
...@@ -107,6 +107,9 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -107,6 +107,9 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
// Billing agreement is CC // Billing agreement is CC
if (isset($data['card']['number'])) { if (isset($data['card']['number'])) {
$ccType = $data['variant']; $ccType = $data['variant'];
if (strpos($ccType, "paywithgoogle") !== false && !empty($data['paymentMethodVariant'])) {
$ccType = $data['paymentMethodVariant'];
}
$ccTypes = $this->adyenHelper->getCcTypesAltData(); $ccTypes = $this->adyenHelper->getCcTypesAltData();
if (isset($ccTypes[$ccType])) { if (isset($ccTypes[$ccType])) {
...@@ -190,7 +193,10 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -190,7 +193,10 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
} }
// Billing agreement is CC // Billing agreement is CC
$ccType = $contractDetail['paymentMethod']; $ccType = $variant = $contractDetail['paymentMethod'];
if (strpos($ccType, "paywithgoogle") !== false && !empty($contractDetail['paymentMethodVariant'])) {
$ccType = $variant = $contractDetail['paymentMethodVariant'];
}
$ccTypes = $this->adyenHelper->getCcTypesAltData(); $ccTypes = $this->adyenHelper->getCcTypesAltData();
if (isset($ccTypes[$ccType])) { if (isset($ccTypes[$ccType])) {
...@@ -243,7 +249,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -243,7 +249,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
'expiryMonth' => $expiryDate[0], 'expiryMonth' => $expiryDate[0],
'expiryYear' => $expiryDate[1] 'expiryYear' => $expiryDate[1]
], ],
'variant' => $contractDetail['paymentMethod'], 'variant' => $variant,
'contractTypes' => explode(',', $recurringType) 'contractTypes' => explode(',', $recurringType)
]; ];
......
<?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\Ui;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
class AdyenGooglePayConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_google_pay';
const GOOGLE_PAY_VAULT_CODE = 'adyen_google_pay_vault';
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $urlBuilder;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;
/**
* AdyenGooglePayConfigProvider constructor.
*
* @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\UrlInterface $urlBuilder
*/
public function __construct(
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Checkout\Model\Session $checkoutSession
) {
$this->paymentHelper = $paymentHelper;
$this->adyenHelper = $adyenHelper;
$this->_request = $request;
$this->urlBuilder = $urlBuilder;
$this->storeManager = $storeManager;
$this->checkoutSession = $checkoutSession;
}
/**
* Retrieve assoc array of checkout configuration
*
* @return array
*/
public function getConfig()
{
// set to active
$config = [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->urlBuilder->getUrl(
'checkout/onepage/success/',
['_secure' => $this->_getRequest()->isSecure()]
)
]
]
];
$config['payment']['adyenGooglePay']['active'] = (bool)$this->adyenHelper->isAdyenGooglePayEnabled($this->storeManager->getStore()->getId());
$config['payment']['adyenGooglePay']['checkoutEnvironment'] = $this->adyenHelper->getCheckoutEnvironment($this->storeManager->getStore()->getId());
$config['payment']['adyenGooglePay']['locale'] = $this->adyenHelper->getStoreLocale($this->storeManager->getStore()->getId());
$config['payment']['adyenGooglePay']['merchantAccount'] = $this->adyenHelper->getAdyenMerchantAccount("adyen_google_pay", $this->storeManager->getStore()->getId());
$quote = $this->checkoutSession->getQuote();
$currency = $quote->getCurrency();
$config['payment']['adyenGooglePay']['format'] = $this->adyenHelper->decimalNumbers($currency);
$config['payment']['adyenGooglePay']['merchantIdentifier'] = $this->adyenHelper->getAdyenGooglePayMerchantIdentifier($this->storeManager->getStore()->getId());
return $config;
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
}
<?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\Ui;
use Adyen\Payment\Helper\Data;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterface;
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
use Magento\Framework\UrlInterface;
/**
* Class TokenGooglePayUiComponentProvider
*/
class TokenGooglePayUiComponentProvider implements TokenUiComponentProviderInterface
{
/**
* @var TokenUiComponentInterfaceFactory
*/
private $componentFactory;
/**
* @var Data
*/
private $adyenHelper;
/**
* @param TokenUiComponentInterfaceFactory $componentFactory
* @param UrlInterface $urlBuilder
*/
public function __construct(
TokenUiComponentInterfaceFactory $componentFactory,
Data $adyenHelper
) {
$this->componentFactory = $componentFactory;
$this->adyenHelper = $adyenHelper;
}
/**
* Get UI component for token
* @param PaymentTokenInterface $paymentToken
* @return TokenUiComponentInterface
*/
public function getComponentForToken(PaymentTokenInterface $paymentToken)
{
$details = json_decode($paymentToken->getTokenDetails() ?: '{}', true);
$details['icon'] = $this->adyenHelper->getVariantIcon($details['type']);
$component = $this->componentFactory->create(
[
'config' => [
'code' => AdyenGooglePayConfigProvider::GOOGLE_PAY_VAULT_CODE,
TokenUiComponentProviderInterface::COMPONENT_DETAILS => $details,
TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash()
],
'name' => 'Adyen_Payment/js/view/payment/method-renderer/vault'
]
);
return $component;
}
}
\ No newline at end of file
<?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\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/**
* Class AdyenGooglePayDataAssignObserver
*/
class AdyenGooglePayDataAssignObserver extends AbstractDataAssignObserver
{
const TOKEN = 'token';
/**
* @var array
*/
protected $additionalInformationList = [
self::TOKEN
];
/**
* @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);
// set ccType
$paymentInfo->setCcType('google_pay');
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
<include path="Adyen_Payment::system/adyen_pay_by_mail.xml"/> <include path="Adyen_Payment::system/adyen_pay_by_mail.xml"/>
<include path="Adyen_Payment::system/adyen_boleto.xml"/> <include path="Adyen_Payment::system/adyen_boleto.xml"/>
<include path="Adyen_Payment::system/adyen_apple_pay.xml"/> <include path="Adyen_Payment::system/adyen_apple_pay.xml"/>
<include path="Adyen_Payment::system/adyen_google_pay.xml"/>
</group> </group>
</section> </section>
</system> </system>
......
<?xml version="1.0"?>
<!--
~ ######
~ ######
~ ############ ####( ###### #####. ###### ############ ############
~ ############# #####( ###### #####. ###### ############# #############
~ ###### #####( ###### #####. ###### ##### ###### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ######
~ ############# ############# ############# ############# ##### ######
~ ############ ############ ############# ############ ##### ######
~ ######
~ #############
~ ############
~
~ 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>
-->
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="adyen_google_pay" translate="label" type="text" sortOrder="460" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[Google Pay integration]]></label>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
<fieldset_css>adyen-method-adyen-cc</fieldset_css>
<comment>Process Google Pay transactions</comment>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_google_pay/active</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
<config_path>payment/adyen_google_pay/title</config_path>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sort Order</label>
<frontend_class>validate-number</frontend_class>
<config_path>payment/adyen_google_pay/sort_order</config_path>
</field>
<field id="merchant_identifier" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Google Merchant Identifier</label>
<comment><![CDATA[Your Google Merchant ID from Google Pay Developer Profile. For more information refer to <a href="https://developers.google.com/pay/api/web/guides/test-and-deploy/deploy-production-environment#obtain-your-merchantID">Obtain your merchantID</a>.]]></comment>
<config_path>payment/adyen_google_pay/merchant_identifier</config_path>
</field>
</group>
</include>
\ No newline at end of file
...@@ -73,6 +73,14 @@ ...@@ -73,6 +73,14 @@
<tokenFormat>Adyen\Payment\Model\InstantPurchase\CreditCard\TokenFormatter</tokenFormat> <tokenFormat>Adyen\Payment\Model\InstantPurchase\CreditCard\TokenFormatter</tokenFormat>
</instant_purchase> </instant_purchase>
</adyen_cc_vault> </adyen_cc_vault>
<adyen_google_pay_vault>
<model>AdyenPaymentGooglePayVaultFacade</model>
<title>Stored Cards (Adyen)</title>
<instant_purchase>
<available>Adyen\Payment\Model\InstantPurchase\CreditCard\AvailabilityChecker</available>
<tokenFormat>Adyen\Payment\Model\InstantPurchase\CreditCard\TokenFormatter</tokenFormat>
</instant_purchase>
</adyen_google_pay_vault>
<adyen_oneclick> <adyen_oneclick>
<active>1</active> <active>1</active>
<model>AdyenPaymentOneclickFacade</model> <model>AdyenPaymentOneclickFacade</model>
...@@ -201,6 +209,27 @@ ...@@ -201,6 +209,27 @@
<can_cancel>1</can_cancel> <can_cancel>1</can_cancel>
<group>adyen</group> <group>adyen</group>
</adyen_apple_pay> </adyen_apple_pay>
<adyen_google_pay>
<active>0</active>
<model>AdyenPaymentGooglePayFacade</model>
<title>Adyen Google Pay</title>
<allowspecific>0</allowspecific>
<sort_order>10</sort_order>
<payment_action>authorize</payment_action>
<is_gateway>1</is_gateway>
<can_use_checkout>1</can_use_checkout>
<can_authorize>1</can_authorize>
<can_capture>1</can_capture>
<can_capture_partial>1</can_capture_partial>
<can_use_internal>0</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<can_authorize_vault>1</can_authorize_vault>
<can_capture_vault>1</can_capture_vault>
<group>adyen</group>
</adyen_google_pay>
</payment> </payment>
</default> </default>
</config> </config>
...@@ -53,6 +53,16 @@ ...@@ -53,6 +53,16 @@
<argument name="vaultProvider" xsi:type="object">AdyenPaymentCcFacade</argument> <argument name="vaultProvider" xsi:type="object">AdyenPaymentCcFacade</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayVaultFacade" type="Magento\Vault\Model\Method\Vault">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenGooglePayConfigProvider::GOOGLE_PAY_VAULT_CODE
</argument>
<argument name="config" xsi:type="object">AdyenPaymentCcVaultConfig</argument>
<argument name="valueHandlerPool" xsi:type="object">AdyenPaymentCcVaultPaymentValueHandlerPool</argument>
<argument name="vaultProvider" xsi:type="object">AdyenPaymentGooglePayFacade</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentOneclickFacade" type="Adyen\Payment\Model\Method\Adapter"> <virtualType name="AdyenPaymentOneclickFacade" type="Adyen\Payment\Model\Method\Adapter">
<arguments> <arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider::CODE</argument> <argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider::CODE</argument>
...@@ -113,6 +123,16 @@ ...@@ -113,6 +123,16 @@
<argument name="commandPool" xsi:type="object">AdyenPaymentApplePayCommandPool</argument> <argument name="commandPool" xsi:type="object">AdyenPaymentApplePayCommandPool</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenGooglePayConfigProvider::CODE</argument>
<argument name="formBlockType" xsi:type="string">Adyen\Payment\Block\Form\GooglePay</argument>
<argument name="infoBlockType" xsi:type="string">Adyen\Payment\Block\Info\GooglePay</argument>
<argument name="valueHandlerPool" xsi:type="object">AdyenPaymentGooglePayValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">AdyenPaymentGooglePayValidatorPool</argument>
<argument name="commandPool" xsi:type="object">AdyenPaymentGooglePayCommandPool</argument>
</arguments>
</virtualType>
<!-- Value handlers infrastructure --> <!-- Value handlers infrastructure -->
<virtualType name="AdyenPaymentCcVaultPaymentValueHandler" type="VaultPaymentDefaultValueHandler"> <virtualType name="AdyenPaymentCcVaultPaymentValueHandler" type="VaultPaymentDefaultValueHandler">
...@@ -232,6 +252,19 @@ ...@@ -232,6 +252,19 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">AdyenPaymentGooglePayConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentGooglePayConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">AdyenPaymentGooglePayConfig</argument>
</arguments>
</virtualType>
<!-- Configuration reader --> <!-- Configuration reader -->
<virtualType name="AdyenPaymentGenericConfig" type="Magento\Payment\Gateway\Config\Config"> <virtualType name="AdyenPaymentGenericConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments> <arguments>
...@@ -280,6 +313,11 @@ ...@@ -280,6 +313,11 @@
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider::CODE</argument> <argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider::CODE</argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenGooglePayConfigProvider::CODE</argument>
</arguments>
</virtualType>
<!-- Commands infrastructure --> <!-- Commands infrastructure -->
...@@ -306,6 +344,7 @@ ...@@ -306,6 +344,7 @@
<arguments> <arguments>
<argument name="executors" xsi:type="array"> <argument name="executors" xsi:type="array">
<item name="adyen_cc" xsi:type="string">AdyenPaymentCcCommandManager</item> <item name="adyen_cc" xsi:type="string">AdyenPaymentCcCommandManager</item>
<item name="adyen_google_pay" xsi:type="string">AdyenPaymentCcCommandManager</item>
</argument> </argument>
</arguments> </arguments>
</type> </type>
...@@ -393,6 +432,18 @@ ...@@ -393,6 +432,18 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="authorize" xsi:type="string">AdyenPaymentGooglePayAuthorizeCommand</item>
<item name="capture" xsi:type="string">AdyenPaymentCaptureCommand</item>
<item name="void" xsi:type="string">AdyenPaymentCancelCommand</item>
<item name="refund" xsi:type="string">AdyenPaymentRefundCommand</item>
<item name="cancel" xsi:type="string">AdyenPaymentCancelCommand</item>
</argument>
</arguments>
</virtualType>
<!-- Authorization command --> <!-- Authorization command -->
<virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand"> <virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments> <arguments>
...@@ -454,6 +505,16 @@ ...@@ -454,6 +505,16 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
<argument name="requestBuilder" xsi:type="object">AdyenPaymentGooglePayAuthorizeRequest</argument>
<argument name="transferFactory" xsi:type="object">Adyen\Payment\Gateway\Http\TransferFactory</argument>
<argument name="client" xsi:type="object">Adyen\Payment\Gateway\Http\Client\TransactionPayment</argument>
<argument name="validator" xsi:type="object">CheckoutResponseValidator</argument>
<argument name="handler" xsi:type="object">AdyenPaymentGooglePayResponseHandlerComposite</argument>
</arguments>
</virtualType>
<!-- Capture command --> <!-- Capture command -->
<virtualType name="AdyenPaymentCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand"> <virtualType name="AdyenPaymentCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments> <arguments>
...@@ -586,6 +647,21 @@ ...@@ -586,6 +647,21 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayAuthorizeRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments>
<argument name="builders" xsi:type="array">
<item name="merchantaccount" xsi:type="string">Adyen\Payment\Gateway\Request\MerchantAccountDataBuilder</item>
<item name="customer" xsi:type="string">Adyen\Payment\Gateway\Request\CustomerDataBuilder</item>
<item name="customerip" xsi:type="string">Adyen\Payment\Gateway\Request\CustomerIpDataBuilder</item>
<item name="address" xsi:type="string">Adyen\Payment\Gateway\Request\AddressDataBuilder</item>
<item name="payment" xsi:type="string">Adyen\Payment\Gateway\Request\PaymentDataBuilder</item>
<item name="browserinfo" xsi:type="string">Adyen\Payment\Gateway\Request\BrowserInfoDataBuilder</item>
<item name="transaction" xsi:type="string">Adyen\Payment\Gateway\Request\GooglePayAuthorizationDataBuilder</item>
<item name="recurring" xsi:type="string">Adyen\Payment\Gateway\Request\RecurringDataBuilder</item>
</argument>
</arguments>
</virtualType>
<!-- Capture Request --> <!-- Capture Request -->
<virtualType name="AdyenPaymentCaptureRequest" type="Magento\Payment\Gateway\Request\BuilderComposite"> <virtualType name="AdyenPaymentCaptureRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments> <arguments>
...@@ -633,6 +709,15 @@ ...@@ -633,6 +709,15 @@
</argument> </argument>
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="payment_details" xsi:type="string">Adyen\Payment\Gateway\Response\CheckoutPaymentsDetailsHandler</item>
<item name="vault_details" xsi:type="string">Adyen\Payment\Gateway\Response\VaultDetailsHandler</item>
<item name="payment_comments" xsi:type="string">Adyen\Payment\Gateway\Response\CheckoutPaymentCommentHistoryHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentPosCloudResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain"> <virtualType name="AdyenPaymentPosCloudResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments> <arguments>
...@@ -769,6 +854,19 @@ ...@@ -769,6 +854,19 @@
</arguments> </arguments>
</virtualType> </virtualType>
<virtualType name="AdyenPaymentGooglePayValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">AdyenGooglePayCountryValidator</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenGooglePayCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">AdyenPaymentGooglePayConfig</argument>
</arguments>
</virtualType>
<!--General Response validator--> <!--General Response validator-->
<virtualType name="GeneralResponseValidator" type="Adyen\Payment\Gateway\Validator\GeneralResponseValidator"> <virtualType name="GeneralResponseValidator" type="Adyen\Payment\Gateway\Validator\GeneralResponseValidator">
......
...@@ -41,4 +41,7 @@ ...@@ -41,4 +41,7 @@
<event name="payment_method_assign_data_adyen_apple_pay"> <event name="payment_method_assign_data_adyen_apple_pay">
<observer name="adyen_apple_pay_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenApplePayDataAssignObserver" /> <observer name="adyen_apple_pay_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenApplePayDataAssignObserver" />
</event> </event>
<event name="payment_method_assign_data_adyen_google_pay">
<observer name="adyen_google_pay_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenGooglePayDataAssignObserver" />
</event>
</config> </config>
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
<item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider</item> <item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider</item>
<item name="adyen_pos_cloud_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider</item> <item name="adyen_pos_cloud_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider</item>
<item name="adyen_apple_pay_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider</item> <item name="adyen_apple_pay_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider</item>
<item name="adyen_google_pay_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenGooglePayConfigProvider</item>
</argument> </argument>
</arguments> </arguments>
</type> </type>
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
<arguments> <arguments>
<argument name="tokenUiComponentProviders" xsi:type="array"> <argument name="tokenUiComponentProviders" xsi:type="array">
<item name="adyen_cc" xsi:type="object">Adyen\Payment\Model\Ui\TokenUiComponentProvider</item> <item name="adyen_cc" xsi:type="object">Adyen\Payment\Model\Ui\TokenUiComponentProvider</item>
<item name="adyen_google_pay" xsi:type="object">Adyen\Payment\Model\Ui\TokenGooglePayUiComponentProvider</item>
</argument> </argument>
</arguments> </arguments>
</type> </type>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<referenceContainer name="content"> <referenceContainer name="content">
<referenceBlock name="vault.cards.list"> <referenceBlock name="vault.cards.list">
<block class="Adyen\Payment\Block\Customer\CardRenderer" name="adyen.card.renderer" <block class="Adyen\Payment\Block\Customer\CardRenderer" name="adyen.card.renderer"
template="Magento_Vault::customer_account/credit_card.phtml"/> template="Magento_Vault::customer_account/credit_card.phtml" cacheable="false"/>
</referenceBlock> </referenceBlock>
</referenceContainer> </referenceContainer>
</body> </body>
......
...@@ -103,6 +103,11 @@ ...@@ -103,6 +103,11 @@
height: 43px; height: 43px;
} }
.checkout-payment-method .payment-method-title label div.adyen-sprite.adyen_google_pay {
background: url(../images/logos/Google-Pay-Mark.png) no-repeat;
height: 43px;
}
.checkout-payment-method .input-text._has-datepicker { .checkout-payment-method .input-text._has-datepicker {
width: 20%; width: 20%;
margin-right: 10px; margin-right: 10px;
...@@ -176,6 +181,11 @@ ...@@ -176,6 +181,11 @@
min-height: 42px; /* override magento min-height */ min-height: 42px; /* override magento min-height */
} }
.gpay-button:hover, .gpay-button:active, .gpay-button:focus{
background-repeat: no-repeat;
background-position: center center;
}
/* /*
Custom style for ideal component Custom style for ideal component
*/ */
......
...@@ -55,6 +55,10 @@ define( ...@@ -55,6 +55,10 @@ define(
{ {
type: 'adyen_pos_cloud', type: 'adyen_pos_cloud',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-pos-cloud-method' component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-pos-cloud-method'
},
{
type: 'adyen_google_pay',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-google-pay-method'
} }
); );
/** Add view logic here if needed */ /** Add view logic here if needed */
...@@ -69,10 +73,19 @@ define( ...@@ -69,10 +73,19 @@ define(
checkoutCardComponentScriptTag.src = self.getCheckoutCardComponentSource(); checkoutCardComponentScriptTag.src = self.getCheckoutCardComponentSource();
checkoutCardComponentScriptTag.type = "text/javascript"; checkoutCardComponentScriptTag.type = "text/javascript";
document.body.appendChild(checkoutCardComponentScriptTag); document.body.appendChild(checkoutCardComponentScriptTag);
if (this.isGooglePayEnabled()) {
var googlepayscript = document.createElement('script');
googlepayscript.src = "https://pay.google.com/gp/p/js/pay.js";
googlepayscript.type = "text/javascript";
document.body.appendChild(googlepayscript);
}
}, },
getCheckoutCardComponentSource: function() { getCheckoutCardComponentSource: function() {
return window.checkoutConfig.payment.checkoutCardComponentSource; return window.checkoutConfig.payment.checkoutCardComponentSource;
}, },
isGooglePayEnabled: function() {
return window.checkoutConfig.payment.adyenGooglePay.active;
}
}); });
} }
); );
\ No newline at end of file
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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>
*/
/*browser:true*/
/*global define*/
define(
[
'ko',
'jquery',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/action/place-order',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'Magento_Checkout/js/model/full-screen-loader',
'mage/url',
'Magento_Vault/js/view/payment/vault-enabler'
],
function (ko, $, Component, placeOrderAction, quote, urlBuilder, fullScreenLoader, url, VaultEnabler) {
'use strict';
/**
* Shareble adyen checkout component
* @type {AdyenCheckout}
*/
var checkoutComponent;
return Component.extend({
self: this,
defaults: {
template: 'Adyen_Payment/payment/google-pay-form',
googlePayToken: null,
googlePayAllowed: null
},
/**
* @returns {Boolean}
*/
isShowLegend: function () {
return true;
},
setPlaceOrderHandler: function (handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function (handler) {
this.validateHandler = handler;
},
getCode: function () {
return 'adyen_google_pay';
},
getData: function () {
return {
'method': this.item.method,
'additional_data': {}
};
},
isActive: function () {
return true;
},
initObservable: function () {
this._super()
.observe([
'googlePayToken',
'googlePayAllowed'
]);
return this;
}, initialize: function () {
var self = this;
this.vaultEnabler = new VaultEnabler();
this.vaultEnabler.setPaymentCode(this.getVaultCode());
this.vaultEnabler.isActivePaymentTokenEnabler(false);
this._super();
},
renderGooglePay: function () {
var self = this;
var googlePayNode = document.getElementById('googlePay');
self.checkoutComponent = new AdyenCheckout({
locale: self.getLocale(),
risk: {
enabled: false
}
});
var googlepay = self.checkoutComponent.create('paywithgoogle', {
environment: self.getCheckoutEnvironment().toUpperCase(),
configuration: {
// Adyen's merchant account
gatewayMerchantId: self.getMerchantAccount(),
// https://developers.google.com/pay/api/web/reference/object#MerchantInfo
merchantIdentifier: self.getMerchantIdentifier(),
merchantName: self.getMerchantAccount()
},
// Payment
amount: self.formatAmount(quote.totals().grand_total, self.getFormat()),
currency: quote.totals().quote_currency_code,
totalPriceStatus: 'FINAL',
onChange: function (state) {
if (!!state.isValid) {
self.googlePayToken(state.data.paymentMethod["paywithgoogle.token"]);
self.getPlaceOrderDeferredObject()
.fail(
function () {
fullScreenLoader.stopLoader();
self.isPlaceOrderActionAllowed(true);
}
).done(
function () {
self.afterPlaceOrder();
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
}
);
}
},
buttonColor: 'black', // default/black/white
buttonType: 'long', // long/short
showButton: true // show or hide the Google Pay button
});
var promise = googlepay.isAvailable();
promise.then(function (success) {
self.googlePayAllowed(true);
googlepay.mount(googlePayNode);
}, function (error) {
console.log(error);
self.googlePayAllowed(false);
});
},
getCheckoutEnvironment: function () {
return window.checkoutConfig.payment.adyenGooglePay.checkoutEnvironment;
},
isGooglePayAllowed: function () {
if (this.googlePayAllowed()) {
return true;
}
return false;
},
getMerchantAccount: function () {
return window.checkoutConfig.payment.adyenGooglePay.merchantAccount;
},
showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo;
},
getLocale: function () {
return window.checkoutConfig.payment.adyenGooglePay.locale;
},
getFormat: function () {
return window.checkoutConfig.payment.adyenGooglePay.format;
},
getMerchantIdentifier: function () {
return window.checkoutConfig.payment.adyenGooglePay.merchantIdentifier;
},
context: function () {
return this;
},
validate: function () {
return true;
},
getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
getPlaceOrderUrl: function () {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
/**
* Get data for place order
* @returns {{method: *}}
*/
getData: function () {
return {
'method': "adyen_google_pay",
'additional_data': {
'token': this.googlePayToken()
}
};
},
/**
* Return the formatted currency. Adyen accepts the currency in multiple formats.
* @param $amount
* @param $currency
* @return string
*/
formatAmount: function (amount, format) {
return Math.round(amount * (Math.pow(10, format)))
},
isVaultEnabled: function () {
return this.vaultEnabler.isVaultEnabled();
},
getVaultCode: function () {
return "adyen_google_pay_vault";
}
});
}
);
<!--
~ ######
~ ######
~ ############ ####( ###### #####. ###### ############ ############
~ ############# #####( ###### #####. ###### ############# #############
~ ###### #####( ###### #####. ###### ##### ###### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ######
~ ############# ############# ############# ############# ##### ######
~ ############ ############ ############# ############ ##### ######
~ ######
~ #############
~ ############
~
~ 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>
-->
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method-title field choice">
<input type="radio"
name="payment[method]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<label data-bind="attr: {'for': getCode()}" class="label">
<!-- ko if: showLogo() -->
<div data-bind="attr: { 'class': 'adyen-sprite ' + getCode() }"></div>
<!--/ko-->
<span data-bind="text: getTitle()"></span>
</label>
</div>
<div class="payment-method-content">
<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="field number googlePay">
<div afterRender="renderGooglePay()" data-bind="attr: { id: 'googlePay'}">
<!-- ko ifnot: isGooglePayAllowed() -->
Google Pay is not available
<!--/ko--></div>
</div>
<div id="adyen-google-pay-button" class="google-pay-button-with-text google-pay-button-black-with-text"
data-bind= "click: placeOrder">
<span class="logo"></span>
</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