Completed
Push — master ( 150399...ff4d75 )
by Bram
07:30
created

TicketPayment::onAuthorized()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.2
c 0
b 0
f 0
cc 4
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace Broarm\EventTickets;
4
5
use DataExtension;
6
use SilverStripe\Omnipay\Service\ServiceResponse;
7
8
/**
9
 * Class TicketPayment
10
 *
11
 * @author Bram de Leeuw
12
 * @property TicketPayment|\Payment $owner
13
 *
14
 * @property int                    ReservationID
15
 */
16
class TicketPayment extends DataExtension
17
{
18
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'Reservation' => 'Broarm\EventTickets\Reservation',
20
    );
21
22
    /**
23
     * Fix issue manual gateway doesn't call onCaptured hook
24
     *
25
     * @param ServiceResponse $response
26
     */
27
    public function onAuthorized(ServiceResponse $response)
28
    {
29
        if ($response->getPayment()->Gateway === 'Manual') {
30
            if (($reservation = Reservation::get()->byID($this->owner->ReservationID)) && $reservation->exists()) {
31
                $reservation->complete();
32
            }
33
        }
34
    }
35
36
    /**
37
     * Complete the order on a successful transaction
38
     *
39
     * @param ServiceResponse $response
40
     *
41
     * @throws \ValidationException
42
     */
43
    public function onCaptured(ServiceResponse $response)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        /** @var Reservation $reservation */
46
        if (($reservation = Reservation::get()->byID($this->owner->ReservationID)) && $reservation->exists()) {
47
            $reservation->complete();
48
        }
49
    }
50
}
51