Skip to content

Commit

Permalink
Merge branch 'master' into feature/PLUG-3273
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinverschoor committed Jun 19, 2024
2 parents 6fd4b32 + c428396 commit 2522fa7
Show file tree
Hide file tree
Showing 98 changed files with 751 additions and 195 deletions.
94 changes: 94 additions & 0 deletions Block/Adminhtml/Render/Obscured.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Paynl\Payment\Block\Adminhtml\Render;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;

class Obscured extends Field
{
protected $configPath;
protected $_template = 'Paynl_Payment::system/config/obscured.phtml';

/**
*
* @var Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;

/**
*
* @var Magento\Framework\App\RequestInterface
*/
protected $request;

/**
* Constructor.
*
* @param Context $context
* @param ScopeConfigInterface $scopeConfig
* @param RequestInterface $request
*/
public function __construct(Context $context, ScopeConfigInterface $scopeConfig, RequestInterface $request)
{
$this->scopeConfig = $scopeConfig;
$this->request = $request;
parent::__construct($context);
}

/**
*
* @param AbstractElement $element
*
* @return string
*/
protected function _getElementHtml(AbstractElement $element) // phpcs:ignore
{
$this->configPath = $element->getData('field_config')['config_path'];
$this->setNamePrefix($element->getName())
->setHtmlId($element->getHtmlId());
return $this->_toHtml();
}

/**
*
* @return string
*/
public function getValue()
{
$data = $this->getConfigData();
if (isset($data[$this->configPath])) {
$data = $data[$this->configPath];
} else {
$data = '';
}
return $data;
}

/**
* @return string
*/
public function getDecryptedValue()
{
$storeId = $this->request->getParam('store');
$websiteId = $this->request->getParam('website');

$scope = 'default';
$scopeId = 0;

if ($storeId) {
$scope = 'stores';
$scopeId = $storeId;
}
if ($websiteId) {
$scope = 'websites';
$scopeId = $websiteId;
}

$apiToken = trim((string) $this->scopeConfig->getValue($this->configPath, $scope, $scopeId));
return $apiToken ?? $this->getValue();
}
}
9 changes: 9 additions & 0 deletions Controller/Checkout/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ public function execute()
}
}

if ($transaction->isChargeBack() && substr($action, 0, 10) == 'chargeback') {
try {
$response = $this->payPayment->chargebackOrder($orderEntityId);
} catch (Exception $e) {
$response = $e->getMessage();
}
return $this->result->setContents($response === true ? 'TRUE|Chargeback success' : 'FALSE|' . $response);
}

if ($order->getTotalDue() <= 0) {
$this->payHelper->logDebug($action . '. Ignoring - already paid: ' . $orderEntityId);
if (!$this->config->registerPartialPayments()) {
Expand Down
15 changes: 15 additions & 0 deletions Controller/Checkout/Finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public function execute()
} else {
$cancelMessage = $bDenied ? __('Payment denied') : __('Payment cancelled');
$this->messageManager->addNoticeMessage($cancelMessage);
$this->reactivateCart($order);
if ($multiShipFinish) {
$session = $this->checkoutSession;
$sessionId = $session->getLastQuoteId();
Expand All @@ -236,6 +237,7 @@ public function execute()
} else {
$this->messageManager->addNoticeMessage(__('Unfortunately something went wrong'));
}
$this->reactivateCart($order);
$resultRedirect->setPath('checkout/cart');
}

Expand Down Expand Up @@ -279,4 +281,17 @@ private function deactivateCart(Order $order, string $payOrderId)
$quote->setIsActive(false);
$this->quoteRepository->save($quote);
}

/**
* @param Order $order
* @return void
*/
private function reactivateCart(Order $order)
{
# Make the cart active
$quote = $this->quoteRepository->get($order->getQuoteId());
$quote->setIsActive(true)->setReservedOrderId(null);
$this->checkoutSession->replaceQuote($quote);
$this->quoteRepository->save($quote);
}
}
6 changes: 0 additions & 6 deletions Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ public function execute()
throw new Error('No order found in session, please try again');
}

