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 832f4ff4 authored by Alessio Zampatti's avatar Alessio Zampatti Committed by Rik ter Beek

Feature applepay (#227)

* PW-179: Integrate Apple Pay

* PW-179: Integrate Apple Pay

* PW-179: Integrate Apple Pay

* PW-179: Added ApplePay logo

* PW-179: Fixed ApplePay button and fixed the border of the payment methods by removing the hidden dfvalue input field

* PW-179: Removed commented statements

* PW-179 cleanup code, use dynamic data for currency, language. Get domain name from store and add debugging logging

* use same template as cc because it is a card payment

* Remove duplicate promise, remove unused method and fix label description

* allow merchant validation as well for quest users
parent 3281c8ab
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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\Api;
interface AdyenRequestMerchantSessionInterface
{
/**
* @return mixed
*/
public function getMerchantSession();
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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 ApplePay extends \Magento\Payment\Block\Form
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* ApplePay 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;
}
/**
* @return array
*/
public function getApplePayShippingTypes()
{
$applePayShippingTypes = $this->_adyenHelper->getApplePayShippingTypes();
$types = [];
foreach ($applePayShippingTypes as $applePayShippingType) {
$types[$applePayShippingType['value']] = $applePayShippingType['label'];
}
return $types;
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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 ApplePay extends AbstractInfo
{
/**
* @var string
*/
protected $_template = 'Adyen_Payment::info/adyen_cc.phtml';
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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 ApplePayAuthorizationDataBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $_adyenHelper;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
private $_adyenLogger;
/**
* CaptureDataBuilder 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');
// get payment data
if ($token) {
$parsedToken = json_decode($token);
$paymentData = $parsedToken->token->paymentData;
try {
$paymentData = base64_encode(json_encode($paymentData));
$request['additionalData']['payment.token'] = $paymentData;
} catch (\Exception $exception) {
$this->_adyenLogger->addAdyenDebug("exception: " . $exception->getMessage());
}
} else {
$this->_adyenLogger->addAdyenDebug("PaymentToken is empty");
}
return $request;
}
}
\ No newline at end of file
......@@ -454,6 +454,45 @@ class Data extends AbstractHelper
return $this->getConfigData($field, 'adyen_boleto', $storeId, true);
}
/**
* @desc Gives back adyen_apple_pay configuration values
* @param $field
* @param null $storeId
* @return mixed
*/
public function getAdyenApplePayConfigData($field, $storeId = null)
{
return $this->getConfigData($field, 'adyen_apple_pay', $storeId);
}
/**
* @param null $storeId
* @return mixed
*/
public function getAdyenApplePayMerchantIdentifier($storeId = null)
{
$demoMode = $this->getAdyenAbstractConfigDataFlag('demo_mode');
if ($demoMode) {
return $this->getAdyenApplePayConfigData('merchant_identifier_test', $storeId);
} else {
return $this->getAdyenApplePayConfigData('merchant_identifier_live', $storeId);
}
}
/**
* @param null $storeId
* @return mixed
*/
public function getAdyenApplePayPemFileLocation($storeId = null)
{
$demoMode = $this->getAdyenAbstractConfigDataFlag('demo_mode');
if ($demoMode) {
return $this->getAdyenApplePayConfigData('full_path_location_pem_file_test', $storeId);
} else {
return $this->getAdyenApplePayConfigData('full_path_location_pem_file_live', $storeId);
}
}
/**
* @desc Retrieve decrypted hmac key
* @return string
......@@ -870,6 +909,28 @@ class Data extends AbstractHelper
return $this->scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
}
public function getApplePayShippingTypes()
{
return [
[
'value' => 'shipping',
'label' => __('Shipping Method')
],
[
'value' => 'delivery',
'label' => __('Delivery Method')
],
[
'value' => 'storePickup',
'label' => __('Store Pickup Method')
],
[
'value' => 'servicePickup',
'label' => __('Service Pickup Method')
]
];
}
public function getUnprocessedNotifications()
{
$notifications = $this->_notificationFactory->create();
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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;
use Adyen\Payment\Api\AdyenRequestMerchantSessionInterface;
class AdyenRequestMerchantSession implements AdyenRequestMerchantSessionInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $_adyenLogger;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* AdyenRequestMerchantSession constructor.
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
$this->_storeManager = $storeManager;
}
/**
* Get the merchant Session from Apple to start Apple Pay transaction
*
* @return mixed
*/
public function getMerchantSession()
{
// Works for test and live. Maybe we need to switch for validationUrl from callback event waiting for apple to respond
$validationUrl = "https://apple-pay-gateway-cert.apple.com/paymentservices/startSession";
// create a new cURL resource
$ch = curl_init();
$merchantIdentifier = $this->_adyenHelper->getAdyenApplePayMerchantIdentifier();
$domainName = parse_url($this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB))['host'];
$displayName = $this->_storeManager->getStore()->getName();
$data = '{
"merchantIdentifier":"' . $merchantIdentifier . '",
"domainName":"' . $domainName . '",
"displayName":"' . $displayName . '"
}';
$this->_adyenLogger->addAdyenDebug("JSON Requesst is: " . print_r($data,true));
curl_setopt($ch, CURLOPT_URL, $validationUrl);
// location applepay certificates
$fullPathLocationPEMFile = $this->_adyenHelper->getAdyenApplePayPemFileLocation();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSLCERT, $fullPathLocationPEMFile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
)
);
$result = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// log the raw response
$this->_adyenLogger->addAdyenDebug("JSON Response is: " . $result);
// result not 200 throw error
if ($httpStatus != 200 && $result) {
$this->_adyenLogger->addAdyenDebug("Error Apple, API HTTP Status is: " . $httpStatus . " result is:" . $result);
} elseif(!$result) {
$errno = curl_errno($ch);
$message = curl_error($ch);
$msg = "(Network error [errno $errno]: $message)";
$this->_adyenLogger->addAdyenDebug($msg);
}
curl_close($ch);
return $result;
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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\Config\Source;
class ApplePayShippingType implements \Magento\Framework\Option\ArrayInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* ApplePayShippingType constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->_adyenHelper = $adyenHelper;
}
/**
* @return array
*/
public function toOptionArray() {
return $this->_adyenHelper->getApplePayShippingTypes();
}
}
\ No newline at end of file
......@@ -1199,7 +1199,7 @@ class Cron
*/
protected function _isAutoCapture()
{
// validate if payment methods allowes manual capture
// validate if payment methods allows manual capture
if ($this->_manualCaptureAllowed()) {
$captureMode = trim($this->_getConfigData(
'capture_mode', 'adyen_abstract', $this->_order->getStoreId())
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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 AdyenApplePayConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_apple_pay';
/**
* @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;
/**
* AdyenApplePayConfigProvider 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
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
}
/**
* Retrieve assoc array of checkout configuration
*
* @return array
*/
public function getConfig()
{
// set to active
return [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'checkout/onepage/success/', ['_secure' => $this->_getRequest()->isSecure()]),
'merchant_identifier' => $this->_adyenHelper->getAdyenApplePayMerchantIdentifier()
]
]
];
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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 DataAssignObserver
*/
class AdyenApplePayDataAssignObserver 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('apple_pay');
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}
......@@ -46,6 +46,7 @@
<include path="Adyen_Payment::system/adyen_pos.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_apple_pay.xml"/>
</group>
<group id="test" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Test</label>
......
<?xml version="1.0"?>
<!--
~ ######
~ ######
~ ############ ####( ###### #####. ###### ############ ############
~ ############# #####( ###### #####. ###### ############# #############
~ ###### #####( ###### #####. ###### ##### ###### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
~ ###### ###### #####( ###### #####. ###### ##### ##### ######
~ ############# ############# ############# ############# ##### ######
~ ############ ############ ############# ############ ##### ######
~ ######
~ #############
~ ############
~
~ Adyen Payment Module
~
~ Copyright (c) 2017 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_apple_pay" translate="label" type="text" sortOrder="460" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[Apple 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 Apple 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_apple_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_apple_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_apple_pay/sort_order</config_path>
</field>
<field id="merchant_identifier_test" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Test: Apple Merchant Identifier</label>
<tooltip>You can retrieve this from your Apple Account.</tooltip>
<config_path>payment/adyen_apple_pay/merchant_identifier_test</config_path>
</field>
<field id="merchant_identifier_live" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Live: Apple Merchant Identifier</label>
<tooltip>You can retrieve this from your Apple Account.</tooltip>
<config_path>payment/adyen_apple_pay/merchant_identifier_live</config_path>
</field>
<field id="full_path_location_pem_file_test" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Test: PEM File location</label>
<tooltip>You need to generate a pem file from the apple certificate. You need to upload this to your webserver and define the full path location here.</tooltip>
<config_path>payment/adyen_apple_pay/full_path_location_pem_file_test</config_path>
</field>
<field id="full_path_location_pem_file_live" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Live: PEM File location</label>
<tooltip>You need to generate a pem file from the apple certificate. You need to upload this to your webserver and define the full path location here.</tooltip>
<config_path>payment/adyen_apple_pay/full_path_location_pem_file_live</config_path>
</field>
</group>
</include>
\ No newline at end of file
......@@ -189,6 +189,25 @@
<can_cancel>1</can_cancel>
<group>adyen</group>
</adyen_boleto>
<adyen_apple_pay>
<active>0</active>
<model>AdyenPaymentApplePayFacade</model>
<title>Adyen Apple Pay</title>
<allowspecific>0</allowspecific>
<sort_order>8</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>
<group>adyen</group>
</adyen_apple_pay>
</payment>
</default>
</config>
......@@ -104,6 +104,16 @@
<argument name="commandPool" xsi:type="object">AdyenPaymentPayByMailCommandPool</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayFacade" type="Magento\Payment\Model\Method\Adapter">
<arguments>
<argument name="code" xsi:type="const">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider::CODE</argument>
<argument name="formBlockType" xsi:type="string">Adyen\Payment\Block\Form\ApplePay</argument>
<argument name="infoBlockType" xsi:type="string">Adyen\Payment\Block\Info\ApplePay</argument>
<argument name="valueHandlerPool" xsi:type="object">AdyenPaymentApplePayValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">AdyenPaymentApplePayValidatorPool</argument>
<argument name="commandPool" xsi:type="object">AdyenPaymentApplePayCommandPool</argument>
</arguments>
</virtualType>
<!-- Value handlers infrastructure -->
<virtualType name="AdyenPaymentGenericValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
......@@ -211,6 +221,19 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">AdyenPaymentApplePayConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">AdyenPaymentApplePayConfig</argument>
</arguments>
</virtualType>
<!-- Configuration reader -->
<virtualType name="AdyenPaymentGenericConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
......@@ -253,6 +276,12 @@
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenPayByMailConfigProvider::CODE</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider::CODE</argument>
</arguments>
</virtualType>
<!-- Commands infrastructure -->
<virtualType name="AdyenPaymentCcCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
......@@ -341,6 +370,18 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="authorize" xsi:type="string">AdyenPaymentApplePayAuthorizeCommand</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 -->
<virtualType name="AdyenPaymentCcAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
......@@ -391,6 +432,16 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
<argument name="requestBuilder" xsi:type="object">AdyenPaymentApplePayAuthorizeRequest</argument>
<argument name="transferFactory" xsi:type="object">Adyen\Payment\Gateway\Http\TransferFactory</argument>
<argument name="client" xsi:type="object">Adyen\Payment\Gateway\Http\Client\TransactionAuthorization</argument>
<argument name="validator" xsi:type="object">GeneralResponseValidator</argument>
<argument name="handler" xsi:type="object">AdyenPaymentResponseHandlerComposite</argument>
</arguments>
</virtualType>
<!-- Capture command -->
<virtualType name="AdyenPaymentCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
......@@ -496,6 +547,20 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayAuthorizeRequest" 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\ApplePayAuthorizationDataBuilder</item>
</argument>
</arguments>
</virtualType>
<!-- Capture Request -->
<virtualType name="AdyenPaymentCaptureRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments>
......@@ -549,6 +614,15 @@
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="payment_details" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentAuthorisationDetailsHandler</item>
<item name="payment_comments" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentCommentHistoryHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentCaptureResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
......@@ -667,6 +741,19 @@
</arguments>
</virtualType>
<virtualType name="AdyenPaymentApplePayValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">AdyenApplePayCountryValidator</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenApplePayCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">AdyenPaymentApplePayConfig</argument>
</arguments>
</virtualType>
<!--General Response validator-->
<virtualType name="GeneralResponseValidator" type="Adyen\Payment\Gateway\Validator\GeneralResponseValidator">
......@@ -743,4 +830,5 @@
</type>
<preference for="Adyen\Payment\Api\GuestAdyenPaymentMethodManagementInterface" type="Adyen\Payment\Model\GuestAdyenPaymentMethodManagement" />
<preference for="Adyen\Payment\Api\AdyenPaymentMethodManagementInterface" type="Adyen\Payment\Model\AdyenPaymentMethodManagement" />
<preference for="Adyen\Payment\Api\AdyenRequestMerchantSessionInterface" type="Adyen\Payment\Model\AdyenRequestMerchantSession" />
</config>
\ No newline at end of file
......@@ -38,4 +38,7 @@
<event name="payment_method_assign_data_adyen_boleto">
<observer name="adyen_boleto_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_apple_pay">
<observer name="adyen_apple_pay_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenApplePayDataAssignObserver" />
</event>
</config>
......@@ -34,6 +34,7 @@
<item name="adyen_sepa_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenSepaConfigProvider</item>
<item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider</item>
<item name="adyen_pos_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenPosConfigProvider</item>
<item name="adyen_apple_pay_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenApplePayConfigProvider</item>
</argument>
</arguments>
</type>
......
......@@ -39,6 +39,9 @@
<method name="adyen_hpp">
<allow_multiple_address>0</allow_multiple_address>
</method>
<method name="adyen_apple_pay">
<allow_multiple_address>0</allow_multiple_address>
</method>
</methods>
</payment>
......
......@@ -30,18 +30,24 @@
<route url="/V1/guest-carts/:cartId/retrieve-adyen-payment-methods" method="POST">
<service class="Adyen\Payment\Api\GuestAdyenPaymentMethodManagementInterface" method="getPaymentMethods"/>
<resources>
<resource ref="anonymous" />
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/carts/mine/retrieve-adyen-payment-methods" method="POST">
<service class="Adyen\Payment\Api\AdyenPaymentMethodManagementInterface" method="getPaymentMethods"/>
<resources>
<resource ref="self" />
<resource ref="self"/>
</resources>
<data>
<parameter name="cartId" force="true">%cart_id%</parameter>
</data>
</route>
<route url="/V1/adyen/request-merchant-session" method="POST">
<service class="Adyen\Payment\Api\AdyenRequestMerchantSessionInterface" method="getMerchantSession"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
\ No newline at end of file
......@@ -61,6 +61,9 @@
<item name="adyen_boleto" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="adyen_apple_pay" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
......
......@@ -61,11 +61,76 @@
background-position: 0 -272px;
}
.checkout-payment-method .payment-method-title label div.adyen-sprite.adyen_apple_pay {
background:url(../images/logos/apple_pay.png) no-repeat;
height:43px;
}
.checkout-payment-method .input-text._has-datepicker {
width:20%;
margin-right:10px;
}
.apple-pay-button-with-text {
--apple-pay-scale: 1.5625; /* (height / 32) */
display: inline-flex;
justify-content: center;
font-size: 12px;
border-radius: 5px;
padding: 0px;
box-sizing: border-box;
/*min-width: 200px;*/
width:100%;
min-height: 32px;
max-height: 64px;
margin-bottom: 10px;
cursor: pointer;
}
.apple-pay-button-black-with-text {
background-color: black;
color: white;
}
.apple-pay-button-white-with-text {
background-color: white;
color: black;
}
.apple-pay-button-white-with-line-with-text {
background-color: white;
color: black;
border: .5px solid black;
}
.apple-pay-button-with-text.apple-pay-button-black-with-text > .logo {
background-image: -webkit-named-image(apple-pay-logo-white);
background-color: black;
}
.apple-pay-button-with-text.apple-pay-button-white-with-text > .logo {
background-image: -webkit-named-image(apple-pay-logo-black);
background-color: white;
}
.apple-pay-button-with-text.apple-pay-button-white-with-line-with-text > .logo {
background-image: -webkit-named-image(apple-pay-logo-black);
background-color: white;
}
.apple-pay-button-with-text > .text {
font-family: -apple-system;
font-size: calc(1em * var(--apple-pay-scale));
font-weight: 300;
align-self: center;
margin-right: calc(2px * var(--apple-pay-scale));
}
.apple-pay-button-with-text > .logo {
width: calc(35px * var(--apple-pay-scale));
height: 100%;
background-size: 100% 60%;
background-repeat: no-repeat;
background-position: 0 50%;
margin: 0;
border: none;
min-width: 0px; /* override magento min-width */
min-height: 42px; /* override magento min-height */
}
......@@ -35,7 +35,6 @@ define(
return function (paymentData, redirectOnSuccess) {
var serviceUrl,
payload;
//redirectOnSuccess = redirectOnSuccess !== false;
redirectOnSuccess = redirectOnSuccess === false ? false : true;
......@@ -60,13 +59,14 @@ define(
}
fullScreenLoader.startLoader();
return storage.post(
serviceUrl, JSON.stringify(payload)
).done(
function () {
function (response) {
if (redirectOnSuccess) {
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
} else{
fullScreenLoader.stopLoader();
}
}
).fail(
......
......@@ -55,6 +55,10 @@ define(
{
type: 'adyen_boleto',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-boleto-method'
},
{
type: 'adyen_apple_pay',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-apple-pay-method'
}
);
/** Add view logic here if needed */
......
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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>
*/
define(
[
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/action/place-order',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'mage/url',
'Magento_Ui/js/model/messages',
'mage/translate',
],
function ($, quote, Component, placeOrderAction, additionalValidators, urlBuilder, storage, url, Messages, $t) {
'use strict';
return Component.extend({
self: this,
defaults: {
template: 'Adyen_Payment/payment/apple-pay-form'
},
/**
* @returns {Boolean}
*/
isShowLegend: function () {
return true;
},
setPlaceOrderHandler: function (handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function (handler) {
this.validateHandler = handler;
},
getCode: function () {
return 'adyen_apple_pay';
},
getData: function () {
return {
'method': this.item.method,
'additional_data': {}
};
},
isActive: function () {
return true;
},
/**
* @override
*/
placeApplePayOrder: function (data, event) {
event.preventDefault();
var self = this;
if (!additionalValidators.validate()) {
return false;
}
var request = {
countryCode: quote.billingAddress().countryId,
currencyCode: quote.totals().quote_currency_code,
supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'],
merchantCapabilities: ['supports3DS'],
total: {label: $t('Grand Total'), amount: quote.totals().base_grand_total}
};
var session = new ApplePaySession(2, request);
session.onvalidatemerchant = function (event) {
var promise = self.performValidation(event.validationURL);
promise.then(function (merchantSession) {
session.completeMerchantValidation(merchantSession);
});
}
session.onpaymentauthorized = function (event) {
var data = {
'method': self.item.method,
'additional_data': {'token': JSON.stringify(event.payment)}
};
var promise = self.sendPayment(event.payment, data);
promise.then(function (success) {
var status;
if (success)
status = ApplePaySession.STATUS_SUCCESS;
else
status = ApplePaySession.STATUS_FAILURE;
session.completePayment(status);
if (success) {
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
}
}, function (reason) {
if (reason.message == "ERROR BILLING") {
var status = session.STATUS_INVALID_BILLING_POSTAL_ADDRESS;
} else if (reason.message == "ERROR SHIPPING") {
var status = session.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS;
} else {
var status = session.STATUS_FAILURE;
}
session.completePayment(status);
});
}
session.begin();
},
getControllerName: function () {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
getPlaceOrderUrl: function () {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
context: function () {
return this;
},
validate: function () {
return true;
},
showLogo: function () {
return window.checkoutConfig.payment.adyen.showLogo;
},
isApplePayAllowed: function () {
if (window.ApplePaySession) {
return true;
}
return false;
},
performValidation: function (validationURL) {
// Return a new promise.
return new Promise(function (resolve, reject) {
// retrieve payment methods
var serviceUrl = urlBuilder.createUrl('/adyen/request-merchant-session', {});
storage.post(
serviceUrl, JSON.stringify('{}')
).done(
function (response) {
var data = JSON.parse(response);
resolve(data);
}
).fail(function (error) {
console.log(JSON.stringify(error));
reject(Error("Network Error"));
});
});
},
sendPayment: function (payment, data) {
var deferred = $.Deferred();
return $.when(
placeOrderAction(data, new Messages())
).fail(
function (response) {
deferred.reject(Error(response));
}
).done(
function () {
deferred.resolve(true);
}
);
}
});
}
);
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2017 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
-->
<!-- ko if: isApplePayAllowed() -->
<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 id="adyen-apple-pay-button" class="apple-pay-button-with-text apple-pay-button-black-with-text"
data-bind= "click: placeApplePayOrder">
<span class="logo"></span>
</div>
</div>
</div>
<!--/ko-->
\ No newline at end of file
......@@ -179,10 +179,6 @@
<!--/ko-->
<input type="hidden" name="payment[dfValue]" data-bind="attr: { id: 'dfValue', value: dfValue }" />
<!-- ko if: (isPaymentMethodSelectionOnAdyen()) -->
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
......
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