mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 05:44:32 -04:00
wip: first initial setup for creating expenses from webhooks
This commit is contained in:
parent
0e24ac0a14
commit
e05db36841
@ -11,16 +11,41 @@
|
|||||||
|
|
||||||
namespace App\Helpers\Mail\Webhook;
|
namespace App\Helpers\Mail\Webhook;
|
||||||
|
|
||||||
|
use App\Factory\ExpenseFactory;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
|
use App\Utils\Traits\SavesDocuments;
|
||||||
|
|
||||||
interface BaseWebhookHandler
|
interface BaseWebhookHandler
|
||||||
{
|
{
|
||||||
|
use GeneratesCounter;
|
||||||
|
use SavesDocuments;
|
||||||
public function process()
|
public function process()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
protected function createExpense(string $email, string $subject, string $plain_message, string $html_message, string $date, array $documents)
|
||||||
|
{
|
||||||
|
$company = $this->matchCompany($email);
|
||||||
|
if (!$company)
|
||||||
|
return false;
|
||||||
|
|
||||||
protected function matchCompany(string $email)
|
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
|
||||||
|
|
||||||
|
$expense->public_notes = $subject;
|
||||||
|
$expense->private_notes = $plain_message;
|
||||||
|
$expense->date = $date;
|
||||||
|
|
||||||
|
// TODO: add html_message as document to the expense
|
||||||
|
|
||||||
|
$this->saveDocuments($documents, $expense);
|
||||||
|
|
||||||
|
$expense->saveQuietly();
|
||||||
|
|
||||||
|
return $expense;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function matchCompany(string $email)
|
||||||
{
|
{
|
||||||
return Company::where("expense_mailbox", $email)->first();
|
return Company::where("expense_mailbox", $email)->first();
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,104 @@ use App\Helpers\Mail\Webhook\BaseWebhookHandler;
|
|||||||
|
|
||||||
interface PostmarkWebhookHandler extends BaseWebhookHandler
|
interface PostmarkWebhookHandler extends BaseWebhookHandler
|
||||||
{
|
{
|
||||||
|
// {
|
||||||
|
// "FromName": "Postmarkapp Support",
|
||||||
|
// "MessageStream": "inbound",
|
||||||
|
// "From": "support@postmarkapp.com",
|
||||||
|
// "FromFull": {
|
||||||
|
// "Email": "support@postmarkapp.com",
|
||||||
|
// "Name": "Postmarkapp Support",
|
||||||
|
// "MailboxHash": ""
|
||||||
|
// },
|
||||||
|
// "To": "\"Firstname Lastname\" <yourhash+SampleHash@inbound.postmarkapp.com>",
|
||||||
|
// "ToFull": [
|
||||||
|
// {
|
||||||
|
// "Email": "yourhash+SampleHash@inbound.postmarkapp.com",
|
||||||
|
// "Name": "Firstname Lastname",
|
||||||
|
// "MailboxHash": "SampleHash"
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// "Cc": "\"First Cc\" <firstcc@postmarkapp.com>, secondCc@postmarkapp.com>",
|
||||||
|
// "CcFull": [
|
||||||
|
// {
|
||||||
|
// "Email": "firstcc@postmarkapp.com",
|
||||||
|
// "Name": "First Cc",
|
||||||
|
// "MailboxHash": ""
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "Email": "secondCc@postmarkapp.com",
|
||||||
|
// "Name": "",
|
||||||
|
// "MailboxHash": ""
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// "Bcc": "\"First Bcc\" <firstbcc@postmarkapp.com>, secondbcc@postmarkapp.com>",
|
||||||
|
// "BccFull": [
|
||||||
|
// {
|
||||||
|
// "Email": "firstbcc@postmarkapp.com",
|
||||||
|
// "Name": "First Bcc",
|
||||||
|
// "MailboxHash": ""
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "Email": "secondbcc@postmarkapp.com",
|
||||||
|
// "Name": "",
|
||||||
|
// "MailboxHash": ""
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// "OriginalRecipient": "yourhash+SampleHash@inbound.postmarkapp.com",
|
||||||
|
// "Subject": "Test subject",
|
||||||
|
// "MessageID": "73e6d360-66eb-11e1-8e72-a8904824019b",
|
||||||
|
// "ReplyTo": "replyto@postmarkapp.com",
|
||||||
|
// "MailboxHash": "SampleHash",
|
||||||
|
// "Date": "Fri, 1 Aug 2014 16:45:32 -04:00",
|
||||||
|
// "TextBody": "This is a test text body.",
|
||||||
|
// "HtmlBody": "<html><body><p>This is a test html body.<\/p><\/body><\/html>",
|
||||||
|
// "StrippedTextReply": "This is the reply text",
|
||||||
|
// "Tag": "TestTag",
|
||||||
|
// "Headers": [
|
||||||
|
// {
|
||||||
|
// "Name": "X-Header-Test",
|
||||||
|
// "Value": ""
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "Name": "X-Spam-Status",
|
||||||
|
// "Value": "No"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "Name": "X-Spam-Score",
|
||||||
|
// "Value": "-0.1"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "Name": "X-Spam-Tests",
|
||||||
|
// "Value": "DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_PASS"
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// "Attachments": [
|
||||||
|
// {
|
||||||
|
// "Name": "test.txt",
|
||||||
|
// "Content": "VGhpcyBpcyBhdHRhY2htZW50IGNvbnRlbnRzLCBiYXNlLTY0IGVuY29kZWQu",
|
||||||
|
// "ContentType": "text/plain",
|
||||||
|
// "ContentLength": 45
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
public function process($data)
|
public function process($data)
|
||||||
{
|
{
|
||||||
|
|
||||||
$email = '';
|
$from = $data["From"];
|
||||||
|
$subject = $data["Subject"];
|
||||||
|
$plain_message = $data["TextBody"];
|
||||||
|
$html_message = $data["HtmlBody"];
|
||||||
|
$date = $data["Date"]; // TODO
|
||||||
|
$attachments = $data["Attachments"]; // TODO
|
||||||
|
|
||||||
$company = $this->matchCompany($email);
|
return $this->createExpense(
|
||||||
if (!$company)
|
$from, // from
|
||||||
return false;
|
$subject, // subject
|
||||||
|
$plain_message, // plain_message
|
||||||
$expense = ExpenseFactory::create($company->id, $company->owner()->id);
|
$html_message, // html_message
|
||||||
|
$date, // date
|
||||||
|
$attachments, // attachments
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user