Skip to content

Commit 2c3f76e

Browse files
authored
Merge pull request #88 from bobbrodie/5.0.x
PHPCS Updates
2 parents 7ca584b + d345efe commit 2c3f76e

File tree

5 files changed

+59
-36
lines changed

5 files changed

+59
-36
lines changed

modules/gateways/bitpaycheckout.php

+26-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
die("This file cannot be accessed directly");
2020
}
2121

22-
include_once(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
23-
use BitPaySDK\PosClient;
22+
include_once(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout'
23+
. DIRECTORY_SEPARATOR . 'vendor'
24+
. DIRECTORY_SEPARATOR . 'autoload.php');
25+
26+
use BitPaySDK\PosClient;
2427
use BitPaySDK\Model\Invoice\Invoice;
2528
use BitPaySDK\Model\Invoice\Buyer;
2629
use BitPaySDK\Model\Facade;
@@ -80,8 +83,7 @@ function ($table) {
8083
* @return array
8184
*/
8285

83-
if (!function_exists('bitpaycheckout_config'))
84-
{
86+
if (!function_exists('bitpaycheckout_config')) {
8587
function bitpaycheckout_config()
8688
{
8789
return array(
@@ -97,6 +99,7 @@ function bitpaycheckout_config()
9799
'Type' => 'text',
98100
'Size' => '25',
99101
'Default' => '',
102+
// @phpcs:ignore Generic.Files.LineLength.TooLong
100103
'Description' => 'Your <b>development</b> merchant token. <a href = "https://test.bitpay.com/dashboard/merchant/api-tokens" target = "_blank">Create one here</a> and <b>uncheck</b> `Require Authentication`.',
101104
),
102105
// a text field type allows for single line text input
@@ -105,21 +108,24 @@ function bitpaycheckout_config()
105108
'Type' => 'text',
106109
'Size' => '25',
107110
'Default' => '',
111+
// @phpcs:ignore Generic.Files.LineLength.TooLong
108112
'Description' => 'Your <b>production</b> merchant token. <a href = "https://bitpay.com/dashboard/merchant/api-tokens" target = "_blank">Create one here</a> and <b>uncheck</b> `Require Authentication`.',
109113
),
110114

111115
'bitpay_checkout_endpoint' => array(
112116
'FriendlyName' => 'Endpoint',
113117
'Type' => 'dropdown',
114118
'Options' => 'Test,Production',
119+
// @phpcs:ignore Generic.Files.LineLength.TooLong
115120
'Description' => 'Select <b>Test</b> for testing the plugin, <b>Production</b> when you are ready to go live.<br>',
116121
),
117122
'bitpay_checkout_mode' => array(
118123
'FriendlyName' => 'Payment UX',
119124
'Type' => 'dropdown',
120125
'Options' => 'Modal,Redirect',
126+
// @phpcs:ignore Generic.Files.LineLength.TooLong
121127
'Description' => 'Select <b>Modal</b> to keep the user on the invoice page, or <b>Redirect</b> to have them view the invoice at BitPay.com, and be redirected after payment.<br>',
122-
),
128+
),
123129
);
124130
}
125131
}
@@ -137,7 +143,9 @@ function bitpaycheckout_link($config_params)
137143
$curpage = basename($_SERVER["SCRIPT_FILENAME"]);
138144

139145
$curpage = str_replace("/", "", $curpage);
140-
if ($curpage != 'viewinvoice.php'): return;endif;
146+
if ($curpage != 'viewinvoice.php') {
147+
return;
148+
}
141149
?>
142150
<script src="https://bitpay.com/bitpay.min.js" type="text/javascript"></script>
143151
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
@@ -146,7 +154,7 @@ function bitpaycheckout_link($config_params)
146154

147155
$client = new PosClient($bitpay_checkout_token, $bitpay_checkout_endpoint);
148156

149-
#check to make sure we don't already have a valid BitPay Invoice active
157+
// Check to make sure we don't already have a valid BitPay Invoice active
150158
$checkDup = Capsule::table('_bitpay_checkout_transactions')
151159
->select('transaction_id')
152160
->where('order_id', '=', $config_params['invoiceid'])
@@ -178,7 +186,7 @@ function bitpaycheckout_link($config_params)
178186
$moduleDisplayName = $config_params['name'];
179187
$moduleName = $config_params['paymentmethod'];
180188

