Skip to content

Commit

Permalink
3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hugofintecture committed Sep 22, 2023
1 parent eae8a18 commit 466ae2e
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 32 deletions.
14 changes: 4 additions & 10 deletions Controller/Standard/PaymentCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,11 @@ public function execute()
'refundedSessionId' => $this->request->getParam('refunded_session_id', ''),
];

$decodedState = json_decode(base64_decode($params['state']));
if (!is_object($decodedState) || !property_exists($decodedState, 'order_id')) {
$this->fintectureLogger->error('Webhook', [
'message' => "Can't find an order id in the state",
]);
$result->setHttpResponseCode(400);
$result->setContents('invalid_order');

return $result;
if (!in_array($params['type'], self::ALLOWED_WEBHOOK_TYPES)) {
$result->setContents('invalid_webhook_type');
}

$order = $this->fintectureHelper->getOrderByIncrementId($decodedState->order_id);
$order = $this->fintectureHelper->getOrderBySessionId($params['sessionId']);
if (!$order) {
$this->fintectureLogger->error('Webhook', [
'message' => 'No order found',
Expand All @@ -66,6 +59,7 @@ public function execute()
try {
$isRefund = !empty($params['refundedSessionId']);
if ($isRefund) {
$decodedState = json_decode(base64_decode($params['state']));
if (property_exists($decodedState, 'creditmemo_transaction_id')) {
return $this->refund($order, $params['status'], $decodedState->creditmemo_transaction_id);
} else {
Expand Down
3 changes: 0 additions & 3 deletions Controller/Standard/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public function execute()
return $this->redirectToCart();
}

$order->setExtOrderId($sessionId);
$this->orderRepository->save($order);

$pisToken = $this->sdk->pisClient->token->generate();
if (!$pisToken->error) {
$this->sdk->pisClient->setAccessToken($pisToken); // set token of PIS client
Expand Down
8 changes: 8 additions & 0 deletions Controller/WebhookAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ abstract class WebhookAbstract implements CsrfAwareActionInterface
/** @var Config */
protected $config;

/** @var array<string> */
protected const ALLOWED_WEBHOOK_TYPES = [
'PayByBank',
'Refund',
'BuyNowPayLater',
'ManualTransfer',
];

public function __construct(
FintectureLogger $fintectureLogger,
FintectureHelper $fintectureHelper,
Expand Down
14 changes: 13 additions & 1 deletion Gateway/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Config extends BaseConfig
{
const CODE = 'fintecture';
const VERSION = '3.2.0';
const VERSION = '3.3.0';

const KEY_SHOP_NAME = 'general/store_information/name';
const KEY_ACTIVE = 'active';
Expand All @@ -31,6 +31,8 @@ class Config extends BaseConfig
const KEY_CUSTOM_RECONCILIATION_FIELD_ACTIVE = 'custom_reconciliation_field_active';
const KEY_CUSTOM_RECONCILIATION_FIELD = 'custom_reconciliation_field';
const KEY_RECOMMEND_IT_BADGE = 'recommend_it_badge';
const KEY_FIRST_POSITION_ACTIVE = 'first_position_active';
const KEY_FIRST_POSITION_AMOUNT = 'first_position_amount';

public function getShopName(): ?string
{
Expand Down Expand Up @@ -159,6 +161,16 @@ public function isRecommendedItBadgeActive(): bool
return (bool) $this->getValue(self::KEY_RECOMMEND_IT_BADGE);
}

public function isFirstPositionActive(): bool
{
return (bool) $this->getValue(self::KEY_FIRST_POSITION_ACTIVE);
}

public function getFirstPositionAmount(): float
{
return (float) $this->getValue(self::KEY_FIRST_POSITION_AMOUNT);
}

public function getNewOrderStatus(): string
{
$status = $this->getValue('payment/fintecture/new_order_status');
Expand Down
12 changes: 11 additions & 1 deletion Gateway/Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Fintecture\Payment\Helper\Fintecture as FintectureHelper;
use Fintecture\Payment\Logger\Logger;
use Fintecture\Util\Crypto;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;

class Connect
Expand All @@ -24,16 +25,21 @@ class Connect
/** @var Config */
protected $config;

/** @var OrderRepositoryInterface */
protected $orderRepository;

public function __construct(
FintectureHelper $fintectureHelper,
Logger $fintectureLogger,
Sdk $sdk,
Config $config
Config $config,
OrderRepositoryInterface $orderRepository
) {
$this->fintectureHelper = $fintectureHelper;
$this->fintectureLogger = $fintectureLogger;
$this->sdk = $sdk;
$this->config = $config;
$this->orderRepository = $orderRepository;
}

public function get(Order $order, array $data): ApiResponse
Expand Down Expand Up @@ -74,6 +80,10 @@ public function get(Order $order, array $data): ApiResponse
throw new \Exception($apiResponse->errorMsg);
}

$sessionId = $apiResponse->meta->session_id ?? '';
$order->setExtOrderId($sessionId);
$this->orderRepository->save($order);

return $apiResponse;
}
}
12 changes: 11 additions & 1 deletion Gateway/RequestToPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Fintecture\Payment\Helper\Fintecture as FintectureHelper;
use Fintecture\Payment\Logger\Logger;
use Fintecture\Util\Crypto;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;

class RequestToPay
Expand All @@ -24,16 +25,21 @@ class RequestToPay
/** @var Config */
protected $config;

/** @var OrderRepositoryInterface */
protected $orderRepository;

public function __construct(
FintectureHelper $fintectureHelper,
Logger $fintectureLogger,
Sdk $sdk,
Config $config
Config $config,
OrderRepositoryInterface $orderRepository
) {
$this->fintectureHelper = $fintectureHelper;
$this->fintectureLogger = $fintectureLogger;
$this->sdk = $sdk;
$this->config = $config;
$this->orderRepository = $orderRepository;
}

public function get(Order $order, array $data): ApiResponse
Expand All @@ -58,6 +64,10 @@ public function get(Order $order, array $data): ApiResponse
throw new \Exception($apiResponse->errorMsg);
}

$sessionId = $apiResponse->meta->session_id ?? '';
$order->setExtOrderId($sessionId);
$this->orderRepository->save($order);

return $apiResponse;
}
}
16 changes: 15 additions & 1 deletion Helper/Fintecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ public function getOrderByIncrementId(string $incrementId): ?Order
return $order;
}

public function getOrderBySessionId(string $sessionId): ?Order
{
if (!preg_match('/^[0-9a-f]{32}$/', $sessionId)) {
return null;
}

$searchCriteria = $this->searchCriteriaBuilder->addFilter('ext_order_id', $sessionId)->create();
$orderList = $this->orderRepository->getList($searchCriteria)->getItems();
/** @var Order|null $order */
$order = array_pop($orderList);

return $order;
}

public function getSessionIdByOrderId(string $orderId): ?string
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter('order_id', $orderId)->create();
Expand Down Expand Up @@ -279,7 +293,7 @@ public function generatePayload(Order $order, string $type, string $method = '')
'attributes' => [
'amount' => (string) round((float) $order->getBaseGrandTotal(), 2),
'currency' => $order->getOrderCurrencyCode(),
'communication' => self::PAYMENT_COMMUNICATION . $order->getId(),
'communication' => self::PAYMENT_COMMUNICATION . $order->getIncrementId(),
],
],
];
Expand Down
2 changes: 2 additions & 0 deletions Helper/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function getConfigurationSummary(): array
'module_checkout_design' => $this->config->getCheckoutDesign(),
'module_recommended_it' => $this->config->isRecommendedItBadgeActive(),
'module_recommended_bnpl' => $this->bnplConfig->isRecommendedBnplBadgeActive(),
'module_force_position' => $this->config->isFirstPositionActive(),
'module_force_position_min_amount' => $this->config->getFirstPositionAmount(),
];
}
}
2 changes: 2 additions & 0 deletions Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function getConfig()
'active' => $this->gatewayConfig->isActive(),
'checkoutDesign' => $this->gatewayConfig->getCheckoutDesign(),
'recommendItBadge' => $this->gatewayConfig->isRecommendedItBadgeActive(),
'firstPositionActive' => $this->gatewayConfig->isFirstPositionActive(),
'firstPositionAmount' => $this->gatewayConfig->getFirstPositionAmount(),
],
],
];
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"email": "[email protected]"
},
"type": "magento2-module",
"version": "3.2.0",
"version": "3.3.0",
"license": [
"GPL-3.0"
],
Expand Down
12 changes: 12 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@
<comment>Recommend the payment method on checkout page</comment>
<config_path>payment/fintecture/recommend_it_badge</config_path>
</field>

