Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
14 | class EwayPayment extends EcommercePayment |
||
|
|||
15 | { |
||
16 | private static $db = array( |
||
17 | 'AuthorisationCode' => 'Text' |
||
18 | ); |
||
19 | |||
20 | // Eway Information |
||
21 | |||
22 | private static $privacy_link = 'https://www.eway.com.au/Company/About/Privacy.aspx'; |
||
23 | |||
24 | private static $logo = '/payment_eway/images/eway.png'; |
||
25 | |||
26 | // Company Information |
||
27 | |||
28 | private static $page_title = 'Your Title'; |
||
29 | |||
30 | private static $company_name = 'Your Company Name'; |
||
31 | |||
32 | private static $payment_explanation = 'Your payment will be processed by the eWay payment processing site.'; |
||
33 | |||
34 | /** |
||
35 | * e.g. /themes/mytheme/images/myimage.png |
||
36 | * make sure the location is SSL if you add it |
||
37 | * @var String |
||
38 | */ |
||
39 | private static $company_logo = 'Your company Logo file location'; |
||
40 | |||
41 | // URLs |
||
42 | |||
43 | private static $url = 'https://au.ewaygateway.com/Request'; |
||
44 | |||
45 | |||
46 | private static $confirmation_url = 'https://au.ewaygateway.com/Result'; |
||
47 | |||
48 | // Test Mode |
||
49 | |||
50 | private static $test_customer_id = '87654321'; |
||
51 | |||
52 | private static $test_customer_username = 'TestAccount'; |
||
53 | |||
54 | /** |
||
55 | * NB: this is a string... anything will divert to LIVE |
||
56 | * unless it is set to "yes" |
||
57 | * @var String |
||
58 | */ |
||
59 | private static $test_mode = 'no'; |
||
60 | |||
61 | // Account Information |
||
62 | |||
63 | private static $customer_id; |
||
64 | |||
65 | private static $customer_username; |
||
66 | |||
67 | // Credit Cards |
||
68 | |||
69 | private static $credit_cards = array( |
||
70 | //'Visa' => 'payment/images/payments/methods/visa.jpg', |
||
71 | //'MasterCard' => 'payment/images/payments/methods/mastercard.jpg', |
||
72 | //'American Express' => 'payment/images/payments/methods/american-express.gif', |
||
73 | //'Dinners Club' => 'payment/images/payments/methods/dinners-club.jpg', |
||
74 | //'JCB' => 'payment/images/payments/methods/jcb.jpg' |
||
75 | ); |
||
76 | |||
77 | |||
78 | protected $testCodes = array( |
||
79 | "0" => " --- SELECT RESPONSE TYPE ---", |
||
80 | "00" => "Transaction Approved approved", |
||
81 | "01" => "Refer to Issuer", |
||
82 | "02" => "Refer to Issuer, special", |
||
83 | "03" => "No Merchant", |
||
84 | "04" => "Pick Up Card", |
||
85 | "05" => "Do Not Honour", |
||
86 | "06" => "Error", |
||
87 | "07" => "Pick Up Card, Special", |
||
88 | "08" => "Honour With Identification approved", |
||
89 | "09" => "Request In Progress", |
||
90 | "10" => "Approved For Partial Amount approved", |
||
91 | "11" => "Approved, VIP approved", |
||
92 | "12" => "Invalid Transaction", |
||
93 | "13" => "Invalid Amount", |
||
94 | "14" => "Invalid Card Number", |
||
95 | "15" => "No Issuer", |
||
96 | "16" => "Approved, Update Track 3 approved", |
||
97 | "19" => "Re-enter Last Transaction", |
||
98 | "21" => "No Action Taken", |
||
99 | "22" => "Suspected Malfunction", |
||
100 | "23" => "Unacceptable Transaction Fee", |
||
101 | "25" => "Unable to Locate Record On File", |
||
102 | "30" => "Format Error", |
||
103 | "31" => "Bank Not Supported By Switch", |
||
104 | "33" => "Expired Card, Capture", |
||
105 | "34" => "Suspected Fraud, Retain Card", |
||
106 | "35" => "Card Acceptor, Contact Acquirer, Retain Card", |
||
107 | "36" => "Restricted Card, Retain Card", |
||
108 | "37" => "Contact Acquirer Security Department, Retain Card", |
||
109 | "38" => "PIN Tries Exceeded, Capture", |
||
110 | "39" => "No Credit Account", |
||
111 | "40" => "Function Not Supported", |
||
112 | "41" => "Lost Card", |
||
113 | "42" => "No Universal Account", |
||
114 | "43" => "Stolen Card", |
||
115 | "44" => "No Investment Account", |
||
116 | "51" => "Insufficient Funds", |
||
117 | "52" => "No Cheque Account", |
||
118 | "53" => "No Savings Account", |
||
119 | "54" => "Expired Card", |
||
120 | "55" => "Incorrect PIN", |
||
121 | "56" => "No Card Record", |
||
122 | "57" => "Function Not Permitted to Cardholder", |
||
123 | "58" => "Function Not Permitted to Terminal", |
||
124 | "59" => "Suspected Fraud", |
||
125 | "60" => "Acceptor Contact Acquirer", |
||
126 | "61" => "Exceeds Withdrawal Limit", |
||
127 | "62" => "Restricted Card", |
||
128 | "63" => "Security Violation", |
||
129 | "64" => "Original Amount Incorrect", |
||
130 | "66" => "Acceptor Contact Acquirer, Security", |
||
131 | "67" => "Capture Card", |
||
132 | "75" => "PIN Tries Exceeded", |
||
133 | "82" => "CVV Validation Error", |
||
134 | "90" => "Cutoff In Progress", |
||
135 | "91" => "Card Issuer Unavailable", |
||
136 | "92" => "Unable To Route Transaction", |
||
137 | "93" => "Cannot Complete, Violation Of The Law", |
||
138 | "94" => "Duplicate Transaction", |
||
139 | "96" => "System Error" |
||
140 | ); |
||
141 | |||
142 | public function getPaymentFormFields() |
||
162 | |||
163 | public function getPaymentFormRequirements() |
||
167 | |||
168 | public function processPayment($data, $form) |
||
204 | |||
205 | public function EwayURL() |
||
261 | |||
262 | public function EwayForm($url) |
||
283 | |||
284 | public function EwayConfirmationURL($code) |
||
296 | |||
297 | public function populateDefaults() |
||
302 | } |
||
303 | |||
352 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.