55namespace PayPlug \SyliusPayPlugPlugin \Provider ;
66
77use PayPlug \SyliusPayPlugPlugin \PayPlugGatewayFactory ;
8+ use Payum \Core \Model \GatewayConfigInterface ;
89use Sylius \Component \Core \Model \ChannelInterface ;
910use Sylius \Component \Core \Model \OrderInterface ;
1011use Sylius \Component \Core \Model \PaymentInterface ;
@@ -57,10 +58,25 @@ public function findForChannel(ChannelInterface $channel): array
5758 /** @var OrderInterface|null $order */
5859 $ order = $ this ->orderRepository ->findOneByNumber ($ request ->get ('orderNumber ' ));
5960
60- if (!$ order instanceof OrderInterface || $ this -> isPayPlugPayment ( $ order ) ) {
61+ if (!$ order instanceof OrderInterface) {
6162 return $ paymentMethods ;
6263 }
6364
65+ if ($ this ->isPayPlugPayment ($ order )) {
66+ return array_filter ($ paymentMethods , function (PaymentMethodInterface $ paymentMethod ) use ($ order ): bool {
67+ $ lastPayment = $ order ->getLastPayment ();
68+ if (!$ lastPayment instanceof PaymentInterface) {
69+ return false ;
70+ }
71+ $ lastPaymentMethod = $ lastPayment ->getMethod ();
72+ if (!$ lastPaymentMethod instanceof PaymentMethodInterface) {
73+ return false ;
74+ }
75+
76+ return $ paymentMethod ->getId () === $ lastPaymentMethod ->getId ();
77+ });
78+ }
79+
6480 if (null !== $ order ->getLastPayment () &&
6581 null !== $ order ->getLastPayment ()->getMethod () &&
6682 $ order ->getLastPayment ()->getMethod ()->getCode () === PayPlugGatewayFactory::FACTORY_NAME &&
@@ -80,17 +96,23 @@ public function findForChannel(ChannelInterface $channel): array
8096
8197 private function isPayPlugPayment (OrderInterface $ order ): bool
8298 {
83- $ firstPayment = $ order ->getPayments ()->first ();
84- if (!$ firstPayment instanceof PaymentInterface) {
99+ $ lastPayment = $ order ->getLastPayment ();
100+ if (!$ lastPayment instanceof PaymentInterface) {
101+ return false ;
102+ }
103+
104+ $ paymentMethod = $ lastPayment ->getMethod ();
105+ if (!$ paymentMethod instanceof PaymentMethodInterface) {
85106 return false ;
86107 }
87108
88- $ firstPaymentMethod = $ firstPayment ->getMethod ();
89- if (!$ firstPaymentMethod instanceof PaymentMethodInterface) {
109+ $ gatewayConfig = $ paymentMethod ->getGatewayConfig ();
110+
111+ if (!$ gatewayConfig instanceof GatewayConfigInterface) {
90112 return false ;
91113 }
92114
93- if (PayPlugGatewayFactory::FACTORY_NAME !== $ firstPaymentMethod -> getCode ()) {
115+ if (PayPlugGatewayFactory::FACTORY_NAME !== $ gatewayConfig -> getFactoryName ()) {
94116 return false ;
95117 }
96118
0 commit comments