Completed
Push — 23 ( 2cbb94...e876bd )
by Harald
11:26 queued 05:21
created

OSCOM_PayPal_PS::OSCOM_PayPal_PS()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 14
nc 8
nop 0
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2017 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
  class OSCOM_PayPal_PS {
14
    var $_title;
15
    var $_short_title;
16
    var $_introduction;
17
    var $_req_notes;
18
    var $_pm_code = 'paypal_standard';
19
    var $_sort_order = 400;
20
21
    function OSCOM_PayPal_PS() {
22
      global $OSCOM_PayPal;
23
24
      $this->_title = $OSCOM_PayPal->getDef('module_ps_title');
25
      $this->_short_title = $OSCOM_PayPal->getDef('module_ps_short_title');
26
      $this->_introduction = $OSCOM_PayPal->getDef('module_ps_introduction');
27
28
      $this->_req_notes = array();
29
30
      if ( !function_exists('curl_init') ) {
31
        $this->_req_notes[] = $OSCOM_PayPal->getDef('module_ps_error_curl');
32
      }
33
34
      if ( !$OSCOM_PayPal->hasCredentials('PS', 'email') ) {
35
        $this->_req_notes[] = $OSCOM_PayPal->getDef('module_ps_error_credentials');
36
      }
37
38
      if ( !defined('OSCOM_APP_PAYPAL_PS_PDT_IDENTITY_TOKEN') || (!tep_not_null(OSCOM_APP_PAYPAL_PS_PDT_IDENTITY_TOKEN) && !$OSCOM_PayPal->hasCredentials('PS')) ) {
39
        $this->_req_notes[] = $OSCOM_PayPal->getDef('module_ps_error_credentials_pdt_api');
40
      }
41
42
      $this->_req_notes[] = $OSCOM_PayPal->getDef('module_ps_info_auto_return_url', array(
43
        'auto_return_url' => tep_catalog_href_link('checkout_process.php', '', 'SSL')
44
      ));
45
    }
46
47
    function getTitle() {
48
      return $this->_title;
49
    }
50
51
    function getShortTitle() {
52
      return $this->_short_title;
53
    }
54
55
    function install($OSCOM_PayPal) {
56
      $installed = explode(';', MODULE_PAYMENT_INSTALLED);
57
      $installed[] = $this->_pm_code . '.php';
58
59
      $OSCOM_PayPal->saveParameter('MODULE_PAYMENT_INSTALLED', implode(';', $installed));
60
    }
61
62 View Code Duplication
    function uninstall($OSCOM_PayPal) {
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...
63
      $installed = explode(';', MODULE_PAYMENT_INSTALLED);
64
      $installed_pos = array_search($this->_pm_code . '.php', $installed);
65
66
      if ( $installed_pos !== false ) {
67
        unset($installed[$installed_pos]);
68
69
        $OSCOM_PayPal->saveParameter('MODULE_PAYMENT_INSTALLED', implode(';', $installed));
70
      }
71
    }
72
73 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...
74
      $class = $this->_pm_code;
75
76
      if ( file_exists(DIR_FS_CATALOG . 'includes/modules/payment/' . $class . '.php') ) {
77
        if ( !class_exists($class) ) {
78
          include(DIR_FS_CATALOG . 'includes/modules/payment/' . $class . '.php');
79
        }
80
81
        $module = new $class();
82
83
        if ( isset($module->signature) ) {
84
          $sig = explode('|', $module->signature);
85
86
          if ( isset($sig[0]) && ($sig[0] == 'paypal') && isset($sig[1]) && ($sig[1] == $class) && isset($sig[2]) ) {
87
            return version_compare($sig[2], 4) >= 0;
88
          }
89
        }
90
      }
91
92
      return false;
93
    }
94
95
    function migrate($OSCOM_PayPal) {
96 View Code Duplication
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_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...
97
        $server = (MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_SERVER == 'Live') ? 'LIVE' : 'SANDBOX';
98
99
        if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_ID') ) {
100
          if ( tep_not_null(MODULE_PAYMENT_PAYPAL_STANDARD_ID) ) {
101
            if ( !defined('OSCOM_APP_PAYPAL_' . $server . '_SELLER_EMAIL') || !tep_not_null(constant('OSCOM_APP_PAYPAL_' . $server . '_SELLER_EMAIL')) ) {
102
              $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_' . $server . '_SELLER_EMAIL', MODULE_PAYMENT_PAYPAL_STANDARD_ID);
103
            }
104
          }
105
106
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_ID');
107
        }
108
109
        if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID') ) {
110
          if ( tep_not_null(MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID) ) {
111
            if ( !defined('OSCOM_APP_PAYPAL_' . $server . '_SELLER_EMAIL_PRIMARY') || !tep_not_null(constant('OSCOM_APP_PAYPAL_' . $server . '_SELLER_EMAIL_PRIMARY')) ) {
112
              $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_' . $server . '_SELLER_EMAIL_PRIMARY', MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID);
113
            }
114
          }
