Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS Updates #88

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions modules/gateways/bitpaycheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
die("This file cannot be accessed directly");
}

include_once(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
use BitPaySDK\PosClient;
include_once(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout'
. DIRECTORY_SEPARATOR . 'vendor'
. DIRECTORY_SEPARATOR . 'autoload.php');

use BitPaySDK\PosClient;
use BitPaySDK\Model\Invoice\Invoice;
use BitPaySDK\Model\Invoice\Buyer;
use BitPaySDK\Model\Facade;
Expand Down Expand Up @@ -80,8 +83,7 @@ function ($table) {
* @return array
*/

if (!function_exists('bitpaycheckout_config'))
{
if (!function_exists('bitpaycheckout_config')) {
function bitpaycheckout_config()
{
return array(
Expand All @@ -97,6 +99,7 @@ function bitpaycheckout_config()
'Type' => 'text',
'Size' => '25',
'Default' => '',
// @phpcs:ignore Generic.Files.LineLength.TooLong
'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`.',
),
// a text field type allows for single line text input
Expand All @@ -105,21 +108,24 @@ function bitpaycheckout_config()
'Type' => 'text',
'Size' => '25',
'Default' => '',
// @phpcs:ignore Generic.Files.LineLength.TooLong
'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`.',
),

'bitpay_checkout_endpoint' => array(
'FriendlyName' => 'Endpoint',
'Type' => 'dropdown',
'Options' => 'Test,Production',
// @phpcs:ignore Generic.Files.LineLength.TooLong
'Description' => 'Select <b>Test</b> for testing the plugin, <b>Production</b> when you are ready to go live.<br>',
),
'bitpay_checkout_mode' => array(
'FriendlyName' => 'Payment UX',
'Type' => 'dropdown',
'Options' => 'Modal,Redirect',
// @phpcs:ignore Generic.Files.LineLength.TooLong
'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>',
),
),
);
}
}
Expand All @@ -137,7 +143,9 @@ function bitpaycheckout_link($config_params)
$curpage = basename($_SERVER["SCRIPT_FILENAME"]);

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

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

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

#BITPAY INVOICE DETAILS
// BITPAY INVOICE DETAILS
$params = new stdClass();

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

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

$protocol = 'https://';

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

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

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

Expand All @@ -249,8 +262,10 @@ function bitpaycheckout_link($config_params)
}

