Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
dc374fa
[PIPRES-539] [PIPRES-539] init new lines
MarijusDilys Jun 23, 2025
95a816a
[PIPRES-539] add description into PaymentData
MarijusDilys Jun 23, 2025
c1154f8
Revert "[PIPRES-539] add description into PaymentData"
MarijusDilys Jun 23, 2025
d120377
revert "[PIPRES-539] [PIPRES-539] init new lines"
MarijusDilys Jun 23, 2025
c2e0908
[PIPRES-539] seperate Line DTO for payment and order
MarijusDilys Jun 23, 2025
d0aeb21
[PIPRES-539]
MarijusDilys Jun 23, 2025
5bbce71
[PIPRES-539] format code
MarijusDilys Jun 23, 2025
c8a43cb
[PIPRES-539] minor fixes object
MarijusDilys Jun 23, 2025
c54756e
[PIPRES-539] cs fixer
MarijusDilys Jun 23, 2025
2eb52ee
[PIPRES-539] remove items from only orders api
MarijusDilys Jun 23, 2025
eb6d0d6
[PIPRES-539] remove useless order api validation and add missing fields
MarijusDilys Jun 25, 2025
2191255
[PIPRES-539] refactored to work vouchers with payments api
MarijusDilys Jun 25, 2025
146a3ef
[PIPRES-539] fix unit
MarijusDilys Jun 25, 2025
68cc3bc
[PIPRES-539] fix units
MarijusDilys Jun 25, 2025
370ea78
[PIPRES-539] fix units
MarijusDilys Jun 25, 2025
9d2dbba
[PIPRES-539] fix ci/cd
MarijusDilys Jun 25, 2025
d51a4d4
[PIPRES-539] fix ci/cd
MarijusDilys Jun 25, 2025
7d6b99e
[PIPRES-539] fix
MarijusDilys Jun 25, 2025
67a7a9c
[PIPRES-539] fix
MarijusDilys Jun 25, 2025
24020a2
[PIPRES-539] fix test
MarijusDilys Jun 25, 2025
4ab11f3
[PIPRES-539] add enum for line types
MarijusDilys Jun 30, 2025
377f955
[PIPRES-539] add return types and arg types
MarijusDilys Jun 30, 2025
77d5abf
[PIPRES-539] add return types
MarijusDilys Jun 30, 2025
b03aa65
[PIPRES-539] add return types
MarijusDilys Jun 30, 2025
44f99b2
[PIPRES-539] add paymentmethods
MarijusDilys Jun 30, 2025
be93517
[PIPRES-539] remove for now
MarijusDilys Jun 30, 2025
c841f0d
[PIPRES-539] fix stan linter
MarijusDilys Jul 1, 2025
3131574
[PIPRES-539] add return type
MarijusDilys Jul 1, 2025
4a75f13
[PIPRES-539] return type
MarijusDilys Jul 1, 2025
95cc62c
[PIPRES-539] return types
MarijusDilys Jul 1, 2025
8d3b23d
[PIPRES-539] add return types
MarijusDilys Jul 1, 2025
c223b35
[PIPRES-539] fix return types
MarijusDilys Jul 1, 2025
18eab41
[PIPRES-539] remove return in set methods
MarijusDilys Jul 1, 2025
3cfe472
[PIPRES-539] add return types
MarijusDilys Jul 1, 2025
453e9e2
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
e1e320d
[PIPRES-539] return type and default desc n/a
MarijusDilys Jul 1, 2025
0f6e511
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
f439c21
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
3111d4d
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
dfad307
[PIPRES-539] add returntypes
MarijusDilys Jul 1, 2025
5dcd8de
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
a69d369
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
b7ce4e5
[PIPRES-539] fix
MarijusDilys Jul 1, 2025
7e2d91e
Merge branch 'develop' of github.com:mollie/PrestaShop into PIPRES-53…
MarijusDilys Jul 1, 2025
1930e79
[PIPRES-539] add payments api orders shippable to verify
MarijusDilys Jul 7, 2025
4e6c5f3
[PIPRES-539] delete legacy code
MarijusDilys Jul 7, 2025
9ccd8a7
[PIPRES-539] add guidelines for rebuilding react
MarijusDilys Jul 7, 2025
3f2e28b
[PIPRES-539] add makefile
MarijusDilys Jul 7, 2025
2f736a3
[PIPRES-539] edit react
MarijusDilys Jul 7, 2025
60a75b9
[PIPRES-539] add full and partial capturing compatibility
MarijusDilys Jul 8, 2025
65ee722
[PIPRES-539] add dto
MarijusDilys Jul 8, 2025
dc69b02
Merge branch 'develop' of github.com:mollie/PrestaShop into PIPRES-53…
MarijusDilys Jul 8, 2025
16aa154
Merge branch 'PIPRES-539/add-line-items-payments-api' of github.com:m…
MarijusDilys Jul 8, 2025
31be954
[PIPRES-539] fix cslinter
MarijusDilys Jul 8, 2025
668171e
[PIPRES-539] fix tests
MarijusDilys Jul 8, 2025
a005789
[PIPRES-601] removed react
MarijusDilys Jul 22, 2025
a263d1e
[PIPRES-601] WIP removing react
MarijusDilys Jul 22, 2025
a297d10
[PIPRES-601] remove url utility
MarijusDilys Jul 22, 2025
c4ded92
[PIPRES-601] REMOVAL OF DIST JS
MarijusDilys Jul 22, 2025
1d1ec7e
[PIPRES-601] remove babel, linters etc
MarijusDilys Jul 22, 2025
3271683
[PIPRES-601] removed react
MarijusDilys Jul 22, 2025
f968da7
[PIPRES-601] wip redesign admin orders
MarijusDilys Jul 22, 2025
89f14e1
[PIPRES-601] wip captures compatibility
MarijusDilys Jul 22, 2025
4aafa0d
[PIPRES-601] fixed bug
MarijusDilys Jul 28, 2025
22a3ebe
[PIPRES-601] WIP
MarijusDilys Jul 28, 2025
9eff7cb
[PIPRES-601] wip
MarijusDilys Jul 29, 2025
bf985a1
[PIPRES-601] add loader
MarijusDilys Jul 29, 2025
b29f135
[PIPRES-601] add licence
MarijusDilys Jul 29, 2025
9f01c4e
[PIPRES-601] fx
MarijusDilys Jul 29, 2025
9304ceb
[PIPRES-601] rewrite
MarijusDilys Jul 29, 2025
d6c12a2
[PIPRES-601] wip
MarijusDilys Jul 29, 2025
1f71615
[PIPRES-601] wip
MarijusDilys Jul 29, 2025
960d35a
[PIPRES-601] wip
MarijusDilys Jul 29, 2025
fc8d634
[PIPRES-601] working refund
MarijusDilys Jul 29, 2025
7d476b9
fixed issue with payments api
MarijusDilys Aug 4, 2025
d766ef3
Merge branch 'PIPRES-601/react-removal' of github.com:mollie/PrestaSh…
MarijusDilys Aug 4, 2025
a1e7d59
WIP captures API
MarijusDilys Aug 4, 2025
16a7ff3
WIP logic connection
MarijusDilys Aug 5, 2025
abdf0f9
working on shipping logic handling
MarijusDilys Aug 5, 2025
ff5ad37
wip refunds:
MarijusDilys Aug 5, 2025
f1bc60d
fix
MarijusDilys Aug 5, 2025
18fac46
refunds working
MarijusDilys Aug 11, 2025
4ee02a9
disable refund buttons if refunded
MarijusDilys Aug 11, 2025
97c5d2c
terminate
MarijusDilys Aug 11, 2025
7588390
implement check for order or payments api
MarijusDilys Aug 11, 2025
bc70e1f
disable additional refund button
MarijusDilys Aug 11, 2025
c64d4a5
add capture mode
MarijusDilys Aug 12, 2025
14b2051
full amount refunds works
MarijusDilys Aug 12, 2025
65d074f
partial refunds
MarijusDilys Aug 12, 2025
8b97c79
fixed minor issue
MarijusDilys Aug 12, 2025
ec9cae1
minor changes to adapt shipping api
MarijusDilys Aug 25, 2025
6684f1c
disable if refunded orders
MarijusDilys Aug 25, 2025
6b53b7e
add doc
MarijusDilys Aug 25, 2025
46b6f0c
fix
MarijusDilys Aug 25, 2025
20b896d
fixing shipping
MarijusDilys Aug 25, 2025
0386a89
fixes
MarijusDilys Aug 25, 2025
0fcb1a8
add shipping
MarijusDilys Aug 26, 2025
11b7bf9
fix
MarijusDilys Aug 26, 2025
70dad7b
logic correction
MarijusDilys Aug 26, 2025
5b02522
shipping fi
MarijusDilys Aug 26, 2025
8b6ef66
Merge branch 'develop' of github.com:mollie/PrestaShop into PIPRES-53…
MarijusDilys Aug 26, 2025
cbd4a8a
Merge branch 'PIPRES-539/add-line-items-payments-api' of github.com:m…
MarijusDilys Aug 26, 2025
e0323b4
Merge branch 'PIPRES-539/captures-api' of github.com:mollie/PrestaSho…
MarijusDilys Aug 26, 2025
de0498a
Merge branch 'PIPRES-601/react-removal' of github.com:mollie/PrestaSh…
MarijusDilys Aug 26, 2025
44a61d2
fix
MarijusDilys Aug 26, 2025
1bd6b60
fix
MarijusDilys Aug 26, 2025
5f31c4d
fix shipping
MarijusDilys Aug 26, 2025
3aba168
minor fixes
MarijusDilys Aug 26, 2025
21af352
fixes
MarijusDilys Aug 26, 2025
b282d61
fix
MarijusDilys Aug 26, 2025
aa3c3ad
WORKIN REFUNDING PER ORDER LINE
MarijusDilys Aug 27, 2025
3c36cba
fixes
MarijusDilys Aug 27, 2025
aa26f89
fix partial shipping
MarijusDilys Aug 27, 2025
69ede03
minor fixes
MarijusDilys Aug 27, 2025
9f4d83c
fix
MarijusDilys Aug 27, 2025
0db6b74
stable shipping
MarijusDilys Aug 27, 2025
830bccc
add discounts
MarijusDilys Aug 27, 2025
2525c42
discounts
MarijusDilys Aug 27, 2025
7433584
fix
MarijusDilys Aug 28, 2025
b5c73cd
fix
MarijusDilys Aug 29, 2025
cb980e7
fix
MarijusDilys Aug 29, 2025
986253f
fix
MarijusDilys Aug 29, 2025
e2a951d
add skip shipping options
MarijusDilys Aug 29, 2025
e10e0df
fix|
MarijusDilys Aug 29, 2025
20af16e
fix
MarijusDilys Aug 29, 2025
66d9846
fox|
MarijusDilys Aug 29, 2025
6fb482b
testing capturing
MarijusDilys Aug 29, 2025
06b79b1
fix
MarijusDilys Aug 29, 2025
d06a032
dynamic button disabling
MarijusDilys Aug 29, 2025
c2b2227
fix
MarijusDilys Aug 29, 2025
84b8739
fix
MarijusDilys Aug 29, 2025
737c7be
add to try catch block
MarijusDilys Aug 29, 2025
3bd0241
init
MarijusDilys Sep 1, 2025
9fed204
fixed orders api
MarijusDilys Sep 1, 2025
e3385e5
refactor cpaturing
MarijusDilys Sep 2, 2025
65143d3
fix cpatures
MarijusDilys Sep 2, 2025
427e09a
minor fices
MarijusDilys Sep 2, 2025
0e0b7f4
handle shipping
MarijusDilys Sep 2, 2025
39a0e0c
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 2, 2025
dbef570
minor refunds fix
MarijusDilys Sep 3, 2025
6428bd2
fixes
MarijusDilys Sep 3, 2025
b3cd7d6
fix
MarijusDilys Sep 3, 2025
757b07a
edit OrderLine
MarijusDilys Sep 3, 2025
a99ae54
fix
MarijusDilys Sep 3, 2025
047cc40
Merge branch 'develop' of github.com:mollie/PrestaShop into PIPRES-53…
MarijusDilys Sep 8, 2025
e1e8a46
Merge branch 'PIPRES-539/add-line-items-payments-api' of github.com:m…
MarijusDilys Sep 8, 2025
888a549
Merge branch 'PIPRES-539/captures-api' of github.com:mollie/PrestaSho…
MarijusDilys Sep 8, 2025
42a0771
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 8, 2025
c9a4044
fix
MarijusDilys Sep 8, 2025
7a4a271
fix
MarijusDilys Sep 9, 2025
18c2677
fix
MarijusDilys Sep 9, 2025
99de9d8
fix minor issues
MarijusDilys Sep 9, 2025
f633109
fix
MarijusDilys Sep 9, 2025
0ce5f40
refactor order gathering
MarijusDilys Sep 9, 2025
a1081b8
fix
MarijusDilys Sep 9, 2025
db2ad41
Merge branch 'develop' of github.com:mollie/PrestaShop into PIPRES-53…
MarijusDilys Sep 9, 2025
ab9ee06
Merge branch 'PIPRES-601/react-removal' of github.com:mollie/PrestaSh…
MarijusDilys Sep 9, 2025
9f069cc
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 9, 2025
efb9ee0
Merge branch 'PIPRES-539/add-line-items-payments-api' of github.com:m…
MarijusDilys Sep 9, 2025
529e432
Merge branch 'PIPRES-539/captures-api' of github.com:mollie/PrestaSho…
MarijusDilys Sep 9, 2025
3923e4c
Merge branch 'PIPRES-601/react-removal' of github.com:mollie/PrestaSh…
MarijusDilys Sep 9, 2025
3f9f9d9
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 9, 2025
e40f4fd
fix
MarijusDilys Sep 9, 2025
51f85ac
fix
MarijusDilys Sep 9, 2025
396eb1b
fixes
MarijusDilys Sep 9, 2025
d1e025b
fix capturing
MarijusDilys Sep 10, 2025
bc8fa39
foix
MarijusDilys Sep 10, 2025
efa9073
recognize exceeding amount message
MarijusDilys Sep 10, 2025
1c7105a
fix
MarijusDilys Sep 10, 2025
d28a713
minor fixes
MarijusDilys Sep 10, 2025
08e0545
stan fix
MarijusDilys Sep 10, 2025
c07b4b1
fox
MarijusDilys Sep 10, 2025
1fc4ec3
fix
MarijusDilys Sep 10, 2025
88b9c87
remove old code
MarijusDilys Sep 10, 2025
b8adbd8
remove old code
MarijusDilys Sep 10, 2025
1d5cd67
fox
MarijusDilys Sep 10, 2025
1433b9e
fixes
MarijusDilys Sep 10, 2025
df3885d
fix
MarijusDilys Sep 10, 2025
f3d0903
fox
MarijusDilys Sep 10, 2025
068d6e8
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 10, 2025
aa83075
fx
MarijusDilys Sep 10, 2025
0de99dd
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 10, 2025
1878016
fox
MarijusDilys Sep 10, 2025
1e9d1fe
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 15, 2025
31bcf05
fix stan
MarijusDilys Sep 15, 2025
d4e0544
fix stan
MarijusDilys Sep 15, 2025
46c1d38
fix
MarijusDilys Sep 15, 2025
6ee9fc3
fix
MarijusDilys Sep 15, 2025
1681fd8
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 15, 2025
5e3607e
removed code
MarijusDilys Sep 16, 2025
57f0a7e
fix
MarijusDilys Sep 16, 2025
aa044d0
fix info text
MarijusDilys Sep 16, 2025
566f0d6
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 16, 2025
3023998
fiox
MarijusDilys Sep 16, 2025
c7cc79d
fix
MarijusDilys Sep 17, 2025
7a7968b
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 17, 2025
e41b97f
Merge branch 'develop' of github.com:mollie/PrestaShop into PIPRES-53…
MarijusDilys Sep 17, 2025
bddeb6c
Merge branch 'PIPRES-539/add-line-items-payments-api' of github.com:m…
MarijusDilys Sep 17, 2025
5abfa24
Merge branch 'PIPRES-539/captures-api' of github.com:mollie/PrestaSho…
MarijusDilys Sep 17, 2025
d1e8dd3
Merge branch 'PIPRES-601/react-removal' of github.com:mollie/PrestaSh…
MarijusDilys Sep 17, 2025
5f6a4fd
Merge branch 'PIPRES-601/redesign-admin-orders' of github.com:mollie/…
MarijusDilys Sep 17, 2025
c4b48c1
CS Linter
MarijusDilys Sep 17, 2025
ae009f0
CS Linter
MarijusDilys Sep 17, 2025
9b85a4a
CS Linter
MarijusDilys Sep 17, 2025
f1614b8
CS Linter
MarijusDilys Sep 17, 2025
7d9d74d
Merge pull request #1185 from mollie/PIPRES-600/multiple-vouchers
MarijusDilys Sep 17, 2025
662a61d
review fixes
MarijusDilys Sep 17, 2025
c0779f4
Merge pull request #1163 from mollie/PIPRES-601/redesign-admin-orders
MarijusDilys Sep 17, 2025
271b280
Merge pull request #1162 from mollie/PIPRES-601/react-removal
MarijusDilys Sep 17, 2025
039b6b1
Merge pull request #1151 from mollie/PIPRES-539/captures-api
MarijusDilys Sep 17, 2025
d6d390e
fix
MarijusDilys Sep 17, 2025
14b4411
change version
MarijusDilys Sep 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ run-ps-unit-tests:

