Skip to content

Commit

Permalink
Merge pull request #2956 from notbakaneko/feature/store/confirmation-…
Browse files Browse the repository at this point in the history
…mail

Send order confirmation mail after store payment received
  • Loading branch information
nanaya committed Apr 12, 2018
2 parents e7df9a1 + a4aa705 commit 196e2e6
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/Listeners/Fulfillments/PaymentSubscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
namespace App\Listeners\Fulfillments;

use App\Libraries\Fulfillments\FulfillmentFactory;
use App\Mail\StorePaymentCompleted;
use App\Models\Store\Order;
use App\Traits\StoreNotifiable;
use DB;
use Exception;
use Log;
use Mail;

/**
* store.payments event dispatcher.
Expand All @@ -48,6 +52,8 @@ public function onPaymentCompleted($eventName, $data)
foreach ($fulfillers as $fulfiller) {
$fulfiller->run();
}

static::sendPaymentCompletedMail($event->order);
} catch (Exception $exception) {
$this->notifyError($exception, $event->order, $eventName);
throw $exception;
Expand Down Expand Up @@ -125,4 +131,15 @@ public function subscribe($events)
static::class.'@onPaymentRejected'
);
}

private static function sendPaymentCompletedMail(Order $order)
{
if (!$order->isPaidOrDelivered()) {
Log::warning("Trying to send mail for unpaid order ({$order->order_id}), aborted.");

return;
}

Mail::to($order->user->user_email)->queue(new StorePaymentCompleted($order));
}
}
59 changes: 59 additions & 0 deletions app/Mail/StorePaymentCompleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Copyright 2015-2018 ppy Pty. Ltd.
*
* This file is part of osu!web. osu!web is distributed with the hope of
* attracting more community contributions to the core ecosystem of osu!.
*
* osu!web is free software: you can redistribute it and/or modify
* it under the terms of the Affero GNU General Public License version 3
* as published by the Free Software Foundation.
*
* osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with osu!web. If not, see <http://www.gnu.org/licenses/>.
*/

namespace App\Mail;

use App\Models\Store\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class StorePaymentCompleted extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;

private $params;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->params = [
'order' => $order,
];
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->text(i18n_view('emails.store.payment_completed'))
->with($this->params)
->from('osustore@ppy.sh', 'osu!store team')
->subject(trans('store.mail.payment_completed.subject'));
}
}
6 changes: 6 additions & 0 deletions resources/lang/en/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

'discount' => 'save :percent%',

'mail' => [
'payment_completed' => [
'subject' => 'We received your osu!store order!',
],
],

'order' => [
'item' => [
'display_name' => [
Expand Down
41 changes: 41 additions & 0 deletions resources/views/emails/store/payment_completed-en.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{--
Copyright 2015-2018 ppy Pty. Ltd.
This file is part of osu!web. osu!web is distributed with the hope of
attracting more community contributions to the core ecosystem of osu!.
osu!web is free software: you can redistribute it and/or modify
it under the terms of the Affero GNU General Public License version 3
as published by the Free Software Foundation.
osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with osu!web. If not, see <http://www.gnu.org/licenses/>.
--}}

Hi {{ $order->user->username }},

Thanks for your osu!store order!

@foreach ($order->items as $item)
{{ $item->quantity }} x {{ $item->getDisplayName() }} ({{ currency($item->subtotal()) }})
@endforeach

@if ($order->shipping > 0)
Shipping ({{ currency($order->shipping) }})
@endif
Total ({{ currency($order->getTotal()) }})

@if ($order->requiresShipping())
We have received your payment and are preparing your order for shipping. It may take a few days for us to send it out, depending on the quantity of orders. You can follow the progress of your order at {{ route('store.invoice.show', $order) }}, including tracking details where available.
@else
We have received your payment and are currently processing your order. You can follow the progress of your order at {{ route('store.invoice.show', $order) }}.
@endif

If you have any questions, don't hesitate to reply to this email.

Regards,
The osu!store team

0 comments on commit 196e2e6

Please sign in to comment.