sage_pay_direct::getSubmitCardDetailsJavascript()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 134
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 134
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

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
  * osCommerce Online Merchant
4
  *
5
  * @copyright (c) 2016 osCommerce; https://www.oscommerce.com
6
  * @license MIT; https://www.oscommerce.com/license/mit.txt
7
  */
8
9
  use OSC\OM\HTML;
10
  use OSC\OM\HTTP;
11
  use OSC\OM\Mail;
12
  use OSC\OM\OSCOM;
13
  use OSC\OM\Registry;
14
15
  class sage_pay_direct {
16
    var $code, $title, $description, $enabled;
17
18 View Code Duplication
    function __construct() {
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...
19
      global $PHP_SELF, $order;
20
21
      $this->signature = 'sage_pay|sage_pay_direct|3.1|2.3';
0 ignored issues
show
Bug introduced by
The property signature does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
      $this->api_version = '3.00';
0 ignored issues
show
Bug introduced by
The property api_version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
24
      $this->code = 'sage_pay_direct';
25
      $this->title = OSCOM::getDef('module_payment_sage_pay_direct_text_title');
26
      $this->public_title = OSCOM::getDef('module_payment_sage_pay_direct_text_public_title');
0 ignored issues
show
Bug introduced by
The property public_title does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
      $this->description = OSCOM::getDef('module_payment_sage_pay_direct_text_description');
28
      $this->sort_order = defined('MODULE_PAYMENT_SAGE_PAY_DIRECT_SORT_ORDER') ? MODULE_PAYMENT_SAGE_PAY_DIRECT_SORT_ORDER : 0;
0 ignored issues
show
Bug introduced by
The property sort_order does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
      $this->enabled = defined('MODULE_PAYMENT_SAGE_PAY_DIRECT_STATUS') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_STATUS == 'True') ? true : false;
30
      $this->order_status = defined('MODULE_PAYMENT_SAGE_PAY_DIRECT_ORDER_STATUS_ID') && ((int)MODULE_PAYMENT_SAGE_PAY_DIRECT_ORDER_STATUS_ID > 0) ? (int)MODULE_PAYMENT_SAGE_PAY_DIRECT_ORDER_STATUS_ID : 0;
0 ignored issues
show
Bug introduced by
The property order_status does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
32
      if ( defined('MODULE_PAYMENT_SAGE_PAY_DIRECT_STATUS') ) {
33
        if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Test' ) {
34
          $this->title .= ' [Test]';
35
          $this->public_title .= ' (' . $this->code . '; Test)';
36
        }
37
38
        $this->description .= $this->getTestLinkInfo();
39
      }
40
41
      if ( !function_exists('curl_init') ) {
42
        $this->description = '<div class="secWarning">' . OSCOM::getDef('module_payment_sage_pay_direct_error_admin_curl') . '</div>' . $this->description;
43
44
        $this->enabled = false;
45
      }
46
47
      if ( $this->enabled === true ) {
48
        if ( !tep_not_null(MODULE_PAYMENT_SAGE_PAY_DIRECT_VENDOR_LOGIN_NAME) ) {
49
          $this->description = '<div class="secWarning">' . OSCOM::getDef('module_payment_sage_pay_direct_error_admin_configuration') . '</div>' . $this->description;
50
51
          $this->enabled = false;
52
        }
53
      }
54
55
      if ( $this->enabled === true ) {
56
        if ( isset($order) && is_object($order) ) {
57
          $this->update_status();
58
        }
59
      }
60
61
      if ( defined('FILENAME_MODULES') && (basename($PHP_SELF) == 'modules.php') && isset($_GET['action']) && ($_GET['action'] == 'install') && isset($_GET['subaction']) && ($_GET['subaction'] == 'conntest') ) {
62
        echo $this->getTestConnectionResult();
63
        exit;
64
      }
65
    }
66
67 View Code Duplication
    function update_status() {
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...
68
      global $order;
69
70
      $OSCOM_Db = Registry::get('Db');
71
72
      if ( ($this->enabled == true) && ($this->hasCards() == false) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
73
        $this->enabled = false;
74
      }
75
76
      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SAGE_PAY_DIRECT_ZONE > 0) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
77
        $check_flag = false;
78
        $Qcheck = $OSCOM_Db->get('zones_to_geo_zones', 'zone_id', ['geo_zone_id' => MODULE_PAYMENT_SAGE_PAY_DIRECT_ZONE, 'zone_country_id' => $order->billing['country']['id']], 'zone_id');
79
        while ($Qcheck->fetch()) {
80
          if ($Qcheck->valueInt('zone_id') < 1) {
81
            $check_flag = true;
82
            break;
83
          } elseif ($Qcheck->valueInt('zone_id') == $order->billing['zone_id']) {
84
            $check_flag = true;
85
            break;
86
          }
87
        }
88
89
        if ($check_flag == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
90
          $this->enabled = false;
91
        }
92
      }
93
    }
94
95
    function javascript_validation() {
96
      return false;
97
    }
98
99
    function selection() {
100
      $OSCOM_Db = Registry::get('Db');
101
102
      if ( (MODULE_PAYMENT_SAGE_PAY_DIRECT_TOKENS == 'True') && !isset($_SESSION['payment']) ) {
103
        $Qtokens = $OSCOM_Db->get('customers_sagepay_tokens', '1', ['customers_id' => $_SESSION['customer_id']], null, 1);
104
105
        if ( $Qtokens->fetch() !== false ) {
106
          $_SESSION['payment'] = $this->code;
107
        }
108
      }
109
110
      return array('id' => $this->code,
111
                   'module' => $this->public_title);
112
    }
113
114
    function pre_confirmation_check() {
115
      if ( $this->templateClassExists() ) {
116
        $GLOBALS['oscTemplate']->addBlock($this->getSubmitCardDetailsJavascript(), 'header_tags');
117
      }
118
    }
119
120
    function confirmation() {
121
      global $order;
122
123
      $OSCOM_Db = Registry::get('Db');
124
125
      $card_types = array();
126
      foreach ($this->getCardTypes() as $key => $value) {
127
        $card_types[] = array('id' => $key,
128
                              'text' => $value);
129
      }
130
131
      $today = getdate();
132
133
      $months_array = array();
134
      for ($i=1; $i<13; $i++) {
135
        $months_array[] = array('id' => sprintf('%02d', $i), 'text' => sprintf('%02d', $i));
136
      }
137
138
      $year_valid_to_array = array();
139 View Code Duplication
      for ($i=$today['year']; $i < $today['year']+10; $i++) {
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...
140
        $year_valid_to_array[] = array('id' => strftime('%y', mktime(0, 0, 0, 1, 1, $i)), 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)));
141
      }
142
143
      $year_valid_from_array = array();
144 View Code Duplication
      for ($i=$today['year']-4; $i < $today['year']+1; $i++) {
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...
145
        $year_valid_from_array[] = array('id' => strftime('%y', mktime(0, 0, 0, 1, 1, $i)), 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)));
146
      }
147
148
      $content = '';
149
150
      if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TOKENS == 'True' ) {
151
        $Qtokens = $OSCOM_Db->get('customers_sagepay_tokens', ['id', 'card_type', 'number_filtered', 'expiry_date'], ['customers_id' => $_SESSION['customer_id']], 'date_added');
152
153
        if ($Qtokens->fetch() !== false) {
154
          $content .= '<table id="sagepay_table" border="0" width="100%" cellspacing="0" cellpadding="2">';
155
156
          do {
157
            $content .= '<tr class="moduleRow" id="sagepay_card_' . $Qtokens->valueInt('id') . '">' .
158
                        '  <td width="40" valign="top"><input type="radio" name="sagepay_card" value="' . $Qtokens->valueInt('id') . '" /></td>' .
159
                        '  <td valign="top">' . $Qtokens->valueProtected('number_filtered') . '&nbsp;&nbsp;' . HTML::outputProtected(substr($Qtokens->value('expiry_date'), 0, 2)) . '/' . strftime('%Y', mktime(0, 0, 0, 1, 1, (2000 + substr($Qtokens->value('expiry_date'), 2)))) . '&nbsp;&nbsp;' . $Qtokens->valueProtected('card_type') . '</td>' .
160
                        '</tr>';
161
162
            if (MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_WITH_CVC == 'True') {
163
              $content .= '<tr class="moduleRowExtra" id="sagepay_card_cvc_' . $Qtokens->valueInt('id') . '">' .
164
                          '  <td width="40" valign="top">&nbsp;</td>' .
165
                          '  <td valign="top">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_cvc') . '&nbsp;' . HTML::inputField('cc_cvc_tokens_nh-dns[' . $Qtokens->valueInt('id') . ']', '', 'size="5" maxlength="4"') . '</td>' .
166
                          '</tr>';
167
            }
168
          } while ($Qtokens->fetch());
169
170
          $content .= '<tr class="moduleRow" id="sagepay_card_0">' .
171
                      '  <td width="40" valign="top"><input type="radio" name="sagepay_card" value="0" /></td>' .
172
                      '  <td valign="top">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_new') . '</td>' .
