Skip to content

Commit

Permalink
Merge branch 'develop' into MAG-310
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanBouchierAgenceDnD committed Aug 28, 2024
2 parents fa5bea4 + b026e1b commit d4a3e5d
Show file tree
Hide file tree
Showing 14 changed files with 1,522 additions and 1,255 deletions.
70 changes: 70 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Changelog - Payplug Payments Module

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.0](https://github.com/payplug/payplug-magento2/releases/tag/4.0.0) - 2024-XX-XX

> **NOTE**
> This new version goes directly from 1.27.4 to 4.0.0 to make a clean slate and avoid maintaining two logics as was done on previous versions (one in 1.27.X and the other one in 3.5.X).
### Features

- Optimize Oney payment load and script

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.27.4...4.0.0)**

### Added

- Add CHANGELOG.md [#211](https://github.com/payplug/payplug-magento2/pull/211)
- Add declare strict types along with real returns and php 8.0 [#209](https://github.com/payplug/payplug-magento2/pull/209)
- Add missing xml version declarations [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Add secure-magenta.dalenys.com in CSP whitelist [#212](https://github.com/payplug/payplug-magento2/pull/212)
- Add strict returns and fix typos for CheckPayment class [#209](https://github.com/payplug/payplug-magento2/pull/209)
- Add the real exceptions throw to function declaration [#209](https://github.com/payplug/payplug-magento2/pull/209)

### Changed

- Factorize payment simulation Ajax calls [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Get popin payment option navigation back [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Optimize Oney popin script show/hide [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Update and refacto Oney view handler script [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Update oney popin script constructor [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Update order status [#209](https://github.com/payplug/payplug-magento2/pull/209)
- Update payment standard method script indentation and declaration [#209](https://github.com/payplug/payplug-magento2/pull/209)
- Update Payplug Integrated Payments library call aliasing [#208](https://github.com/payplug/payplug-magento2/pull/208)

### Removed

- Remove Oney script head tag call [#208](https://github.com/payplug/payplug-magento2/pull/208)
- Remove residual comment - Update order status [#209](https://github.com/payplug/payplug-magento2/pull/209)

## [1.27.4](https://github.com/payplug/payplug-magento2/releases/tag/1.27.4) - 2024-05-02

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.27.3...1.27.4)**

## [1.27.3](https://github.com/payplug/payplug-magento2/releases/tag/1.27.3) - 2024-03-28

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.27.2...1.27.3)**

## [1.27.2](https://github.com/payplug/payplug-magento2/releases/tag/1.27.2) - 2023-10-26

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.27.1...1.27.2)**

## [1.27.1](https://github.com/payplug/payplug-magento2/releases/tag/1.27.1) - 2023-10-10

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.27.0...1.27.1)**

## [1.27.0](https://github.com/payplug/payplug-magento2/releases/tag/1.27.0) - 2023-09-21

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.26.0...1.27.0)**

## [1.26.0](https://github.com/payplug/payplug-magento2/releases/tag/1.26.0) - 2023-09-06

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.25.0...1.26.0)**

## [1.25.0](https://github.com/payplug/payplug-magento2/releases/tag/1.25.0) - 2023-07-10

**[view diff](https://github.com/payplug/payplug-magento2/compare/1.24.1...1.25.0)**
1 change: 1 addition & 0 deletions Controller/Payment/CheckPayment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


declare(strict_types=1);

namespace Payplug\Payments\Controller\Payment;
Expand Down
59 changes: 24 additions & 35 deletions Controller/Payment/PaymentReturn.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
<?php

declare(strict_types=1);

namespace Payplug\Payments\Controller\Payment;

use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderRepository;
use Magento\Framework\Controller\ResultInterface;
use Magento\Sales\Model\OrderFactory;
use Payplug\Exception\PayplugException;
use Payplug\Payments\Exception\OrderAlreadyProcessingException;
use Payplug\Payments\Helper\Data;
use Payplug\Payments\Logger\Logger;
use Payplug\Resource\Payment;

class PaymentReturn extends AbstractPayment
{
/**
* @var OrderRepository
*/
private $orderRepository;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Sales\Model\OrderFactory $salesOrderFactory
* @param Logger $logger
* @param Data $payplugHelper
* @param OrderRepository $orderRepository
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $salesOrderFactory,
Logger $logger,
Data $payplugHelper,
OrderRepository $orderRepository
) {
parent::__construct($context, $checkoutSession, $salesOrderFactory, $logger, $payplugHelper);
$this->orderRepository = $orderRepository;
}

/**
* Handle return from PayPlug payment page
*
* @return mixed
*/
public function execute()
public function execute(): Redirect|ResultInterface
{
$resultRedirect = $this->resultRedirectFactory->create();

Expand All @@ -61,13 +36,12 @@ public function execute()

$payment = $this->payplugHelper->getOrderPayment($lastIncrementId)->retrieve();


if (!$payment->is_paid) {
if (!$payment->is_paid && !$this->isOneyPending($payment)) {
$this->payplugHelper->cancelOrderAndInvoice($order);

$failureMessage = $this->_request->getParam(
'failure_message',
__('The transaction was aborted and your card has not been charged')
(string)__('The transaction was aborted and your card has not been charged')
);

if (!empty($failureMessage)) {
Expand Down Expand Up @@ -113,4 +87,19 @@ public function execute()
return $resultRedirect->setPath($redirectUrlSuccess);
}
}

/**
* Return true if we are paying with oney and the payment isn't rejected but waiting for approval
*/
public function isOneyPending(?Payment $payment): bool
{
if ($payment && isset($payment->payment_method)) {
$paymentMethod = $payment->payment_method;
if ($payment->is_paid === false && isset($paymentMethod['is_pending']) && isset($paymentMethod['type'])) {
return (str_contains($paymentMethod['type'], 'oney') && $paymentMethod['is_pending'] === true);
}
}

return false;
}
}
10 changes: 5 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function updateOrderStatus(Order $order, bool $save = true): void
if ($field !== null) {
$orderStatus = $order->getPayment()->getMethodInstance()->getConfigData($field, $order->getStoreId());
if (!empty($orderStatus) && $orderStatus !== $order->getStatus()) {
$order->addStatusToHistory($orderStatus, __('Custom Payplug Payments status'));
$order->addStatusToHistory($orderStatus, (string)__('Custom Payplug Payments status'));
if ($save) {
$this->orderRepository->save($order);
}
Expand All @@ -335,7 +335,7 @@ public function updateOrder(Order $order, array $data = []): Order
$createdAt = new \DateTime($orderProcessing->getCreatedAt());
if ($createdAt > new \DateTime("now - 1 min")) {
// Order is currently being processed
throw new OrderAlreadyProcessingException(__('Order is currently being processed.'));
throw new OrderAlreadyProcessingException((string)__('Order is currently being processed.'));
}
// Order has been set as processing for more than a minute
// Delete and recreate a new flag
Expand Down Expand Up @@ -527,7 +527,7 @@ public function forceOrderCancel(Order $order): void
if ($order->getState() !== Order::STATE_CANCELED) {
// Order is no longer in review and hasn't been canceled
// It means that the payment was validated
throw new LocalizedException(__('The order has been updated without being canceled ' .
throw new LocalizedException((string)__('The order has been updated without being canceled ' .
'because its payment has been validated.'));
}

Expand Down Expand Up @@ -567,7 +567,7 @@ public function cancelOrderPayment(Order $order): bool
// Payment is already aborted, keep processing to cancel order
return true;
}
throw new LocalizedException(__('An error occurred. Please try again.'));
throw new LocalizedException((string)__('An error occurred. Please try again.'));
}
}

Expand Down Expand Up @@ -668,7 +668,7 @@ public function sendNewPaymentLink(Order $order, array $paymentLinkData): Order
$createdAt = new \DateTime($orderProcessing->getCreatedAt());
if ($createdAt > new \DateTime("now - 1 min")) {
// Order is currently being processed
throw new OrderAlreadyProcessingException(__('Order is currently being processed.'));
throw new OrderAlreadyProcessingException((string)__('Order is currently being processed.'));
}
// Order has been set as processing for more than a minute
// Delete and recreate a new flag
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Payplug Payments Module

## Installation
## Installation

### Installation via Magento Back Office

Expand Down
32 changes: 22 additions & 10 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
<?xml version="1.0"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp/etc/csp_whitelist.xsd">
<policies>
<policy id="script-src">
<values>
<value id="api_payplug" type="host">api.payplug.com</value>
<value id="apple_pay" type="host">applepay.cdn-apple.com</value>
<value id="payplug_integrated" type="host">https://cdn.payplug.com/js/integrated-payment/</value>
<value id="apple-pay" type="host">applepay.cdn-apple.com</value>
<value id="payplug-api" type="host">api-qa.payplug.com</value>
<value id="payplug-script-cd-qa" type="host">cdn-qa.payplug.com</value>
<value id="payplug-script-qa" type="host">https://cdn-qa.payplug.com</value>
<value id="secure-magenta" type="host">https://secure-magenta.dalenys.com</value>
</values>
</policy>
<policy id="frame-src">
<policy id="style-src">
<values>
<value id="api_payplug" type="host">api.payplug.com</value>
<value id="secure_payplug" type="host">secure.payplug.com</value>
<value id="secure-magenta" type="host">https://secure-magenta.dalenys.com</value>
</values>
</policy>
<policy id="frame-src">
<values>
<value id="api_payplug" type="host">api-qa.payplug.com</value>
<value id="secure_payplug" type="host">secure-qa.payplug.com</value>
<value id="spayplug" type="host">*.payplug.com</value>
</values>
</policy>
<policy id="font-src">
<values>
<value id="apple-pay" type="host">applepay.cdn-apple.com</value>
</values>
</policy>
<policy id="img-src">
<values>
<value id="apple_pay" type="host">applepay.cdn-apple.com</value>
<value id="secure-magenta" type="host">https://secure-magenta.dalenys.com</value>
</values>
</policy>
</policies>
Expand Down
Loading

0 comments on commit d4a3e5d

Please sign in to comment.