|
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( |
|
|
|
|
|
|
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'; |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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
|
|
|
|