Commit e078b0ce authored by Rik ter Beek's avatar Rik ter Beek

implemented some functionality for apple pay for the web

parent 2749977b
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Block;
use Magento\Framework\View\Element\Template;
class ApplePay extends \Magento\Framework\View\Element\Template
{
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* @var \Adyen\Payment\Helper\ApplePay
*/
protected $_adyenApplePayHelper;
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
* Customer session
*
* @var \Magento\Framework\App\Http\Context
*/
protected $httpContext;
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry;
/**
* @var ProductRepositoryInterface
*/
protected $_productRepository;
/**
* @var \Magento\Customer\Helper\Session\CurrentCustomer
*/
protected $_currentCustomer;
/**
* Constructor
*
* @param Template\Context $context
* @param array $data
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Helper\ApplePay $adyenApplePayHelper,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\App\Http\Context $httpContext,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Catalog\Block\Product\Context $productContext,
\Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
Template\Context $context,
array $data = []
) {
$this->_adyenHelper = $adyenHelper;
$this->_adyenApplePayHelper = $adyenApplePayHelper;
$this->_customerSession = $customerSession;
$this->httpContext = $httpContext;
$this->_productRepository = $productRepository;
if ($productContext) {
$this->_coreRegistry = $productContext->getRegistry();
}
$this->_currentCustomer = $currentCustomer;
parent::__construct($context, $data);
// $this->_isScopePrivate = true;
}
/**
* @return bool
*/
public function hasApplePayEnabled()
{
if (!$this->_adyenHelper->getAdyenApplePayConfigDataFlag("active")) {
return false;
}
// if user is not logged in and quest checkout is not enabled don't show the button
if ($this->_customerSession->isLoggedIn() &&
!$this->_adyenHelper->getAdyenApplePayConfigData('allow_quest_checkout')) {
return false;
}
return true;
}
/**
* Retrieve current product model
*
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
if ($this->_coreRegistry) {
if (!$this->_coreRegistry->registry('product') && $this->getProductId()) {
$product = $this->_productRepository->getById($this->getProductId());
$this->_coreRegistry->register('product', $product);
}
$product = $this->_coreRegistry->registry('product');
print_r(get_class($product));die();
return $this->_coreRegistry->registry('product');
}
return null;
}
/**
* @return array
*/
public function getShippingMethods()
{
echo 'getShippingMethods';
$product = $this->getProduct();
// print_r($this->_customerSession->getId());
//die();
if ($this->_customerSession->isLoggedIn()) {
echo "LOGGED IN CORRECT WAY";
}
if ($this->isLoggedIn()) {
// logged in
echo 'loggedin';
$customerId = $this->_currentCustomer->getCustomerId();
echo 'customerid:'.$customerId;
echo 'customerid2:'. $this->_customerSession->getCustomerId();
echo 'test';
echo 'end';
die();
// $defaultBilling = $this->getCustomerSession()->getCustomer()->getDefaultBilling();
}
}
/**
* @return mixed
*/
public function getMerchantIdentifier()
{
return $this->_adyenHelper->getApplePayMerchantIdentifier();
}
/**
* Only possible if quest checkout is turned off
*
* @return bool
*/
public function optionToChangeAddress()
{
if (
!$this->_adyenHelper->getAdyenApplePayConfigData('allow_quest_checkout')
) {
return $this->_adyenHelper->getAdyenApplePayConfigData('change_address');
}
return true;
}
/**
* @return mixed
*/
public function getShippingType()
{
return $this->_adyenHelper->getAdyenApplePayConfigData('shipping_type');
}
/**
* Is logged in
*
* @return bool
*/
public function isLoggedIn()
{
return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}
/**
* retrieve customer session
*/
public function getCustomerSession()
{
return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH)->getSession();
}
/**
* Renders captcha HTML (if required)
*
* @return string
*/
// protected function _toHtml()
// {
//// $data = $this->_adyenApplePayHelper->getApplePayData();
//// print_r($data);die();
//
//// if ($this->_customerSession->isLoggedIn()) {
//// echo "LOGGED IN CORRECT WAY";
//// }
//
//// die();
//
////// $blockPath = $this->_captchaData->getCaptcha($this->getFormId())->getBlockName();
////// $block = $this->getLayout()->createBlock($blockPath);
////// $block->setData($this->getData());
////// return $block->toHtml();
// }
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\CustomerData;
use Magento\Customer\CustomerData\SectionSourceInterface;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Customer\Helper\Session\CurrentCustomerAddress;
class ApplePay implements SectionSourceInterface
{
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
* @var CurrentCustomerAddress
*/
protected $_currentCustomerAddress;
/**
* @var CurrentCustomer
*/
protected $currentCustomer;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $_adyenLogger;
protected $_localeLists;
/**
* ApplePay constructor.
* @param CurrentCustomer $currentCustomer
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
CurrentCustomer $currentCustomer,
CurrentCustomerAddress $currentCustomerAddress,
\Magento\Customer\Model\Session $customerSession,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Framework\Locale\ListsInterface $localeLists
) {
$this->_customerSession = $customerSession;
$this->_currentCustomerAddress = $currentCustomerAddress;
$this->currentCustomer = $currentCustomer;
$this->_adyenLogger = $adyenLogger;
$this->_localeLists = $localeLists;
}
/**
* {@inheritdoc}
*/
public function getSectionData()
{
$this->_adyenLogger->error("START SECIOTN DATA");
$customerId = null;
if ($this->_customerSession->isLoggedIn()) {
$this->_adyenLogger->error("CUSSTOMER LOGIN!");
$customerId = $this->_customerSession->getCustomerId();
$customer = $this->currentCustomer->getCustomer();
$this->_adyenLogger->error("CUSSTOMER LOGIN2!");
$billingAddress = $this->_currentCustomerAddress->getDefaultBillingAddress();
$this->_adyenLogger->error("CUSSTOMER LOGIN3!");
if ($billingAddress) {
$lastName = trim($billingAddress->getMiddlename() . " " . $billingAddress->getLastName());
$countryName = $this->_localeLists->getCountryTranslation($billingAddress->getCountryId());
$billingContract = [
'emailAddress' => $customer->getEmail(),
'phoneNumber' => $billingAddress->getTelephone(),
'familyName' => $lastName,
'givenName' => $billingAddress->getFirstname(),
'addressLines' => $billingAddress->getStreet(),
'locality' => $billingAddress->getCity(),
'postalCode' => $billingAddress->getPostcode(),
'administrativeArea' => $billingAddress->getRegionId(), // state
'country' => $countryName,
'countryCode' => $billingAddress->getCountryId()
];
}
$this->_adyenLogger->error("CUSSTOMER LOGIN4!");
$shippingAddress = $this->_currentCustomerAddress->getDefaultShippingAddress();
if ($shippingAddress) {
$lastName = trim($shippingAddress->getMiddlename() . " " . $shippingAddress->getLastName());
$countryName = $this->_localeLists->getCountryTranslation($shippingAddress->getCountryId());
$shippingContract = [
'emailAddress' => $customer->getEmail(),
'phoneNumber' => $billingAddress->getTelephone(),
'familyName' => $lastName,
'givenName' => $billingAddress->getFirstname(),
'addressLines' => $billingAddress->getStreet(),
'locality' => $billingAddress->getCity(),
'postalCode' => $billingAddress->getPostcode(),
'administrativeArea' => $billingAddress->getRegionId(), // state
'country' => $countryName,
'countryCode' => $billingAddress->getCountryId()
];
}
$lastName = trim($customer->getMiddlename() . " " . $customer->getLastName());
$this->_adyenLogger->error(print_r($billingContract, true));
$this->_adyenLogger->error(print_r($shippingContract, true));
return [
'customerId' => $customerId,
'firstname' => $customer->getFirstname(),
'givenName' => $customer->getFirstname(),
'familyName' => $lastName,
'emailAddress' => $customer->getEmail(),
'billingContact' => $billingContract,
'shippingContact' => $shippingContract
];
}
return [];
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
/**
* @SuppressWarnings(PHPMD.LongVariable)
*/
class ApplePay extends AbstractHelper
{
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
* ApplePay constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Customer\Model\Session $customerSession
) {
parent::__construct($context);
$this->_customerSession = $customerSession;
}
/**
*
*/
public function getApplePayData()
{
if ($this->_customerSession->isLoggedIn()) {
echo "LOGGED IN CORRECT WAY";
}
echo 'hier2';
die();
}
}
\ No newline at end of file
......@@ -85,6 +85,20 @@ class Data extends AbstractHelper
];
}
/**
* @desc return recurring types for configuration setting
* @return array
*/
public function getShippingTypes()
{
return [
\Adyen\Payment\Model\ShippingType::SHIPPING_METHOD => __('Shipping Method'),
\Adyen\Payment\Model\ShippingType::DELIVERY_METHOD => __('Delivery Method'),
\Adyen\Payment\Model\ShippingType::STORE_PICKUP => __('Store Pickup Method'),
\Adyen\Payment\Model\ShippingType::SERVICE_PICKUP =>__('Service Pickup Method')
];
}
/**
* @desc return recurring types for configuration setting
* @return array
......@@ -386,6 +400,28 @@ class Data extends AbstractHelper
return $this->getConfigData($field, 'adyen_pay_by_mail', $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);
}
/**
* @desc Gives back adyen_pay_by_mail configuration values as flag
* @param $field
* @param null $storeId
* @return mixed
*/
public function getAdyenApplePayConfigDataFlag($field, $storeId = null)
{
return $this->getConfigData($field, 'adyen_apple_pay', $storeId, true);
}
/**
* @desc Retrieve decrypted hmac key
* @return string
......@@ -416,6 +452,32 @@ class Data extends AbstractHelper
return $secretWord;
}
public function getApplePayMerchantIdentifier()
{
switch ($this->isDemoMode()) {
case true:
$applePayIdentifier = trim($this->getAdyenApplePayConfigData('merchant_identifier_test'));
break;
default:
$applePayIdentifier = trim($this->getAdyenApplePayConfigData('merchant_identifier_test'));
break;
}
return $applePayIdentifier;
}
public function getApplePayFullPathLocationPEMFile()
{
switch ($this->isDemoMode()) {
case true:
$applePayIdentifier = trim($this->getAdyenApplePayConfigData('full_path_location_pem_file_test'));
break;
default:
$applePayIdentifier = trim($this->getAdyenApplePayConfigData('full_path_location_pem_file_live'));
break;
}
return $applePayIdentifier;
}
/**
* @desc Check if configuration is set to demo mode
* @return mixed
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Config\Source;
class ShippingType implements \Magento\Framework\Option\ArrayInterface
{
const UNDEFINED_OPTION_LABEL = 'NONE';
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* RecurringType constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
)
{
$this->_adyenHelper = $adyenHelper;
}
/**
* @return array
*/
public function toOptionArray()
{
$recurringTypes = $this->_adyenHelper->getShippingTypes();
foreach ($recurringTypes as $code => $label) {
$options[] = ['value' => $code, 'label' => $label];
}
return $options;
}
}
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Method;
/**
* Adyen CreditCard payment method
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ApplePay extends \Magento\Payment\Model\Method\Cc
{
const METHOD_CODE = 'adyen_apple_pay';
/**
* Payment Method feature
*
* @var bool
*/
protected $_canAuthorize = true;
/**
* @var bool
*/
protected $_canCapture = true;
/**
* @var bool
*/
protected $_canCapturePartial = true;
/**
* @var bool
*/
protected $_canCaptureOnce = true;
/**
* @var bool
*/
protected $_canRefund = true;
/**
* @var bool
*/
protected $_canRefundInvoicePartial = true;
/**
* @var bool
*/
protected $_isGateway = true;
/**
* @var string
*/
protected $_code = self::METHOD_CODE;
/**
* @var string
*/
protected $_formBlockType = 'Adyen\Payment\Block\Form\Cc';
/**
* @var string
*/
protected $_infoBlockType = 'Adyen\Payment\Block\Info\Cc';
/**
* @var \Adyen\Payment\Model\Api\PaymentRequest
*/
protected $_paymentRequest;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* Cc constructor.
*
* @param \Magento\Framework\App\RequestInterface $request
* @param \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Payment\Model\Method\Logger $logger
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Adyen\Payment\Model\Api\PaymentRequest $paymentRequest,
\Magento\Framework\UrlInterface $urlBuilder,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
\Magento\Payment\Helper\Data $paymentData,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Payment\Model\Method\Logger $logger,
\Magento\Framework\Module\ModuleListInterface $moduleList,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct(
$context,
$registry,
$extensionFactory,
$customAttributeFactory,
$paymentData,
$scopeConfig,
$logger,
$moduleList,
$localeDate,
$resource,
$resourceCollection,
$data
);
$this->_paymentRequest = $paymentRequest;
$this->_urlBuilder = $urlBuilder;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
}
/**
* @var string
*/
protected $_paymentMethodType = 'api';
/**
* @return string
*/
public function getPaymentMethodType()
{
return $this->_paymentMethodType;
}
/**
* Assign data to info model instance
*
* @param \Magento\Framework\DataObject|mixed $data
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function assignData(\Magento\Framework\DataObject $data)
{
parent::assignData($data);
if (!$data instanceof \Magento\Framework\DataObject) {
$data = new \Magento\Framework\DataObject($data);
}
$additionalData = $data->getAdditionalData();
$infoInstance = $this->getInfoInstance();
if (isset($additionalData['cc_type'])) {
$infoInstance->setCcType($additionalData['cc_type']);
}
if ($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled')) {
if (isset($additionalData['encrypted_data'])) {
$infoInstance->setAdditionalInformation('encrypted_data', $additionalData['encrypted_data']);
} else {
throw new \Magento\Framework\Exception\LocalizedException(__('Card encryption failed'));
}
}
// save value remember details checkbox
if (isset($additionalData['store_cc'])) {
$infoInstance->setAdditionalInformation('store_cc', $additionalData['store_cc']);
}
return $this;
}
/**
* Validate payment method information object
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)authorize
*/
public function validate()
{
// validation only possible on front-end for CSE script
return $this;
}
/**
* @param \Magento\Payment\Model\InfoInterface $payment
* @param float $amount
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
{
if (!$this->canAuthorize()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The authorize action is not available.'));
}
/*
* do not send order confirmation mail after order creation wait for
* Adyen AUTHORIISATION notification
*/
$order = $payment->getOrder();
$order->setCanSendNewEmailFlag(false);
// do not let magento set status to processing
$payment->setLastTransId($this->getTransactionId())->setIsTransactionPending(true);
// DO authorisation
$this->_processRequest($payment, $amount, "authorise");
return $this;
}
/**
* @param \Magento\Sales\Model\Order\Payment $payment
* @param $amount
* @param $request
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _processRequest(\Magento\Sales\Model\Order\Payment $payment, $amount, $request)
{
switch ($request) {
case "authorise":
$response = $this->_paymentRequest->fullApiRequest($payment, $this->_code);
break;
}
if (!empty($response)) {
$this->_processResponse($payment, $response);
} else {
throw new \Magento\Framework\Exception\LocalizedException(__('Empty result.'));
}
}
/**
* @param \Magento\Payment\Model\InfoInterface $payment
* @param $response
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _processResponse(\Magento\Payment\Model\InfoInterface $payment, $response)
{
$payment->setAdditionalInformation('3dActive', false);
switch ($response['resultCode']) {
case "Authorised":
$this->_addStatusHistory($payment, $response['resultCode'], $response['pspReference']);
$payment->setAdditionalInformation('pspReference', $response['pspReference']);
break;
case "RedirectShopper":
// 3d is active so set the param to true checked in Controller/Validate3d
$payment->setAdditionalInformation('3dActive', true);
$issuerUrl = $response['issuerUrl'];
$paReq = $response['paRequest'];
$md = $response['md'];
if (!empty($paReq) && !empty($md) && !empty($issuerUrl)) {
$payment->setAdditionalInformation('issuerUrl', $response['issuerUrl']);
$payment->setAdditionalInformation('paRequest', $response['paRequest']);
$payment->setAdditionalInformation('md', $response['md']);
} else {
throw new \Magento\Framework\Exception\LocalizedException(__('3D secure is not valid'));
}
break;
case "Refused":
// refusalReason
if ($response['refusalReason']) {
$refusalReason = $response['refusalReason'];
switch($refusalReason) {
case "Transaction Not Permitted":
$errorMsg = __('The transaction is not permitted.');
break;
case "CVC Declined":
$errorMsg = __('Declined due to the Card Security Code(CVC) being incorrect. Please check your CVC code!');
break;
case "Restricted Card":
$errorMsg = __('The card is restricted.');
break;
case "803 PaymentDetail not found":
$errorMsg = __('The payment is REFUSED because the saved card is removed. Please try an other payment method.');
break;
case "Expiry month not set":
$errorMsg = __('The expiry month is not set. Please check your expiry month!');
break;
default:
$errorMsg = __('The payment is REFUSED.');
break;
}
} else {
$errorMsg = __('The payment is REFUSED.');
}
if ($errorMsg) {
$this->_logger->critical($errorMsg);
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
}
break;
}
}
/**
* @param $payment
* @param $responseCode
* @param $pspReference
* @return $this
*/
protected function _addStatusHistory($payment, $responseCode, $pspReference)
{
$type = 'Adyen Result URL response:';
$comment = __('%1 <br /> authResult: %2 <br /> pspReference: %3 <br /> paymentMethod: %4',
$type, $responseCode, $pspReference, "");
$payment->getOrder()->setAdyenResulturlEventCode($responseCode);
$payment->getOrder()->addStatusHistoryComment($comment);
return $this;
}
/**
* Called by validate3d controller when cc payment has 3D secure
*
* @param $payment
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function authorise3d($payment)
{
try {
$response = $this->_paymentRequest->authorise3d($payment);
} catch(\Exception $e) {
throw $e;
}
$responseCode = $response['resultCode'];
return $responseCode;
}
/**
* Checkout redirect URL getter for onepage checkout (hardcode)
*
* @see \Magento\Checkout\Controller\Onepage::savePaymentAction()
* @see \Magento\Quote\Model\Quote\Payment::getCheckoutRedirectUrl()
* @return string
*/
public function getCheckoutRedirectUrl()
{
return $this->_urlBuilder->getUrl('adyen/process/validate3d/', ['_secure' => $this->_getRequest()->isSecure()]);
}
/**
* Capture on Adyen
*
* @param \Magento\Payment\Model\InfoInterface $payment
* @param float $amount
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
{
parent::capture($payment, $amount);
$this->_paymentRequest->capture($payment, $amount);
return $this;
}
/**
* Refund specified amount for payment
*
* @param \Magento\Payment\Model\InfoInterface $payment
* @param float $amount
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
{
parent::refund($payment, $amount);
$order = $payment->getOrder();
/*
* if amount is a full refund send a refund/cancelled request so
* if it is not captured yet it will cancel the order
*/
$grandTotal = $order->getGrandTotal();
if ($grandTotal == $amount) {
$this->_paymentRequest->cancelOrRefund($payment);
} else {
$this->_paymentRequest->refund($payment, $amount);
}
return $this;
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
class ShippingType
{
CONST SHIPPING_METHOD = 'shipping';
const DELIVERY_METHOD = 'delivery';
const STORE_PICKUP = 'storePickup';
const SERVICE_PICKUP = 'servicePickup';
}
\ No newline at end of file
......@@ -40,6 +40,7 @@
<include path="Adyen_Payment::system/adyen_manual_review.xml"/>
<include path="Adyen_Payment::system/adyen_cc.xml"/>
<include path="Adyen_Payment::system/adyen_oneclick.xml"/>
<include path="Adyen_Payment::system/adyen_apple_pay.xml"/>
<include path="Adyen_Payment::system/adyen_hpp.xml"/>
<include path="Adyen_Payment::system/adyen_sepa.xml"/>
<include path="Adyen_Payment::system/adyen_pos.xml"/>
......
<?xml version="1.0"?>
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* 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="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[Apple Pay for the Web]]></label>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
<fieldset_css>adyen-method-adyen-cc</fieldset_css>
<comment><![CDATA[You need to configure Apple Pay on the Adyen Platform. Please contact support@adyen.com and provide us CSR + merchant Identifier.<br /> Apple Pay will only be visable if you are running on IOS10 and higher. You need to browse on a Safari browser and you need to have active creditcards in your wallet.]]></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="0">
<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 you 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 you 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>
<field id="shipping_type" translate="label" type="select" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Shipping Type</label>
<tooltip>Title of the shipping method selection on the payments sheet you only these options this is limited by Apple</tooltip>
<source_model>Adyen\Payment\Model\Config\Source\ShippingType</source_model>
<config_path>payment/adyen_apple_pay/shipping_type</config_path>
</field>
<field id="allow_quest_checkout" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Allow Guest Checkout</label>
<tooltip>Show Apple Pay icon if user is not logged in. The user has the option to set his own contact detals and shipping\billing address</tooltip>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_apple_pay/allow_quest_checkout</config_path>
</field>
<field id="change_address" translate="label" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Option to change address details in Apple Payment Sheet</label>
<tooltip>Do you want to offer the customer that is logged in to change his address in the Apple Payment Sheet?</tooltip>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_apple_pay/change_address</config_path>
<depends><field id="allow_quest_checkout">0</field></depends>
</field>
<field id="show_in_payment_step_checkout" translate="label" type="select" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show payment method as well in the Payment Information step of the checkout</label>
<tooltip>If you set this to NO this will not be shown as a payment method option in the checkout steps. It will be visable on the product and shopping basket page</tooltip>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_apple_pay/show_in_payment_step_checkout</config_path>
</field>
<field id="show_outside_of_checkout" translate="label" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Apple buy button on product and cart page</label>
<tooltip>Set this to 'no' if you have advanced options for, for example, shipping that are not supported by the Apple Pay checkout forcing the user to first go through the Magento Checkout</tooltip>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_apple_pay/show_outside_of_checkout</config_path>
<depends><field id="show_in_payment_step_checkout">1</field></depends>
</field>
</group>
</include>
\ No newline at end of file
......@@ -60,6 +60,18 @@
<payment_action>authorize</payment_action>
<group>adyen</group>
</adyen_oneclick>
<adyen_apple_pay translate="title" module="adyen">
<active>0</active>
<model>Adyen\Payment\Model\Method\ApplePay</model>
<group>adyen</group>
<title>Adyen Apple Pay</title>
<sort_order>6</sort_order>
<shipping_type>shipping</shipping_type>
<allow_quest_checkout>1</allow_quest_checkout>
<change_address>1</change_address>
<show_in_payment_step_checkout>1</show_in_payment_step_checkout>
<show_outside_of_checkout>1</show_outside_of_checkout>
</adyen_apple_pay>
<adyen_hpp>
<active>0</active>
<model>Adyen\Payment\Model\Method\Hpp</model>
......
......@@ -35,4 +35,11 @@
</argument>
</arguments>
</type>
<type name="Magento\Customer\CustomerData\SectionPoolInterface">
<arguments>
<argument name="sectionSourceMap" xsi:type="array">
<item name="adyen-apple-pay" xsi:type="string">Adyen\Payment\CustomerData\ApplePay</item>
</argument>
</arguments>
</type>
</config>
\ No newline at end of file
<?xml version="1.0"?>
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Adyen_Payment::css/adyen_apple_pay.css"/>
<!--<script src="Adyen_Payment::js/adyen_apple_pay.js"/>-->
</head>
<body>
<!--<referenceContainer name="product.info.form.content">-->
<!--<block class="Adyen\Payment\Block\ApplePay" name="product.info.applepay" after="product.info.addtocart" template="apple_pay.phtml"/>-->
<!--</referenceContainer>-->
<referenceContainer name="product.info.form.content">
<block class="Adyen\Payment\Block\ApplePay" name="product.info.applepay"
after="product.info.addtocart" template="apple_pay.phtml" cacheable="false" >
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="applePay" xsi:type="array">
<item name="component" xsi:type="string">Adyen_Payment/js/adyen_apple_pay</item>
</item>
</item>
</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
......@@ -5,6 +5,11 @@
/*jshint browser:true jquery:true*/
/*global alert*/
var config = {
// map: {
// '*': {
// adyen_apple_pay: 'Adyen_Payment/js/adyen_apple_pay'
// }
// },
paths: {
'adyen/encrypt' : 'Adyen_Payment/js/view/payment/adyen.encrypt.min'
},
......
<?php
//
//$_product = $block->getProduct();
//
//if ($_product) {
// // in product
//}
//
//$block->getShippingMethods();
//echo 'hier';
//die();
?>
<div data-bind="scope: 'apple-pay'">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"apple-pay": {
"component": "Adyen_Payment/js/adyen_apple_pay",
"template" : "Adyen_Payment/apple_pay",
"productId": "<?php echo $block->getProduct()->getDescription() . "test"; ?>"
}
}
}
}
}
</script>
.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;
}
.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-left: calc(2px * var(--apple-pay-scale));
border: none;
min-width: 0px; /* override magento min-width */
}
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
// define(['uiComponent'], function(Component) {
//
// return Component.extend({
// initialize: function () {
// this._super();
// this.sayHello = "Hello this is content populated with KO!";
// }
// });
// });
define([
'uiComponent',
'Magento_Customer/js/customer-data',
'jquery'
], function (Component, customerData, $) {
'use strict';
return Component.extend({
initialize: function () {
this._super();
this.sayHello = "Hello this is content populated with KO!";
this.applePayData = customerData.get('adyen-apple-pay');
// this.applePay = {customerId: 'test' };
// test2
var productId = this.productId;
// TODO: add observer on qty
var qty = $('qty');
// qty.subscribe(function (event) {
// alert("DF");
// });
},
processApplePay: function () {
var paymentRequest = {
currencyCode: ''
};
alert("DF");
},
});
});
\ No newline at end of file
<p>I am 2 template located on: app/code/Adyen/Payment/view/frontend/web/template/apple_pay.html and dynamically loaded. This is my message to you:</p>
<p data-bind="text: sayHello"></p>
<div id="adyen-apple-pay-button" class="apple-pay-button-with-text apple-pay-button-black-with-text" style="" data-bind="click: processApplePay">
<span class="text">Buy With</span>
<span class="logo"></span>
</div>
\ 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