181-
#BITPAY INVOICE DETAILS
189+
// BITPAY INVOICE DETAILS
182190
$params = new stdClass();
183191

184192
$dir = dirname($_SERVER['REQUEST_URI']);
@@ -187,13 +195,17 @@ function bitpaycheckout_link($config_params)
187195
}
188196

189197
$params->orderId = trim($invoiceId);
190-
$params->notificationURL = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php';
198+
// @phpcs:ignore Generic.Files.LineLength.TooLong
199+
$params->notificationURL = $protocol . $_SERVER['SERVER_NAME']. $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php';
200+
// @phpcs:ignore Generic.Files.LineLength.TooLong
191201
$params->redirectURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
192202
$params->fullNotifications = true;
193203

194204
$protocol = 'https://';
195205

206+
// @phpcs:ignore Generic.Files.LineLength.TooLong
196207
$notificationURL = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php';
208+
// @phpcs:ignore Generic.Files.LineLength.TooLong
197209
$redirectURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
198210

199211
$invoice = new Invoice($amount, $currencyCode);
@@ -230,6 +242,7 @@ function bitpaycheckout_link($config_params)
230242

231243
try {
232244
$statement = $pdo->prepare(
245+
// @phpcs:ignore Generic.Files.LineLength.TooLong
233246
'insert into _bitpay_checkout_transactions (order_id, transaction_id, transaction_status,created_at) values (:order_id, :transaction_id, :transaction_status,:created_at)'
234247
);
235248

@@ -249,8 +262,10 @@ function bitpaycheckout_link($config_params)
249262
}
250263

251264
if ($bitpay_checkout_mode == 'Modal') {
265+
// @phpcs:ignore Generic.Files.LineLength.TooLong
252266
$htmlOutput .= '<button name = "bitpay-payment" class = "btn btn-success btn-sm" onclick = "showModal(\'' . $basicInvoice->getId() . '\');return false;">' . $config_params['langpaynow'] . '</button>';
253267
} else {
268+
// @phpcs:ignore Generic.Files.LineLength.TooLong
254269
$htmlOutput .= '<button name = "bitpay-payment" class = "btn btn-success btn-sm" onclick = "redirectURL(\'' . $basicInvoice->getUrl(). '\');return false;">' . $config_params['langpaynow'] . '</button>';
255270
}
256271
?>
@@ -272,8 +287,8 @@ function redirectURL($url){
272287
}
273288
}, false);
274289
function showModal(){
275-
//show the modal
276-
<?php if ($bitpay_checkout_endpoint == 'Test'): ?>
290+
// Show the modal
291+
<?php if ($bitpay_checkout_endpoint == 'Test') : ?>
277292
bitpay.enableTestMode()
278293
<?php endif;?>
279294
bitpay.showInvoice('<?php echo $basicInvoice->getId(); ?>');

modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php

+29-25
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@
1919
*/
2020

2121
use WHMCS\Database\Capsule;
22+
2223
// Require libraries needed for gateway module functions.
2324
require_once '../../../../init.php';
24-
require_once '../../../../includes/gatewayfunctions.php';
25-
require_once '../../../../includes/invoicefunctions.php';
25+
require_once ROOTDIR . "/includes/gatewayfunctions.php";
26+
require_once ROOTDIR . "/includes/invoicefunctions.php";
2627

2728
// Detect module name from filename.
2829
$gatewayModuleName = 'bitpaycheckout';
30+
2931
// Fetch gateway configuration parameters.
3032
$gatewayParams = getGatewayVariables($gatewayModuleName);
3133
define("TEST_URL", 'https://test.bitpay.com/invoices/');
3234
define("PROD_URL", 'https://bitpay.com/invoices/');
3335

34-
function checkInvoiceStatus($url) {
36+
function checkInvoiceStatus($url)
37+
{
3538
$ch = curl_init();
3639
curl_setopt($ch, CURLOPT_URL, $url);
3740
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
@@ -47,10 +50,10 @@ function checkInvoiceStatus($url) {
4750
$file = 'bitpay.txt';
4851
$err = "bitpay_err.txt";
4952

50-
file_put_contents($file,"===========INCOMING IPN=========================",FILE_APPEND);
51-
file_put_contents($file,date('d.m.Y H:i:s'),FILE_APPEND);
52-
file_put_contents($file,print_r($response, true),FILE_APPEND);
53-
file_put_contents($file,"===========END OF IPN===========================",FILE_APPEND);
53+
file_put_contents($file, "===========INCOMING IPN=========================", FILE_APPEND);
54+
file_put_contents($file, date('d.m.Y H:i:s'), FILE_APPEND);
55+
file_put_contents($file, print_r($response, true), FILE_APPEND);
56+
file_put_contents($file, "===========END OF IPN===========================", FILE_APPEND);
5457

5558
$order_status = $data['status'];
5659
$order_invoice = $data['id'];
@@ -94,16 +97,16 @@ function checkInvoiceStatus($url) {
9497
['transaction_id', '=', $order_invoice],
9598
])
9699
->update($update);
97-
} catch (Exception $e ) {
98-
file_put_contents($file,$e,FILE_APPEND);
100+
} catch (Exception $e) {
101+
file_put_contents($file, $e, FILE_APPEND);
99102
}
100103

101104
addInvoicePayment(
102-
$orderid,
103-
$order_invoice,
104-
$price,
105-
0,
106-
'bitpaycheckout'
105+
$orderid,
106+
$order_invoice,
107+
$price,
108+
0,
109+
'bitpaycheckout'
107110
);
108111
break;
109112

@@ -119,8 +122,8 @@ function checkInvoiceStatus($url) {
119122
['paymentmethod', '=', 'bitpaycheckout'],
120123
])
121124
->update($update);
122-
} catch (Exception $e ) {
123-
file_put_contents($file,$e,FILE_APPEND);
125+
} catch (Exception $e) {
126+
file_put_contents($file, $e, FILE_APPEND);
124127
}
125128

