DpsPxPayPayment_Handler::complete_link()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
class DpsPxPayPayment_Handler extends Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions 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...
7
        "complete_link",
8
        "absolute_complete_link",
9
        "paid"
10
    );
11
12
    private static $url_segment = 'dpspxpaypayment';
0 ignored issues
show
Unused Code introduced by
The property $url_segment 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...
13
14
    public static function complete_link()
15
    {
16
        return Config::inst()->get('DpsPxPayPayment_Handler', 'url_segment') . '/paid/';
17
    }
18
19
    public static function absolute_complete_link()
20
    {
21
        return Director::AbsoluteURL(self::complete_link());
22
    }
23
24
    public function paid()
25
    {
26
        EcommercePayment::get_supported_methods();
27
        $this->extend("DpsPxPayPayment_Handler_completion_start");
28
        $commsObject = new DpsPxPayComs();
29
        $response = $commsObject->processRequestAndReturnResultsAsObject();
30
        if ($payment = DpsPxPayPayment::get()->byID($response->getMerchantReference())) {
31
            if (1 == $response->getSuccess()) {
32
                $payment->Status = 'Success';
33
            } else {
34
                $payment->Status = 'Failure';
35
            }
36
            if ($DpsTxnRef = $response->getDpsTxnRef()) {
37
                $payment->TxnRef = $DpsTxnRef;
38
            }
39
            if ($ResponseText = $response->getResponseText()) {
40
                $payment->Message = $ResponseText;
41
            }
42
            $payment->write();
43
            $payment->redirectToOrder();
44
        } else {
45
            USER_ERROR("could not find payment with matching ID", E_USER_WARNING);
46
        }
47
        return;
48
    }
49
}
50