create-env:
echo "SENTRY_ENV='$(env)'" > .env

rebuild-js:
cd views/js && npm i --legacy-peer-deps
cd views/js && npm install html-webpack-plugin@4.5.2 --legacy-peer-deps
cd views/js && npm run build
228 changes: 228 additions & 0 deletions controllers/admin/AdminMollieAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
use Mollie\Provider\CreditCardLogoProvider;
use Mollie\Provider\TaxCalculatorProvider;
use Mollie\Repository\PaymentMethodRepository;
use Mollie\Repository\PaymentMethodRepositoryInterface;
use Mollie\Service\ApiService;
use Mollie\Service\CancelService;
use Mollie\Service\CaptureService;
use Mollie\Service\MolliePaymentMailService;
use Mollie\Service\RefundService;
use Mollie\Service\ShipService;
use Mollie\Utility\NumberUtility;
use Mollie\Utility\TimeUtility;
use Mollie\Utility\TransactionUtility;

if (!defined('_PS_VERSION_')) {
exit;
Expand All @@ -31,6 +38,10 @@ class AdminMollieAjaxController extends ModuleAdminController

public function postProcess()
{
if (!Tools::isSubmit('ajax')) {
return;
}

$action = Tools::getValue('action');

$this->context->smarty->assign('bootstrap', true);
Expand All @@ -54,6 +65,25 @@ public function postProcess()
case 'updateFixedPaymentFeePrice':
$this->updateFixedPaymentFeePrice();
break;
case 'refundAll':
case 'refund':
$this->processRefund();
break;
case 'shipAll':
case 'ship':
$this->processShip();
break;
case 'captureAll':
case 'capture':
$this->processCapture();
break;
case 'cancelAll':
case 'cancel':
$this->processCancel();
break;
case 'retrieve':
$this->retrieveOrderInfo();
break;
default:
break;
}
Expand Down Expand Up @@ -213,4 +243,202 @@ private function updateFixedPaymentFeePrice(): void
])
);
}

