wel i have simple problem i'm trying to load this class in to my own class: https://github.com/picqer/moneybird-php-client/blob/master/src/Picqer/Financials/Moneybird/Moneybird.php
logicaly is to call it in __construct: \Picqer\Financials\Moneybird\Moneybird $moneybird
but the problem is that it requires \Picqer\Financials\Moneybird\Connection to be established beforehand
so how can i use it in my code:
class OnepageControllerSuccessAction implements \Magento\Framework\Event\ObserverInterface
{
protected $_order;
protected $_connection;
protected $_invoiceFactory;
protected $_moneybird;
public function __construct(
\Magento\Sales\Api\Data\OrderInterface $order,
\Picqer\Financials\Moneybird\Connection $connection,
\Picqer\Financials\Moneybird\Moneybird $moneybird,
\Wemessage\Moneybird\Model\InvoiceFactory $invoiceFactory
){
$this->_order = $order;
$this->_connection = $connection;
$this->_invoiceFactory = $invoiceFactory;
$this->_moneybird = $moneybird;
}
...
public function execute(
\Magento\Framework\Event\Observer $observer
) {
$orderids = $observer->getEvent()->getOrderIds();
foreach($orderids as $orderid){
$order = $this->_order->load($orderid);
$this->_connection->setRedirectUrl('');
...
// connection has been established and now we need to pass it to the moneybird
$moneybird = $this->_moneybird($this->_connection);
which results in fault: PHP Fatal error: Uncaught Error: Function name must be a string...
wel one way to fix it, is to add method setConnection in that class and call it, but the problem that it's being downloaded from repository by composer so if i want to use my module in another installation i will have to do same steps.
any other workaround ?
added construct of moneybird file:
/**
* Moneybird constructor.
* @param \Picqer\Financials\Moneybird\Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
so it will not lead to confusions and unnecessary questions.