Completed
Push — 23 ( 09d773...16ee8e )
by Harald
11s
created

OSCOM_Braintree_CC::OSCOM_Braintree_CC()   F

Complexity

Conditions 26
Paths 6072

Size

Total Lines 79
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 26
eloc 43
nc 6072
nop 0
dl 0
loc 79
rs 2.3272
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2016 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
  class OSCOM_Braintree_CC {
14
    var $_title;
15
    var $_short_title;
16
    var $_req_notes;
17
    var $_pm_code = 'braintree_cc';
18
    var $_sort_order = 100;
19
20
    function OSCOM_Braintree_CC() {
21
      global $OSCOM_Braintree;
22
23
      $this->_title = $OSCOM_Braintree->getDef('module_cc_title');
24
      $this->_short_title = $OSCOM_Braintree->getDef('module_cc_short_title');
25
26
      $this->_req_notes = array();
27
28
      if ( version_compare(PHP_VERSION, '5.4.0', '<') ) {
29
        $this->_req_notes[] = $OSCOM_Braintree->getDef('module_cc_error_php', array('version' => '5.4.0'));
30
      }
31
32
      $requiredExtensions = array('xmlwriter', 'openssl', 'dom', 'hash', 'curl');
33
34
      $exts = array();
35
36
      foreach ( $requiredExtensions as $ext ) {
37
        if ( !extension_loaded($ext) ) {
38
          $exts[] = $ext;
39
        }
40
      }
41
42
      if ( !empty($exts) ) {
43
        $this->_req_notes[] = $OSCOM_Braintree->getDef('module_cc_error_php_ext', array('ext' => implode('<br />', $exts)));
44
      }
45
46
      if ( defined('OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS') ) {
47
        $warning = false;
48
49
        if (OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS == '1') {
50
          if ( !tep_not_null(OSCOM_APP_PAYPAL_BRAINTREE_MERCHANT_ID) || !tep_not_null(OSCOM_APP_PAYPAL_BRAINTREE_PUBLIC_KEY) || !tep_not_null(OSCOM_APP_PAYPAL_BRAINTREE_PRIVATE_KEY) ) {
51
            $warning = true;
52
          }
53
        } elseif (OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS == '0') {
54
          if ( !tep_not_null(OSCOM_APP_PAYPAL_BRAINTREE_SANDBOX_MERCHANT_ID) || !tep_not_null(OSCOM_APP_PAYPAL_BRAINTREE_SANDBOX_PUBLIC_KEY) || !tep_not_null(OSCOM_APP_PAYPAL_BRAINTREE_SANDBOX_PRIVATE_KEY) ) {
55
            $warning = true;
56
          }
57
        }
58
59
        if ($warning === true) {
60
          $this->_req_notes[] = $OSCOM_Braintree->getDef('module_cc_error_credentials');
61
        }
62
      }
63
64
      if ( defined('OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS') ) {
65
        $ma = null;
66
67
        if (OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS == '1') {
68
          if ( defined('OSCOM_APP_PAYPAL_BRAINTREE_CURRENCIES_MA') ) {
69
            $ma = OSCOM_APP_PAYPAL_BRAINTREE_CURRENCIES_MA;
70
          }
71
        } elseif (OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS == '0') {
72
          if ( defined('OSCOM_APP_PAYPAL_BRAINTREE_SANDBOX_CURRENCIES_MA') ) {
73
            $ma = OSCOM_APP_PAYPAL_BRAINTREE_SANDBOX_CURRENCIES_MA;
74
          }
75
        }
76
77
        if (isset($ma)) {
78
          $ma_error = true;
79
80
          if ( tep_not_null($ma) ) {
81
            $mas = explode(';', $ma);
82
83
            foreach ( $mas as $a ) {
84
              $ac = explode(':', $a, 2);
85
86
              if ( isset($ac[1]) && ($ac[1] == DEFAULT_CURRENCY) ) {
87
                $ma_error = false;
88
                break;
89
              }
90
            }
91
          }
92
93
          if ( $ma_error === true ) {
94
            $this->_req_notes[] = $OSCOM_Braintree->getDef('module_cc_error_merchant_accounts_currency', array('currency' => DEFAULT_CURRENCY));
95
          }
96
        }
97
      }
98
    }
99
100
    function getTitle() {
101
      return $this->_title;
102
    }
103
104
    function getShortTitle() {
105
      return $this->_short_title;
106
    }
107
108
    function install($OSCOM_Braintree) {
109
      $installed = explode(';', MODULE_PAYMENT_INSTALLED);
110
      $installed[] = $this->_pm_code . '.php';
111
112
      $OSCOM_Braintree->saveParameter('MODULE_PAYMENT_INSTALLED', implode(';', $installed));
113
    }
114
115
    function uninstall($OSCOM_Braintree) {
116
      $installed = explode(';', MODULE_PAYMENT_INSTALLED);
117
      $installed_pos = array_search($this->_pm_code . '.php', $installed);
118
119
      if ( $installed_pos !== false ) {
120
        unset($installed[$installed_pos]);
121
122
        $OSCOM_Braintree->saveParameter('MODULE_PAYMENT_INSTALLED', implode(';', $installed));
123
      }
124
    }
125
126 View Code Duplication
    function canMigrate() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
127
      $class = $this->_pm_code;
128
129
      if ( file_exists(DIR_FS_CATALOG . 'includes/modules/payment/' . $class . '.php') ) {
130
        if ( !class_exists($class) ) {
131
          include(DIR_FS_CATALOG . 'includes/modules/payment/' . $class . '.php');
132
        }
133
134
        $module = new $class();
135
136
        if ( isset($module->signature) ) {
137
          $sig = explode('|', $module->signature);
138
139
          if ( isset($sig[0]) && ($sig[0] == 'braintree') && isset($sig[1]) && ($sig[1] == $class) && isset($sig[2]) ) {
140
            return version_compare($sig[2], 2) >= 0;
141
          }
142
        }
143
      }
144
145
      return false;
146
    }