private function processRefund(): void
{
try {
$transactionId = Tools::getValue('transactionId');
$refundAmount = (float) Tools::getValue('refundAmount') ?: null;
$orderLineId = Tools::getValue('orderline') ?: null;

/** @var RefundService $refundService */
$refundService = $this->module->getService(RefundService::class);

$status = $refundService->handleRefund($transactionId, $refundAmount, $orderLineId);

$this->ajaxRender(json_encode($status));
} catch (\Throwable $e) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('An error occurred while processing the request.'),
'error' => $e->getMessage(),
])
);
}
}

private function processShip(): void
{
$orderId = (int) Tools::getValue('orderId');
$orderLines = Tools::getValue('orderLines') ?: [];
$tracking = Tools::getValue('tracking');
$orderlineId = Tools::getValue('orderline');

try {
$order = new Order($orderId);

/** @var PaymentMethodRepositoryInterface $paymentMethodRepo */
$paymentMethodRepo = $this->module->getService(PaymentMethodRepositoryInterface::class);
$transactionId = $paymentMethodRepo->getPaymentBy('order_id', (string) $orderId)['transaction_id'];

/** @var ShipService $shipService */
$shipService = $this->module->getService(ShipService::class);
$status = $shipService->handleShip($transactionId, $orderlineId, $tracking);

$this->ajaxRender(json_encode($status));
} catch (\Throwable $e) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('An error occurred while processing the request.'),
'error' => $e->getMessage(),
])
);
}
}

