Skip to content

Commit

Permalink
Fixing plugin review problems. Fixing unhandled exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeet committed Jan 14, 2022
1 parent 81f2670 commit 63fa2db
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
15 changes: 10 additions & 5 deletions btcpay-greenfield-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://btcpayserver.org
* Text Domain: btcpay-greenfield-for-woocommerce
* Domain Path: /languages
* Version: 0.1.1
* Version: 0.1.2
* Requires PHP: 7.4
* Tested up to: 5.8
* Requires at least: 5.2
Expand Down Expand Up @@ -146,9 +146,9 @@ public function processAjaxApiUrl() {
}

if ( current_user_can( 'manage_options' ) ) {
$host = $_POST['host'];
$host = filter_var($_POST['host'], FILTER_VALIDATE_URL);

if (!filter_var($host, FILTER_VALIDATE_URL) || (substr( $host, 0, 7 ) !== "http://" && substr( $host, 0, 8 ) !== "https://")) {
if ($host === false || (substr( $host, 0, 7 ) !== "http://" && substr( $host, 0, 8 ) !== "https://")) {
wp_send_json_error("Error validating BTCPayServer URL.");
}

Expand Down Expand Up @@ -214,11 +214,16 @@ function init_btcpay_greenfield() {
$btcPaySettingsUrl = admin_url('admin.php?page=wc-settings&tab=btcpay_settings');

$rawData = file_get_contents('php://input');
$data = json_decode( $rawData, TRUE );
$data = json_decode( $rawData, true );

// Seems data does get submitted with url-encoded payload.
if (!empty($_POST)) {
$data = $_POST;
$data['apiKey'] = esc_attr($_POST['apiKey'] ?? null);
if (is_array($_POST['permissions'])) {
foreach ($_POST['permissions'] as $key => $value) {
$data['permissions'][$key] = esc_attr($_POST['permissions'][$key] ?? null);
}
}
}

if (isset($data['apiKey']) && isset($data['permissions'])) {
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: bitcoin, btcpay, BTCPay Server, btcpayserver, WooCommerce, payment gateway
Requires at least: 4.5
Tested up to: 5.8.2
Requires PHP: 7.4
Stable tag: 0.1.1
Stable tag: 0.1.2
License: MIT
License URI: https://github.com/btcpayserver/woocommerce-greenfield-plugin/blob/master/license.txt

Expand Down
3 changes: 1 addition & 2 deletions src/Admin/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ public static function addNotice( string $level, string $message, bool $dismissi
add_action(
'admin_notices',
function () use ( $level, $message, $dismissible ) {
$levelC = esc_attr( $level );
$dismiss = $dismissible ? ' is-dismissible' : '';
?>
<div class="notice notice-<?php echo $levelC . $dismiss; ?>" style="padding:12px 12px">
<div class="notice notice-<?php echo esc_attr( $level ) . esc_attr( $dismiss ); ?>" style="padding:12px 12px">
<?php echo '<strong>BTCPay Server:</strong> ' . wp_kses_post( $message ) ?>
</div>
<?php
Expand Down
1 change: 1 addition & 0 deletions src/Gateway/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct() {
* Initialise Gateway Settings Form Fields
*/
public function init_form_fields() {
wp_enqueue_media();
wp_register_script(
'btcpay_gf_abstract_gateway',
BTCPAYSERVER_PLUGIN_URL . 'assets/js/gatewayIconMedia.js',
Expand Down
24 changes: 14 additions & 10 deletions src/Helper/GreenfieldApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,21 @@ public static function supportedPaymentMethods(): array {
if ($config = self::getConfig()) {
$client = new StorePaymentMethod($config['url'], $config['api_key']);
if ($storeId = get_option('btcpay_gf_store_id')) {
$pmResult = $client->getPaymentMethods($storeId);
/** @var AbstractStorePaymentMethodResult $pm */
foreach ($pmResult as $pm) {
if ($pm->isEnabled() && $pmName = $pm->getData()['paymentMethod'] ) {
// Convert - to _ for later use in gateway class generator.
$symbol = str_replace('-', '_', $pmName);
$paymentMethods[] = [
'symbol' => $symbol,
'className' => "BTCPay_GF_{$symbol}"
];
try {
$pmResult = $client->getPaymentMethods($storeId);
/** @var AbstractStorePaymentMethodResult $pm */
foreach ($pmResult as $pm) {
if ($pm->isEnabled() && $pmName = $pm->getData()['paymentMethod'] ) {
// Convert - to _ for later use in gateway class generator.
$symbol = str_replace('-', '_', $pmName);
$paymentMethods[] = [
'symbol' => esc_attr($symbol),
'className' => "BTCPay_GF_{$symbol}"
];
}
}
} catch (\Throwable $e) {
Logger::debug('Exception loading payment methods: ' . $e->getMessage(), true);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Helper/OrderStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function renderOrderStatesHtml($value) {
foreach ($btcpayStates as $btcpayState => $btcpayName) {
?>
<tr>
<th><?php echo $btcpayName; ?></th>
<th><?php echo esc_html($btcpayName); ?></th>
<td>
<select name="<?php echo esc_attr($value['id']) ?>[<?php echo $btcpayState; ?>]">
<select name="<?php echo esc_attr($value['id']) ?>[<?php echo esc_html($btcpayState); ?>]">
<?php

foreach ($wcStates as $wcState => $wcName) {
Expand All @@ -72,9 +72,9 @@ public function renderOrderStatesHtml($value) {
}

if ($selectedOption === $wcState) {
echo "<option value=\"$wcState\" selected>$wcName</option>" . PHP_EOL;
echo '<option value="' . esc_attr($wcState) . '" selected>' . esc_html($wcName) . '</option>' . PHP_EOL;
} else {
echo "<option value=\"$wcState\">$wcName</option>" . PHP_EOL;
echo '<option value="' . esc_attr($wcState) . '">' . esc_html($wcName) . '</option>' . PHP_EOL;
}
}
?>
Expand Down

0 comments on commit 63fa2db

Please sign in to comment.