Skip to content

Commit

Permalink
BP-2673 Add payment method: PayByBank (PaymentInitiation) (#749)
Browse files Browse the repository at this point in the history
* BP-2673 Add payment method: PayByBank (PaymentInitiation)

* Add correct issuers

* BP-2673 - code review

* change logo n26

* Update module.xml

* Update UpgradeData.php

---------

Co-authored-by: Ivascu Madalin <[email protected]>
Co-authored-by: Lucian Turiac <[email protected]>
Co-authored-by: Lucian Turiac <[email protected]>
  • Loading branch information
4 people authored Jul 10, 2023
1 parent c1bed1e commit de8c028
Show file tree
Hide file tree
Showing 21 changed files with 1,211 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function getPaymentLogo(string $method): string
"sofortbanking" => "svg/sofort.svg",
"emandate" => "emandate.png",
"pospayment" => "pos.png",
"transfer" => "svg/sepa-credittransfer.svg"
"transfer" => "svg/sepa-credittransfer.svg",
"paybybank" => "paybybank.gif"
];

$name = "svg/{$method}.svg";
Expand Down
6 changes: 3 additions & 3 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ public function getMode($paymentMethod = null, $store = null)
*/
public function isMobile()
{
$useragent = $_SERVER['HTTP_USER_AGENT'];
$userAgent = $this->httpHeader->getHttpUserAgent();
return preg_match(
'/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',
substr($useragent,0,4)
'/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$userAgent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',
substr($userAgent,0,4)
);
}