private function processCapture(): void
{
$orderId = (int) Tools::getValue('orderId');
$captureAmount = Tools::getValue('captureAmount') ?: null;

try {
$order = new Order($orderId);

/** @var PaymentMethodRepositoryInterface $paymentMethodRepo */
$paymentMethodRepo = $this->module->getService(PaymentMethodRepositoryInterface::class);
$transactionId = $paymentMethodRepo->getPaymentBy('order_id', (string) $orderId)['transaction_id'];

/** @var CaptureService $captureService */
$captureService = $this->module->getService(CaptureService::class);

// Use provided amount for individual product capture, or full order amount for capture all
$amount = $captureAmount ? (float) $captureAmount : $order->total_paid;
$status = $captureService->handleCapture($transactionId, $amount);

$this->ajaxRender(json_encode($status));
} catch (\Throwable $e) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('An error occurred while processing the request.'),
'error' => $e->getMessage(),
])
);
}
}

private function processCancel(): void
{
$orderId = (int) Tools::getValue('orderId');
$orderlineId = Tools::getValue('orderline') ?: null;

try {
$order = new Order($orderId);

/** @var PaymentMethodRepositoryInterface $paymentMethodRepo */
$paymentMethodRepo = $this->module->getService(PaymentMethodRepositoryInterface::class);
$transactionId = $paymentMethodRepo->getPaymentBy('order_id', (string) $orderId)['transaction_id'];

/** @var CancelService $cancelService */
$cancelService = $this->module->getService(CancelService::class);
$status = $cancelService->handleCancel($transactionId, $orderlineId);

$this->ajaxRender(json_encode($status));
} catch (\Throwable $e) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('An error occurred while processing the request.'),
'error' => $e->getMessage(),
])
);
}
}