173
                      '</tr>' .
174
                      '</table>';
175
        }
176
      }
177
178
      $content .= '<table id="sagepay_table_new_card" border="0" width="100%" cellspacing="0" cellpadding="2">' .
179
                  '<tr>' .
180
                  '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_type') . '</td>' .
181
                  '  <td>' . HTML::selectField('cc_type', $card_types, '', 'id="sagepay_card_type"') . '</td>' .
182
                  '</tr>' .
183
                  '<tr>' .
184
                  '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_owner') . '</td>' .
185
                  '  <td>' . HTML::inputField('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'maxlength="50"') . '</td>' .
186
                  '</tr>' .
187
                  '<tr>' .
188
                  '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_number') . '</td>' .
189
                  '  <td>' . HTML::inputField('cc_number_nh-dns', '', 'maxlength="20"') . '</td>' .
190
                  '</tr>';
191
192
      if ( (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True') || (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_AMEX == 'True') ) {
193
        $content .= '<tr>' .
194
                    '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_starts') . '</td>' .
195
                    '  <td>' . HTML::selectField('cc_starts_month', $months_array, '', 'id="sagepay_card_date_start"') . '&nbsp;' . HTML::selectField('cc_starts_year', $year_valid_from_array) . '&nbsp;' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_starts_info') . '</td>' .
196
                    '</tr>';
197
      }
198
199
      $content .= '<tr>' .
200
                  '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_expires') . '</td>' .
201
                  '  <td>' . HTML::selectField('cc_expires_month', $months_array) . '&nbsp;' . HTML::selectField('cc_expires_year', $year_valid_to_array) . '</td>' .
202
                  '</tr>';
203
204
      if ( (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True') ) {
205
        $content .= '<tr>' .
206
                    '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_issue_number') . '</td>' .
207
                    '  <td>' . HTML::inputField('cc_issue_nh-dns', '', 'id="sagepay_card_issue" size="3" maxlength="2"') . '&nbsp;' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_issue_number_info') . '</td>' .
208
                    '</tr>';
209
      }
210
211 View Code Duplication
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_WITH_CVC == 'True') {
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...
212
        $content .= '<tr>' .
213
                    '  <td width="30%">' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_cvc') . '</td>' .
214
                    '  <td>' . HTML::inputField('cc_cvc_nh-dns', '', 'size="5" maxlength="4"') . '</td>' .
215
                    '</tr>';
216
      }
217
218 View Code Duplication
      if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TOKENS == 'True' ) {
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...
219
        $content .= '<tr>' .
220
                    '  <td width="30%">&nbsp;</td>' .
221
                    '  <td>' . HTML::checkboxField('cc_save', 'true') . ' ' . OSCOM::getDef('module_payment_sage_pay_direct_credit_card_save') . '</td>' .
222
                    '</tr>';
223
      }
224
225
      $content .= '</table>';
226
227
      $content .= !$this->templateClassExists() ? $this->getSubmitCardDetailsJavascript() : '';
228
229
      $confirmation = array('title' => $content);
230
231
      return $confirmation;
232
    }
233
234
    function process_button() {
235
      return false;
236
    }
237
238
    function before_process() {
239
      global $order, $order_totals, $sage_pay_response;
240
241
      $OSCOM_Db = Registry::get('Db');
242
243
      $transaction_response = null;
244
      $sage_pay_response = null;
245
246
      $error = null;
0 ignored issues
show
Unused Code introduced by
$error is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
247
248
      if ( isset($_GET['check']) ) {
249
        if ( ($_GET['check'] == '3D') && isset($_POST['MD']) && tep_not_null($_POST['MD']) && isset($_POST['PaRes']) && tep_not_null($_POST['PaRes']) ) {
250
          if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Live' ) {
251
            $gateway_url = 'https://live.sagepay.com/gateway/service/direct3dcallback.vsp';
252
          } else {
253
            $gateway_url = 'https://test.sagepay.com/gateway/service/direct3dcallback.vsp';
254
          }
255
256
          $post_string = 'MD=' . $_POST['MD'] . '&PARes=' . $_POST['PaRes'];
257
258
          $transaction_response = $this->sendTransactionToGateway($gateway_url, $post_string);
259
        } elseif ( ($_GET['check'] == 'PAYPAL') && isset($_POST['Status']) ) {
260
          if ( ($_POST['Status'] == 'PAYPALOK') && isset($_POST['VPSTxId']) && isset($_POST['CustomerEMail']) && isset($_POST['PayerID']) ) {
261
            $params = array('VPSProtocol' => $this->api_version,
262
                            'TxType' => 'COMPLETE',
263
                            'VPSTxId' => $_POST['VPSTxId'],
264
                            'Amount' => $this->format_raw($order->info['total']),
265
                            'Accept' => 'YES');
266
267
            $post_string = '';
268
269
            foreach ($params as $key => $value) {
270
              $post_string .= $key . '=' . urlencode(trim($value)) . '&';
271
            }
272
273
            if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Live' ) {
274
              $gateway_url = 'https://live.sagepay.com/gateway/service/complete.vsp';
275
            } else {
276
              $gateway_url = 'https://test.sagepay.com/gateway/service/complete.vsp';
277
            }
278
279
            $transaction_response = $this->sendTransactionToGateway($gateway_url, $post_string);
280
          } elseif ( isset($_POST['StatusDetail']) && ($_POST['StatusDetail'] == 'Paypal transaction cancelled by client.') ) {
281
            OSCOM::redirect('checkout_confirmation.php');
282
          }
283
        }
284
      } else {
285
        $sagepay_token = null;
286
        $sagepay_token_cvc = null;
287
288
        if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TOKENS == 'True' ) {
289
          if ( isset($_POST['sagepay_card']) && is_numeric($_POST['sagepay_card']) && ($_POST['sagepay_card'] > 0) ) {
290
            $Qtoken = $OSCOM_Db->get('customers_sagepay_tokens', 'sagepay_token', ['id' => $_POST['sagepay_card'], 'customers_id' => $_SESSION['customer_id']]);
291
292
            if ( $Qtoken->fetch() !== false ) {
293
              $sagepay_token = $Qtoken->value('sagepay_token');
294
295
              if ( isset($_POST['cc_cvc_tokens_nh-dns']) && is_array($_POST['cc_cvc_tokens_nh-dns']) && isset($_POST['cc_cvc_tokens_nh-dns'][$_POST['sagepay_card']]) ) {
296
                $sagepay_token_cvc = substr($_POST['cc_cvc_tokens_nh-dns'][$_POST['sagepay_card']], 0, 4);
297
              }
298
            }
299
          }
300
        }
