mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #7128 from turbo124/v5-develop
Fixes for client store request
This commit is contained in:
commit
88c6fc6d4c
@ -92,7 +92,10 @@ class NinjaPlanController extends Controller
|
||||
->first();
|
||||
|
||||
//account status means user cannot perform upgrades until they pay their account.
|
||||
$data['late_invoice'] = $late_invoice;
|
||||
// $data['late_invoice'] = $late_invoice;
|
||||
|
||||
//14-01-2022 remove late invoices from blocking upgrades
|
||||
$data['late_invoice'] = false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ class SwitchCompanyController extends Controller
|
||||
|
||||
auth()->guard('contact')->loginUsingId($client_contact->id, true);
|
||||
|
||||
request()->session()->regenerate();
|
||||
|
||||
return redirect('/client/dashboard');
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\DataMapper\Analytics\Mail\EmailBounce;
|
||||
use App\DataMapper\Analytics\Mail\EmailSpam;
|
||||
use App\Jobs\PostMark\ProcessPostmarkWebhook;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\CreditInvitation;
|
||||
@ -77,27 +78,7 @@ class PostMarkController extends BaseController
|
||||
if($request->header('X-API-SECURITY') && $request->header('X-API-SECURITY') == config('postmark.secret'))
|
||||
{
|
||||
|
||||
MultiDB::findAndSetDbByCompanyKey($request->input('Tag'));
|
||||
|
||||
$this->invitation = $this->discoverInvitation($request->input('MessageID'));
|
||||
|
||||
if($this->invitation)
|
||||
$this->invitation->email_error = $request->input('Details');
|
||||
else
|
||||
return response()->json(['message' => 'Message not found']);
|
||||
|
||||
switch ($request->input('RecordType'))
|
||||
{
|
||||
case 'Delivery':
|
||||
return $this->processDelivery($request);
|
||||
case 'Bounce':
|
||||
return $this->processBounce($request);
|
||||
case 'SpamComplaint':
|
||||
return $this->processSpamComplaint($request);
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
ProcessPostmarkWebhook::dispatch($request->all());
|
||||
|
||||
return response()->json(['message' => 'Success'], 200);
|
||||
|
||||
@ -107,139 +88,4 @@ class PostMarkController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
// {
|
||||
// "RecordType": "Delivery",
|
||||
// "ServerID": 23,
|
||||
// "MessageStream": "outbound",
|
||||
// "MessageID": "00000000-0000-0000-0000-000000000000",
|
||||
// "Recipient": "john@example.com",
|
||||
// "Tag": "welcome-email",
|
||||
// "DeliveredAt": "2021-02-21T16:34:52Z",
|
||||
// "Details": "Test delivery webhook details",
|
||||
// "Metadata": {
|
||||
// "example": "value",
|
||||
// "example_2": "value"
|
||||
// }
|
||||
// }
|
||||
private function processDelivery($request)
|
||||
{
|
||||
$this->invitation->email_status = 'delivered';
|
||||
$this->invitation->save();
|
||||
|
||||
SystemLogger::dispatch($request->all(),
|
||||
SystemLog::CATEGORY_MAIL,
|
||||
SystemLog::EVENT_MAIL_DELIVERY,
|
||||
SystemLog::TYPE_WEBHOOK_RESPONSE,
|
||||
$this->invitation->contact->client,
|
||||
$this->invitation->company
|
||||
);
|
||||
}
|
||||
|
||||
// {
|
||||
// "Metadata": {
|
||||
// "example": "value",
|
||||
// "example_2": "value"
|
||||
// },
|
||||
// "RecordType": "Bounce",
|
||||
// "ID": 42,
|
||||
// "Type": "HardBounce",
|
||||
// "TypeCode": 1,
|
||||
// "Name": "Hard bounce",
|
||||
// "Tag": "Test",
|
||||
// "MessageID": "00000000-0000-0000-0000-000000000000",
|
||||
// "ServerID": 1234,
|
||||
// "MessageStream": "outbound",
|
||||
// "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
|
||||
// "Details": "Test bounce details",
|
||||
// "Email": "john@example.com",
|
||||
// "From": "sender@example.com",
|
||||
// "BouncedAt": "2021-02-21T16:34:52Z",
|
||||
// "DumpAvailable": true,
|
||||
// "Inactive": true,
|
||||
// "CanActivate": true,
|
||||
// "Subject": "Test subject",
|
||||
// "Content": "Test content"
|
||||
// }
|
||||
|
||||
private function processBounce($request)
|
||||
{
|
||||
$this->invitation->email_status = 'bounced';
|
||||
$this->invitation->save();
|
||||
|
||||
$bounce = new EmailBounce(
|
||||
$request->input('Tag'),
|
||||
$request->input('From'),
|
||||
$request->input('MessageID')
|
||||
);
|
||||
|
||||
LightLogs::create($bounce)->queue();
|
||||
|
||||
SystemLogger::dispatch($request->all(), SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company);
|
||||
|
||||
if(config('ninja.notification.slack'))
|
||||
$this->invitation->company->notification(new EmailBounceNotification($this->invitation->company->account))->ninja();
|
||||
|
||||
}
|
||||
|
||||
// {
|
||||
// "Metadata": {
|
||||
// "example": "value",
|
||||
// "example_2": "value"
|
||||
// },
|
||||
// "RecordType": "SpamComplaint",
|
||||
// "ID": 42,
|
||||
// "Type": "SpamComplaint",
|
||||
// "TypeCode": 100001,
|
||||
// "Name": "Spam complaint",
|
||||
// "Tag": "Test",
|
||||
// "MessageID": "00000000-0000-0000-0000-000000000000",
|
||||
// "ServerID": 1234,
|
||||
// "MessageStream": "outbound",
|
||||
// "Description": "The subscriber explicitly marked this message as spam.",
|
||||
// "Details": "Test spam complaint details",
|
||||
// "Email": "john@example.com",
|
||||
// "From": "sender@example.com",
|
||||
// "BouncedAt": "2021-02-21T16:34:52Z",
|
||||
// "DumpAvailable": true,
|
||||
// "Inactive": true,
|
||||
// "CanActivate": false,
|
||||
// "Subject": "Test subject",
|
||||
// "Content": "Test content"
|
||||
// }
|
||||
private function processSpamComplaint($request)
|
||||
{
|
||||
|
||||
$this->invitation->email_status = 'spam';
|
||||
$this->invitation->save();
|
||||
|
||||
$spam = new EmailSpam(
|
||||
$request->input('Tag'),
|
||||
$request->input('From'),
|
||||
$request->input('MessageID')
|
||||
);
|
||||
|
||||
LightLogs::create($spam)->queue();
|
||||
|
||||
SystemLogger::dispatch($request->all(), SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company);
|
||||
|
||||
if(config('ninja.notification.slack'))
|
||||
$this->invitation->company->notification(new EmailSpamNotification($this->invitation->company->account))->ninja();
|
||||
|
||||
}
|
||||
|
||||
private function discoverInvitation($message_id)
|
||||
{
|
||||
$invitation = false;
|
||||
|
||||
if($invitation = InvoiceInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
elseif($invitation = QuoteInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
elseif($invitation = RecurringInvoiceInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
elseif($invitation = CreditInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
else
|
||||
return $invitation;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ use App\Http\Middleware\PasswordProtection;
|
||||
use App\Http\Middleware\PhantomSecret;
|
||||
use App\Http\Middleware\QueryLogging;
|
||||
use App\Http\Middleware\RedirectIfAuthenticated;
|
||||
use App\Http\Middleware\SessionDomains;
|
||||
use App\Http\Middleware\SetDb;
|
||||
use App\Http\Middleware\SetDbByCompanyKey;
|
||||
use App\Http\Middleware\SetDocumentDb;
|
||||
@ -83,6 +84,7 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
SessionDomains::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
@ -103,6 +105,7 @@ class Kernel extends HttpKernel
|
||||
'query_logging',
|
||||
],
|
||||
'client' => [
|
||||
SessionDomains::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
@ -161,10 +164,12 @@ class Kernel extends HttpKernel
|
||||
'check_client_existence' => CheckClientExistence::class,
|
||||
'user_verified' => UserVerified::class,
|
||||
'document_db' => SetDocumentDb::class,
|
||||
'session_domain' => SessionDomains::class,
|
||||
];
|
||||
|
||||
|
||||
protected $middlewarePriority = [
|
||||
SessionDomains::class,
|
||||
Cors::class,
|
||||
SetDomainNameDb::class,
|
||||
SetDb::class,
|
||||
|
@ -409,7 +409,7 @@ class BillingPortalPurchase extends Component
|
||||
'quantity' => $this->quantity,
|
||||
'contact_id' => $this->contact->id,
|
||||
'client_id' => $this->contact->client->id,
|
||||
'coupon' => '',
|
||||
'coupon' => $this->coupon,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class CheckClientExistence
|
||||
return $query->where('is_deleted', false);
|
||||
})
|
||||
->whereHas('company', function ($query){
|
||||
return $query->where('account_id', auth('contact')->user()->client->company->account->id);
|
||||
return $query->where('id', auth('contact')->user()->client->company_id);
|
||||
})
|
||||
->get();
|
||||
|
||||
|
50
app/Http/Middleware/SessionDomains.php
Normal file
50
app/Http/Middleware/SessionDomains.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
|
||||
class SessionDomains
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if(Ninja::isSelfHost())
|
||||
return $next($request);
|
||||
|
||||
$domain_name = $request->getHost();
|
||||
|
||||
if (strpos($domain_name, 'invoicing.co') !== false)
|
||||
{
|
||||
config(['session.domain' => '.invoicing.co']);
|
||||
}
|
||||
else{
|
||||
|
||||
Cookie::queue(Cookie::forget('invoice_ninja_session', '/'));
|
||||
|
||||
config(['session.domain' => $domain_name]);
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
@ -30,4 +31,17 @@ class VerifyCsrfToken extends Middleware
|
||||
protected $except = [
|
||||
// 'livewire/message/*'
|
||||
];
|
||||
|
||||
|
||||
// public function handle($request, \Closure $next) {
|
||||
|
||||
// try {
|
||||
// return parent::handle($request, $next);
|
||||
// } catch (TokenMismatchException $ex) {
|
||||
|
||||
// throw new TokenMismatchException('CSRF token mismatch.');
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -89,8 +89,6 @@ class StoreClientRequest extends Request
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
//@todo implement feature permissions for > 50 clients
|
||||
|
||||
$settings = ClientSettings::defaults();
|
||||
|
||||
@ -133,6 +131,10 @@ class StoreClientRequest extends Request
|
||||
$input['shipping_country_id'] = $this->getCountryCode($input['shipping_country_code']);
|
||||
}
|
||||
|
||||
/* If there is no number, just unset it here. */
|
||||
if(array_key_exists('number', $input) && ( is_null($input['number']) || empty($input['number'])))
|
||||
unset($input['number']);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
@ -71,10 +71,6 @@ class UpdatePaymentRequest extends Request
|
||||
unset($input['amount']);
|
||||
}
|
||||
|
||||
// if (isset($input['number'])) {
|
||||
// unset($input['number']);
|
||||
// }
|
||||
|
||||
if (isset($input['invoices']) && is_array($input['invoices']) !== false) {
|
||||
foreach ($input['invoices'] as $key => $value) {
|
||||
$input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($value['invoice_id']);
|
||||
|
@ -111,6 +111,10 @@ class StoreRecurringInvoiceRequest extends Request
|
||||
}
|
||||
}
|
||||
|
||||
/* If there is no number, just unset it here. */
|
||||
if(array_key_exists('number', $input) && ( is_null($input['number']) || empty($input['number'])))
|
||||
unset($input['number']);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class PaymentAppliedValidAmount implements Rule
|
||||
|
||||
private function calculateAmounts() :bool
|
||||
{
|
||||
$payment = Payment::whereId($this->decodePrimaryKey(request()->segment(4)))->company()->first();
|
||||
$payment = Payment::withTrashed()->whereId($this->decodePrimaryKey(request()->segment(4)))->company()->first();
|
||||
|
||||
if (! $payment) {
|
||||
return false;
|
||||
@ -53,6 +53,15 @@ class PaymentAppliedValidAmount implements Rule
|
||||
|
||||
$payment_amounts = $payment->amount - $payment->refunded - $payment->applied;
|
||||
|
||||
if(request()->has('credits')
|
||||
&& is_array(request()->input('credits'))
|
||||
&& count(request()->input('credits')) == 0
|
||||
&& request()->has('invoices')
|
||||
&& is_array(request()->input('invoices'))
|
||||
&& count(request()->input('invoices')) == 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (request()->input('credits') && is_array(request()->input('credits'))) {
|
||||
foreach (request()->input('credits') as $credit) {
|
||||
$payment_amounts += $credit['amount'];
|
||||
|
@ -31,6 +31,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
/*Multi Mailer implemented*/
|
||||
|
||||
@ -74,8 +75,10 @@ class PaymentFailedMailer implements ShouldQueue
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
App::setLocale($this->client->locale());
|
||||
|
||||
$settings = $this->client->getMergedSettings();
|
||||
|
||||
$amount = 0;
|
||||
$invoice = false;
|
||||
|
||||
|
233
app/Jobs/PostMark/ProcessPostmarkWebhook.php
Normal file
233
app/Jobs/PostMark/ProcessPostmarkWebhook.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Jobs\PostMark;
|
||||
|
||||
use App\DataMapper\Analytics\Mail\EmailBounce;
|
||||
use App\DataMapper\Analytics\Mail\EmailSpam;
|
||||
use App\Events\Payment\PaymentWasEmailed;
|
||||
use App\Events\Payment\PaymentWasEmailedAndFailed;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Engine\PaymentEmailEngine;
|
||||
use App\Mail\TemplateEmail;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\Payment;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Models\SystemLog;
|
||||
use App\Notifications\Ninja\EmailBounceNotification;
|
||||
use App\Notifications\Ninja\EmailSpamNotification;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Turbo124\Beacon\Facades\LightLogs;
|
||||
|
||||
class ProcessPostmarkWebhook implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
private array $request;
|
||||
|
||||
public $invitation;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param Payment $payment
|
||||
* @param $email_builder
|
||||
* @param $contact
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct(array $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
MultiDB::findAndSetDbByCompanyKey($this->request['Tag']);
|
||||
|
||||
$this->invitation = $this->discoverInvitation($this->request['MessageID']);
|
||||
|
||||
if(!$this->invitation)
|
||||
return;
|
||||
|
||||
$this->invitation->email_error = $this->request['Details'];
|
||||
|
||||
switch ($this->request['RecordType'])
|
||||
{
|
||||
case 'Delivery':
|
||||
return $this->processDelivery();
|
||||
case 'Bounce':
|
||||
return $this->processBounce();
|
||||
case 'SpamComplaint':
|
||||
return $this->processSpamComplaint();
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// {
|
||||
// "RecordType": "Delivery",
|
||||
// "ServerID": 23,
|
||||
// "MessageStream": "outbound",
|
||||
// "MessageID": "00000000-0000-0000-0000-000000000000",
|
||||
// "Recipient": "john@example.com",
|
||||
// "Tag": "welcome-email",
|
||||
// "DeliveredAt": "2021-02-21T16:34:52Z",
|
||||
// "Details": "Test delivery webhook details",
|
||||
// "Metadata": {
|
||||
// "example": "value",
|
||||
// "example_2": "value"
|
||||
// }
|
||||
// }
|
||||
private function processDelivery()
|
||||
{
|
||||
$this->invitation->email_status = 'delivered';
|
||||
$this->invitation->save();
|
||||
|
||||
SystemLogger::dispatch($this->request,
|
||||
SystemLog::CATEGORY_MAIL,
|
||||
SystemLog::EVENT_MAIL_DELIVERY,
|
||||
SystemLog::TYPE_WEBHOOK_RESPONSE,
|
||||
$this->invitation->contact->client,
|
||||
$this->invitation->company
|
||||
);
|
||||
}
|
||||
|
||||
// {
|
||||
// "Metadata": {
|
||||
// "example": "value",
|
||||
// "example_2": "value"
|
||||
// },
|
||||
// "RecordType": "Bounce",
|
||||
// "ID": 42,
|
||||
// "Type": "HardBounce",
|
||||
// "TypeCode": 1,
|
||||
// "Name": "Hard bounce",
|
||||
// "Tag": "Test",
|
||||
// "MessageID": "00000000-0000-0000-0000-000000000000",
|
||||
// "ServerID": 1234,
|
||||
// "MessageStream": "outbound",
|
||||
// "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
|
||||
// "Details": "Test bounce details",
|
||||
// "Email": "john@example.com",
|
||||
// "From": "sender@example.com",
|
||||
// "BouncedAt": "2021-02-21T16:34:52Z",
|
||||
// "DumpAvailable": true,
|
||||
// "Inactive": true,
|
||||
// "CanActivate": true,
|
||||
// "Subject": "Test subject",
|
||||
// "Content": "Test content"
|
||||
// }
|
||||
|
||||
private function processBounce()
|
||||
{
|
||||
$this->invitation->email_status = 'bounced';
|
||||
$this->invitation->save();
|
||||
|
||||
$bounce = new EmailBounce(
|
||||
$this->request['Tag'],
|
||||
$this->request['From'],
|
||||
$this->request['MessageID']
|
||||
);
|
||||
|
||||
LightLogs::create($bounce)->queue();
|
||||
|
||||
SystemLogger::dispatch($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company);
|
||||
|
||||
if(config('ninja.notification.slack'))
|
||||
$this->invitation->company->notification(new EmailBounceNotification($this->invitation->company->account))->ninja();
|
||||
|
||||
}
|
||||
|
||||
// {
|
||||
// "Metadata": {
|
||||
// "example": "value",
|
||||
// "example_2": "value"
|
||||
// },
|
||||
// "RecordType": "SpamComplaint",
|
||||
// "ID": 42,
|
||||
// "Type": "SpamComplaint",
|
||||
// "TypeCode": 100001,
|
||||
// "Name": "Spam complaint",
|
||||
// "Tag": "Test",
|
||||
// "MessageID": "00000000-0000-0000-0000-000000000000",
|
||||
// "ServerID": 1234,
|
||||
// "MessageStream": "outbound",
|
||||
// "Description": "The subscriber explicitly marked this message as spam.",
|
||||
// "Details": "Test spam complaint details",
|
||||
// "Email": "john@example.com",
|
||||
// "From": "sender@example.com",
|
||||
// "BouncedAt": "2021-02-21T16:34:52Z",
|
||||
// "DumpAvailable": true,
|
||||
// "Inactive": true,
|
||||
// "CanActivate": false,
|
||||
// "Subject": "Test subject",
|
||||
// "Content": "Test content"
|
||||
// }
|
||||
private function processSpamComplaint()
|
||||
{
|
||||
|
||||
$this->invitation->email_status = 'spam';
|
||||
$this->invitation->save();
|
||||
|
||||
$spam = new EmailSpam(
|
||||
$this->request['Tag'],
|
||||
$this->request['From'],
|
||||
$this->request['MessageID']
|
||||
);
|
||||
|
||||
LightLogs::create($spam)->queue();
|
||||
|
||||
SystemLogger::dispatch($this->request, SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company);
|
||||
|
||||
if(config('ninja.notification.slack'))
|
||||
$this->invitation->company->notification(new EmailSpamNotification($this->invitation->company->account))->ninja();
|
||||
|
||||
}
|
||||
|
||||
private function discoverInvitation($message_id)
|
||||
{
|
||||
$invitation = false;
|
||||
|
||||
if($invitation = InvoiceInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
elseif($invitation = QuoteInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
elseif($invitation = RecurringInvoiceInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
elseif($invitation = CreditInvitation::where('message_id', $message_id)->first())
|
||||
return $invitation;
|
||||
else
|
||||
return $invitation;
|
||||
}
|
||||
}
|
@ -83,7 +83,8 @@ class ReminderJob implements ShouldQueue
|
||||
$invoice->service()->touchPdf();
|
||||
|
||||
//check if this reminder needs to be emailed
|
||||
if(in_array($reminder_template, ['reminder1','reminder2','reminder3','reminder_endless']) && $invoice->client->getSetting("enable_".$reminder_template))
|
||||
//15-01-2022 - insert addition if block if send_reminders is definitely set
|
||||
if(in_array($reminder_template, ['reminder1','reminder2','reminder3','reminder_endless']) && $invoice->client->getSetting("enable_".$reminder_template) && $invoice->client->getSetting("send_reminders"))
|
||||
{
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
|
||||
|
@ -124,7 +124,8 @@ class ClientPaymentFailureObject
|
||||
'settings' => $this->client->getMergedSettings(),
|
||||
'whitelabel' => $this->company->account->isPaid() ? true : false,
|
||||
'url' => $this->invoices->first()->invitations->first()->getPaymentLink(),
|
||||
'button' => 'texts.pay_now',
|
||||
// 'button' => 'texts.pay_now',
|
||||
'button' => ctrans('texts.pay_now'),
|
||||
'additional_info' => false,
|
||||
'company' => $this->company,
|
||||
];
|
||||
|
@ -16,6 +16,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class BouncedEmail extends Mailable
|
||||
{
|
||||
@ -34,9 +35,11 @@ class BouncedEmail extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->invitation->company->getLocale());
|
||||
|
||||
$entity_type = class_basename(lcfirst($this->invitation->getEntityType()));
|
||||
|
||||
$subject = ctrans("texts.notification_{$entity_type}_bounced_subject", ['invoice' => $invoice->number]);
|
||||
$subject = ctrans("texts.notification_{$entity_type}_bounced_subject", ['invoice' => $this->invitation->invoice->number]);
|
||||
|
||||
return
|
||||
$this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
|
@ -35,19 +35,19 @@ class ClientContactResetPasswordObject
|
||||
public function build()
|
||||
{
|
||||
|
||||
$settings = $this->client_contact->client->getMergedSettings();
|
||||
App::forgetInstance('translator');
|
||||
$t = app('translator');
|
||||
App::setLocale($this->client_contact->preferredLocale());
|
||||
$t->replace(Ninja::transformTranslations($this->client_contact->client->getMergedSettings()));
|
||||
|
||||
$t->replace(Ninja::transformTranslations($settings));
|
||||
|
||||
$data = [
|
||||
'title' => ctrans('texts.your_password_reset_link'),
|
||||
'content' => ctrans('texts.reset_password'),
|
||||
'url' => route('client.password.reset', ['token' => $this->token, 'email' => $this->client_contact->email]),
|
||||
'button' => ctrans('texts.reset'),
|
||||
'signature' => $this->company->settings->email_signature,
|
||||
'settings' => $this->company->settings,
|
||||
'signature' => $settings->email_signature,
|
||||
'settings' => $settings,
|
||||
'company' => $this->company,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
];
|
||||
|
@ -15,6 +15,7 @@ namespace App\Mail\Company;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class CompanyDeleted extends Mailable
|
||||
{
|
||||
@ -47,6 +48,8 @@ class CompanyDeleted extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->subject(ctrans('texts.company_deleted'))
|
||||
->view('email.admin.company_deleted')
|
||||
|
@ -18,6 +18,7 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class ContactPasswordlessLogin extends Mailable
|
||||
{
|
||||
@ -52,6 +53,9 @@ class ContactPasswordlessLogin extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
return $this
|
||||
->subject(ctrans('texts.account_passwordless_login'))
|
||||
->view('email.billing.passwordless-login', [
|
||||
|
@ -6,6 +6,7 @@ use App\Models\Company;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class DownloadInvoices extends Mailable
|
||||
{
|
||||
@ -27,6 +28,9 @@ class DownloadInvoices extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
return $this->from(config('mail.from.address'), config('mail.from.name'))
|
||||
->subject(ctrans('texts.download_files'))
|
||||
->view('email.admin.download_invoices', [
|
||||
|
@ -45,6 +45,7 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
public function build()
|
||||
{
|
||||
App::forgetInstance('translator');
|
||||
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace App\Mail\Gateways;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class ACHVerificationNotification extends Mailable
|
||||
{
|
||||
@ -49,6 +50,8 @@ class ACHVerificationNotification extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
return $this
|
||||
->subject(ctrans('texts.ach_verification_notification_label'))
|
||||
->view('email.gateways.ach-verification-notification', [
|
||||
|
@ -14,6 +14,7 @@ namespace App\Mail\Import;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class CompanyImportFailure extends Mailable
|
||||
{
|
||||
@ -51,6 +52,8 @@ class CompanyImportFailure extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
$this->settings = $this->company->settings;
|
||||
$this->logo = $this->company->present()->logo();
|
||||
$this->title = ctrans('texts.company_import_failure_subject', ['company' => $this->company->present()->name()]);
|
||||
|
@ -49,6 +49,8 @@ class ImportCompleted extends Mailable
|
||||
{
|
||||
|
||||
App::forgetInstance('translator');
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace App\Mail\Migration;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class MaxCompanies extends Mailable
|
||||
{
|
||||
@ -48,6 +49,8 @@ class MaxCompanies extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
$this->settings = $this->company->settings;
|
||||
$this->logo = $this->company->present()->logo();
|
||||
$this->title = ctrans('texts.max_companies');
|
||||
|
@ -14,6 +14,7 @@ namespace App\Mail\Migration;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class StripeConnectMigration extends Mailable
|
||||
{
|
||||
@ -44,6 +45,8 @@ class StripeConnectMigration extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
$this->settings = $this->company->settings;
|
||||
$this->logo = $this->company->present()->logo();
|
||||
$this->whitelabel = $this->company->account->isPaid();
|
||||
|
@ -14,6 +14,7 @@ namespace App\Mail\Ninja;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class EmailQuotaExceeded extends Mailable
|
||||
{
|
||||
@ -47,6 +48,8 @@ class EmailQuotaExceeded extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
$this->settings = $this->company->settings;
|
||||
$this->logo = $this->company->present()->logo();
|
||||
$this->title = ctrans('texts.email_quota_exceeded_subject');
|
||||
|
@ -37,6 +37,8 @@ class ClientContactRequestCancellationObject
|
||||
{
|
||||
|
||||
App::forgetInstance('translator');
|
||||
App::setLocale($this->company->getLocale());
|
||||
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||
|
||||
|
@ -222,7 +222,9 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
*/
|
||||
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
|
||||
{
|
||||
$this->confirmGatewayFee();
|
||||
|
||||
if(in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING]) )
|
||||
$this->confirmGatewayFee();
|
||||
|
||||
/*Never create a payment with a duplicate transaction reference*/
|
||||
if(array_key_exists('transaction_reference', $data)){
|
||||
@ -253,6 +255,10 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
$payment->client_contact_id = $client_contact_id;
|
||||
$payment->saveQuietly();
|
||||
|
||||
/* Return early if the payment is no completed or pending*/
|
||||
if(!in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING]) )
|
||||
return $payment;
|
||||
|
||||
$this->payment_hash->payment_id = $payment->id;
|
||||
$this->payment_hash->save();
|
||||
|
||||
|
@ -312,11 +312,12 @@ class MolliePaymentDriver extends BaseDriver
|
||||
|
||||
if($record){
|
||||
$client = $record->client;
|
||||
$this->client = $client;
|
||||
}
|
||||
else{
|
||||
|
||||
$client = Client::withTrashed()->find($this->decodePrimaryKey($payment->metadata->client_id));
|
||||
|
||||
$this->client = $client;
|
||||
// sometimes if the user is not returned to the site with a response from Mollie
|
||||
// we may not have a payment record - in these cases we need to re-construct the payment
|
||||
// record from the meta data in the payment hash.
|
||||
@ -326,6 +327,9 @@ class MolliePaymentDriver extends BaseDriver
|
||||
/* Harvest Payment Hash*/
|
||||
$payment_hash = PaymentHash::where('hash', $payment->metadata->hash)->first();
|
||||
|
||||
/* If we are here, then we do not have access to the class payment hash, so lets set it here*/
|
||||
$this->payment_hash = $payment_hash;
|
||||
|
||||
$data = [
|
||||
'gateway_type_id' => $payment->metadata->gateway_type_id,
|
||||
'amount' => $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total,
|
||||
|
@ -40,6 +40,7 @@ class ActivityTransformer extends EntityTransformer
|
||||
'activity_type_id' => (string) $activity->activity_type_id,
|
||||
'client_id' => $activity->client_id ? (string) $this->encodePrimaryKey($activity->client_id) : '',
|
||||
'recurring_invoice_id' => $activity->recurring_invoice_id ? (string) $this->encodePrimaryKey($activity->recurring_invoice_id) : '',
|
||||
'recurring_expense_id' => $activity->recurring_expense_id ? (string) $this->encodePrimaryKey($activity->recurring_expense_id) : '',
|
||||
'company_id' => $activity->company_id ? (string) $this->encodePrimaryKey($activity->company_id) : '',
|
||||
'user_id' => (string) $this->encodePrimaryKey($activity->user_id),
|
||||
'invoice_id' => $activity->invoice_id ? (string) $this->encodePrimaryKey($activity->invoice_id) : '',
|
||||
|
@ -36,8 +36,6 @@ trait GeneratesCounter
|
||||
//todo in the form validation, we need to ensure that if a prefix and pattern is set we throw a validation error,
|
||||
//only one type is allow else this will cause confusion to the end user
|
||||
|
||||
|
||||
|
||||
private function getNextEntityNumber($entity, Client $client, $is_recurring = false)
|
||||
{
|
||||
$prefix = '';
|
||||
|
@ -68,6 +68,56 @@ class ClientApiTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
public function testClientNoneValidation()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'name' => $this->faker->firstName,
|
||||
'number' => '',
|
||||
];
|
||||
|
||||
$response = false;
|
||||
|
||||
try{
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/clients/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testClientNullValidation()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'name' => $this->faker->firstName,
|
||||
'number' => null,
|
||||
];
|
||||
|
||||
$response = false;
|
||||
|
||||
try{
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/clients/', $data);
|
||||
} catch (ValidationException $e) {
|
||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||
nlog($message);
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testClientCountryCodeValidationTrueIso3()
|
||||
{
|
||||
|
||||
|
@ -111,4 +111,90 @@ class InvoiceAmountPaymentTest extends TestCase
|
||||
$this->assertEquals(10, $payment->amount);
|
||||
|
||||
}
|
||||
|
||||
public function testMarkPaidRemovesUnpaidGatewayFees()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'name' => 'A Nice Client',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/clients', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$client_hash_id = $arr['data']['id'];
|
||||
$client = Client::find($this->decodePrimaryKey($client_hash_id));
|
||||
|
||||
$this->assertEquals($client->balance, 0);
|
||||
$this->assertEquals($client->paid_to_date, 0);
|
||||
//create new invoice.
|
||||
|
||||
$line_items = [];
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 10;
|
||||
|
||||
$line_items[] = (array)$item;
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 10;
|
||||
|
||||
$line_items[] = (array)$item;
|
||||
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
$item->cost = 5;
|
||||
$item->type_id = "3";
|
||||
|
||||
$line_items[] = (array)$item;
|
||||
|
||||
$invoice = [
|
||||
'status_id' => 1,
|
||||
'number' => '',
|
||||
'discount' => 0,
|
||||
'is_amount_discount' => 1,
|
||||
'po_number' => '3434343',
|
||||
'public_notes' => 'notes',
|
||||
'is_deleted' => 0,
|
||||
'custom_value1' => 0,
|
||||
'custom_value2' => 0,
|
||||
'custom_value3' => 0,
|
||||
'custom_value4' => 0,
|
||||
'client_id' => $client_hash_id,
|
||||
'line_items' => (array)$line_items,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/invoices?mark_sent=true', $invoice)
|
||||
->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$invoice_one_hashed_id = $arr['data']['id'];
|
||||
|
||||
$invoice = Invoice::find($this->decodePrimaryKey($invoice_one_hashed_id));
|
||||
|
||||
$this->assertEquals(25, $invoice->balance);
|
||||
$this->assertEquals(25, $invoice->amount);
|
||||
|
||||
$invoice->service()->markPaid()->save();
|
||||
|
||||
$invoice->fresh();
|
||||
|
||||
$this->assertEquals(20, $invoice->amount);
|
||||
$this->assertEquals(0, $invoice->balance);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
141
tests/Integration/PostmarkWebhookTest.php
Normal file
141
tests/Integration/PostmarkWebhookTest.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
namespace Tests\Integration;
|
||||
|
||||
use App\Jobs\PostMark\ProcessPostmarkWebhook;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class PostmarkWebhookTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if(!config('postmark.secret'))
|
||||
$this->markTestSkipped('Postmark Secret Set');
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testDeliveryReport()
|
||||
{
|
||||
|
||||
$invitation = $this->invoice->invitations->first();
|
||||
$invitation->message_id = '00000000-0000-0000-0000-000000000000';
|
||||
$invitation->save();
|
||||
|
||||
$data = [
|
||||
'RecordType' => "Delivery",
|
||||
'ServerID' => "23",
|
||||
'MessageStream' => "outbound",
|
||||
'MessageID' => "00000000-0000-0000-0000-000000000000",
|
||||
'Recipient' => "john@example.com",
|
||||
'Tag' => $this->company->company_key,
|
||||
'DeliveredAt' => "2021-02-21T16:34:52Z",
|
||||
'Details' => "Test delivery webhook details",
|
||||
];
|
||||
|
||||
$response = $this->post('/api/v1/postmark_webhook', $data);
|
||||
|
||||
$response->assertStatus(403);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECURITY' => config('postmark.secret')
|
||||
])->post('/api/v1/postmark_webhook', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
public function testDeliveryJob()
|
||||
{
|
||||
|
||||
$invitation = $this->invoice->invitations->first();
|
||||
$invitation->message_id = '00000000-0000-0000-0000-000000000000';
|
||||
$invitation->save();
|
||||
|
||||
ProcessPostmarkWebhook::dispatchNow([
|
||||
'RecordType' => "Delivery",
|
||||
'ServerID' => "23",
|
||||
'MessageStream' => "outbound",
|
||||
'MessageID' => "00000000-0000-0000-0000-000000000000",
|
||||
'Recipient' => "john@example.com",
|
||||
'Tag' => $this->company->company_key,
|
||||
'DeliveredAt' => "2021-02-21T16:34:52Z",
|
||||
'Details' => "Test delivery webhook details",
|
||||
]);
|
||||
|
||||
$this->assertEquals('delivered', $invitation->fresh()->email_status);
|
||||
|
||||
}
|
||||
|
||||
public function testSpamReport()
|
||||
{
|
||||
|
||||
$invitation = $this->invoice->invitations->first();
|
||||
$invitation->message_id = '00000000-0000-0000-0000-000000000001';
|
||||
$invitation->save();
|
||||
|
||||
$data = [
|
||||
'RecordType' => "SpamComplaint",
|
||||
'ServerID' => "23",
|
||||
'MessageStream' => "outbound",
|
||||
'MessageID' => "00000000-0000-0000-0000-000000000001",
|
||||
'Recipient' => "john@example.com",
|
||||
'Tag' => $this->company->company_key,
|
||||
'DeliveredAt' => "2021-02-21T16:34:52Z",
|
||||
'Details' => "Test delivery webhook details",
|
||||
];
|
||||
|
||||
$response = $this->post('/api/v1/postmark_webhook', $data);
|
||||
|
||||
$response->assertStatus(403);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECURITY' => config('postmark.secret')
|
||||
])->post('/api/v1/postmark_webhook', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
public function testSpamJob()
|
||||
{
|
||||
|
||||
$invitation = $this->invoice->invitations->first();
|
||||
$invitation->message_id = '00000000-0000-0000-0000-000000000001';
|
||||
$invitation->save();
|
||||
|
||||
ProcessPostmarkWebhook::dispatchNow([
|
||||
'RecordType' => "SpamComplaint",
|
||||
'ServerID' => "23",
|
||||
'MessageStream' => "outbound",
|
||||
'MessageID' => "00000000-0000-0000-0000-000000000001",
|
||||
'From' => "john@example.com",
|
||||
'Tag' => $this->company->company_key,
|
||||
'DeliveredAt' => "2021-02-21T16:34:52Z",
|
||||
'Details' => "Test delivery webhook details",
|
||||
]);
|
||||
|
||||
$this->assertEquals('spam', $invitation->fresh()->email_status);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user