Use Parcel2Go public API scope by default
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m1s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m1s
This commit is contained in:
@@ -46,8 +46,13 @@ class DashboardController extends Controller
|
||||
$shippingConfig = $settings->for('parcel2go');
|
||||
if ($isAdmin && filled($shippingConfig['client_id'] ?? null) && filled($shippingConfig['client_secret'] ?? null) && filled($shippingConfig['auth_url'] ?? null)) {
|
||||
try {
|
||||
$shipments = array_slice($parcel2Go->fetch('me/orders/detail')['Orders'] ?? [], 0, 4);
|
||||
$shippingStatus = 'Live account';
|
||||
if ($parcel2Go->hasScope('my-profile')) {
|
||||
$shipments = array_slice($parcel2Go->fetch('me/orders/detail')['Orders'] ?? [], 0, 4);
|
||||
$shippingStatus = 'Live account';
|
||||
} else {
|
||||
$parcel2Go->verifyCredentials();
|
||||
$shippingStatus = 'Quotes available';
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
$shippingStatus = 'Temporarily unavailable';
|
||||
|
||||
@@ -35,6 +35,7 @@ class EtsySettingsController extends Controller
|
||||
'configured' => filled($parcel2go['client_id'] ?? null) && filled($parcel2go['client_secret'] ?? null) && filled($parcel2go['auth_url'] ?? null),
|
||||
'auth_url' => $parcel2go['auth_url'] ?? '',
|
||||
'base_url' => $parcel2go['base_url'] ?? '',
|
||||
'scope' => $parcel2go['scope'] ?? 'public-api',
|
||||
],
|
||||
'bambuddy' => [
|
||||
'stored' => in_array('bambuddy', $storedIntegrations, true),
|
||||
|
||||
@@ -20,6 +20,7 @@ class IntegrationSettingsController extends Controller
|
||||
'client_secret' => ['nullable', 'string', 'max:255'],
|
||||
'auth_url' => ['nullable', 'url:https', 'max:2048'],
|
||||
'base_url' => ['nullable', 'url:https', 'max:2048'],
|
||||
'scope' => ['nullable', 'string', 'in:public-api,public-api my-profile,public-api payment,public-api payment my-profile'],
|
||||
],
|
||||
default => [
|
||||
'url' => ['nullable', 'url:https', 'max:2048'],
|
||||
|
||||
@@ -15,11 +15,27 @@ class ShippingController extends Controller
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
try {
|
||||
$account = $parcel2Go->fetch('me/detail');
|
||||
$balance = $parcel2Go->fetch('me/prepay/balance');
|
||||
$orders = $parcel2Go->fetch('me/orders/detail');
|
||||
$account = [];
|
||||
$balance = [];
|
||||
$orders = [];
|
||||
$profileAvailable = $parcel2Go->hasScope('my-profile');
|
||||
$profileNotice = null;
|
||||
|
||||
return view('shipping', compact('account', 'balance', 'orders') + [
|
||||
if ($profileAvailable) {
|
||||
try {
|
||||
$account = $parcel2Go->fetch('me/detail');
|
||||
$balance = $parcel2Go->fetch('me/prepay/balance');
|
||||
$orders = $parcel2Go->fetch('me/orders/detail');
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
$profileNotice = 'Parcel2Go connected, but account history is unavailable. Check that this client has my-profile access.';
|
||||
}
|
||||
} else {
|
||||
$parcel2Go->verifyCredentials();
|
||||
$profileNotice = 'Parcel2Go connected for quotes and collections. Add my-profile access in Parcel2Go to show account history and labels.';
|
||||
}
|
||||
|
||||
return view('shipping', compact('account', 'balance', 'orders', 'profileAvailable', 'profileNotice') + [
|
||||
'quotes' => $request->session()->get('shipping_quotes', []),
|
||||
'collectionDates' => $request->session()->get('shipping_collection_dates', []),
|
||||
'selectedService' => $request->session()->get('shipping_selected_service'),
|
||||
@@ -31,6 +47,8 @@ class ShippingController extends Controller
|
||||
|
||||
return view('shipping', [
|
||||
'account' => [], 'balance' => [], 'orders' => [],
|
||||
'profileAvailable' => false,
|
||||
'profileNotice' => null,
|
||||
'quotes' => $request->session()->get('shipping_quotes', []),
|
||||
'collectionDates' => $request->session()->get('shipping_collection_dates', []),
|
||||
'selectedService' => $request->session()->get('shipping_selected_service'),
|
||||
|
||||
@@ -10,6 +10,16 @@ class Parcel2Go
|
||||
{
|
||||
public function __construct(private IntegrationSettings $settings) {}
|
||||
|
||||
public function hasScope(string $scope): bool
|
||||
{
|
||||
return in_array($scope, explode(' ', (string) ($this->settings->for('parcel2go')['scope'] ?? 'public-api')), true);
|
||||
}
|
||||
|
||||
public function verifyCredentials(): void
|
||||
{
|
||||
$this->accessToken();
|
||||
}
|
||||
|
||||
public function fetch(string $path): array
|
||||
{
|
||||
return Http::withToken($this->accessToken())->acceptJson()->connectTimeout(3)->timeout(15)
|
||||
@@ -104,7 +114,7 @@ class Parcel2Go
|
||||
|
||||
$token = Http::asForm()->timeout(10)->post($settings['auth_url'], [
|
||||
'grant_type' => 'client_credentials',
|
||||
'scope' => 'public-api my-profile',
|
||||
'scope' => $settings['scope'] ?? 'public-api',
|
||||
'client_id' => $settings['client_id'],
|
||||
'client_secret' => $settings['client_secret'],
|
||||
])->throw()->json('access_token');
|
||||
|
||||
Reference in New Issue
Block a user