301
302
        if ( !isset($sagepay_token) ) {
303
          $cc_type = isset($_POST['cc_type']) ? substr($_POST['cc_type'], 0, 15) : null;
304
305
          if ( !isset($cc_type) || ($this->isCard($cc_type) == false) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
306
            OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardtype');
307
          }
308
309
          if ( $cc_type != 'PAYPAL' ) {
310
            $cc_owner = isset($_POST['cc_owner']) ? substr($_POST['cc_owner'], 0, 50) : null;
311
            $cc_number = isset($_POST['cc_number_nh-dns']) ? substr(preg_replace('/[^0-9]/', '', $_POST['cc_number_nh-dns']), 0, 20) : null;
312
            $cc_start = null;
313
            $cc_expires = null;
0 ignored issues
show
Unused Code introduced by
$cc_expires is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
314
            $cc_issue = isset($_POST['cc_issue_nh-dns']) ? substr($_POST['cc_issue_nh-dns'], 0, 2) : null;
315
            $cc_cvc = isset($_POST['cc_cvc_nh-dns']) ? substr($_POST['cc_cvc_nh-dns'], 0, 4) : null;
316
317
            $today = getdate();
318
319
            $months_array = array();
320
            for ($i=1; $i<13; $i++) {
321
              $months_array[] = sprintf('%02d', $i);
322
            }
323
324
            $year_valid_to_array = array();
325 View Code Duplication
            for ($i=$today['year']; $i < $today['year']+10; $i++) {
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...
326
              $year_valid_to_array[] = strftime('%y',mktime(0,0,0,1,1,$i));
327
            }
328
329
            $year_valid_from_array = array();
330 View Code Duplication
            for ($i=$today['year']-4; $i < $today['year']+1; $i++) {
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...
331
              $year_valid_from_array[] = strftime('%y',mktime(0,0,0,1,1,$i));
332
            }
333
334
            if ( !isset($cc_owner) || empty($cc_owner) ) {
335
              OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardowner');
336
            }
337
338
            if ( !isset($cc_number) || (is_numeric($cc_number) == false) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
339
              OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardnumber');
340
            }
341
342
            if ( (($cc_type == 'MAESTRO') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True')) || (($cc_type == 'AMEX') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_AMEX == 'True')) ) {
343 View Code Duplication
              if ( !isset($_POST['cc_starts_month']) || !in_array($_POST['cc_starts_month'], $months_array) ) {
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...
344
                OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardstart');
345
              }
346
347 View Code Duplication
              if ( !isset($_POST['cc_starts_year']) || !in_array($_POST['cc_starts_year'], $year_valid_from_array) ) {
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...
348
                OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardstart');
349
              }
350
351
              $cc_start = substr($_POST['cc_starts_month'] . $_POST['cc_starts_year'], 0, 4);
352
            }
353
354 View Code Duplication
            if ( !isset($_POST['cc_expires_month']) || !in_array($_POST['cc_expires_month'], $months_array) ) {
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...
355
              OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardexpires');
356
            }
357
358 View Code Duplication
            if ( !isset($_POST['cc_expires_year']) || !in_array($_POST['cc_expires_year'], $year_valid_to_array) ) {
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...
359
              OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardexpires');
360
            }
361
362
            if ( ($_POST['cc_expires_year'] == date('y')) && ($_POST['cc_expires_month'] < date('m')) ) {
363
              OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardexpires');
364
            }
365
366
            $cc_expires = substr($_POST['cc_expires_month'] . $_POST['cc_expires_year'], 0, 4);
367
368 View Code Duplication
            if ( (($cc_type == 'MAESTRO') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True')) ) {
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...
369
              if ( !isset($cc_issue) || empty($cc_issue) ) {
370
                OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardissue');
371
              }
372
            }
373
374 View Code Duplication
            if (MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_WITH_CVC == 'True') {
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...
375
              if ( !isset($cc_cvc) || empty($cc_cvc) ) {
376
                OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . '&error=cardcvc');
377
              }
378
            }
379
          }
380
        }
381
382
        $params = array('VPSProtocol' => $this->api_version,
383
                        'ReferrerID' => 'C74D7B82-E9EB-4FBD-93DB-76F0F551C802',
384
                        'Vendor' => substr(MODULE_PAYMENT_SAGE_PAY_DIRECT_VENDOR_LOGIN_NAME, 0, 15),
385
                        'VendorTxCode' => substr(date('YmdHis') . '-' . $_SESSION['customer_id'] . '-' . $_SESSION['cartID'], 0, 40),
386
                        'Amount' => $this->format_raw($order->info['total']),
387
                        'Currency' => $_SESSION['currency'],
388
                        'Description' => substr(STORE_NAME, 0, 100),
389
                        'BillingSurname' => substr($order->billing['lastname'], 0, 20),
390
                        'BillingFirstnames' => substr($order->billing['firstname'], 0, 20),
391
                        'BillingAddress1' => substr($order->billing['street_address'], 0, 100),
392
                        'BillingCity' => substr($order->billing['city'], 0, 40),
393
                        'BillingPostCode' => substr($order->billing['postcode'], 0, 10),
394
                        'BillingCountry' => $order->billing['country']['iso_code_2'],
395
                        'BillingPhone' => substr($order->customer['telephone'], 0, 20),
396
                        'DeliverySurname' => substr($order->delivery['lastname'], 0, 20),
397
                        'DeliveryFirstnames' => substr($order->delivery['firstname'], 0, 20),
398
                        'DeliveryAddress1' => substr($order->delivery['street_address'], 0, 100),
399
                        'DeliveryCity' => substr($order->delivery['city'], 0, 40),
400
                        'DeliveryPostCode' => substr($order->delivery['postcode'], 0, 10),
401
                        'DeliveryCountry' => $order->delivery['country']['iso_code_2'],
402
                        'DeliveryPhone' => substr($order->customer['telephone'], 0, 20),
403
                        'CustomerEMail' => substr($order->customer['email_address'], 0, 255),
404
                        'Apply3DSecure' => '0',
405
                        'VendorData' => 'Customer ID ' . $_SESSION['customer_id']);
406
407
        if ( isset($sagepay_token) ) {
408
          $params['Token'] = $sagepay_token;
409
          $params['StoreToken'] = '1';
410
411
          if (MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_WITH_CVC == 'True') {
412
            $params['CV2'] = $sagepay_token_cvc;
413
          }
414
        } else {
415
          $params['CardType'] = $cc_type;
0 ignored issues
show
Bug introduced by
The variable $cc_type does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
416
417
          if ( $cc_type == 'PAYPAL' ) {
418
            $params['PayPalCallbackURL'] = OSCOM::link('checkout_process.php', 'check=PAYPAL');
419
          } else {
420
            $params['CardHolder'] = $cc_owner;
0 ignored issues
show
Bug introduced by
The variable $cc_owner does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
421
            $params['CardNumber'] = $cc_number;
0 ignored issues
show
Bug introduced by
The variable $cc_number does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
422
            $params['ExpiryDate'] = $cc_expires;
0 ignored issues
show
Bug introduced by
The variable $cc_expires does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
423
            $params['CreateToken'] = ((MODULE_PAYMENT_SAGE_PAY_DIRECT_TOKENS == 'True') && isset($_POST['cc_save']) && ($_POST['cc_save'] == 'true') ? '1' : '0');
424
425
            if ( (($cc_type == 'MAESTRO') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True')) || (($cc_type == 'AMEX') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_AMEX == 'True')) ) {
426
              $params['StartDate'] = $cc_start;
0 ignored issues
show
Bug introduced by
The variable $cc_start does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
427
            }
428
429
            if ( (($cc_type == 'MAESTRO') && (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True')) ) {
430
              $params['IssueNumber'] = $cc_issue;
0 ignored issues
show
Bug introduced by
The variable $cc_issue does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
431
            }
432
433
            if (MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_WITH_CVC == 'True') {
434
              $params['CV2'] = $cc_cvc;
0 ignored issues
show
Bug introduced by
The variable $cc_cvc does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
435
            }
436
          }
437
        }
438
439
        $ip_address = HTTP::getIpAddress();
440
441
        if ( !empty($ip_address) && (ip2long($ip_address) != -1) && (ip2long($ip_address) != false) ) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing ip2long($ip_address) of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
442
          $params['ClientIPAddress']= $ip_address;
443
        }
444
445 View Code Duplication
        if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_METHOD == 'Payment' ) {
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...
446
          $params['TxType'] = 'PAYMENT';
447
        } elseif ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_METHOD == 'Deferred' ) {
448
          $params['TxType'] = 'DEFERRED';
449
        } else {
450
          $params['TxType'] = 'AUTHENTICATE';
451
        }
452
453 View Code Duplication
        if ($params['BillingCountry'] == 'US') {
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...
454
          $params['BillingState'] = tep_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], '');