147
148
    function migrate($OSCOM_PayPal) {
149 View Code Duplication
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER') ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
150
        $server = (MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live') ? '' : 'SANDBOX_';
151
152
        if ( defined('MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID') && defined('MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY') && defined('MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY') ) {
153
          if ( tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID) && tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY) && tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY) ) {
154
            if ( !defined('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'MERCHANT_ID') || !tep_not_null(constant('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'MERCHANT_ID')) ) {
155
              if ( !defined('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'PUBLIC_KEY') || !tep_not_null(constant('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'PUBLIC_KEY')) ) {
156
                if ( !defined('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'PRIVATE_KEY') || !tep_not_null(constant('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'PRIVATE_KEY')) ) {
157
                  $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'MERCHANT_ID', MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID);
158
                  $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'PUBLIC_KEY', MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY);
159
                  $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'PRIVATE_KEY', MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY);
160
                }
161
              }
162
            }
163
          }
164
165
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID');
166
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY');
167
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY');
168
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_CLIENT_KEY');
169
        }
170
      }
171
172
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER') ) {
173
        $server = (MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live') ? '' : 'SANDBOX_';
174
175
        if ( defined('MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ACCOUNTS') ) {
176
          if ( tep_not_null(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ACCOUNTS) ) {
177
            if ( !defined('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'CURRENCIES_MA') || !tep_not_null(constant('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'CURRENCIES_MA')) ) {
178
              $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_' . $server . 'CURRENCIES_MA', MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ACCOUNTS);
179
            }
180
          }
181
182
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ACCOUNTS');
183
        }
184
      }
185
186
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_METHOD') ) {
187
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_CC_TRANSACTION_METHOD', (MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_METHOD == 'Payment') ? '1' : '0');
188
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_METHOD');
189
      }
190
191
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_ORDER_STATUS_ID') ) {
192
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_CC_ORDER_STATUS_ID', MODULE_PAYMENT_BRAINTREE_CC_ORDER_STATUS_ID);
193
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_ORDER_STATUS_ID');
194
      }
195
196
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_ZONE') ) {
197
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_CC_ZONE', MODULE_PAYMENT_BRAINTREE_CC_ZONE);
198
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_ZONE');
199
      }
200
201
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_SORT_ORDER') ) {
202
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_SORT_ORDER', MODULE_PAYMENT_BRAINTREE_CC_SORT_ORDER, 'Sort Order', 'Sort order of display (lowest to highest).');
203
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_SORT_ORDER');
204
      }
205
206
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_ORDER_STATUS_ID') ) {
207
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_ORDER_STATUS_ID');
208
      }
209
210
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_STATUS') ) {
211
        $status = '-1';
212
213
        if ( (MODULE_PAYMENT_BRAINTREE_CC_STATUS == 'True') && defined('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER') ) {
214
          if ( MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live' ) {
215
            $status = '1';
216
          } else {
217
            $status = '0';
218
          }
219
        }
220
221
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS', $status);
222
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_STATUS');
223
      }
224
225
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER') ) {
226
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER');
227
      }
228
229
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_TOKENS') ) {
230
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_CC_CC_TOKENS', (MODULE_PAYMENT_BRAINTREE_CC_TOKENS == 'True') ? '1' : '0');
231
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_TOKENS');
232
      }
233
234
      if ( defined('MODULE_PAYMENT_BRAINTREE_CC_VERIFY_WITH_CVV') ) {
235
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_BRAINTREE_CC_VERIFY_CVV', (MODULE_PAYMENT_BRAINTREE_CC_VERIFY_WITH_CVV == 'True') ? '1' : '0');
236
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_BRAINTREE_CC_VERIFY_WITH_CVV');
237
      }
238
    }
239
  }
240
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
241