fetchesPerfexCRMCustomer = $fetchesPerfexCRMCustomer; $this->fetchesPerfexCRMInvoice = $fetchesPerfexCRMInvoice; $this->createPerfexCRMInvoiceProcessor = $createPerfexCRMInvoiceProcessor; } public function execute(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject) { //get the client id $customer = $this->fetchesPerfexCRMCustomer->execute($updatePerfexCRMInvoiceObject->getEmail()); $transaction = $updatePerfexCRMInvoiceObject->getTransaction(); //get the invoice id $invoiceId = 0; $number = $transaction->bill_no; $prefix = "INV-"; //This will remove the prefix if prefix already exist in the string if (substr($number, 0, strlen($prefix)) == $prefix) { $number = substr($number, strlen($prefix)); } $number = 'EXC-'.$number; $invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number); Log::error(json_encode('CreatePerfexCRMInvoiceV2Processor debug $number: '.$number)); if(is_null($invoice)){ $result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null, $updatePerfexCRMInvoiceObject->getIsPaid()); if ($result) { $invoiceId = $result->payload['id']; } else { $log['message'] = 'CreatePerfexCRMInvoiceV2Processor CreatePerfexCRMInvoiceProcessor failed'; Helper::debugLoggerForPerfexCRM($log); } } return $invoiceId; } }