455
        }
456
457 View Code Duplication
        if ($params['DeliveryCountry'] == 'US') {
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...
458
          $params['DeliveryState'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], '');
459
        }
460
461
        $contents = array();
462
463 View Code Duplication
        foreach ($order->products as $product) {
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...
464
          $product_name = $product['name'];
465
466
          if (isset($product['attributes'])) {
467
            foreach ($product['attributes'] as $att) {
468
              $product_name .= '; ' . $att['option'] . '=' . $att['value'];
469
            }
470
          }
471
472
          $contents[] = str_replace(array(':', "\n", "\r", '&'), '', $product_name) . ':' . $product['qty'] . ':' . $this->format_raw($product['final_price']) . ':' . $this->format_raw(($product['tax'] / 100) * $product['final_price']) . ':' . $this->format_raw((($product['tax'] / 100) * $product['final_price']) + $product['final_price']) . ':' . $this->format_raw(((($product['tax'] / 100) * $product['final_price']) + $product['final_price']) * $product['qty']);
473
        }
474
475 View Code Duplication
        foreach ($order_totals as $ot) {
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...
476
          $contents[] = str_replace(array(':', "\n", "\r", '&'), '', strip_tags($ot['title'])) . ':---:---:---:---:' . $this->format_raw($ot['value']);
477
        }
478
479
        $params['Basket'] = substr(sizeof($contents) . ':' . implode(':', $contents), 0, 7500);
480
481
        $post_string = '';
482
483
        foreach ($params as $key => $value) {
484
          $post_string .= $key . '=' . urlencode(trim($value)) . '&';
485
        }
486
487
        if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Live' ) {
488
          $gateway_url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp';
489
        } else {
490
          $gateway_url = 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp';
491
        }
492
493
        $transaction_response = $this->sendTransactionToGateway($gateway_url, $post_string);
494
      }
495
496
      $string_array = explode(chr(10), $transaction_response);
497
      $sage_pay_response = array();
498
499 View Code Duplication
      foreach ($string_array as $string) {
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...
500
        if (strpos($string, '=') != false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($string, '=') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
501
          $parts = explode('=', $string, 2);
502
          $sage_pay_response[trim($parts[0])] = trim($parts[1]);
503
        }
504
      }
505
506
      if ( isset($params['CreateToken']) && ($params['CreateToken'] == '1') ) {
507
        $_SESSION['sagepay_token_cc_type'] = $params['CardType'];
508
        $_SESSION['sagepay_token_cc_number'] = str_repeat('X', strlen($params['CardNumber']) - 4) . substr($params['CardNumber'], -4);
509
        $_SESSION['sagepay_token_cc_expiry_date'] = $params['ExpiryDate'];
510
      }
511
512
      if ($sage_pay_response['Status'] == '3DAUTH') {
513
        $_SESSION['sage_pay_direct_acsurl'] = $sage_pay_response['ACSURL'];
514
        $_SESSION['sage_pay_direct_pareq'] = $sage_pay_response['PAReq'];
515
        $_SESSION['sage_pay_direct_md'] = $sage_pay_response['MD'];
516
517
        OSCOM::redirect('ext/modules/payment/sage_pay/checkout.php');
518
      }
519
520
      if ($sage_pay_response['Status'] == 'PPREDIRECT') {
521
        HTTP::redirect($sage_pay_response['PayPalRedirectURL']);
522
      }
523
524 View Code Duplication
      if ( ($sage_pay_response['Status'] != 'OK') && ($sage_pay_response['Status'] != 'AUTHENTICATED') && ($sage_pay_response['Status'] != 'REGISTERED') ) {
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...
525
          $this->sendDebugEmail($sage_pay_response);
526
527
        $error = $this->getErrorMessageNumber($sage_pay_response['StatusDetail']);
528
529
        OSCOM::redirect('checkout_payment.php', 'payment_error=' . $this->code . (tep_not_null($error) ? '&error=' . $error : ''));
530
      }
531
    }
532
533
    function after_process() {
534
      global $insert_id, $sage_pay_response;
535
536
      $OSCOM_Db = Registry::get('Db');
537
538
      $result = array();
539
540
      if ( isset($sage_pay_response['VPSTxId']) ) {
541
        $result['ID'] = $sage_pay_response['VPSTxId'];
542
      }
543
544
      if ( isset($sage_pay_response['SecurityKey']) ) {
545
        $result['Security Key'] = $sage_pay_response['SecurityKey'];
546
      }
547
548
      if ( isset($sage_pay_response['AVSCV2']) ) {
549
        $result['AVS/CV2'] = $sage_pay_response['AVSCV2'];
550
      }
551
552
      if ( isset($sage_pay_response['AddressResult']) ) {
553
        $result['Address'] = $sage_pay_response['AddressResult'];
554
      }
555
556
      if ( isset($sage_pay_response['PostCodeResult']) ) {
557
        $result['Post Code'] = $sage_pay_response['PostCodeResult'];
558
      }
559
560
      if ( isset($sage_pay_response['CV2Result']) ) {
561
        $result['CV2'] = $sage_pay_response['CV2Result'];
562
      }
563
564
      if ( isset($sage_pay_response['3DSecureStatus']) ) {
565
        $result['3D Secure'] = $sage_pay_response['3DSecureStatus'];
566
      }
567
568
      if ( isset($sage_pay_response['Token']) && isset($_SESSION['sagepay_token_cc_number']) ) {
569
        $Qcheck = $OSCOM_Db->get('customers_sagepay_tokens', 'id', ['customers_id' => $_SESSION['customer_id'], 'sagepay_token' => $sage_pay_response['Token']], null, 1);
570
571
        if ($Qcheck->fetch() === false) {
572
          $sql_data_array = array('customers_id' => $_SESSION['customer_id'],
573
                                  'sagepay_token' => $sage_pay_response['Token'],
574
                                  'card_type' => $_SESSION['sagepay_token_cc_type'],
575
                                  'number_filtered' => $_SESSION['sagepay_token_cc_number'],
576
                                  'expiry_date' => $_SESSION['sagepay_token_cc_expiry_date'],
577
                                  'date_added' => 'now()');
578
579
          $OSCOM_Db->save('customers_sagepay_tokens', $sql_data_array);
580
        }
581
582
        $result['Token Created'] = 'Yes';
583
584
        unset($_SESSION['sagepay_token_cc_type']);
585
        unset($_SESSION['sagepay_token_cc_number']);
586
        unset($_SESSION['sagepay_token_cc_expiry_date']);
587
      }
588
589
      if ( isset($_GET['check']) && ($_GET['check'] == 'PAYPAL') && isset($_POST['Status']) && ($_POST['Status'] == 'PAYPALOK') && isset($_POST['VPSTxId']) && isset($sage_pay_response['VPSTxId']) && ($_POST['VPSTxId'] == $sage_pay_response['VPSTxId']) ) {
590
        $result['PayPal Payer E-Mail'] = $_POST['CustomerEMail'];
591
        $result['PayPal Payer Status'] = $_POST['PayerStatus'];
592
        $result['PayPal Payer ID'] = $_POST['PayerID'];
593
        $result['PayPal Payer Address'] = $_POST['AddressStatus'];
594
      }
595
596
      $result_string = '';
597
598
      foreach ( $result as $k => $v ) {
599
        $result_string .= $k . ': ' . $v . "\n";
600
      }
601
602
      $sql_data_array = array('orders_id' => $insert_id,
603
                              'orders_status_id' => MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_ORDER_STATUS_ID,
604
                              'date_added' => 'now()',
605
                              'customer_notified' => '0',
606
                              'comments' => trim($result_string));
607
608
      $OSCOM_Db->save('orders_status_history', $sql_data_array);
609
610
      if (isset($_SESSION['sage_pay_direct_acsurl'])) {
611
        unset($_SESSION['sage_pay_direct_acsurl']);
612
        unset($_SESSION['sage_pay_direct_pareq']);
613
        unset($_SESSION['sage_pay_direct_md']);
614
      }
615
616
      $sage_pay_response = null;
617
    }