126129
#update the bitpay_invoice table
@@ -133,8 +136,8 @@ function checkInvoiceStatus($url) {
133136
['transaction_id', '=', $order_invoice],
134137
])
135138
->update($update);
136-
} catch (Exception $e ) {
137-
file_put_contents($file,$e,FILE_APPEND);
139+
} catch (Exception $e) {
140+
file_put_contents($file, $e, FILE_APPEND);
138141
}
139142
break;
140143

@@ -146,8 +149,8 @@ function checkInvoiceStatus($url) {
146149
Capsule::table($table)
147150
->where('transaction_id', '=', $order_invoice)
148151
->delete();
149-
} catch (Exception $e ) {
150-
file_put_contents($file,$e,FILE_APPEND);
152+
} catch (Exception $e) {
153+
file_put_contents($file, $e, FILE_APPEND);
151154
}
152155
break;
153156

@@ -164,8 +167,8 @@ function checkInvoiceStatus($url) {
164167
['paymentmethod', '=', 'bitpaycheckout'],
165168
])
166169
->update($update);
167-
} catch (Exception $e ) {
168-
file_put_contents($file,$e,FILE_APPEND);
170+
} catch (Exception $e) {
171+
file_put_contents($file, $e, FILE_APPEND);
169172
}
170173

171174
#update the bitpay invoice table
@@ -178,11 +181,12 @@ function checkInvoiceStatus($url) {
178181
['transaction_id', '=', $order_invoice],
179182
])
180183
->update($update);
181-
} catch (Exception $e ) {
182-
file_put_contents($file,$e,FILE_APPEND);
184+
} catch (Exception $e) {
185+
file_put_contents($file, $e, FILE_APPEND);
183186
}
184187
break;
185188
}
186189
}
187-
http_response_code(200);
190+
191+
http_response_code(200);
188192
}

phpcbf.phar

1.41 MB
Binary file not shown.

phpcs.phar

1.41 MB
Binary file not shown.

phpcs.xml

+4
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
<file>modules/</file>
1313
<exclude-pattern>*/vendor/*</exclude-pattern>
1414

15+
<rule ref="PSR1.Files.SideEffects">
16+
<exclude name="PSR1.Files.SideEffects"/>
17+
</rule>
18+
1519
</ruleset>

0 commit comments

Comments
 (0)