# Restore the quote
$quote = $this->quoteRepository->get($order->getQuoteId());
$quote->setIsActive(true)->setReservedOrderId(null);
$this->checkoutSession->replaceQuote($quote);
$this->quoteRepository->save($quote);

$payment = $order->getPayment();

if (empty($payment)) {
Expand Down
8 changes: 8 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ public function refundFromPay()
return $this->store->getConfig('payment/paynl/allow_refund_from_pay');
}

/**
* @return string|null
*/
public function chargebackFromPayEnabled()
{
return $this->store->getConfig('payment/paynl/allow_chargeback_from_pay');
}

/**
* @param string $paymentProfileId
* @return mixed|void
Expand Down
22 changes: 22 additions & 0 deletions Model/PayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ public function uncancelOrder(Order $order)
$this->eventManager->dispatch('order_uncancel_after', ['order' => $order]);
}

/**
* @param integer $orderEntityId
* @return true
* @throws \Exception
*/
public function chargebackOrder($orderEntityId)
{
$order = $this->orderRepository->get($orderEntityId);
if (!$this->config->chargebackFromPayEnabled() || $order->getTotalDue() != 0 || $order->getBaseTotalRefunded() == $order->getBaseGrandTotal()) {
throw new \Exception("Ignoring chargeback");
}
try {
$creditmemo = $this->cmFac->createByOrder($order);
$this->cmService->refund($creditmemo);
$order->addStatusHistoryComment(__('PAY. - Chargeback initiated by customer'))->save();
} catch (\Exception $e) {
$this->payHelper->logDebug('Chargeback failed:', ['error' => $e->getMessage(), 'orderEntityId' => $orderEntityId]);
throw new \Exception('Could not chargeback');
}
return true;
}