115
116
          $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_PRIMARY_ID');
117
        }
118
      }
119
120
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_PAGE_STYLE') ) {
121
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_PAGE_STYLE');
122
      }
123
124
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_TRANSACTION_METHOD') ) {
125
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_TRANSACTION_METHOD', (MODULE_PAYMENT_PAYPAL_STANDARD_TRANSACTION_METHOD == 'Sale') ? '1' : '0');
126
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_TRANSACTION_METHOD');
127
      }
128
129
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID') ) {
130
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_PREPARE_ORDER_STATUS_ID', MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID);
131
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_PREPARE_ORDER_STATUS_ID');
132
      }
133
134
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID') ) {
135
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_ORDER_STATUS_ID', MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID);
136
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_ORDER_STATUS_ID');
137
      }
138
139
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_ZONE') ) {
140
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_ZONE', MODULE_PAYMENT_PAYPAL_STANDARD_ZONE);
141
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_ZONE');
142
      }
143
144
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_SORT_ORDER') ) {
145
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_SORT_ORDER', MODULE_PAYMENT_PAYPAL_STANDARD_SORT_ORDER, 'Sort Order', 'Sort order of display (lowest to highest).');
146
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_SORT_ORDER');
147
      }
148
149
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_TRANSACTIONS_ORDER_STATUS_ID') ) {
150
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_TRANSACTIONS_ORDER_STATUS_ID');
151
      }
152
153 View Code Duplication
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_STATUS') ) {
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...
154
        $status = '-1';
155
156
        if ( (MODULE_PAYMENT_PAYPAL_STANDARD_STATUS == 'True') && defined('MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_SERVER') ) {
157
          if ( MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_SERVER == 'Live' ) {
158
            $status = '1';
159
          } else {
160
            $status = '0';
161
          }
162
        }
163
164
        $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_STATUS', $status);
165
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_STATUS');
166
      }
167
168
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_SERVER') ) {
169
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_GATEWAY_SERVER');
170
      }
171
172 View Code Duplication
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_VERIFY_SSL') ) {
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...
173
        if ( !defined('OSCOM_APP_PAYPAL_VERIFY_SSL') ) {
174
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_VERIFY_SSL', (MODULE_PAYMENT_PAYPAL_STANDARD_VERIFY_SSL == 'True') ? '1' : '0');
175
        }
176
177
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_VERIFY_SSL');
178
      }
179
180 View Code Duplication
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_PROXY') ) {
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...
181
        if ( !defined('OSCOM_APP_PAYPAL_PROXY') ) {
182
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PROXY', MODULE_PAYMENT_PAYPAL_STANDARD_PROXY);
183
        }
184
185
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_PROXY');
186
      }
187
188
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_DEBUG_EMAIL') ) {
189
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_DEBUG_EMAIL');
190
      }
191
192
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_STATUS') ) {
193
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_STATUS') ) {
194
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_STATUS', (MODULE_PAYMENT_PAYPAL_STANDARD_EWP_STATUS == 'True') ? '1' : '-1');
195
        }
196
197
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_STATUS');
198
      }
199
200
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PRIVATE_KEY') ) {
201
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_PRIVATE_KEY') ) {
202
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_PRIVATE_KEY', MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PRIVATE_KEY);
203
        }
204
205
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PRIVATE_KEY');
206
      }
207
208
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PUBLIC_KEY') ) {
209
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT') ) {
210
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT', MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PUBLIC_KEY);
211
        }
212
213
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PUBLIC_KEY');
214
      }
215
216
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_CERT_ID') ) {
217
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT_ID') ) {
218
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_PUBLIC_CERT_ID', MODULE_PAYMENT_PAYPAL_STANDARD_EWP_CERT_ID);
219
        }
220
221
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_CERT_ID');
222
      }
223
224
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PAYPAL_KEY') ) {
225
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_PAYPAL_CERT') ) {
226
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_PAYPAL_CERT', MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PAYPAL_KEY);
227
        }
228
229
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_PAYPAL_KEY');
230
      }
231
232
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_WORKING_DIRECTORY') ) {
233
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY') ) {
234
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_WORKING_DIRECTORY', MODULE_PAYMENT_PAYPAL_STANDARD_EWP_WORKING_DIRECTORY);
235
        }
236
237
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_WORKING_DIRECTORY');
238
      }
239
240
      if ( defined('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_OPENSSL') ) {
241
        if ( !defined('OSCOM_APP_PAYPAL_PS_EWP_OPENSSL') ) {
242
          $OSCOM_PayPal->saveParameter('OSCOM_APP_PAYPAL_PS_EWP_OPENSSL', MODULE_PAYMENT_PAYPAL_STANDARD_EWP_OPENSSL);
243
        }
244
245
        $OSCOM_PayPal->deleteParameter('MODULE_PAYMENT_PAYPAL_STANDARD_EWP_OPENSSL');
246
      }
247
    }
248
  }
249
?>
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...
250