@@ -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