<field id="first_position_active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>First position depending of cart amount</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/fintecture/first_position_active</config_path>
</field>

<field id="first_position_amount" translate="label" type="text" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Minimal cart amount to place Fintecture in first position (in €)</label>
<config_path>payment/fintecture/first_position_amount</config_path>
<frontend_class>validate-number</frontend_class>
</field>
</group>
<!-- End design options -->

Expand Down
3 changes: 3 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<alternative_method>qrcode</alternative_method>
<checkout_design_selection>it</checkout_design_selection>
<recommend_it_badge>0</recommend_it_badge>
<first_position_active>0</first_position_active>
<first_position_amount>0</first_position_amount>
<custom_reconciliation_field_active>0</custom_reconciliation_field_active>
</fintecture>
<fintecture_bnpl>
<debug>0</debug>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Fintecture_Payment" setup_version="3.2.0">
<module name="Fintecture_Payment" setup_version="3.3.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
4 changes: 3 additions & 1 deletion i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@
"Your purchase is confirmed!","Your purchase is confirmed!"
"""Recommended"" badge", """Recommended"" badge"
"Recommend the payment method on checkout page","Recommend the payment method on checkout page"
"RECOMMENDED","RECOMMENDED"
"RECOMMENDED","RECOMMENDED"
"First position depending of cart amount","First position depending of cart amount"
"Minimal cart amount to place Fintecture in first position (in €)","Minimal cart amount to place Fintecture in first position (in €)"
4 changes: 3 additions & 1 deletion i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@
"Your purchase is confirmed!","Votre achat est confirmé !"
"""Recommended"" badge", "Badge ""recommandé"""
"Recommend the payment method on checkout page","Recommander la méthode de paiement dans la page de paiement"
"RECOMMENDED","RECOMMANDÉ"
"RECOMMENDED","RECOMMANDÉ"
"First position depending of cart amount","Première position en fonction du montant du panier"
"Minimal cart amount to place Fintecture in first position (in €)","Montant minimum du panier pour placer Fintecture en première position (en €)"
15 changes: 10 additions & 5 deletions view/adminhtml/web/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,16 @@ requirejs(['jquery', 'mage/translate'], function ($, $t) {
}

const it_st_input = document.querySelector('input[id$="fintecture_design_options_checkout_design_selectionist"]');
if (it_st_input) {
it_st_input.disabled = true;
}
const it_st_short_input = document.querySelector('input[id$="fintecture_design_options_checkout_design_selectionist_short"]');
if (it_st_short_input) {
it_st_short_input.style.marginLeft = '15px';
}
const it_st_long_input = document.querySelector('input[id$="fintecture_design_options_checkout_design_selectionist_long"]');

it_st_input.disabled = true;
it_st_short_input.style.marginLeft = '15px';
it_st_long_input.style.marginLeft = '15px';
});
if (it_st_long_input) {
it_st_long_input.style.marginLeft = '15px';
}
});
});
2 changes: 1 addition & 1 deletion view/frontend/web/css/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.checkout_block {
padding-left: 30px;
margin-bottom: 40px;
}

