Skip to content

Commit 6c44b51

Browse files
authored
Merge pull request #31 from satispay/feature/BCSAT-65-68-pending-payment
Pending payment
2 parents ac8a909 + fde2a2c commit 6c44b51

File tree

8 files changed

+71
-49
lines changed

8 files changed

+71
-49
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 2.2.0
8+
- Change flow for PENDING payments coming from Satispay API
9+
-
10+
## 2.1.2
11+
- Fixed bug regarding the <public_key> parameter. If the user didn't flush the cache after enabling the Plugin, the website threw an error.
12+
- Now the user has to: Enable the Plugin > Save the configuration > Set the token
13+
714
## 2.1.1
815
- Added Satispay logo on checkout
916

Diff for: Controller/Callback/Index.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
class Index extends \Magento\Framework\App\Action\Action
66
{
77
protected $checkoutSession;
8-
98
protected $orderSender;
10-
119
protected $finalizePaymentService;
1210

1311
public function __construct(
@@ -29,7 +27,7 @@ public function execute()
2927
$satispayPayment = \SatispayGBusiness\Payment::get($this->getRequest()->getParam("payment_id"));
3028
$order = $this->order->load($satispayPayment->metadata->order_id);
3129

32-
if ($order->getState() == $order::STATE_NEW) {
30+
if ($order->getState() == $order::STATE_NEW || $order->getState() == $order::STATE_PENDING_PAYMENT) {
3331
$this->finalizePaymentService->finalizePayment($satispayPayment, $order);
3432
}
3533

Diff for: Controller/Payment/Index.php

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function execute()
2727
$order = $this->checkoutSession->getLastRealOrder();
2828

2929
if ($order->getState() == $order::STATE_NEW) {
30+
$order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT)->setStatus(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT);
31+
$this->orderRepository->save($order);
3032
$satispayPayment = \SatispayGBusiness\Payment::create([
3133
"flow" => "MATCH_CODE",
3234
"amount_unit" => $order->getGrandTotal() * 100,

Diff for: Controller/Redirect/Index.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22

33
namespace Satispay\Satispay\Controller\Redirect;
44

5-
65
class Index extends \Magento\Framework\App\Action\Action
76
{
87
protected $checkoutSession;
9-
108
protected $orderRepository;
9+
protected $messageManager;
1110

1211
public function __construct(
1312
\Magento\Framework\App\Action\Context $context,
1413
\Magento\Checkout\Model\Session $checkoutSession,
1514
\Satispay\Satispay\Model\Method\Satispay $satispay,
16-
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository
15+
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
16+
\Magento\Framework\Message\ManagerInterface $messageManager,
1717
)
1818
{
1919
parent::__construct($context);
2020
$this->checkoutSession = $checkoutSession;
2121
$this->orderRepository = $orderRepository;
22+
$this->messageManager = $messageManager;
2223
}
2324

2425
public function execute()
@@ -37,11 +38,17 @@ public function execute()
3738

3839
if ($satispayPayment->status == 'ACCEPTED') {
3940
$this->_redirect('checkout/onepage/success');
40-
} else {
41-
$order->registerCancellation(__('Payment has been cancelled.'));
42-
$this->orderRepository->save($order);
43-
$this->checkoutSession->restoreQuote();
41+
return;
42+
}
43+
if ($satispayPayment->status == 'PENDING') {
44+
$this->messageManager->addWarningMessage(__('Payment is pending.'));
4445
$this->_redirect('checkout/cart');
46+
return;
4547
}
48+
$order->registerCancellation(__('Payment has been cancelled.'));
49+
$this->orderRepository->save($order);
50+
$this->checkoutSession->restoreQuote();
51+
$this->messageManager->addWarningMessage(__('Payment has been cancelled.'));
52+
$this->_redirect('checkout/cart');
4653
}
4754
}

Diff for: Model/FinalizePayment.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
<?php
22

3-
43
namespace Satispay\Satispay\Model;
54

6-
75
class FinalizePayment
86
{
97
/**
108
* @var \Magento\Sales\Model\Order\Email\Sender\OrderSender
119
*/
1210
protected $orderSender;
1311

12+
/**
13+
* @var \Magento\Sales\Api\OrderRepositoryInterface
14+
*/
15+
protected $orderRepository;
16+
1417
/**
1518
* @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender
1619
* @param \Satispay\Satispay\Model\Method\Satispay $satispay
1720
*/
1821
public function __construct(
1922
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender,
20-
\Satispay\Satispay\Model\Method\Satispay $satispay
23+
\Satispay\Satispay\Model\Method\Satispay $satispay,
24+
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository
2125
) {
2226
$this->orderSender = $orderSender;
27+
$this->orderRepository = $orderRepository;
2328
}
2429

2530
/**
@@ -40,7 +45,7 @@ public function finalizePayment($satispayPayment, \Magento\Sales\Model\Order $or
4045

4146
$order->setState($order::STATE_PROCESSING);
4247
$order->setStatus($order::STATE_PROCESSING);
43-
$order->save();
48+
$this->orderRepository->save($order);
4449

4550
// Payment is OK: send the new order email
4651
if (!$order->getEmailSent()) {
@@ -50,7 +55,7 @@ public function finalizePayment($satispayPayment, \Magento\Sales\Model\Order $or
5055
}
5156
if ($satispayPayment->status == 'CANCELED') {
5257
$order->registerCancellation(__('Payment received with status CANCELED.'));
53-
$order->save();
58+
$this->orderRepository->save($order);
5459
return true;
5560
}
5661

Diff for: Model/FinalizeUnhandledOrders.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Satispay\Satispay\Model;
54

6-
75
use Psr\Log\LoggerInterface;
86

97
class FinalizeUnhandledOrders
@@ -88,7 +86,7 @@ public function finalizeUnhandledOrders()
8886
$rangeEnd = $this->getEndDateScheduledTime();
8987

9088
$searchCriteria = $this->searchCriteriaBuilder
91-
->addFilter('state', \Magento\Sales\Model\Order::STATE_NEW)
89+
->addFilter('state', [\Magento\Sales\Model\Order::STATE_NEW, \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT], 'in')
9290
->addFilter('store_id', $storeId)
9391
->addFilter('updated_at', $rangeStart, 'gteq')
9492
->addFilter('updated_at', $rangeEnd, 'lteq')
@@ -119,7 +117,7 @@ private function processOrder(\Magento\Sales\Model\Order $order)
119117
$orderId = $order->getEntityId();
120118
$payment = $order->getPayment();
121119
$satispayPaymentId = $payment->getLastTransId();
122-
if(isset($satispayPaymentId)) {
120+
if (isset($satispayPaymentId)) {
123121
$satispayPayment = \SatispayGBusiness\Payment::get($satispayPaymentId);
124122
$hasBeenFinalized = $this->finalizePaymentService->finalizePayment($satispayPayment, $order);
125123
if ($hasBeenFinalized) {

Diff for: composer.json

+34-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
{
2-
"name": "satispay/magento2-plugin",
3-
"description": "Satispay Magento2 Plugin",
4-
"license": "MIT",
5-
"keywords": [
6-
"satispay",
7-
"magento2",
8-
"plugin"
9-
],
10-
"authors": [
11-
{
12-
"name": "Satispay",
13-
"homepage": "http://satispay.com"
14-
}
15-
],
16-
"require": {
17-
"magento/framework": ">=100.0.0",
18-
"magento/module-sales": ">=100.0.0",
19-
"magento/module-payment": ">=100.0.0",
20-
"magento/module-checkout": ">=100.0.0",
21-
"satispay/gbusiness-api-php-sdk": "^1.2"
22-
},
23-
"type": "magento2-module",
24-
"autoload": {
25-
"files": [
26-
"registration.php"
2+
"name": "satispay/magento2-plugin",
3+
"description": "Satispay Magento2 Plugin",
4+
"type": "magento2-module",
5+
"license": "MIT",
6+
"version": "2.2.0",
7+
8+
"keywords": [
9+
"satispay",
10+
"magento2",
11+
"plugin"
2712
],
28-
"psr-4": {
29-
"Satispay\\Satispay\\": ""
13+
14+
"authors": [{
15+
"name": "Satispay",
16+
"homepage": "http://satispay.com"
17+
18+
}],
19+
20+
"require": {
21+
"magento/framework": ">=100.0.0",
22+
"magento/module-sales": ">=100.0.0",
23+
"magento/module-payment": ">=100.0.0",
24+
"magento/module-checkout": ">=100.0.0",
25+
"satispay/gbusiness-api-php-sdk": "^1.2"
26+
},
27+
28+
"autoload": {
29+
"files": [
30+
"registration.php"
31+
],
32+
"psr-4": {
33+
"Satispay\\Satispay\\": ""
34+
}
3035
}
31-
}
32-
}
36+
37+
}

Diff for: etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Satispay_Satispay" setup_version="2.0.2">
3+
<module name="Satispay_Satispay" setup_version="2.2.0">
44
<sequence>
55
<module name="Magento_Sales"/>
66
<module name="Magento_Payment"/>

0 commit comments

Comments
 (0)