618
619
    function get_error() {
620
      $message = OSCOM::getDef('module_payment_sage_pay_direct_error_general');
621
622
      if ( isset($_GET['error']) && tep_not_null($_GET['error']) ) {
623
        if ( is_numeric($_GET['error']) && $this->errorMessageNumberExists($_GET['error']) ) {
624
          $message = $this->getErrorMessage($_GET['error']) . ' ' . OSCOM::getDef('module_payment_sage_pay_direct_error_general');
625
        } else {
626
          switch ($_GET['error']) {
627
            case 'cardtype':
628
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardtype');
629
              break;
630
631
            case 'cardowner':
632
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardowner');
633
              break;
634
635
            case 'cardnumber':
636
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardnumber');
637
              break;
638
639
            case 'cardstart':
640
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardstart');
641
              break;
642
643
            case 'cardexpires':
644
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardexpires');
645
              break;
646
647
            case 'cardissue':
648
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardissue');
649
              break;
650
651
            case 'cardcvc':
652
              $message = OSCOM::getDef('module_payment_sage_pay_direct_error_cardcvc');
653
              break;
654
          }
655
        }
656
      }
657
658
      $error = array('title' => OSCOM::getDef('module_payment_sage_pay_direct_error_title'),
659
                     'error' => $message);
660
661
      return $error;
662
    }
663
664
    function check() {
665
      return defined('MODULE_PAYMENT_SAGE_PAY_DIRECT_STATUS');
666
    }
667
668 View Code Duplication
    function install($parameter = null) {
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...
669
      $OSCOM_Db = Registry::get('Db');
670
671
      $params = $this->getParams();
672
673
      if (isset($parameter)) {
674
        if (isset($params[$parameter])) {
675
          $params = array($parameter => $params[$parameter]);
676
        } else {
677
          $params = array();
678
        }
679
      }
680
681
      foreach ($params as $key => $data) {
682
        $sql_data_array = array('configuration_title' => $data['title'],
683
                                'configuration_key' => $key,
684
                                'configuration_value' => (isset($data['value']) ? $data['value'] : ''),
685
                                'configuration_description' => $data['desc'],
686
                                'configuration_group_id' => '6',
687
                                'sort_order' => '0',
688
                                'date_added' => 'now()');
689
690
        if (isset($data['set_func'])) {
691
          $sql_data_array['set_function'] = $data['set_func'];
692
        }
693
694
        if (isset($data['use_func'])) {
695
          $sql_data_array['use_function'] = $data['use_func'];
696
        }
697
698
        $OSCOM_Db->save('configuration', $sql_data_array);
699
      }
700
    }
701
702
    function remove() {
703
      return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")');
704
    }
705
706 View Code Duplication
    function keys() {
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...
707
      $keys = array_keys($this->getParams());
708
709
      if ($this->check()) {
710
        foreach ($keys as $key) {
711
          if (!defined($key)) {
712
            $this->install($key);
713
          }
714
        }
715
      }
716
717
      return $keys;
718
    }
719
720
    function getParams() {
721
      $OSCOM_Db = Registry::get('Db');
722
723
      $Qcheck = $OSCOM_Db->query('show tables like "customers_sagepay_tokens"');
724
725
      if ($Qcheck->fetch() === false) {
726
        $sql = <<<EOD
727
CREATE TABLE customers_sagepay_tokens (
728
  id int NOT NULL auto_increment,
729
  customers_id int NOT NULL,
730
  sagepay_token char(38) NOT NULL,
731
  card_type varchar(15) NOT NULL,
732
  number_filtered varchar(20) NOT NULL,
733
  expiry_date char(4) NOT NULL,
734
  date_added datetime NOT NULL,
735
  PRIMARY KEY (id),
736
  KEY idx_csagepayt_customers_id (customers_id),
737
  KEY idx_csagepayt_token (sagepay_token)
738
);
739
EOD;
740
741
        $OSCOM_Db->exec($sql);
742
      }
743
744 View Code Duplication
      if (!defined('MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_ORDER_STATUS_ID')) {
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...
745
        $Qcheck = $OSCOM_Db->get('orders_status', 'orders_status_id', ['orders_status_name' => 'Sage Pay [Transactions]'], null, 1);
746
747
        if ($Qcheck->fetch() === false) {
748
          $Qstatus = $OSCOM_Db->get('orders_status', 'max(orders_status_id) as status_id');
749
750
          $status_id = $Qstatus->valueInt('status_id') + 1;
751
752
          $languages = tep_get_languages();
753
754
          foreach ($languages as $lang) {
755
            $OSCOM_Db->save('orders_status', [
756
              'orders_status_id' => $status_id,
757
              'language_id' => $lang['id'],
758
              'orders_status_name' => 'Sage Pay [Transactions]',
759
              'public_flag' => 0,
760
              'downloads_flag' => 0
761
            ]);
762
          }
763
        } else {
764
          $status_id = $Qcheck->valueInt('orders_status_id');
765
        }
766
      } else {
767
        $status_id = MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_ORDER_STATUS_ID;
768
      }
769
770
      $params = array('MODULE_PAYMENT_SAGE_PAY_DIRECT_STATUS' => array('title' => 'Enable Sage Pay Direct Module',
771
                                                                       'desc' => 'Do you want to accept Sage Pay Direct payments?',
772
                                                                       'value' => 'True',
773
                                                                       'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
774
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_VENDOR_LOGIN_NAME' => array('title' => 'Vendor Login Name',
775
                                                                                  'desc' => 'The vendor login name to connect to the gateway with.',
776
                                                                                  'value' => ''),
777
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_WITH_CVC' => array('title' => 'Verify With CVC',
778
                                                                                'desc' => 'Verify the credit card with the billing address with the Credit Card Verification Checknumber (CVC)?',
779
                                                                                'value' => 'True',
780
                                                                                'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
781
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_TOKENS' => array('title' => 'Create Tokens',
782
                                                                       'desc' => 'Create and store tokens for card payments customer can use on their next purchase?',
783
                                                                       'value' => 'False',
784
                                                                       'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
785
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_METHOD' => array('title' => 'Transaction Method',
786
                                                                                   'desc' => 'The processing method to use for each transaction.',
787
                                                                                   'value' => 'Authenticate',
788
                                                                                   'set_func' => 'tep_cfg_select_option(array(\'Authenticate\', \'Deferred\', \'Payment\'), '),
789
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ORDER_STATUS_ID' => array('title' => 'Set Order Status',
790
                                                                                'desc' => 'Set the status of orders made with this payment module to this value',
791
                                                                                'value' => '0',
792
                                                                                'use_func' => 'tep_get_order_status_name',
793
                                                                                'set_func' => 'tep_cfg_pull_down_order_statuses('),
794
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_ORDER_STATUS_ID' => array('title' => 'Transaction Order Status',
795
                                                                                            'desc' => 'Include transaction information in this order status level',
796
                                                                                            'value' => $status_id,
797
                                                                                            'set_func' => 'tep_cfg_pull_down_order_statuses(',
798
                                                                                            'use_func' => 'tep_get_order_status_name'),
799
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ZONE' => array('title' => 'Payment Zone',
800
                                                                     'desc' => 'If a zone is selected, only enable this payment method for that zone.',
801
                                                                     'value' => '0',
802
                                                                     'use_func' => 'tep_get_zone_class_title',
803
                                                                     'set_func' => 'tep_cfg_pull_down_zone_classes('),
804
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER' => array('title' => 'Transaction Server',
805
                                                                                   'desc' => 'Perform transactions on the production server or on the testing server.',
806
                                                                                   'value' => 'Live',
807
                                                                                   'set_func' => 'tep_cfg_select_option(array(\'Live\', \'Test\'), '),
808
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_SSL' => array('title' => 'Verify SSL Certificate',
809
                                                                           'desc' => 'Verify transaction server SSL certificate on connection?',
