Completed
Push — master ( 4e86ed...433ab3 )
by Bram
15:33
created

SuccessController::sendNotification()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 24
rs 8.9713
cc 3
eloc 16
nc 4
nop 0
1
<?php
2
/**
3
 * SuccessController.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 16/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use Config;
12
use Email;
13
use SiteConfig;
14
15
/**
16
 * Class SuccessController
17
 *
18
 * @package Broarm\EventTickets
19
 */
20
class SuccessController extends CheckoutStepController
21
{
22
    protected $step = 'success';
23
24
    /**
25
     * Init the success controller, check if files should be created and send
26
     */
27
    public function init()
28
    {
29
        parent::init();
30
        $reservation = $this->getReservation();
31
32
        // If we get to the success controller form any state except PENDING or PAID
33
        // This would mean someone would be clever and change the url from summary to success bypassing the payment
34
        // End the session, thus removing the reservation, and redirect back
35
        if (!in_array($reservation->Status, array('PENDING', 'PAID'))) {
36
            ReservationSession::end();
37
            $this->redirect($this->Link('/'));
38
        } elseif ($reservation->Status !== 'PAID' && $reservation->changeState('PAID')) {
39
            $reservation->send();
40
            $this->extend('afterPaymentComplete', $reservation);
41
            $reservation->write();
42
        }
43
    }
44
}
45