0

I have to create Payment object in

vendor/magento/module-paypal/Plugin/OrderCanInvoice.php

Is it $foo = new Payment() ?

It gives me an error

Uncaught ArgumentCountError: Too few arguments to function Magento\Sales\Model\Order\Payment::__construct()

How to create an object of Payment class

vendor/magento/module-sales/Model/Order/Payment.php

1

You cannot Object like $foo = new Payment() way.

OrderCanInvoice.php has some required the class at__construct function, So you have provided this parameter with Payment().

Or at magento2, if you want to create an object of a class then you need to use injection like:

private $orderPayment;
public function __construct(
 \Magento\Sales\Model\Order\Payment $orderPayment
)
{
// Create Object of vendor/magento/module-sales/Model/Order/Payment.php
  $this->orderPayment = $orderPayment;  
}

Also don't understand why you want to create Payment object of vendor/magento/module-sales/Model/Order/Payment.php in vendor/magento/module-paypal/Plugin/OrderCanInvoice.php, where the object is already exited at $order->getPayment().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.