1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Payment object representing a DirectCredit payment. |
5
|
|
|
* @author Nicolaas [at] sunnysideup.co.nz |
6
|
|
|
* @package payment |
7
|
|
|
*/ |
8
|
|
View Code Duplication |
class DirectCreditPayment extends EcommercePayment |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Message shown before payment is made |
13
|
|
|
* @var String |
14
|
|
|
*/ |
15
|
|
|
private static $before_payment_message = ""; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Message shown after payment is made |
19
|
|
|
* @var String |
20
|
|
|
*/ |
21
|
|
|
private static $after_payment_message = ""; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Default Status for Payment |
25
|
|
|
* @var String |
26
|
|
|
*/ |
27
|
|
|
private static $default_status = "Pending"; |
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Process the DirectCredit payment method |
32
|
|
|
*/ |
33
|
|
|
public function processPayment($data, $form) |
34
|
|
|
{ |
35
|
|
|
$this->Status = Config::inst()->get("DirectCreditPayment", "default_status"); |
|
|
|
|
36
|
|
|
$this->Message = Config::inst()->get("DirectCreditPayment", "after_payment_message"); |
|
|
|
|
37
|
|
|
$this->write(); |
38
|
|
|
return EcommercePayment_Success::create(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getPaymentFormFields() |
42
|
|
|
{ |
43
|
|
|
return new FieldList( |
44
|
|
|
new LiteralField($this->ClassName.'_BeforeMessage', '<div id="'.$this->ClassName.'_BeforeMessage">' . Config::inst()->get("DirectCreditPayment", "before_payment_message") . '</div>'), |
45
|
|
|
new HiddenField($this->ClassName, $this->ClassName, 0) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getPaymentFormRequirements() |
50
|
|
|
{ |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
class DirectCreditPayment_ViaCreditCart extends EcommercePayment |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Message shown before payment is made |
60
|
|
|
* @var String |
61
|
|
|
*/ |
62
|
|
|
private static $before_payment_message = ""; |
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Message shown after payment is made |
66
|
|
|
* @var String |
67
|
|
|
*/ |
68
|
|
|
private static $after_payment_message = ""; |
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Default Status for Payment |
72
|
|
|
* @var String |
73
|
|
|
*/ |
74
|
|
|
private static $default_status = "Pending"; |
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Process the DirectCredit payment method |
78
|
|
|
*/ |
79
|
|
|
public function processPayment($data, $form) |
80
|
|
|
{ |
81
|
|
|
$this->Status = Config::inst()->get("DirectCreditPayment_ViaCreditCart", "default_status"); |
|
|
|
|
82
|
|
|
$this->Message = Config::inst()->get("DirectCreditPayment_ViaCreditCart", "after_payment_message"); |
|
|
|
|
83
|
|
|
$this->write(); |
84
|
|
|
return EcommercePayment_Success::create(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getPaymentFormFields() |
88
|
|
|
{ |
89
|
|
|
return new FieldList( |
90
|
|
|
new LiteralField($this->ClassName.'_BeforeMessage', '<div id="'.$this->ClassName.'_BeforeMessage">' . Config::inst()->get("DirectCreditPayment_ViaCreditCart", "before_payment_message") . '</div>'), |
91
|
|
|
new HiddenField($this->ClassName, $this->ClassName, 0) |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getPaymentFormRequirements() |
96
|
|
|
{ |
97
|
|
|
return null; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
class DirectCreditPayment_ViaCheque extends EcommercePayment |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Message shown before payment is made |
106
|
|
|
* @var String |
107
|
|
|
*/ |
108
|
|
|
private static $before_payment_message = ""; |
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Message shown after payment is made |
112
|
|
|
* @var String |
113
|
|
|
*/ |
114
|
|
|
private static $after_payment_message = ""; |
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Default Status for Payment |
118
|
|
|
* @var String |
119
|
|
|
*/ |
120
|
|
|
private static $default_status = "Pending"; |
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Process the DirectCredit payment method |
124
|
|
|
*/ |
125
|
|
|
public function processPayment($data, $form) |
126
|
|
|
{ |
127
|
|
|
$this->Status = Config::inst()->get("DirectCreditPayment_ViaCheque", "default_status"); |
|
|
|
|
128
|
|
|
$this->Message = Config::inst()->get("DirectCreditPayment_ViaCheque", "after_payment_message"); |
|
|
|
|
129
|
|
|
$this->write(); |
130
|
|
|
return EcommercePayment_Success::create(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function getPaymentFormFields() |
134
|
|
|
{ |
135
|
|
|
return new FieldList( |
136
|
|
|
new LiteralField($this->ClassName.'_BeforeMessage', '<div id="'.$this->ClassName.'_BeforeMessage">' . Config::inst()->get("DirectCreditPayment_ViaCheque", "before_payment_message") . '</div>'), |
137
|
|
|
new HiddenField($this->ClassName, $this->ClassName, 0) |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function getPaymentFormRequirements() |
142
|
|
|
{ |
143
|
|
|
return null; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
View Code Duplication |
class DirectCreditPayment_TESTSUCCESS extends EcommercePayment |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Message shown before payment is made |
152
|
|
|
* @var String |
153
|
|
|
*/ |
154
|
|
|
private static $before_payment_message = "This is for testing purposes only"; |
|
|
|
|
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Message shown after payment is made |
158
|
|
|
* @var String |
159
|
|
|
*/ |
160
|
|
|
private static $after_payment_message = "Payment is always successful"; |
|
|
|
|
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Default Status for Payment |
164
|
|
|
* @var String |
165
|
|
|
*/ |
166
|
|
|
private static $default_status = "Success"; |
|
|
|
|
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Process the DirectCredit payment method |
170
|
|
|
*/ |
171
|
|
|
public function processPayment($data, $form) |
172
|
|
|
{ |
173
|
|
|
$this->Status = Config::inst()->get("DirectCreditPayment_TESTSUCCESS", "default_status"); |
|
|
|
|
174
|
|
|
$this->Message = Config::inst()->get("DirectCreditPayment_TESTSUCCESS", "after_payment_message"); |
|
|
|
|
175
|
|
|
$this->write(); |
176
|
|
|
return EcommercePayment_Success::create(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function getPaymentFormFields() |
180
|
|
|
{ |
181
|
|
|
return new FieldList( |
182
|
|
|
new LiteralField($this->ClassName.'_BeforeMessage', '<div id="'.$this->ClassName.'_BeforeMessage">' . Config::inst()->get("DirectCreditPayment_TESTSUCCESS", "before_payment_message") . '</div>'), |
183
|
|
|
new HiddenField($this->ClassName, $this->ClassName, 0) |
184
|
|
|
); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function getPaymentFormRequirements() |
188
|
|
|
{ |
189
|
|
|
return null; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
View Code Duplication |
class DirectCreditPayment_TESTFAILURE extends EcommercePayment |
|
|
|
|
195
|
|
|
{ |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Message shown before payment is made |
199
|
|
|
* @var String |
200
|
|
|
*/ |
201
|
|
|
private static $before_payment_message = "This is for testing purposes only"; |
|
|
|
|
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Message shown after payment is made |
205
|
|
|
* @var String |
206
|
|
|
*/ |
207
|
|
|
private static $after_payment_message = "Payment is always unsuccessful"; |
|
|
|
|
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Default Status for Payment |
211
|
|
|
* @var String |
212
|
|
|
*/ |
213
|
|
|
private static $default_status = "Failure"; |
|
|
|
|
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Process the DirectCredit payment method |
217
|
|
|
*/ |
218
|
|
|
public function processPayment($data, $form) |
219
|
|
|
{ |
220
|
|
|
$this->Status = Config::inst()->get("DirectCreditPayment_TESTFAILURE", "default_status"); |
|
|
|
|
221
|
|
|
$this->Message = Config::inst()->get("DirectCreditPayment_TESTFAILURE", "after_payment_message"); |
|
|
|
|
222
|
|
|
$this->write(); |
223
|
|
|
return EcommercePayment_Success::create(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function getPaymentFormFields() |
227
|
|
|
{ |
228
|
|
|
return new FieldList( |
229
|
|
|
new LiteralField($this->ClassName.'_BeforeMessage', '<div id="'.$this->ClassName.'_BeforeMessage">' . Config::inst()->get("DirectCreditPayment_TESTFAILURE", "before_payment_message") . '</div>'), |
230
|
|
|
new HiddenField($this->ClassName, $this->ClassName, 0) |
231
|
|
|
); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function getPaymentFormRequirements() |
235
|
|
|
{ |
236
|
|
|
return null; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.