/**
* @param integer $orderEntityId
* @return true
Expand Down
47 changes: 23 additions & 24 deletions Model/PayPaymentCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ private function getShippingAddress()
}

$shippingAddress = [
'initials' => $arrShippingAddress['firstname'],
'lastName' => $arrShippingAddress['lastname'],
'initials' => mb_substr($arrShippingAddress['firstname'] ?? '', 0, 32),
'lastName' => mb_substr($arrShippingAddress['lastname'] ?? '', 0, 64),
];
$arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']);
$shippingAddress['streetName'] = $arrAddress2[0] ?? '';
$shippingAddress['houseNumber'] = $arrAddress2[1] ?? '';
$shippingAddress['zipCode'] = $arrShippingAddress['postcode'];
$shippingAddress['city'] = $arrShippingAddress['city'];
$shippingAddress['streetName'] = mb_substr($arrAddress2[0] ?? '', 0, 128);
$shippingAddress['houseNumber'] = mb_substr($arrAddress2[1] ?? '', 0, 10);
$shippingAddress['zipCode'] = mb_substr($arrShippingAddress['postcode'] ?? '', 0, 24);
$shippingAddress['city'] = mb_substr($arrShippingAddress['city'] ?? '', 0, 40);
$shippingAddress['country'] = $arrShippingAddress['country_id'];
}

Expand All @@ -358,33 +358,33 @@ private function getEnduserData()
if ($arrBillingAddress) {
$arrBillingAddress = $arrBillingAddress->toArray();
$enduser = [
'initials' => $arrBillingAddress['firstname'],
'lastName' => $arrBillingAddress['lastname'],
'initials' => mb_substr($arrBillingAddress['firstname'] ?? '', 0, 32),
'lastName' => mb_substr($arrBillingAddress['lastname'] ?? '', 0, 64),
'phoneNumber' => payHelper::validatePhoneNumber($arrBillingAddress['telephone']),
'emailAddress' => $arrBillingAddress['email'],
'emailAddress' => mb_substr($arrBillingAddress['email'] ?? '', 0, 100),
];
if (isset($this->additionalData['dob']) && !empty($this->additionalData['dob'])) {
$enduser['dob'] = $this->additionalData['dob'];
$enduser['dob'] = mb_substr($this->additionalData['dob'], 0, 32);
}
if (isset($this->additionalData['gender'])) {
$enduser['gender'] = $this->additionalData['gender'];
$enduser['gender'] = mb_substr($this->additionalData['gender'], 0, 1);
}
$enduser['gender'] = payHelper::genderConversion((empty($enduser['gender'])) ? $this->order->getCustomerGender($this->order) : $enduser['gender']);
if (!empty($arrBillingAddress['company'])) {
$enduser['company']['name'] = $arrBillingAddress['company'];
$enduser['company']['name'] = mb_substr($arrBillingAddress['company'], 0, 128);
} elseif (!empty($this->companyField)) {
$enduser['company']['name'] = $this->companyField;
$enduser['company']['name'] = mb_substr($this->companyField, 0, 128);
}
if (!empty($arrBillingAddress['country_id'])) {
$enduser['company']['countryCode'] = $arrBillingAddress['country_id'];
$enduser['company']['countryCode'] = mb_substr($arrBillingAddress['country_id'], 0, 2);
}
if (!empty($this->cocNumber)) {
$enduser['company']['cocNumber'] = $this->cocNumber;
$enduser['company']['cocNumber'] = mb_substr($this->cocNumber, 0, 64);
}
if (!empty($arrBillingAddress['vat_id'])) {
$enduser['company']['vatNumber'] = $arrBillingAddress['vat_id'];
$enduser['company']['vatNumber'] = mb_substr($arrBillingAddress['vat_id'], 0, 32);
} elseif (!empty($this->vatNumber)) {
$enduser['company']['vatNumber'] = $this->vatNumber;
$enduser['company']['vatNumber'] = mb_substr($this->vatNumber, 0, 32);
}
}

Expand All @@ -403,15 +403,14 @@ private function getInvoiceAddress()
$arrBillingAddress = $arrBillingAddress->toArray();

$invoiceAddress = [
'initials' => $arrBillingAddress['firstname'] ?? '',
'lastName' => $arrBillingAddress['lastname'] ?? '',
'initials' => mb_substr($arrBillingAddress['firstname'] ?? '', 0, 32),
'lastName' => mb_substr($arrBillingAddress['lastname'] ?? '', 0, 64),
];

$arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']);
$invoiceAddress['streetName'] = $arrAddress[0];
$invoiceAddress['houseNumber'] = $arrAddress[1];
$invoiceAddress['zipCode'] = $arrBillingAddress['postcode'];
$invoiceAddress['city'] = $arrBillingAddress['city'];
$invoiceAddress['streetName'] = mb_substr($arrAddress[0] ?? '', 0, 128);
$invoiceAddress['houseNumber'] = mb_substr($arrAddress[1] ?? '', 0, 10);
$invoiceAddress['zipCode'] = mb_substr($arrBillingAddress['postcode'] ?? '', 0, 24);
$shippingAddress['city'] = mb_substr($arrBillingAddress['city'] ?? '', 0, 40);
$invoiceAddress['country'] = $arrBillingAddress['country_id'];
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "paynl/magento2-plugin",
"description": "PAY. Payment methods for Magento2",
"type": "magento2-module",
"version": "3.11.4",
"version": "3.12.0",
"require": {
"magento/module-sales": "^102.0.0 || ^103.0.0",
"magento/module-payment": "^100.3.0",
Expand Down
7 changes: 5 additions & 2 deletions etc/adminhtml/paymentmethods/afterpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@
<comment><![CDATA[Hold CTRL button to select/deselect multiple]]></comment>
</field>
<field id="showforcompany" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show for</label>
<label>Customer Type</label>
<source_model>Paynl\Payment\Model\Config\Source\ShowCompanyOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_afterpay/showforcompany</config_path>
<comment><![CDATA[Show payment method for both business and private customers, private customers only or businesses only.]]></comment>
<tooltip>By default payment methods are available in the checkout for all customer types.
Private, B2C: Only show this payment method when the customer didn't enter a company name.
Business, BB2: Only show this payment method when the customer entered a company name.</tooltip>
<comment><![CDATA[Specify which type of customer this payment method should be available to.]]></comment>
</field>
<field id="showforgroup" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customer Group</label>
Expand Down
7 changes: 5 additions & 2 deletions etc/adminhtml/paymentmethods/afterpay_international.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@
<comment><![CDATA[Hold CTRL button to select/deselect multiple]]></comment>
</field>
<field id="showforcompany" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show for</label>
<label>Customer Type</label>
<source_model>Paynl\Payment\Model\Config\Source\ShowCompanyOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_afterpay_international/showforcompany</config_path>
<comment><![CDATA[Show payment method for both business and private customers, private customers only or businesses only.]]></comment>
<tooltip>By default payment methods are available in the checkout for all customer types.
Private, B2C: Only show this payment method when the customer didn't enter a company name.
Business, BB2: Only show this payment method when the customer entered a company name.</tooltip>
<comment><![CDATA[Specify which type of customer this payment method should be available to.]]></comment>
</field>
<field id="showforgroup" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customer Group</label>
Expand Down
7 changes: 5 additions & 2 deletions etc/adminhtml/paymentmethods/alipay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@
<comment><![CDATA[Hold CTRL button to select/deselect multiple]]></comment>
</field>
<field id="showforcompany" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show for</label>
<label>Customer Type</label>
<source_model>Paynl\Payment\Model\Config\Source\ShowCompanyOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_alipay/showforcompany</config_path>
<comment><![CDATA[Show payment method for both business and private customers, private customers only or businesses only.]]></comment>
<tooltip>By default payment methods are available in the checkout for all customer types.
Private, B2C: Only show this payment method when the customer didn't enter a company name.
Business, BB2: Only show this payment method when the customer entered a company name.</tooltip>
<comment><![CDATA[Specify which type of customer this payment method should be available to.]]></comment>
</field>
<field id="showforgroup" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customer Group</label>
Expand Down
7 changes: 5 additions & 2 deletions etc/adminhtml/paymentmethods/amazonpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@
<comment><![CDATA[Hold CTRL button to select/deselect multiple]]></comment>
</field>
<field id="showforcompany" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show for</label>
<label>Customer Type</label>
<source_model>Paynl\Payment\Model\Config\Source\ShowCompanyOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_amazonpay/showforcompany</config_path>
<comment><![CDATA[Show payment method for both business and private customers, private customers only or businesses only.]]></comment>
<tooltip>By default payment methods are available in the checkout for all customer types.
Private, B2C: Only show this payment method when the customer didn't enter a company name.
Business, BB2: Only show this payment method when the customer entered a company name.</tooltip>
<comment><![CDATA[Specify which type of customer this payment method should be available to.]]></comment>
</field>
<field id="showforgroup" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customer Group</label>
Expand Down
7 changes: 5 additions & 2 deletions etc/adminhtml/paymentmethods/amex.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@
<comment><![CDATA[Hold CTRL button to select/deselect multiple]]></comment>
</field>
<field id="showforcompany" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show for</label>
<label>Customer Type</label>
<source_model>Paynl\Payment\Model\Config\Source\ShowCompanyOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_amex/showforcompany</config_path>
<comment><![CDATA[Show payment method for both business and private customers, private customers only or businesses only.]]></comment>
<tooltip>By default payment methods are available in the checkout for all customer types.
Private, B2C: Only show this payment method when the customer didn't enter a company name.
Business, BB2: Only show this payment method when the customer entered a company name.</tooltip>
<comment><![CDATA[Specify which type of customer this payment method should be available to.]]></comment>
</field>
<field id="showforgroup" translate="label" type="select" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Customer Group</label>
Expand Down
Loading

0 comments on commit 2522fa7

Please sign in to comment.