810
                                                                           'value' => 'True',
811
                                                                           'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
812
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_PROXY' => array('title' => 'Proxy Server',
813
                                                                      'desc' => 'Send API requests through this proxy server. (host:port, eg: 123.45.67.89:8080 or proxy.example.com:8080)'),
814
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_DEBUG_EMAIL' => array('title' => 'Debug E-Mail Address',
815
                                                                            'desc' => 'All parameters of an invalid transaction will be sent to this email address.'),
816
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_SORT_ORDER' => array('title' => 'Sort order of display.',
817
                                                                           'desc' => 'Sort order of display. Lowest is displayed first.',
818
                                                                           'value' => '0'),
819
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_VISA' => array('title' => 'Accept Visa',
820
                                                                           'desc' => 'Do you want to accept Visa payments?',
821
                                                                           'value' => 'True',
822
                                                                           'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
823
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MC' => array('title' => 'Accept Mastercard',
824
                                                                         'desc' => 'Do you want to accept Mastercard payments?',
825
                                                                         'value' => 'True',
826
                                                                         'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
827
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MCDEBIT' => array('title' => 'Accept Mastercard Debit',
828
                                                                              'desc' => 'Do you want to accept Mastercard Debit payments?',
829
                                                                              'value' => 'True',
830
                                                                              'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
831
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_DELTA' => array('title' => 'Accept Visa Delta/Debit',
832
                                                                            'desc' => 'Do you want to accept Visa Delta/Debit payments?',
833
                                                                            'value' => 'True',
834
                                                                            'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
835
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO' => array('title' => 'Accept Maestro',
836
                                                                              'desc' => 'Do you want to accept Maestro payments?',
837
                                                                              'value' => 'True',
838
                                                                              'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
839
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_UKE' => array('title' => 'Accept Visa Electron UK Debit',
840
                                                                          'desc' => 'Do you want to accept Visa Electron UK Debit payments?',
841
                                                                          'value' => 'True',
842
                                                                          'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
843
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_AMEX' => array('title' => 'Accept American Express',
844
                                                                           'desc' => 'Do you want to accept American Express payments?',
845
                                                                           'value' => 'True',
846
                                                                           'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
847
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_DC' => array('title' => 'Accept Diners Club',
848
                                                                         'desc' => 'Do you want to accept Diners Club payments?',
849
                                                                         'value' => 'True',
850
                                                                         'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
851
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_JCB' => array('title' => 'Accept Japan Credit Bureau',
852
                                                                          'desc' => 'Do you want to accept Japan Credit Bureau payments?',
853
                                                                          'value' => 'True',
854
                                                                          'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
855
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_LASER' => array('title' => 'Accept Laser Card',
856
                                                                            'desc' => 'Do you want to accept Laser Card payments?',
857
                                                                            'value' => 'True',
858
                                                                            'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '),
859
                      'MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_PAYPAL' => array('title' => 'Accept PayPal',
860
                                                                             'desc' => 'Do you want to accept PayPal payments?',
861
                                                                             'value' => 'False',
862
                                                                             'set_func' => 'tep_cfg_select_option(array(\'True\', \'False\'), '));
863
864
      return $params;
865
    }
866
867 View Code Duplication
    function sendTransactionToGateway($url, $parameters) {
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...
868
      $server = parse_url($url);
869
870
      if (isset($server['port']) === false) {
871
        $server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
872
      }
873
874
      if (isset($server['path']) === false) {
875
        $server['path'] = '/';
876
      }
877
878
      $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
879
      curl_setopt($curl, CURLOPT_PORT, $server['port']);
880
      curl_setopt($curl, CURLOPT_HEADER, false);
881
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
882
      curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
883
      curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
884
      curl_setopt($curl, CURLOPT_POST, true);
885
      curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
886
887
      if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_VERIFY_SSL == 'True' ) {
888
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
889
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
890
891
        if ( is_file(OSCOM::getConfig('dir_root', 'Shop') . 'ext/modules/payment/sage_pay/sagepay.com.crt') ) {
892
          curl_setopt($curl, CURLOPT_CAINFO, OSCOM::getConfig('dir_root', 'Shop') . 'ext/modules/payment/sage_pay/sagepay.com.crt');
893
        } elseif ( is_file(OSCOM::getConfig('dir_root', 'Shop') . 'includes/cacert.pem') ) {
894
          curl_setopt($curl, CURLOPT_CAINFO, OSCOM::getConfig('dir_root', 'Shop') . 'includes/cacert.pem');
895
        }
896
      } else {
897
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
898
      }
899
900
      if ( tep_not_null(MODULE_PAYMENT_SAGE_PAY_DIRECT_PROXY) ) {
901
        curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, true);
902
        curl_setopt($curl, CURLOPT_PROXY, MODULE_PAYMENT_SAGE_PAY_DIRECT_PROXY);
903
      }
904
905
      $result = curl_exec($curl);
906
907
      curl_close($curl);
908
909
      return $result;
910
    }
911
912
// format prices without currency formatting
913 View Code Duplication
    function format_raw($number, $currency_code = '', $currency_value = '') {
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...
914
      global $currencies;
915
916
      if (empty($currency_code) || !$currencies->is_set($currency_code)) {
917
        $currency_code = $_SESSION['currency'];
918
      }
919
920
      if (empty($currency_value) || !is_numeric($currency_value)) {
921
        $currency_value = $currencies->currencies[$currency_code]['value'];
922
      }
923
924
      return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
925
    }
926
927
    function getCardTypes() {
928
      $this->_cards = array();
0 ignored issues
show
Bug introduced by
The property _cards does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
929
930
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_VISA == 'True') {
931
        $this->_cards['VISA'] = 'Visa';
932
      }
933
934
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MC == 'True') {
935
        $this->_cards['MC'] = 'Mastercard';
936
      }
937
938
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MCDEBIT == 'True') {
939
        $this->_cards['MCDEBIT'] = 'Mastercard Debit';
940
      }
941
942
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_DELTA == 'True') {
943
        $this->_cards['DELTA'] = 'Visa Delta/Debit';
944
      }
945
946
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_MAESTRO == 'True') {
947
        $this->_cards['MAESTRO'] = 'Maestro';
948
      }
949
950
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_UKE == 'True') {
951
        $this->_cards['UKE'] = 'Visa Electron UK Debit';
952
      }
953
954
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_AMEX == 'True') {
955
        $this->_cards['AMEX'] = 'American Express';
956
      }
957
958
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_DC == 'True') {
959
        $this->_cards['DC'] = 'Diners Club';
960
      }
961
962
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_JCB == 'True') {
963
        $this->_cards['JCB'] = 'Japan Credit Bureau';
964
      }
965
966
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_LASER == 'True') {
967
        $this->_cards['LASER'] = 'Laser Card';
968
      }
969
970
      if (MODULE_PAYMENT_SAGE_PAY_DIRECT_ALLOW_PAYPAL == 'True') {
971
        $this->_cards['PAYPAL'] = 'PayPal';
972
      }
973
974
      return $this->_cards;
975
    }
976
977
    function hasCards() {
978
      if (!isset($this->_cards)) {
979
        $this->getCardTypes();
980
      }
981
982
      return !empty($this->_cards);
983
    }
984
985
    function isCard($key) {
986
      if (!isset($this->_cards)) {
987
        $this->getCardTypes();
988
      }
989
990
      return isset($this->_cards[$key]);
991
    }
992
993
    function deleteCard($token, $token_id) {
994
      $OSCOM_Db = Registry::get('Db');
995
996
      if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Live' ) {
997
        $gateway_url = 'https://live.sagepay.com/gateway/service/removetoken.vsp';
998
      } else {
999
        $gateway_url = 'https://test.sagepay.com/gateway/service/removetoken.vsp';
1000
      }
1001
1002
      $params = array('VPSProtocol' => $this->api_version,
1003
                      'TxType' => 'REMOVETOKEN',
1004
                      'Vendor' => substr(MODULE_PAYMENT_SAGE_PAY_DIRECT_VENDOR_LOGIN_NAME, 0, 15),
1005
                      'Token' => $token);