.checkout_block p {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ define([
},
isRecommendedBnplBadgeActive: function () {
return window.checkoutConfig.payment.fintecture_bnpl.recommendBnplBadge;
},
forcePosition: function() {
var totalCartAmount = quote.getTotals()()['base_grand_total'];
var firstPositionActive = window.checkoutConfig.payment.fintecture.firstPositionActive;
var firstPositionAmount = window.checkoutConfig.payment.fintecture.firstPositionAmount;

if (firstPositionActive) {
if (totalCartAmount > firstPositionAmount) {
var paymentModuleIT = document.getElementById('fintecture-it');
var paymentModuleBNPL = document.getElementById('fintecture-bnpl');
var paymentMethodsList = document.querySelector('.payment-group .step-title');

if (paymentModuleIT && paymentModuleBNPL && paymentMethodsList) {
paymentModuleIT.after(paymentModuleBNPL);
} else if (paymentModuleBNPL && paymentMethodsList) {
paymentMethodsList.after(paymentModuleBNPL);
}
}
}
}
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
define([
'Magento_Checkout/js/view/payment/default',
'Magento_Checkout/js/model/quote',
'mage/url',
], function (Component, url) {
], function (Component, quote, url) {
'use strict';

return Component.extend({
Expand All @@ -18,6 +19,22 @@ define([
},
isRecommendedItBadgeActive: function () {
return window.checkoutConfig.payment.fintecture.recommendItBadge;
},
forcePosition: function() {
var totalCartAmount = quote.getTotals()()['base_grand_total'];
var firstPositionActive = window.checkoutConfig.payment.fintecture.firstPositionActive;
var firstPositionAmount = window.checkoutConfig.payment.fintecture.firstPositionAmount;

if (firstPositionActive) {
if (totalCartAmount > firstPositionAmount) {
var paymentModuleIT = document.getElementById('fintecture-it');
var paymentMethodsList = document.querySelector('.payment-group .step-title');

if (paymentModuleIT && paymentMethodsList) {
paymentMethodsList.after(paymentModuleIT);
}
}
}
}
});
});
Loading

0 comments on commit 466ae2e

Please sign in to comment.