1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Add listener for Stripe Connect where users have not yet linked Stripe

This commit is contained in:
David Bomba 2023-08-15 22:14:00 +10:00
parent c91e093a41
commit 16c9079583
6 changed files with 280 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\Account;
use App\Models\Company;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
/**
* Class StripeConnectFailure.
*/
class StripeConnectFailure
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(public Company $company, public string $db)
{
}
public function broadcastOn()
{
return [];
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Listeners\Account;
use App\Utils\Ninja;
use App\Libraries\MultiDB;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use Illuminate\Support\Facades\Cache;
use App\Mail\Ninja\StripeConnectFailed;
use Illuminate\Contracts\Queue\ShouldQueue;
class StripeConnectFailureListener implements ShouldQueue
{
/**
* Create the event listener.
*
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->db);
if (Ninja::isHosted() && is_null(Cache::get("stripe_connect_notification:{$event->company->company_key}")))
{
$nmo = new NinjaMailerObject();
$nmo->mailable = new StripeConnectFailed($event->company->owner(), $event->company);
$nmo->company = $event->company;
$nmo->settings = $event->company->settings;
$nmo->to_user = $event->company->owner();
NinjaMailerJob::dispatch($nmo, true);
Cache::put("stripe_connect_notification:{$event->company->company_key}", true, 60 * 60 * 24);
}
}
}

View File

@ -0,0 +1,114 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Mail\Ninja;
use App\Models\User;
use App\Models\Company;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Headers;
use Illuminate\Mail\Mailables\Envelope;
class StripeConnectFailed extends Mailable
{
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(public User $user, public Company $company)
{
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: "Stripe Connect not configured, please login and connect.",
from: "maildelivery@invoicing.co",
to: $this->user->email,
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
view: 'email.admin.stripe_connect_failed',
text: 'email.admin.stripe_connect_failed_text',
with: [
'text_body' => $this->textBody(), //@todo this is a bit hacky here.
'body' => $this->htmlBody(),
'title' => 'Connect your Stripe account',
'settings' => $this->company->settings,
'logo' => $this->company->present()->logo(),
'signature' => '',
'company' => $this->company,
'greeting' => '',
'links' => [],
'url' => 'https://www.loom.com/share/a3dc3131cc924e14a34634d5d48065c8?sid=b1971aa2-9deb-4339-8ebd-53f9947ef633',
'button' => "texts.view"
]
);
}
private function textBody()
{
return "
We note you are yet to connect your Stripe account to Invoice Ninja. Please log in to Invoice Ninja and connect your Stripe account.\n\n
Once logged in you can use the following resource to connect your Stripe account: \n\n
";
}
private function htmlBody()
{
return "
We note you are yet to connect your Stripe account to Invoice Ninja. Please log in to Invoice Ninja and connect your Stripe account.<br><br>
Once logged in you can use the following resource to connect your Stripe account: <br><br>
";
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
/**
* Get the message headers.
*
* @return \Illuminate\Mail\Mailables\Headers
*/
public function headers()
{
return new Headers(
messageId: null,
references: [],
text:['' => ''],
);
}
}

View File

@ -94,6 +94,7 @@ use App\Events\Misc\InvitationWasViewed;
use App\Events\Payment\PaymentWasVoided;
use App\Events\Vendor\VendorWasArchived;
use App\Events\Vendor\VendorWasRestored;
use App\Events\Account\StripeConnectFailure;
use App\Listeners\Mail\MailSentListener;
use App\Observers\ClientContactObserver;
use App\Observers\PurchaseOrderObserver;
@ -198,6 +199,8 @@ use App\Listeners\Invoice\InvoiceRestoredActivity;
use App\Listeners\Invoice\InvoiceReversedActivity;
use App\Listeners\Payment\PaymentRestoredActivity;
use App\Listeners\Quote\QuoteApprovedNotification;
use SocialiteProviders\Apple\AppleExtendSocialite;
use SocialiteProviders\Manager\SocialiteWasCalled;
use App\Events\Subscription\SubscriptionWasCreated;
use App\Events\Subscription\SubscriptionWasDeleted;
use App\Events\Subscription\SubscriptionWasUpdated;
@ -221,10 +224,12 @@ use App\Listeners\Invoice\InvoiceEmailFailedActivity;
use App\Events\PurchaseOrder\PurchaseOrderWasAccepted;
use App\Events\PurchaseOrder\PurchaseOrderWasArchived;
use App\Events\PurchaseOrder\PurchaseOrderWasRestored;
use App\Listeners\Payment\PaymentEmailFailureActivity;
use App\Listeners\Vendor\UpdateVendorContactLastLogin;
use App\Events\RecurringQuote\RecurringQuoteWasCreated;
use App\Events\RecurringQuote\RecurringQuoteWasDeleted;
use App\Events\RecurringQuote\RecurringQuoteWasUpdated;
use App\Listeners\Account\StripeConnectFailureListener;
use App\Listeners\Activity\CreatedSubscriptionActivity;
use App\Listeners\Activity\SubscriptionDeletedActivity;
use App\Listeners\Activity\SubscriptionUpdatedActivity;
@ -234,6 +239,7 @@ use App\Events\RecurringQuote\RecurringQuoteWasRestored;
use App\Listeners\Activity\SubscriptionArchivedActivity;
use App\Listeners\Activity\SubscriptionRestoredActivity;
use App\Listeners\Invoice\InvoiceFailedEmailNotification;
use SocialiteProviders\Microsoft\MicrosoftExtendSocialite;
use App\Events\RecurringExpense\RecurringExpenseWasCreated;
use App\Events\RecurringExpense\RecurringExpenseWasDeleted;
use App\Events\RecurringExpense\RecurringExpenseWasUpdated;
@ -587,6 +593,9 @@ class EventServiceProvider extends ServiceProvider
TaskWasRestored::class => [
TaskRestoredActivity::class,
],
StripeConnectFailure::class => [
StripeConnectFailureListener::class,
],
SubscriptionWasCreated::class => [
CreatedSubscriptionActivity::class,
],

View File

@ -0,0 +1,59 @@
@component('email.template.admin', ['design' => 'light', 'settings' => $settings, 'logo' => $logo])
<div class="center">
@isset($greeting)
<p>{{ $greeting }}</p>
@endisset
@isset($title)
<h1>{{ $title }}</h1>
@endisset
@isset($h2)
<h2>{{ $title }}</h2>
@endisset
<div style="margin-top: 10px; margin-bottom: 30px;">
@isset($body)
{!! $body !!}
@endisset
@isset($slot)
{{ $slot }}
@endisset
</div>
@isset($additional_info)
<p>{{ $additional_info }}</p>
@endisset
@isset($url)
<!--[if (gte mso 9)|(IE)]>
<table align="center" cellspacing="0" cellpadding="0" style="width: 600px;">
<tr>
<td align="center" valign="top">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" >
<tbody><tr>
<td align="center" class="new_button" style="border-radius: 2px; background-color: {{ $settings->primary_color }} ;">
<a href="{{ $url }}" target="_blank" class="new_button" style="text-decoration: none; border: 1px solid {{ $settings->primary_color }}; display: inline-block; border-radius: 2px; padding-top: 15px; padding-bottom: 15px; padding-left: 25px; padding-right: 25px; font-size: 20px; color: #fff">
<singleline label="cta button">{{ ctrans($button) }}</singleline>
</a>
</td>
</tr>
</tbody>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
@endisset
@isset($signature)
<p>{!! nl2br($signature) !!}</p>
@endisset
</div>
@endcomponent

View File

@ -0,0 +1,5 @@
{!! $title !!}
{!! $text_body !!}
{!! $url !!}