33namespace AdyenPayment \Classes \Overrides ;
44
55use Adyen \Core \BusinessLogic \Domain \Multistore \StoreContext ;
6+ use Adyen \Core \BusinessLogic \Domain \TransactionHistory \Models \TransactionHistory ;
67use Adyen \Core \BusinessLogic \Domain \TransactionHistory \Services \TransactionDetailsService ;
8+ use Adyen \Core \BusinessLogic \Domain \TransactionHistory \Services \TransactionHistoryService ;
79use Adyen \Core \Infrastructure \ORM \Exceptions \RepositoryClassException ;
810use Adyen \Core \Infrastructure \ServiceRegister ;
911use AdyenPayment \Classes \Bootstrap ;
@@ -69,13 +71,9 @@ public function insertAdyenPaymentColumn(
6971 public function getOrderPspReference (string $ orderId , \Context $ context ): string
7072 {
7173 $ order = new Order ($ orderId );
72- $ transactionDetails = $ this ->getTransactionDetails ($ order );
73- $ authorisationDetail = $ transactionDetails [array_search (
74- \Adyen \Webhook \EventCodes::AUTHORISATION ,
75- array_column ($ transactionDetails , 'eventCode ' ),
76- true
77- )];
78- $ pspReference = $ order ->module === 'adyenofficial ' && !empty ($ transactionDetails ) ? $ authorisationDetail ['pspReference ' ] : '-- ' ;
74+ $ transactionHistory = $ this ->getTransactionDetails ($ order );
75+ $ authItem = $ transactionHistory ->getLastSuccessfulAuthorizationItem ();
76+ $ pspReference = $ order ->module === 'adyenofficial ' && !empty ($ transactionHistory ) ?$ authItem ->getPspReference () : '-- ' ;
7977
8078 $ context ->smarty ->assign (
8179 [
@@ -102,9 +100,9 @@ public function getOrderPspReference(string $orderId, \Context $context): string
102100 public function getOrderPaymentMethod (string $ orderId , \Context $ context ): string
103101 {
104102 $ order = new Order ($ orderId );
105- $ transactionDetails = $ this ->getTransactionDetails ($ order );
106- $ lastItem = end ( $ transactionDetails );
107- $ paymentMethod = $ order ->module === 'adyenofficial ' && !empty ($ transactionDetails ) ? $ lastItem [ ' paymentMethodType ' ] : '-- ' ;
103+ $ transactionHistory = $ this ->getTransactionDetails ($ order );
104+ $ authItem = $ transactionHistory -> getLastSuccessfulAuthorizationItem ( );
105+ $ paymentMethod = $ order ->module === 'adyenofficial ' && !empty ($ transactionHistory ) ? $ authItem -> getPaymentMethod () : '-- ' ;
108106
109107 $ context ->smarty ->assign (
110108 [
@@ -145,16 +143,20 @@ private function insertElementIntoArrayAfterSpecificKey(array $elementInformatio
145143 /**
146144 * @param Order $order
147145 *
148- * @return array
146+ * @return TransactionHistory
149147 *
150148 * @throws Exception
151149 */
152- private function getTransactionDetails (Order $ order ): array
150+ private function getTransactionDetails (Order $ order ): TransactionHistory
153151 {
152+ /** @var TransactionHistoryService $service */
153+ $ service = ServiceRegister::getService (TransactionHistoryService::class);
154+ /** @var TransactionHistory $transactionHistory */
154155 return StoreContext::doWithStore (
155- (string )$ order ->id_shop ,
156- [self ::getTransactionDetailsService ((string )$ order ->id_shop ), 'getTransactionDetails ' ],
157- [(string )$ order ->id_cart , (string )$ order ->id_shop ]
156+ $ order ->id_shop ,
157+ static function () use ($ order , $ service ) {
158+ return $ service ->getTransactionHistory ($ order ->id_cart );
159+ }
158160 );
159161 }
160162
0 commit comments