1006
1007
      $post_string = '';
1008
1009
      foreach ($params as $key => $value) {
1010
        $post_string .= $key . '=' . urlencode(trim($value)) . '&';
1011
      }
1012
1013
      $response = $this->sendTransactionToGateway($gateway_url, $post_string);
1014
1015
      $string_array = explode(chr(10), $response);
1016
      $sage_pay_response = array();
1017
1018 View Code Duplication
      foreach ($string_array as $string) {
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...
1019
        if (strpos($string, '=') != false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($string, '=') of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
1020
          $parts = explode('=', $string, 2);
1021
          $sage_pay_response[trim($parts[0])] = trim($parts[1]);
1022
        }
1023
      }
1024
1025
      return $OSCOM_Db->delete('customers_sagepay_tokens', ['id' => $token_id, 'customers_id' => $_SESSION['customer_id'], 'sagepay_token' => $token]) === 1;
1026
    }
1027
1028 View Code Duplication
    function loadErrorMessages() {
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...
1029
      $errors = array();
1030
1031
      if (is_file(dirname(__FILE__) . '/../../../ext/modules/payment/sage_pay/errors.php')) {
1032
        include(dirname(__FILE__) . '/../../../ext/modules/payment/sage_pay/errors.php');
1033
      }
1034
1035
      $this->_error_messages = $errors;
0 ignored issues
show
Bug introduced by
The property _error_messages does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1036
    }
1037
1038 View Code Duplication
    function getErrorMessageNumber($string) {
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...
1039
      if (!isset($this->_error_messages)) {
1040
        $this->loadErrorMessages();
1041
      }
1042
1043
      $error = explode(' ', $string, 2);
1044
1045
      if (is_numeric($error[0]) && $this->errorMessageNumberExists($error[0])) {
1046
        return $error[0];
1047
      }
1048
1049
      return false;
1050
    }
1051
1052 View Code Duplication
    function getErrorMessage($number) {
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...
1053
      if (!isset($this->_error_messages)) {
1054
        $this->loadErrorMessages();
1055
      }
1056
1057
      if (is_numeric($number) && $this->errorMessageNumberExists($number)) {
1058
        return $this->_error_messages[$number];
1059
      }
1060
1061
      return false;
1062
    }
1063
1064 View Code Duplication
    function errorMessageNumberExists($number) {
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...
1065
      if (!isset($this->_error_messages)) {
1066
        $this->loadErrorMessages();
1067
      }
1068
1069
      return (is_numeric($number) && isset($this->_error_messages[$number]));
1070
    }
1071
1072
    function getTestLinkInfo() {
1073
      $dialog_title = OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_title');
1074
      $dialog_button_close = OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_button_close');
1075
      $dialog_success = OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_success');
1076
      $dialog_failed = OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_failed');
1077
      $dialog_error = OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_error');
1078
      $dialog_connection_time = OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_time');
1079
1080
      $test_url = OSCOM::link('modules.php', 'set=payment&module=' . $this->code . '&action=install&subaction=conntest');
1081
1082
      $js = <<<EOD
1083
<script>
1084
if ( typeof jQuery == 'undefined' ) {
1085
  document.write('<scr' + 'ipt src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></scr' + 'ipt>');
1086
  document.write('<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/redmond/jquery-ui.css" />');
1087
  document.write('<scr' + 'ipt src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></scr' + 'ipt>');
1088
}
1089
</script>
1090
1091
<script>
1092
(function() {
1093
  $('#tcdprogressbar').progressbar({
1094
    value: false
1095
  });
1096
});
1097
1098
function openTestConnectionDialog() {
1099
  var d = $('<div>').html($('#testConnectionDialog').html()).dialog({
1100
    modal: true,
1101
    title: '{$dialog_title}',
1102
    buttons: {
1103
      '{$dialog_button_close}': function () {
1104
        $(this).dialog('destroy');
1105
      }
1106
    }
1107
  });
1108
1109
  var timeStart = new Date().getTime();
1110
1111
  $.ajax({
1112
    url: '{$test_url}'
1113
  }).done(function(data) {
1114
    if ( data == '1' ) {
1115
      d.find('#testConnectionDialogProgress').html('<p style="font-weight: bold; color: green;">{$dialog_success}</p>');
1116
    } else {
1117
      d.find('#testConnectionDialogProgress').html('<p style="font-weight: bold; color: red;">{$dialog_failed}</p>');
1118
    }
1119
  }).fail(function() {
1120
    d.find('#testConnectionDialogProgress').html('<p style="font-weight: bold; color: red;">{$dialog_error}</p>');
1121
  }).always(function() {
1122
    var timeEnd = new Date().getTime();
1123
    var timeTook = new Date(0, 0, 0, 0, 0, 0, timeEnd-timeStart);
1124
1125
    d.find('#testConnectionDialogProgress').append('<p>{$dialog_connection_time} ' + timeTook.getSeconds() + '.' + timeTook.getMilliseconds() + 's</p>');
1126
  });
1127
}
1128
</script>
1129
EOD;
1130
1131
      $info = '<p><img src="images/icons/locked.gif" border="0">&nbsp;<a href="javascript:openTestConnectionDialog();" style="text-decoration: underline; font-weight: bold;">' . OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_link_title') . '</a></p>' .
1132
              '<div id="testConnectionDialog" style="display: none;"><p>';
1133
1134
      if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Live' ) {
1135
        $info .= 'Live Server:<br />https://live.sagepay.com/gateway/service/vspdirect-register.vsp';
1136
      } else {
1137
        $info .= 'Test Server:<br />https://test.sagepay.com/gateway/service/vspdirect-register.vsp';
1138
      }
1139
1140
      $info .= '</p><div id="testConnectionDialogProgress"><p>' . OSCOM::getDef('module_payment_sage_pay_direct_dialog_connection_general_text') . '</p><div id="tcdprogressbar"></div></div></div>' .
1141
               $js;
1142
1143
      return $info;
1144
    }
1145
1146 View Code Duplication
    function getTestConnectionResult() {
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...
1147
      if ( MODULE_PAYMENT_SAGE_PAY_DIRECT_TRANSACTION_SERVER == 'Live' ) {
1148
        $gateway_url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp';
1149
      } else {
1150
        $gateway_url = 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp';
1151
      }
1152
1153
      $params = array('VPSProtocol' => $this->api_version,
1154
                      'ReferrerID' => 'C74D7B82-E9EB-4FBD-93DB-76F0F551C802',
1155
                      'Vendor' => substr(MODULE_PAYMENT_SAGE_PAY_DIRECT_VENDOR_LOGIN_NAME, 0, 15),
1156
                      'Amount' => 0,
1157
                      'Currency' => DEFAULT_CURRENCY);
1158
1159
      $ip_address = HTTP::getIpAddress();
1160
1161
      if ( !empty($ip_address) && (ip2long($ip_address) != -1) && (ip2long($ip_address) != false) ) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing ip2long($ip_address) of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
1162
        $params['ClientIPAddress']= $ip_address;
1163
      }
1164
1165
      $post_string = '';
1166
1167
      foreach ($params as $key => $value) {
1168
        $post_string .= $key . '=' . urlencode(trim($value)) . '&';
1169
      }
1170
1171
      $response = $this->sendTransactionToGateway($gateway_url, $post_string);
1172
1173
      if ( $response != false ) {
1174
        return 1;
1175
      }
1176
1177
      return -1;
1178
    }
1179
1180
    function templateClassExists() {
1181
      return class_exists('oscTemplate') && isset($GLOBALS['oscTemplate']) && is_object($GLOBALS['oscTemplate']) && (get_class($GLOBALS['oscTemplate']) == 'oscTemplate');
1182
    }
