Skip to content

Commit

Permalink
Small fixes post review
Browse files Browse the repository at this point in the history
  • Loading branch information
fean committed Sep 1, 2021
1 parent 06f0579 commit 52f6c5c
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 27 deletions.
18 changes: 13 additions & 5 deletions includes/admin/admin-order-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function renderFailedSideBarContent($post) {
<ul class="wc-tr-shipment-actions failed">
<li class="action-item">
<a
href="<?php esc_url_e($reannounceUrl) ?>"
href="<?php echo esc_url($reannounceUrl) ?>"
class="button button-primary"
title="<?php esc_attr_e('Hiermee wordt geprobeerd de zending opnieuw aan Trunkrs aan te melden.', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>"
>
Expand Down Expand Up @@ -103,6 +103,9 @@ public function renderSideBarContent($post)
</p>
</li>

<?php
if ($trunkrsOrder->isCancelled) {
?>
<li>
<p>
<b><?php esc_html_e('Geannuleerd', TRUNKRS_WC_Bootstrapper::DOMAIN) ?></b>
Expand All @@ -112,6 +115,9 @@ public function renderSideBarContent($post)
</span>
</p>
</li>
<?php
}
?>
</ul>

<ul class="wc-tr-shipment-actions <?php esc_attr_e($classes) ?>">
Expand All @@ -130,7 +136,7 @@ public function renderSideBarContent($post)
?>
<li class="action-item">
<a
href="<?php esc_url_e($cancelUrl) ?>"
href="<?php echo esc_url($cancelUrl) ?>"
class="cancel-shipment" title="<?php esc_attr_e('Annuleert de zending op het Trunkrs platform.', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>"
>
<?php esc_html_e('Zending annuleren', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>
Expand All @@ -139,10 +145,12 @@ class="cancel-shipment" title="<?php esc_attr_e('Annuleert de zending op het Tru

<li class="action-item">
<a
href="<?php esc_url_e($downloadUrl) ?>"
class="cancel-shipment"
target="_blank"
href="<?php echo esc_url($downloadUrl) ?>"
class="button button-primary"
title="<?php esc_attr_e('Download het zending label.', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>"
>
<span class="dashicons dashicons-printer"></span>
<?php esc_html_e('Label', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>
</a>
</li>
Expand All @@ -156,7 +164,7 @@ class="cancel-shipment"
?>
<li class="action-item">
<a
href="<?php esc_url_e($reannounceUrl) ?>"
href="<?php echo esc_url($reannounceUrl) ?>"
class="button button-primary"
title="<?php esc_attr_e('Hiermee wordt geprobeerd de zending opnieuw aan Trunkrs aan te melden.', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>"
>
Expand Down
30 changes: 19 additions & 11 deletions includes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ private static function makeRequest(string $method, string $resource, array $pay

$requestUrl = TRUNKRS_WC_Settings::getResourceUrl($resource);
$httpRequest = new WP_Http();
return $httpRequest->request($requestUrl, $requestArgs);
try {
return $httpRequest->request($requestUrl, $requestArgs);
} catch (Exception $exception) {
return null;
}
}

/**
Expand Down Expand Up @@ -100,16 +104,20 @@ public static function announceShipment($order, string $reference, $deliveryDate
6000
);

if (is_wp_error($response) || $response['response']['code'] > 201) {
if (is_null($response) || is_wp_error($response) || $response['response']['code'] > 201) {
return null;
}

$response = wp_json_decode($response['body']);
$shipment = TRUNKRS_WC_Utils::findInArray($response->success, function ($shipmentResult) use ($reference) {
return $shipmentResult->overriddenReference === $reference;
});
try {
$response = json_decode($response['body']);
$shipment = TRUNKRS_WC_Utils::findInArray($response->success, function ($shipmentResult) use ($reference) {
return $shipmentResult->overriddenReference === $reference;
});

return $shipment;
return $shipment;
} catch (Exception $exception) {
return null;
}
}

/**
Expand All @@ -124,7 +132,7 @@ public static function getShippingRates(array $orderDetails): array
$orderDetails,
);

if (is_wp_error($response) || $response['response']['code'] !== 200) {
if (is_null($response) || is_wp_error($response) || $response['response']['code'] !== 200) {
return [];
}

Expand All @@ -147,11 +155,11 @@ public static function getLabel(string $trunkrsNr)
6000
);

if (is_wp_error($response) || $response['response']['code'] !== 200) {
if (is_null($response) || is_wp_error($response) || $response['response']['code'] !== 200) {
return null;
}

$response = wp_json_decode($response['body']);
$response = json_decode($response['body']);
return $response->url;
}

Expand All @@ -169,7 +177,7 @@ public static function cancelShipment(string $trunkrNr): bool
6000
);

return !is_wp_error($response)
return !is_null($response) && !is_wp_error($response)
&& $response['response']['code'] < 300;
}
}
Expand Down
2 changes: 1 addition & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class TRUNKRS_WC_Settings
{
const BASE_URL = 'https://shipping.trunkrs.app';
const TRACK_TRACE_BASE_URL = 'https://parcel.trunkrs.app/';
const TRACK_TRACE_BASE_URL = 'https://parcel.trunkrs.nl/';
const API_VERSION = 'v1';

const OPTION_KEY = 'wc_tr_plugin-settings';
Expand Down
4 changes: 2 additions & 2 deletions includes/wc-internal/notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public function renderNotConfiguredNotice()
?>
<div class="error trwc-error indigo">
<span class="trwc-header">
<img alt="Trunkrs Logo" src="<?php esc_url_e($logoUrl) ?>"/>
<img alt="Trunkrs Logo" src="<?php echo esc_url($logoUrl) ?>"/>
<h2>Trunkrs</h2>
</span>
<span class="trwc-content">
<p>
<?php esc_html_e('Dank je wel voor het installeren van de Trunkrs voor WooCommerce plugin, de plugin is nog niet klaar voor gebruik.', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>
<br/>
<?php esc_html_e('Ga naar de', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>
<a href="<?php esc_url_e(admin_url('admin.php?page=tr-wc-settings')) ?>">
<a href="<?php echo esc_url(admin_url('admin.php?page=tr-wc-settings')) ?>">
<?php esc_html_e('instellingen pagina', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>
</a>
<?php esc_html_e('om de installatie af te ronden.', TRUNKRS_WC_Bootstrapper::DOMAIN) ?>
Expand Down
4 changes: 2 additions & 2 deletions includes/wc-internal/shipping-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static function renderLabel($label, $method)
</span>
',
esc_url($logoUrl),
esc_html(wc_price($method->cost)),
esc_html($description),
wc_price($method->cost),
$description,
);
}

Expand Down
2 changes: 1 addition & 1 deletion includes/wc-internal/track-trace.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function renderTrackTraceLink($order, $isAdmin)
$deliveryDate = $trunkrsOrder->getFormattedDate();

?>
<p>
<p style="margin-bottom: 8px;">
<?php
esc_html_e(sprintf(
__('Je hebt gekozen voor Trunkrs, Trunkrs bezorgd jouw bestelling op %s tussen 17 en 22 uur.', TRUNKRS_WC_Bootstrapper::DOMAIN),
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: fean
Tags: delivery, packages, woocommerce, trunkrs, sameday, delivery
Requires at least: 3.6 & WooCommerce 3.0+
Tested up to: 5.8
Stable tag: 1.0.0
Stable tag: 1.0.1
Requires PHP: 7.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down
8 changes: 4 additions & 4 deletions trunkrs-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Add excellent consumer focused shipping to your WooCommerce store.
* Author: Trunkrs
* Author URI: https://trunkrs.nl
* Version: 1.0.0
* Version: 1.0.1
* Requires at least: 3.6 & WooCommerce 3.0+
* Requires PHP: 7.1
* License: GPLv3
Expand All @@ -23,7 +23,7 @@ class TRUNKRS_WC_Bootstrapper
/**
* @var string The semver version of the plugin.
*/
public $version = '1.0.0';
public $version = '1.0.1';

/**
* @var TRUNKRS_WC_Bootstrapper The shared plugin instance.
Expand Down Expand Up @@ -75,7 +75,7 @@ public function notifyWooCommerce()
?>
<div class="error trwc-error">
<div class="trwc-header">
<img alt="Trunkrs Logo" src="<?php esc_url_e(TRUNKRS_WC_Utils::createAssetUrl('icons/trunkrs-small-indigo.svg')) ?>" />
<img alt="Trunkrs Logo" src="<?php echo esc_url(TRUNKRS_WC_Utils::createAssetUrl('icons/trunkrs-small-indigo.svg')) ?>" />
<h2>Trunkrs</h2>
</div>
<span class="trwc-content">
Expand All @@ -94,7 +94,7 @@ public function notifyPHPVersion()
?>
<div class="error trwc-error">
<span class="trwc-header">
<img alt="Trunkrs Logo" src="<?php esc_url_e(TRUNKRS_WC_Utils::createAssetUrl('icons/trunkrs-small-indigo.svg')) ?>"/>
<img alt="Trunkrs Logo" src="<?php echo esc_url(TRUNKRS_WC_Utils::createAssetUrl('icons/trunkrs-small-indigo.svg')) ?>"/>
<h2>Trunkrs</h2>
</span>
<span class="trwc-content">
Expand Down

0 comments on commit 52f6c5c

Please sign in to comment.