private function retrieveOrderInfo(): void
{
$orderId = (int) Tools::getValue('orderId');

try {
$order = new Order($orderId);

/** @var PaymentMethodRepositoryInterface $paymentMethodRepo */
$paymentMethodRepo = $this->module->getService(PaymentMethodRepositoryInterface::class);
$transaction = $paymentMethodRepo->getPaymentBy('order_id', (string) $orderId);

if (!$transaction) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('No Mollie transaction found for this order.'),
])
);

return;
}

$transactionId = $transaction['transaction_id'];
$this->module->updateApiKey((int) $order->id_shop);

if (!$this->module->getApiClient()) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('Unable to connect to Mollie API.'),
])
);

return;
}

/** @var ApiService $apiService */
$apiService = $this->module->getService(ApiService::class);

$mollieApiType = TransactionUtility::isOrderTransaction($transactionId) ? 'orders' : 'payments';

if ($mollieApiType === 'orders') {
$orderInfo = $this->module->getApiClient()->orders->get($transactionId);
$isShipping = $orderInfo->status === 'completed';
$isCaptured = $orderInfo->isPaid();
$isRefunded = $orderInfo->amountRefunded->value > 0;
$isCanceled = $orderInfo->status === 'canceled';

$response = [
'success' => true,
'isShipping' => $isShipping,
'isCaptured' => $isCaptured,
'isRefunded' => $isRefunded,
'isCanceled' => $isCanceled,
'orderStatus' => $orderInfo->status ?? null,
];
} else {
$paymentInfo = $this->module->getApiClient()->payments->get($transactionId);
$isShipping = false;
$isCaptured = false;

$isCaptured = $paymentInfo->isPaid();
$isRefunded = $paymentInfo->amountRefunded->value > 0;

$response = [
'success' => true,
'isShipping' => $isShipping,
'isCaptured' => $isCaptured,
'isRefunded' => $isRefunded,
'orderStatus' => $paymentInfo->status ?? null,
];
}

