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 12a4cd22 authored by rikterbeek's avatar rikterbeek

#32 Added SEPA as seperate payment method using our API integration

parent b8c2a0bc
......@@ -49,7 +49,8 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
\Adyen\Payment\Model\Method\Cc::METHOD_CODE,
\Adyen\Payment\Model\Method\Hpp::METHOD_CODE,
\Adyen\Payment\Model\Method\Oneclick::METHOD_CODE,
\Adyen\Payment\Model\Method\Pos::METHOD_CODE
\Adyen\Payment\Model\Method\Pos::METHOD_CODE,
\Adyen\Payment\Model\Method\Sepa::METHOD_CODE
];
/**
......
......@@ -175,12 +175,14 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$ccEnabled = $this->_config->getValue('payment/'.\Adyen\Payment\Model\Method\Cc::METHOD_CODE.'/active');
$ccTypes = array_keys($this->_adyenHelper->getCcTypesAltData());
$sepaEnabled = $this->_config->getValue('payment/'.\Adyen\Payment\Model\Method\Sepa::METHOD_CODE.'/active');
foreach ($this->_fetchHppMethods($store) as $methodCode => $methodData) {
// skip payment methods if it is a creditcard that is enabled in adyen_cc
if ($ccEnabled
&& in_array($methodCode, $ccTypes)) {
// skip payment methods if it is a creditcard that is enabled in adyen_cc or if payment is sepadirectdebit and SEPA api is enabled
if ($ccEnabled && in_array($methodCode, $ccTypes)) {
continue;
} elseif($methodCode == 'sepadirectdebit' && $sepaEnabled) {
continue;
}
......
<?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;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Directory\Helper\Data;
class AdyenSepaConfigProvider implements ConfigProviderInterface
{
/**
* @var string[]
*/
protected $methodCodes = [
'adyen_sepa'
];
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
*/
protected $methods = [];
/**
* @var PaymentHelper
*/
protected $_paymentHelper;
/**
* @var \Magento\Directory\Model\Config\Source\Country
*/
protected $_country;
/**
* AdyenSepaConfigProvider constructor.
*/
public function __construct(
PaymentHelper $paymentHelper,
\Magento\Directory\Model\Config\Source\Country $country
) {
$this->_paymentHelper = $paymentHelper;
$this->_country = $country;
foreach ($this->methodCodes as $code) {
$this->methods[$code] = $this->_paymentHelper->getMethodInstance($code);
}
}
public function getConfig()
{
$config = [
'payment' => [
'adyenSepa' => [
'countries' => $this->getCountries()
]
]
];
return $config;
}
public function getCountries()
{
$sepaCountriesAllowed = array(
"AT",
"BE",
"BG",
"CH",
"CY",
"CZ",
"DE",
"DK",
"EE",
"ES",
"FI",
"FR",
"GB",
"GF",
"GI",
"GP",
"GR",
"HR",
"HU",
"IE",
"IS",
"IT",
"LI",
"LT",
"LU",
"LV",
"MC",
"MQ",
"MT",
"NL",
"NO",
"PL",
"PT",
"RE",
"RO",
"SE",
"SI",
"SK"
);
$countryList = $this->_country->toOptionArray();
$sepaCountries = [];
foreach ($countryList as $key => $country) {
$value = $country['value'];
if(in_array($value, $sepaCountriesAllowed)) {
$sepaCountries[$value] = $country['label'];
}
}
return $sepaCountries;
}
}
\ No newline at end of file
......@@ -266,21 +266,38 @@ class PaymentRequest extends DataObject
$request['selectedRecurringDetailReference'] = $recurringDetailReference;
}
// If cse is enabled add encrypted card date into request
if($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled')) {
$request['additionalData']['card.encrypted.json'] = $payment->getAdditionalInformation("encrypted_data");
} else {
$requestCreditCardDetails = array(
"expiryMonth" => $payment->getCcExpMonth(),
"expiryYear" => $payment->getCcExpYear(),
"holderName" => $payment->getCcOwner(),
"number" => $payment->getCcNumber(),
"cvc" => $payment->getCcCid(),
);
$cardDetails['card'] = $requestCreditCardDetails;
$request = array_merge($request, $cardDetails);
if($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE || $paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
// If cse is enabled add encrypted card date into request
if($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled')) {
$request['additionalData']['card.encrypted.json'] = $payment->getAdditionalInformation("encrypted_data");
} else {
$requestCreditCardDetails = array(
"expiryMonth" => $payment->getCcExpMonth(),
"expiryYear" => $payment->getCcExpYear(),
"holderName" => $payment->getCcOwner(),
"number" => $payment->getCcNumber(),
"cvc" => $payment->getCcCid(),
);
$cardDetails['card'] = $requestCreditCardDetails;
$request = array_merge($request, $cardDetails);
}
} elseif($paymentMethodCode == \Adyen\Payment\Model\Method\Sepa::METHOD_CODE) {
// set brand to sepa
$request['selectedBrand'] = "sepadirectdebit";
// add bankDetails into request
$bankAccount = [
'iban' => $payment->getAdditionalInformation("iban"),
'ownerName' => $payment->getAdditionalInformation("account_name"),
'countryCode' => $payment->getAdditionalInformation("country")
];
$request['bankAccount'] = $bankAccount;
}
$result = $service->authorise($request);
return $result;
......
......@@ -191,7 +191,7 @@ class Cc extends \Magento\Payment\Model\Method\Cc
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)authorize
*/
public function validate()
{
......
......@@ -97,6 +97,13 @@ class Hpp extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
*/
protected $_adyenLogger;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @param \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest
* @param \Magento\Framework\UrlInterface $urlBuilder
......
......@@ -103,6 +103,13 @@ class Pos extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
*/
protected $_currencyFactory;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @param \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest
* @param \Magento\Framework\UrlInterface $urlBuilder
......
This diff is collapsed.
......@@ -40,6 +40,7 @@
<include path="Adyen_Payment::system/adyen_cc.xml"/>
<include path="Adyen_Payment::system/adyen_oneclick.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"/>
</group>
<group id="test" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
......
<?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_sepa" translate="label" type="text" sortOrder="250" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[SEPA integration]]></label>
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment</frontend_model>
<fieldset_css>adyen-method-adyen-cc</fieldset_css>
<comment>Process SEPA 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_sepa/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_sepa/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_sepa/sort_order</config_path>
</field>
<group id="adyen_sepa_country_specific" translate="label" showInDefault="1" showInWebsite="1" sortOrder="210">
<label>Country Specific Settings</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Applicable Countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
<config_path>payment/adyen_sepa/allowspecific</config_path>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/adyen_sepa/specificcountry</config_path>
</field>
</group>
</group>
</include>
\ No newline at end of file
......@@ -74,13 +74,22 @@
<order_place_redirect_url>adyen/process/redirect</order_place_redirect_url>
<group>adyen</group>
</adyen_hpp>
<adyen_sepa>
<active>0</active>
<model>Adyen\Payment\Model\Method\Sepa</model>
<title>Sepa Direct Debit</title>
<allowspecific>0</allowspecific>
<sort_order>4</sort_order>
<payment_action>authorize</payment_action>
<group>adyen</group>
</adyen_sepa>
<adyen_pos>
<active>0</active>
<model>Adyen\Payment\Model\Method\Pos</model>
<order_status>pending</order_status>
<title>Adyen POS</title>
<allowspecific>0</allowspecific>
<sort_order>4</sort_order>
<sort_order>5</sort_order>
<place_order_url>adyen/process/redirect</place_order_url>
<order_place_redirect_url>adyen/process/redirect</order_place_redirect_url>
<group>adyen</group>
......
......@@ -31,6 +31,7 @@
<item name="adyen_cc_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenCcConfigProvider</item>
<item name="adyen_oneclick_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenOneclickConfigProvider</item>
<item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenHppConfigProvider</item>
<item name="adyen_sepa_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenSepaConfigProvider</item>
</argument>
</arguments>
</type>
......
......@@ -36,9 +36,6 @@
<method name="adyen_hpp">
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name="test">
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>
......
......@@ -55,6 +55,9 @@
<item name="adyen_hpp" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="adyen_sepa" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
......
......@@ -53,6 +53,9 @@
background-position: 0 -1819px;
}
.checkout-payment-method .payment-method-title label div.adyen-sprite.adyen_sepa {
background-position: 0 -1910px;
}
......
......@@ -44,6 +44,10 @@ define(
type: 'adyen_hpp',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-hpp-method'
},
{
type: 'adyen_sepa',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-sepa-method'
},
{
type: 'adyen_pos',
component: 'Adyen_Payment/js/view/payment/method-renderer/adyen-pos-method'
......
......@@ -34,11 +34,6 @@ define(
function (_, $, Component, placeOrderAction, $t, additionalValidators, adyenEncrypt) {
'use strict';
$.validator.addMethod(
'validate-custom-required', function (value) {
return (value === 'test'); // Validation logic here
}, $.mage.__('Enter This is a required field custom.')
);
return Component.extend({
defaults: {
template: 'Adyen_Payment/payment/cc-form',
......
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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>
*/
/*browser:true*/
/*global define*/
define(
[
'underscore',
'jquery',
'Magento_Payment/js/view/payment/cc-form',
'Adyen_Payment/js/action/place-order',
'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators'
],
function (_, $, Component, placeOrderAction, $t, additionalValidators) {
'use strict';
return Component.extend({
self: this,
defaults: {
template: 'Adyen_Payment/payment/sepa-form'
},
initObservable: function () {
this._super()
.observe([
'accountName',
'iban',
'country',
'setAcceptSepa'
]);
return this;
},
setPlaceOrderHandler: function(handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function(handler) {
this.validateHandler = handler;
},
getCode: function() {
return 'adyen_sepa';
},
getData: function() {
return {
'method': this.item.method,
'additional_data': {
'account_name': this.accountName(),
'iban': this.iban(),
'country': this.country(),
'accept_sepa': this.setAcceptSepa()
}
};
},
isActive: function() {
return true;
},
/**
* @override
*/
placeOrder: function(data, event) {
var self = this,
placeOrder;
if (event) {
event.preventDefault();
}
if (this.validate() && additionalValidators.validate()) {
this.isPlaceOrderActionAllowed(false);
placeOrder = placeOrderAction(this.getData(), this.redirectAfterPlaceOrder);
$.when(placeOrder).fail(function(response) {
self.isPlaceOrderActionAllowed(true);
});
return true;
}
return false;
},
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 () {
var form = 'form[data-role=adyen-sepa-form]';
var validate = $(form).validation() && $(form).validation('isValid');
if(!validate) {
return false;
}
return true;
},
showLogo: function() {
return window.checkoutConfig.payment.adyen.showLogo;
},
getCountries: function() {
return _.map(window.checkoutConfig.payment.adyenSepa.countries, function(value, key) {
return {
'key': key,
'value': value
}
});
}
});
}
);
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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>
*/
-->
<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>
<form class="form" id="adyen-sepa-form" data-role="adyen-sepa-form" action="#" method="post" data-bind="mageInit: {
'transparent':{
'context': context(),
'controller': getControllerName(),
'orderSaveUrl':getPlaceOrderUrl(),
}, 'validation':[]}">
<fieldset data-bind="attr: {class: 'fieldset payment items adyen_sepa ' + getCode(), id: 'payment_form_' + getCode()}">
<!-- ko if: (isShowLegend())-->
<legend class="legend">
<span><!-- ko text: $t('Sepa Information')--><!-- /ko --></span>
</legend><br />
<!-- /ko -->
<div class="field accountname type required">
<label data-bind="attr: {for: getCode() + '_account_name'}" class="label">
<span><!-- ko text: $t('Bank account holder name')--><!-- /ko --></span>
</label>
<div class="control">
<input type="text"
class="input-text"
name="payment[account_name]"
autocomplete="off"
data-bind="attr: {id: getCode() + '_account_name', 'data-container': getCode() + '-account-name', 'data-validate': JSON.stringify({required:true})},
enable: isActive($parents),
value: accountName"
data-validate="{required:true}">
</input>
</div>
</div>
<div class="field iban type required">
<label data-bind="attr: {for: getCode() + '_iban'}" class="label">
<span><!-- ko text: $t('IBAN')--><!-- /ko --></span>
</label>
<div class="control">
<input type="text"
class="input-text"
name="payment[iban]"
autocomplete="off"
data-bind="attr: {id: getCode() + '_iban', 'data-container': getCode() + '-iban', 'data-validate': JSON.stringify({required:true})},
enable: isActive($parents),
value: iban"
data-validate="{required:true}">
</input>
</div>
</div>
<div class="field country type required">
<label data-bind="attr: {for: getCode() + '_country'}" class="label">
<span><!-- ko text: $t('Country')--><!-- /ko --></span>
</label>
<div class="control">
<select class="select select-country"
name="payment[country]"
data-bind="attr: {id: getCode() + '_country', 'data-container': getCode() + '-country', 'data-validate': JSON.stringify({required:true})},
enable: isActive($parents),
options: getCountries(),
optionsValue: 'key',
optionsText: 'value',
optionsCaption: $t('Select your country'),
value: country"
data-validate="{required:true}">
</select>
</div>
</div>
<div class="field choice required">
<input type="checkbox"
name="payment[accept_sepa]"
autocomplete="off"
class="checkbox"
data-bind="attr: {id: getCode() + '_accept_sepa', title: $t('I agree that the above amount will be debited from my bank account.')}, checked: setAcceptSepa"
data-validate="{required:true}"
/>
<label data-bind="attr: {for: getCode() + '_accept_sepa'}" class="label">
<span><!-- ko text: $t('I agree that the above amount will be debited from my bank account.')--><!-- /ko --></span>
</label>
</div>
</fieldset>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
type="submit"
data-bind="
click: placeOrder,
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
css: {disabled: !isPlaceOrderActionAllowed()}
"
disabled>
<span data-bind="text: $t('Place Order')"></span>
</button>
</div>
</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