if ($bitpay_checkout_mode == 'Modal') {
// @phpcs:ignore Generic.Files.LineLength.TooLong
$htmlOutput .= '<button name = "bitpay-payment" class = "btn btn-success btn-sm" onclick = "showModal(\'' . $basicInvoice->getId() . '\');return false;">' . $config_params['langpaynow'] . '</button>';
} else {
// @phpcs:ignore Generic.Files.LineLength.TooLong
$htmlOutput .= '<button name = "bitpay-payment" class = "btn btn-success btn-sm" onclick = "redirectURL(\'' . $basicInvoice->getUrl(). '\');return false;">' . $config_params['langpaynow'] . '</button>';
}
?>
Expand All @@ -272,8 +287,8 @@ function redirectURL($url){
}
}, false);
function showModal(){
//show the modal
<?php if ($bitpay_checkout_endpoint == 'Test'): ?>
// Show the modal
<?php if ($bitpay_checkout_endpoint == 'Test') : ?>
bitpay.enableTestMode()
<?php endif;?>
bitpay.showInvoice('<?php echo $basicInvoice->getId(); ?>');
Expand Down
54 changes: 29 additions & 25 deletions modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
*/

use WHMCS\Database\Capsule;

// Require libraries needed for gateway module functions.
require_once '../../../../init.php';
require_once '../../../../includes/gatewayfunctions.php';
require_once '../../../../includes/invoicefunctions.php';
require_once ROOTDIR . "/includes/gatewayfunctions.php";
require_once ROOTDIR . "/includes/invoicefunctions.php";

// Detect module name from filename.
$gatewayModuleName = 'bitpaycheckout';

// Fetch gateway configuration parameters.
$gatewayParams = getGatewayVariables($gatewayModuleName);
define("TEST_URL", 'https://test.bitpay.com/invoices/');
define("PROD_URL", 'https://bitpay.com/invoices/');

function checkInvoiceStatus($url) {
function checkInvoiceStatus($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
Expand All @@ -47,10 +50,10 @@ function checkInvoiceStatus($url) {
$file = 'bitpay.txt';
$err = "bitpay_err.txt";

file_put_contents($file,"===========INCOMING IPN=========================",FILE_APPEND);
file_put_contents($file,date('d.m.Y H:i:s'),FILE_APPEND);
file_put_contents($file,print_r($response, true),FILE_APPEND);
file_put_contents($file,"===========END OF IPN===========================",FILE_APPEND);
file_put_contents($file, "===========INCOMING IPN=========================", FILE_APPEND);
file_put_contents($file, date('d.m.Y H:i:s'), FILE_APPEND);
file_put_contents($file, print_r($response, true), FILE_APPEND);
file_put_contents($file, "===========END OF IPN===========================", FILE_APPEND);

$order_status = $data['status'];
$order_invoice = $data['id'];
Expand Down Expand Up @@ -93,16 +96,16 @@ function checkInvoiceStatus($url) {
['transaction_id', '=', $order_invoice],
])
->update($update);
} catch (Exception $e ) {
file_put_contents($file,$e,FILE_APPEND);
} catch (Exception $e) {
file_put_contents($file, $e, FILE_APPEND);
}

addInvoicePayment(
$orderid,
$order_invoice,
$price,
0,
'bitpaycheckout'
$orderid,
$order_invoice,
$price,
0,
'bitpaycheckout'
);
break;

Expand All @@ -118,8 +121,8 @@ function checkInvoiceStatus($url) {
['paymentmethod', '=', 'bitpaycheckout'],
])
->update($update);
} catch (Exception $e ) {
file_put_contents($file,$e,FILE_APPEND);
} catch (Exception $e) {
file_put_contents($file, $e, FILE_APPEND);
}

#update the bitpay_invoice table
Expand All @@ -132,8 +135,8 @@ function checkInvoiceStatus($url) {
['transaction_id', '=', $order_invoice],
])
->update($update);
} catch (Exception $e ) {
file_put_contents($file,$e,FILE_APPEND);
} catch (Exception $e) {
file_put_contents($file, $e, FILE_APPEND);
}
break;

Expand All @@ -145,8 +148,8 @@ function checkInvoiceStatus($url) {
Capsule::table($table)
->where('transaction_id', '=', $order_invoice)
->delete();
} catch (Exception $e ) {
file_put_contents($file,$e,FILE_APPEND);
} catch (Exception $e) {
file_put_contents($file, $e, FILE_APPEND);
}
break;

Expand All @@ -163,8 +166,8 @@ function checkInvoiceStatus($url) {
['paymentmethod', '=', 'bitpaycheckout'],
])
->update($update);
} catch (Exception $e ) {
file_put_contents($file,$e,FILE_APPEND);
} catch (Exception $e) {
file_put_contents($file, $e, FILE_APPEND);
}

#update the bitpay invoice table
Expand All @@ -177,11 +180,12 @@ function checkInvoiceStatus($url) {
['transaction_id', '=', $order_invoice],
])
->update($update);
} catch (Exception $e ) {
file_put_contents($file,$e,FILE_APPEND);
} catch (Exception $e) {
file_put_contents($file, $e, FILE_APPEND);
}
break;
}
}
http_response_code(200);

http_response_code(200);
}
Binary file added phpcbf.phar
Binary file not shown.
Binary file added phpcs.phar
Binary file not shown.
4 changes: 4 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<file>modules/</file>
<exclude-pattern>*/vendor/*</exclude-pattern>

<rule ref="PSR1.Files.SideEffects">
<exclude name="PSR1.Files.SideEffects"/>
</rule>

</ruleset>