$this->ajaxRender(json_encode($response));
} catch (Exception $e) {
$this->ajaxRender(
json_encode([
'success' => false,
'message' => $this->module->l('An error occurred while retrieving order information.'),
'error' => $e->getMessage(),
])
);
}
}
}
105 changes: 105 additions & 0 deletions controllers/admin/AdminMollieOrderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
/**
* Admin controller for handling Mollie order actions: refund, capture, ship.
*
* Follows PrestaShop module conventions and delegates business logic to services.
*/

use Mollie\Adapter\ToolsAdapter;
use Mollie\Logger\LoggerInterface;
use Mollie\Service\CaptureService;
use Mollie\Service\RefundService;
use Mollie\Service\ShipService;

if (!defined('_PS_VERSION_')) {
exit;
}

class AdminMollieOrderController extends ModuleAdminController
{
const FILE_NAME = 'AdminMollieOrderController';

/** @var Mollie */
public $module;

public function __construct()
{
$this->bootstrap = true;
parent::__construct();
}

public function postProcess(): bool
{
if (!$this->context->employee->can('edit', 'AdminOrders')) {
return false;
}

/** @var ToolsAdapter $tools */
$tools = $this->module->getService(ToolsAdapter::class);
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);
$cookie = \Context::getContext()->cookie;

$orderId = $tools->getValueAsInt('orderId');
$errors = json_decode($cookie->__get('mollie_order_management_errors'), false) ?: [];

if ($tools->isSubmit('capture-order')) {
try {
$amount = (float) $tools->getValue('capture_amount');
/** @var CaptureService $captureService */
$captureService = $this->module->getService(CaptureService::class);
$captureService->handleCapture($orderId, $amount);
} catch (\Throwable $exception) {
$errors[$orderId] = 'Capture failed. See logs.';
$cookie->__set('mollie_order_management_errors', json_encode($errors));
$logger->error('Failed to capture order.', [
'order_id' => $orderId,
'amount' => $amount ?? null,
'exception' => $exception->getMessage(),
]);
}
}

if ($tools->isSubmit('refund-order')) {
try {
$amount = (float) $tools->getValue('refund_amount');
/** @var RefundService $refundService */
$refundService = $this->module->getService(RefundService::class);
$refundService->handleRefund($orderId, $amount);
} catch (\Throwable $exception) {
$errors[$orderId] = 'Refund failed. See logs.';
$cookie->__set('mollie_order_management_errors', json_encode($errors));
$logger->error('Failed to refund order.', [
'order_id' => $orderId,
'amount' => $amount ?? null,
'exception' => $exception->getMessage(),
]);
}
}

if ($tools->isSubmit('ship-order')) {
try {
/** @var ShipService $shipService */
$shipService = $this->module->getService(ShipService::class);
$shipService->handleShip($orderId);
} catch (\Throwable $exception) {
$errors[$orderId] = 'Shipping failed. See logs.';
$cookie->__set('mollie_order_management_errors', json_encode($errors));
$logger->error('Failed to ship order.', [
'order_id' => $orderId,
'exception' => $exception->getMessage(),
]);
}
}

$this->redirectToOrderController('AdminOrders', $orderId);

return true;
}

private function redirectToOrderController(string $controller, int $orderId): void
{
$url = \Context::getContext()->link->getAdminLink($controller, true, [], ['id_order' => $orderId, 'vieworder' => 1]);
\Tools::redirectAdmin($url);
}
}
Loading