1183
1184
    function getSubmitCardDetailsJavascript() {
1185
      $js = <<<EOD
1186
<script>
1187
if ( typeof jQuery == 'undefined' ) {
1188
  document.write('<scr' + 'ipt src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></scr' + 'ipt>');
1189
}
1190
</script>
1191
1192
<script>
1193
$(function() {
1194
  if ( $('#sagepay_table').length > 0 ) {
1195
    if ( typeof($('#sagepay_table').parent().closest('table').attr('width')) == 'undefined' ) {
1196
      $('#sagepay_table').parent().closest('table').attr('width', '100%');
1197
    }
1198
1199
    $('#sagepay_table .moduleRowExtra').hide();
1200
1201
    $('#sagepay_table_new_card').hide();
1202
1203
    $('form[name="checkout_confirmation"] input[name="sagepay_card"]').change(function() {
1204
      var selected = $(this).val();
1205
1206
      if ( selected == '0' ) {
1207
        sagepayShowNewCardFields();
1208
      } else {
1209
        $('#sagepay_table_new_card').hide();
1210
1211
        $('[id^="sagepay_card_cvc_"]').hide();
1212
1213
        $('#sagepay_card_cvc_' + selected).show();
1214
      }
1215
1216
      $('tr[id^="sagepay_card_"]').removeClass('moduleRowSelected');
1217
      $('#sagepay_card_' + selected).addClass('moduleRowSelected');
1218
    });
1219
1220
    $('form[name="checkout_confirmation"] input[name="sagepay_card"]:first').prop('checked', true).trigger('change');
1221
1222
    $('#sagepay_table .moduleRow').hover(function() {
1223
      $(this).addClass('moduleRowOver');
1224
    }, function() {
1225
      $(this).removeClass('moduleRowOver');
1226
    }).click(function(event) {
1227
      var target = $(event.target);
1228
1229
      if ( !target.is('input:radio') ) {
1230
        $(this).find('input:radio').each(function() {
1231
          if ( $(this).prop('checked') == false ) {
1232
            $(this).prop('checked', true).trigger('change');
1233
          }
1234
        });
1235
      }
1236
    });
1237
  } else {
1238
    if ( typeof($('#sagepay_table_new_card').parent().closest('table').attr('width')) == 'undefined' ) {
1239
      $('#sagepay_table_new_card').parent().closest('table').attr('width', '100%');
1240
    }
1241
1242
    sagepayShowNewCardFields();
1243
  }
1244
1245
  $('#sagepay_card_type').change(function() {
1246
    var selected = $(this).val();
1247
1248
    if ( selected == 'PAYPAL' ) {
1249
      $('#sagepay_table_new_card input[name="cc_owner"]').parent().parent().hide();
1250
      $('#sagepay_table_new_card input[name="cc_number_nh-dns"]').parent().parent().hide();
1251
      $('#sagepay_table_new_card select[name="cc_expires_month"]').parent().parent().hide();
1252
      $('#sagepay_table_new_card select[name="cc_expires_year"]').parent().parent().hide();
1253
1254
      if ( $('#sagepay_table_new_card input[name="cc_cvc_nh-dns"]').length > 0 ) {
1255
        $('#sagepay_table_new_card input[name="cc_cvc_nh-dns"]').parent().parent().hide();
1256
      }
1257
1258
      if ( $('#sagepay_table_new_card input[name="cc_save"]').length > 0 ) {
1259
        $('#sagepay_table_new_card input[name="cc_save"]').parent().parent().hide();
1260
      }
1261
    } else {
1262
      $('#sagepay_table_new_card input[name="cc_owner"]').parent().parent().show();
1263
      $('#sagepay_table_new_card input[name="cc_number_nh-dns"]').parent().parent().show();
1264
      $('#sagepay_table_new_card select[name="cc_expires_month"]').parent().parent().show();
1265
      $('#sagepay_table_new_card select[name="cc_expires_year"]').parent().parent().show();
1266
1267
      if ( $('#sagepay_table_new_card input[name="cc_cvc_nh-dns"]').length > 0 ) {
1268
        $('#sagepay_table_new_card input[name="cc_cvc_nh-dns"]').parent().parent().show();
1269
      }
1270
1271
      if ( $('#sagepay_table_new_card input[name="cc_save"]').length > 0 ) {
1272
        $('#sagepay_table_new_card input[name="cc_save"]').parent().parent().show();
1273
      }
1274
    }
1275
1276
    if ( $('#sagepay_card_date_start').length > 0 ) {
1277
      if ( selected == 'MAESTRO' || selected == 'AMEX' ) {
1278
        $('#sagepay_card_date_start').parent().parent().show();
1279
      } else {
1280
        $('#sagepay_card_date_start').parent().parent().hide();
1281
      }
1282
    }
1283
1284
    if ( $('#sagepay_card_issue').length > 0 ) {
1285
      if ( selected == 'MAESTRO' ) {
1286
        $('#sagepay_card_issue').parent().parent().show();
1287
      } else {
1288
        $('#sagepay_card_issue').parent().parent().hide();
1289
      }
1290
    }
1291
  });
1292
});
1293
1294
function sagepayShowNewCardFields() {
1295
  var sagepay_card_type_default = $('#sagepay_card_type').val();
1296
1297
  $('[id^="sagepay_card_cvc_"]').hide();
1298
1299
  $('#sagepay_table_new_card').show();
1300
1301
  if ( $('#sagepay_card_date_start').length > 0 ) {
1302
    if ( sagepay_card_type_default != 'MAESTRO' || sagepay_card_type_default != 'AMEX' ) {
1303
      $('#sagepay_card_date_start').parent().parent().hide();
1304
    }
1305
  }
1306
1307
  if ( $('#sagepay_card_issue').length > 0 ) {
1308
    if ( sagepay_card_type_default != 'MAESTRO' ) {
1309
      $('#sagepay_card_issue').parent().parent().hide();
1310
    }
1311
  }
1312
}
1313
</script>
1314
EOD;
1315
1316
      return $js;
1317
    }
1318
1319
    function sendDebugEmail($response = array()) {
1320
      if (tep_not_null(MODULE_PAYMENT_SAGE_PAY_DIRECT_DEBUG_EMAIL)) {
1321
        $email_body = '';
1322
1323
        if (!empty($response)) {
1324
          $email_body .= 'RESPONSE:' . "\n\n" . print_r($response, true) . "\n\n";
1325
        }
1326
1327
        if (!empty($_POST)) {
1328
          if (isset($_POST['cc_number_nh-dns'])) {
1329
            $_POST['cc_number_nh-dns'] = 'XXXX' . substr($_POST['cc_number_nh-dns'], -4);
1330
          }
1331
1332
          if (isset($_POST['cc_cvc_tokens_nh-dns'])) {
1333
            $_POST['cc_cvc_tokens_nh-dns'] = 'XXX';
1334
          }
1335
1336
          if (isset($_POST['cc_cvc_nh-dns'])) {
1337
            $_POST['cc_cvc_nh-dns'] = 'XXX';
1338
          }
1339
1340
          if (isset($_POST['cc_issue_nh-dns'])) {
1341
            $_POST['cc_issue_nh-dns'] = 'XXX';
1342
          }
1343
1344
          if (isset($_POST['cc_expires_month'])) {
1345
            $_POST['cc_expires_month'] = 'XX';
1346
          }
1347
1348
          if (isset($_POST['cc_expires_year'])) {
1349
            $_POST['cc_expires_year'] = 'XX';
1350
          }
1351
1352
          if (isset($_POST['cc_starts_month'])) {
1353
            $_POST['cc_starts_month'] = 'XX';
1354
          }
1355
1356
          if (isset($_POST['cc_starts_year'])) {
1357
            $_POST['cc_starts_year'] = 'XX';
1358
          }
1359
1360
          $email_body .= '$_POST:' . "\n\n" . print_r($_POST, true) . "\n\n";
1361
        }
1362
1363
        if (!empty($_GET)) {
1364
          $email_body .= '$_GET:' . "\n\n" . print_r($_GET, true) . "\n\n";
1365
        }
1366
1367
        if (!empty($email_body)) {
1368
          $debugEmail = new Mail(MODULE_PAYMENT_SAGE_PAY_DIRECT_DEBUG_EMAIL, null, STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, 'Sage Pay Direct Debug E-Mail');
1369
          $debugEmail->setBody($email_body);
1370
          $debugEmail->send();
1371
        }
1372
      }
1373
    }
1374
  }
1375
?>
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...
1376