EcommercePaymentController::GoodMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
nop 0
1
<?php
2
3
4
/**
5
 * @description: Used to diplay the payment form.
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: control
10
 **/
11
class EcommercePaymentController extends Controller
12
{
13
    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...
14
        'thankyou',
15
        'index',
16
        'pay',
17
        'PaymentForm',
18
    );
19
20
    /**
21
     * @var Order
22
     */
23
    protected $currentOrder = null;
24
25
    /**
26
     * @var string
27
     */
28
    protected $errorMessage = '';
29
30
    /**
31
     * @var string
32
     */
33
    protected $goodMessage = '';
34
35
    /**
36
     * @param string | Int $orderID
37
     *
38
     * @return string (Link)
39
     */
40
    public static function make_payment_link($orderID)
41
    {
42
        $urlSegment = EcommerceConfig::get('EcommercePaymentController', 'url_segment');
43
        $link = Controller::join_links(
44
            Director::baseURL(),
45
            $urlSegment.'/pay/'.$orderID.'/'
46
        );
47
48
        return $link;
49
    }
50
51
    public function init()
52
    {
53
        parent::init();
54
        isset($project) ? $themeBaseFolder = $project : $themeBaseFolder = 'mysite';
0 ignored issues
show
Bug introduced by
The variable $project seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
55
        Requirements::themedCSS('typography', $themeBaseFolder);
56
        Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js');
57
        //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js");
58
        //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
59
        $id = intval($this->request->param('ID'));
60
        if (!$id && isset($_REQUEST['OrderID'])) {
61
            $id = intval($_REQUEST['OrderID']);
62
        }
63
        if ($id) {
64
            $order = Order::get_by_id_if_can_view($id);
65
            if ($order) {
66
                $this->currentOrder = $order;
67
            }
68
        }
69
    }
70
71
    public function index()
72
    {
73
        return array();
74
    }
75
76
    public function pay()
77
    {
78
        return array();
79
    }
80
81
    /**
82
     * TO DO: TEST!!!
83
     */
84
    public function thankyou()
85
    {
86
        $this->goodMessage = _t('EcommercePaymentController.THANKYOU', 'Thank you for your payment.');
87
        $this->currentOrder = null;
88
89
        return array();
90
    }
91
92
    /**
93
     * @param string $action
0 ignored issues
show
Documentation introduced by
Should the type for parameter $action not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
94
     *
95
     * @return string (Link)
96
     */
97
    public function Link($action = null)
98
    {
99
        $URLSegment = Config::inst()->get($this->class, 'url_segment');
100
        if (!$URLSegment) {
101
            $URLSegment = $this->class;
102
        }
103
104
        return Controller::join_links(
105
            Director::baseURL(),
106
            $URLSegment,
107
            $action
108
        );
109
    }
110
111
    /**
112
     * @return Form (OrderForm_Payment) | Array
0 ignored issues
show
Documentation introduced by
Should the return type not be OrderForm_Payment|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
113
     **/
114
    public function PaymentForm()
115
    {
116
        if ($this->currentOrder) {
117
            if ($this->currentOrder->canPay()) {
118
                Requirements::javascript('ecommerce/javascript/EcomPayment.js');
119
120
                return OrderForm_Payment::create($this, 'PaymentForm', $this->currentOrder, $this->Link('thankyou'));
121
            } else {
122
                $this->errorMessage = _t('EcommercePaymentController.CANNOTMAKEPAYMENT', 'You can not make a payment for this order.');
123
            }
124
        } else {
125
            $this->errorMessage = _t('EcommercePaymentController.ORDERCANNOTBEFOUND', 'Order can not be found.');
126
        }
127
128
        return array();
129
    }
130
131
    public function ErrorMessage()
132
    {
133
        return $this->errorMessage;
134
    }
135
136
    public function GoodMessage()
137
    {
138
        return $this->goodMessage;
139
    }
140
}
141