Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 8723de7

Browse files
IngenicoEPaymentsjenkins
authored andcommitted
Release 3.6.1.
1 parent 93ab33f commit 8723de7

File tree

4 files changed

+84
-15
lines changed

4 files changed

+84
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## 3.6.0 - 2024-03-08
9+
10+
- Add support for voiding orders
11+
- Switch between cancel and refund depending on transaction status
12+
813
## 3.6.0 - 2024-03-07
914

1015
- Improved handling of credit memos

Gateway/Command/RefundCommand.php

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,45 @@ public function execute(array $commandSubject)
2525
{
2626
/** @var Payment $payment */
2727
$payment = $commandSubject['payment']->getPayment();
28-
$creditmemo = $payment->getCreditmemo();
29-
$order = $creditmemo->getOrder();
30-
$storeId = $creditmemo->getStoreId();
28+
$worldlinePaymentId = $payment->getRefundTransactionId();
3129

3230
try {
33-
$response = $this->worldlineClient->worldlineRefund(
34-
$payment->getRefundTransactionId(),
35-
$this->refundRequestBuilder->build($order, (float) $creditmemo->getGrandTotal()),
36-
null,
37-
$storeId
38-
);
39-
40-
$this->statusResponseManager->set($payment, $response->id, $response);
41-
42-
$payment->setLastTransId($response->id);
43-
$payment->setTransactionId($response->id);
31+
$response = $this->worldlineClient->worldlinePayment($worldlinePaymentId);
32+
if ($response->statusOutput->isRefundable) {
33+
$this->refundPayment($worldlinePaymentId, $payment);
34+
} elseif ($response->statusOutput->isCancellable) {
35+
$this->cancelPayment($worldlinePaymentId, $payment);
36+
}
4437
} catch (ResponseException $e) {
4538
$this->apiErrorHandler->handleError($e);
4639
}
4740
}
41+
42+
private function refundPayment(string $worldlinePaymentId, Payment $payment): void
43+
{
44+
$creditmemo = $payment->getCreditmemo();
45+
$response = $this->worldlineClient->worldlineRefund(
46+
$worldlinePaymentId,
47+
$this->refundRequestBuilder->build($creditmemo->getOrder(), (float) $creditmemo->getGrandTotal()),
48+
null,
49+
$creditmemo->getStoreId()
50+
);
51+
52+
$this->statusResponseManager->set($payment, $response->id, $response);
53+
54+
$payment->setLastTransId($response->id);
55+
$payment->setTransactionId($response->id);
56+
}
57+
58+
private function cancelPayment(string $worldlinePaymentId, Payment $payment): void
59+
{
60+
$this->worldlineClient->worldlinePaymentCancel($worldlinePaymentId);
61+
62+
$response = $this->worldlineClient->worldlinePayment($worldlinePaymentId);
63+
64+
$this->statusResponseManager->set($payment, $response->id, $response);
65+
66+
$payment->setLastTransId($response->id);
67+
$payment->setTransactionId($response->id);
68+
}
4869
}

0 commit comments

Comments
 (0)