Expand Down
4 changes: 1 addition & 3 deletions Model/ConfigProvider/Method/AbstractConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function getIssuers()
*/
protected function formatIssuers()
{
$issuers = array_map(
return array_map(
function ($issuer) {
if(isset($issuer['imgName'])) {
$issuer['img'] = $this->getImageUrl("ideal/{$issuer['imgName']}", "svg");
Expand All @@ -190,8 +190,6 @@ function ($issuer) {
},
$this->getIssuers()
);

return $issuers;
}

public function getCreditcardLogo(string $code): string
Expand Down
212 changes: 212 additions & 0 deletions Model/ConfigProvider/Method/PayByBank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2\Model\ConfigProvider\Method;

use Buckaroo\Magento2\Model\ConfigProvider\Account;
use Magento\Framework\View\Asset\Repository;
use Buckaroo\Magento2\Helper\PaymentFee;
use Buckaroo\Magento2\Model\ConfigProvider\AllowedCurrencies;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Buckaroo\Magento2\Model\Method\PayByBank as PayByBankMethod;

class PayByBank extends AbstractConfigProvider
{
public const XPATH_PAYBYBANK_ACTIVE = 'payment/buckaroo_magento2_paybybank/active';
public const XPATH_PAYBYBANK_SUBTEXT = 'payment/buckaroo_magento2_paybybank/subtext';
public const XPATH_PAYBYBANK_SUBTEXT_STYLE = 'payment/buckaroo_magento2_paybybank/subtext_style';
public const XPATH_PAYBYBANK_SUBTEXT_COLOR = 'payment/buckaroo_magento2_paybybank/subtext_color';
public const XPATH_PAYBYBANK_ACTIVE_STATUS = 'payment/buckaroo_magento2_paybybank/active_status';
public const XPATH_PAYBYBANK_ORDER_STATUS_SUCCESS = 'payment/buckaroo_magento2_paybybank/order_status_success';
public const XPATH_PAYBYBANK_ORDER_STATUS_FAILED = 'payment/buckaroo_magento2_paybybank/order_status_failed';
public const XPATH_PAYBYBANK_ORDER_EMAIL = 'payment/buckaroo_magento2_paybybank/order_email';
public const XPATH_PAYBYBANK_AVAILABLE_IN_BACKEND = 'payment/buckaroo_magento2_paybybank/available_in_backend';

public const XPATH_ALLOWED_CURRENCIES = 'payment/buckaroo_magento2_paybybank/allowed_currencies';

public const XPATH_ALLOW_SPECIFIC = 'payment/buckaroo_magento2_paybybank/allowspecific';
public const XPATH_SPECIFIC_COUNTRY = 'payment/buckaroo_magento2_paybybank/specificcountry';
public const XPATH_PAYBYBANK_SELECTION_TYPE = 'buckaroo_magento2/account/selection_type';
public const XPATH_SPECIFIC_CUSTOMER_GROUP = 'payment/buckaroo_magento2_paybybank/specificcustomergroup';

protected $issuers = [
[
'name' => 'ABN AMRO',
'code' => 'ABNANL2A',
'imgName' => 'abnamro'
],
[
'name' => 'ASN Bank',
'code' => 'ASNBNL21',
'imgName' => 'asnbank'
],
[
'name' => 'ING',
'code' => 'INGBNL2A',
'imgName' => 'ing'
],
[
'name' => 'Knab Bank',
'code' => 'KNABNL2H',
'imgName' => 'knab'
],
[
'name' => 'Rabobank',
'code' => 'RABONL2U',
'imgName' => 'rabobank'
],
[
'name' => 'RegioBank',
'code' => 'RBRBNL21',
'imgName' => 'regiobank'
],
[
'name' => 'SNS Bank',
'code' => 'SNSBNL2A',
'imgName' => 'sns'
],
[
'name' => 'N26',
'code' => 'NTSBDEB1',
'imgName' => 'n26'
]
];

/**
* @var CustomerSession
*/
protected CustomerSession $customerSession;

/**
* @param Repository $assetRepo
* @param ScopeConfigInterface $scopeConfig
* @param AllowedCurrencies $allowedCurrencies
* @param PaymentFee $paymentFeeHelper
* @param CustomerSession $customerSession
*/
public function __construct(
Repository $assetRepo,
ScopeConfigInterface $scopeConfig,
AllowedCurrencies $allowedCurrencies,
PaymentFee $paymentFeeHelper,
CustomerSession $customerSession
) {
parent::__construct($assetRepo, $scopeConfig, $allowedCurrencies, $paymentFeeHelper);
$this->customerSession = $customerSession;
}

/**
* @var array
*/
protected $allowedCurrencies = [
'EUR'
];

/**
* @return array
*/
public function getConfig(): array
{
if (!$this->scopeConfig->getValue(
static::XPATH_PAYBYBANK_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
return [];
}


$selectionType = $this->scopeConfig->getValue(
self::XPATH_PAYBYBANK_SELECTION_TYPE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return [
'payment' => [
'buckaroo' => [
'paybybank' => [
'banks' => $this->getIssuersWithSelected(),
'subtext' => $this->getSubtext(),
'subtext_style' => $this->getSubtextStyle(),
'subtext_color' => $this->getSubtextColor(),
'allowedCurrencies' => $this->getAllowedCurrencies(),
'selectionType' => $selectionType,
],
],
],
];
}

/**
* @param null|int $storeId
*
* @return float
*/
public function getPaymentFee($storeId = null)
{
return 0;
}

/**
* @param null|int $storeId
*
* @return string
*/
public function getPaymentFeeLabel($storeId = null)
{
return $this->scopeConfig->getValue(
Account::XPATH_ACCOUNT_PAYMENT_FEE_LABEL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* Get bank issuers, move last saved bank issuer first,
* add selected property to the issuers array
*
* @return array
*/
public function getIssuersWithSelected()
{
$issuers = $this->formatIssuers();
$customer = $this->customerSession->getCustomer();
$savedBankIssuer = $customer->getData(PayByBankMethod::EAV_LAST_USED_ISSUER_ID);

if ($savedBankIssuer !== null) {
$issuers = array_map(function ($issuer) use ($savedBankIssuer) {
$issuer['selected'] = is_scalar($savedBankIssuer) && isset($issuer['code']) && $issuer['code'] === $savedBankIssuer;
return $issuer;
}, $issuers);


$savedIssuer = array_filter($issuers, function ($issuer) {
return $issuer['selected'];
});
$issuers = array_filter($issuers, function ($issuer) {
return !$issuer['selected'];
});

return array_merge($savedIssuer, $issuers);
}

return $issuers;
}
}
Loading

0 comments on commit de8c028

Please sign in to comment.