44
55namespace Adyen \Hyva \Magewire \Payment ;
66
7- use Hyva \Checkout \Model \Magewire \Component \EvaluationInterface ;
8- use Hyva \Checkout \Model \Magewire \Component \EvaluationResultFactory ;
9- use Hyva \Checkout \Model \Magewire \Component \EvaluationResultInterface ;
10- use Magento \Checkout \Model \Session as SessionCheckout ;
11- use Magento \Framework \Exception \LocalizedException ;
12- use Magento \Quote \Api \CartRepositoryInterface ;
13- use Magewirephp \Magewire \Component ;
7+ use Hyva \Checkout \Magewire \Checkout \Payment \MethodList as HyvaMethodList ;
148
159/**
1610 * Substitute for \Hyva\Checkout\Magewire\Checkout\Payment\MethodList
1711 */
18- class MethodList extends Component implements EvaluationInterface
12+ class MethodList extends HyvaMethodList
1913{
20- public ?string $ method = null ;
21-
2214 protected $ listeners = [
2315 'billing_address_saved ' => 'refresh ' ,
2416 'shipping_address_saved ' => 'refresh ' ,
@@ -30,56 +22,20 @@ class MethodList extends Component implements EvaluationInterface
3022 'shipping_address_activated ' => 'refresh ' ,
3123 ];
3224
33- protected $ loader = [
34- 'method ' => 'Saving method '
35- ];
36-
37- public function __construct (
38- protected readonly SessionCheckout $ sessionCheckout ,
39- protected readonly CartRepositoryInterface $ cartRepository ,
40- protected readonly EvaluationResultFactory $ evaluationResultFactory
41- ) {
42- }
43-
4425 public function boot (): void
4526 {
46- try {
47- $ method = $ this ->sessionCheckout ->getQuote ()->getPayment ()->getMethod ();
48- } catch (LocalizedException $ exception ) {
49- $ method = null ;
50- }
27+ parent ::boot ();
5128
52- $ this ->method = $ method ;
53- //This custom event notifies that the method list has rebooted
54- $ this ->dispatchBrowserEvent ('checkout:payment:method-list-boot ' , ['method ' => $ method ]);
29+ // This custom event notifies that the method list has rebooted
30+ $ this ->dispatchBrowserEvent ('checkout:payment:method-list-boot ' , ['method ' => $ this ->method ]);
5531 }
5632
5733 public function updatedMethod (string $ value ): string
5834 {
59- try {
60- $ quote = $ this ->sessionCheckout ->getQuote ();
61- $ quote ->getPayment ()->setMethod ($ value );
62-
63- $ this ->cartRepository ->save ($ quote );
64-
65- $ this ->dispatchBrowserEvent ('checkout:payment:method-activate ' , ['method ' => $ value ]);
66- $ this ->emit ('payment_method_selected ' );
67- } catch (LocalizedException $ exception ) {
68- $ this ->dispatchErrorMessage ('Something went wrong while saving your payment preferences. ' );
69- }
35+ $ value = parent ::updatedMethod ($ value );
7036
37+ $ this ->dispatchBrowserEvent ('checkout:payment:method-activate ' , ['method ' => $ value ]);
7138 return $ value ;
7239 }
73-
74- public function evaluateCompletion (EvaluationResultFactory $ resultFactory ): EvaluationResultInterface
75- {
76- if ($ this ->method === null ) {
77- return $ resultFactory ->createErrorMessageEvent ()
78- ->withCustomEvent ('payment:method:error ' )
79- ->withMessage ('The payment method is missing. Select the payment method and try again. ' );
80- }
81-
82- return $ resultFactory ->createSuccess ([], 'payment:method:success ' );
83- }
8440}
8541
0 commit comments