SuccessController::init()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
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') {
39
            // todo move to TicketPayment::onCaptured()
40
            $this->extend('afterPaymentComplete', $reservation);
41
        }
42
    }
43
}
44