Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

ITP #663

Merged
merged 9 commits into from
Jan 21, 2021
Merged

ITP #663

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
8 changes: 3 additions & 5 deletions src/ShopifyApp/Actions/AfterAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
use Osiset\ShopifyApp\Contracts\Objects\Values\ShopId as ShopIdValue;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use function Osiset\ShopifyApp\getShopifyConfig;

/**
* Run after authentication jobs.
*/
class AfterAuthorize
{
use ConfigAccessible;

/**
* Querier for shops.
*
Expand Down Expand Up @@ -59,7 +57,7 @@ public function __invoke(ShopIdValue $shopId): bool
} else {
// Run later
$job::dispatch($shop)
->onQueue($this->getConfig('job_queues')['after_authenticate']);
->onQueue(getShopifyConfig('job_queues')['after_authenticate']);
}

return true;
Expand All @@ -69,7 +67,7 @@ public function __invoke(ShopIdValue $shopId): bool
$shop = $this->shopQuery->getById($shopId);

// Grab the jobs config
$jobsConfig = $this->getConfig('after_authenticate_job');
$jobsConfig = getShopifyConfig('after_authenticate_job');

if (isset($jobsConfig[0])) {
// We have multi-jobs
Expand Down
8 changes: 3 additions & 5 deletions src/ShopifyApp/Actions/AuthorizeShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

use Osiset\ShopifyApp\Contracts\Commands\Shop as IShopCommand;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use function Osiset\ShopifyApp\getShopifyConfig;
use Osiset\ShopifyApp\Objects\Enums\AuthMode;
use Osiset\ShopifyApp\Objects\Values\NullAccessToken;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Services\ShopSession;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use stdClass;

/**
* Authenticates a shop via HTTP request.
*/
class AuthorizeShop
{
use ConfigAccessible;

/**
* Querier for shops.
*
Expand Down Expand Up @@ -86,10 +84,10 @@ public function __invoke(ShopDomain $shopDomain, ?string $code): stdClass

// Access/grant mode
$grantMode = $shop->hasOfflineAccess() ?
AuthMode::fromNative($this->getConfig('api_grant_mode', $shop)) :
AuthMode::fromNative(getShopifyConfig('api_grant_mode', $shop)) :
AuthMode::OFFLINE();

$return['url'] = $apiHelper->buildAuthUrl($grantMode, $this->getConfig('api_scopes', $shop));
$return['url'] = $apiHelper->buildAuthUrl($grantMode, getShopifyConfig('api_scopes', $shop));

// If there's no code
if (empty($code)) {
Expand Down
3 changes: 0 additions & 3 deletions src/ShopifyApp/Actions/CreateScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
use Osiset\BasicShopifyAPI\ResponseAccess;
use Osiset\ShopifyApp\Contracts\Objects\Values\ShopId as ShopIdValue;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

/**
* Create scripttags for this app on the shop.
*/
class CreateScripts
{
use ConfigAccessible;

/**
* Querier for shops.
*
Expand Down
3 changes: 0 additions & 3 deletions src/ShopifyApp/Actions/CreateWebhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
use Osiset\BasicShopifyAPI\ResponseAccess;
use Osiset\ShopifyApp\Contracts\Objects\Values\ShopId as ShopIdValue;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

/**
* Create webhooks for this app on the shop.
*/
class CreateWebhooks
{
use ConfigAccessible;

/**
* Querier for shops.
*
Expand Down
8 changes: 3 additions & 5 deletions src/ShopifyApp/Actions/DispatchScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

use Osiset\ShopifyApp\Contracts\Objects\Values\ShopId as ShopIdValue;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use function Osiset\ShopifyApp\getShopifyConfig;

/**
* Attempt to install script tags on a shop.
*/
class DispatchScripts
{
use ConfigAccessible;

/**
* Querier for shops.
*
Expand Down Expand Up @@ -55,7 +53,7 @@ public function __invoke(ShopIdValue $shopId, bool $inline = false): bool
$shop = $this->shopQuery->getById($shopId);

// Get the scripttags
$scripttags = $this->getConfig('scripttags');
$scripttags = getShopifyConfig('scripttags');
if (count($scripttags) === 0) {
// Nothing to do
return false;
Expand All @@ -71,7 +69,7 @@ public function __invoke(ShopIdValue $shopId, bool $inline = false): bool
($this->jobClass)::dispatch(
$shop->getId(),
$scripttags
)->onQueue($this->getConfig('job_queues')['scripttags']);
)->onQueue(getShopifyConfig('job_queues')['scripttags']);
}

return true;
Expand Down
8 changes: 3 additions & 5 deletions src/ShopifyApp/Actions/DispatchWebhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

use Osiset\ShopifyApp\Contracts\Objects\Values\ShopId as ShopIdValue;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use function Osiset\ShopifyApp\getShopifyConfig;

/**
* Attempt to install webhooks on a shop.
*/
class DispatchWebhooks
{
use ConfigAccessible;

/**
* Querier for shops.
*
Expand Down Expand Up @@ -55,7 +53,7 @@ public function __invoke(ShopIdValue $shopId, bool $inline = false): bool
$shop = $this->shopQuery->getById($shopId);

// Get the webhooks
$webhooks = $this->getConfig('webhooks');
$webhooks = getShopifyConfig('webhooks');
if (count($webhooks) === 0) {
// Nothing to do
return false;
Expand All @@ -71,7 +69,7 @@ public function __invoke(ShopIdValue $shopId, bool $inline = false): bool
($this->jobClass)::dispatch(
$shop->getId(),
$webhooks
)->onQueue($this->getConfig('job_queues')['webhooks']);
)->onQueue(getShopifyConfig('job_queues')['webhooks']);
}

return true;
Expand Down
2 changes: 0 additions & 2 deletions src/ShopifyApp/Exceptions/BaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace Osiset\ShopifyApp\Exceptions;

use Exception;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

/**
* Base exception for all exceptions of the package.
* Mainly to handle render in production.
*/
abstract class BaseException extends Exception
{
use ConfigAccessible;
}
14 changes: 14 additions & 0 deletions src/ShopifyApp/Http/Controllers/ItpController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Osiset\ShopifyApp\Http\Controllers;

use Illuminate\Routing\Controller;
use Osiset\ShopifyApp\Traits\ItpController as ItpControllerTrait;

/**
* Responsible for handling ITP issues.
*/
class ItpController extends Controller
{
use ItpControllerTrait;
}
6 changes: 2 additions & 4 deletions src/ShopifyApp/Http/Middleware/AuthProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use function Osiset\ShopifyApp\createHmac;
use function Osiset\ShopifyApp\getShopifyConfig;
use Osiset\ShopifyApp\Objects\Values\NullableShopDomain;
use function Osiset\ShopifyApp\parseQueryString;
use Osiset\ShopifyApp\Services\ShopSession;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

/**
* Responsible for ensuring a proper app proxy request.
*/
class AuthProxy
{
use ConfigAccessible;

/**
* Shop session helper.
*
Expand Down Expand Up @@ -63,7 +61,7 @@ public function handle(Request $request, Closure $next)
'data' => $query,
'buildQuery' => true,
],
$this->getConfig('api_secret', $shop)
getShopifyConfig('api_secret', $shop)
);
if ($signature !== $signatureLocal || $shop->isNull()) {
// Issue with HMAC or missing shop header
Expand Down
8 changes: 4 additions & 4 deletions src/ShopifyApp/Http/Middleware/AuthShopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use Osiset\ShopifyApp\Contracts\ApiHelper as IApiHelper;
use Osiset\ShopifyApp\Contracts\Objects\Values\ShopDomain as ShopDomainValue;
use Osiset\ShopifyApp\Exceptions\MissingShopDomainException;
use Osiset\ShopifyApp\Exceptions\SignatureVerificationException;
use function Osiset\ShopifyApp\getShopifyConfig;
use Osiset\ShopifyApp\Objects\Enums\DataSource;
use Osiset\ShopifyApp\Objects\Values\NullShopDomain;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Services\ShopSession;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

/**
* Response for ensuring an authenticated request.
*/
class AuthShopify
{
use ConfigAccessible;

/**
* The API helper.
*
Expand Down Expand Up @@ -349,7 +349,7 @@ private function handleBadVerification(Request $request, ShopDomainValue $domain

// Mis-match of shops
return Redirect::route(
$this->getConfig('route_names.authenticate.oauth'),
getShopifyConfig('route_names.authenticate.oauth'),
['shop' => $domain->toNative()]
);
}
Expand Down
8 changes: 3 additions & 5 deletions src/ShopifyApp/Http/Middleware/AuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use function Osiset\ShopifyApp\base64url_decode;
use function Osiset\ShopifyApp\base64url_encode;
use Osiset\ShopifyApp\Exceptions\HttpException;
use function Osiset\ShopifyApp\getShopifyConfig;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Services\ShopSession;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

class AuthToken
{
use ConfigAccessible;

/**
* The shop session helper.
*
Expand Down Expand Up @@ -90,7 +88,7 @@ public function handle(Request $request, Closure $next)
throw new HttpException('Invalid token', 400);
}

if ($body->aud !== $this->getConfig('api_key')) {
if ($body->aud !== getShopifyConfig('api_key')) {
throw new HttpException('Invalid token', 400);
}

Expand Down Expand Up @@ -125,7 +123,7 @@ private function checkSignature($token)
$shop = isset($url['host']) ? $url['host'] : null;
}

$secret = $this->getConfig('api_secret', $shop);
$secret = getShopifyConfig('api_secret', $shop);
$hmac = hash_hmac('sha256', $check, $secret, true);
$encoded = base64url_encode($hmac);

Expand Down
6 changes: 2 additions & 4 deletions src/ShopifyApp/Http/Middleware/AuthWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use function Osiset\ShopifyApp\createHmac;
use Osiset\ShopifyApp\Traits\ConfigAccessible;
use function Osiset\ShopifyApp\getShopifyConfig;

/**
* Response for ensuring a proper webhook request.
*/
class AuthWebhook
{
use ConfigAccessible;

/**
* Handle an incoming request to ensure webhook is valid.
*
Expand All @@ -34,7 +32,7 @@ public function handle(Request $request, Closure $next)
'raw' => true,
'encode' => true,
],
$this->getConfig('api_secret', $shop)
getShopifyConfig('api_secret', $shop)
);

if (! hash_equals($hmac, $hmacLocal) || empty($shop)) {
Expand Down
8 changes: 3 additions & 5 deletions src/ShopifyApp/Http/Middleware/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use function Osiset\ShopifyApp\getShopifyConfig;
use Osiset\ShopifyApp\Services\ShopSession;
use Osiset\ShopifyApp\Traits\ConfigAccessible;

/**
* Responsible for ensuring the shop is being billed.
*/
class Billable
{
use ConfigAccessible;

/**
* The shop session helper.
*
Expand Down Expand Up @@ -44,11 +42,11 @@ public function __construct(ShopSession $shopSession)
*/
public function handle(Request $request, Closure $next)
{
if ($this->getConfig('billing_enabled') === true) {
if (getShopifyConfig('billing_enabled') === true) {
$shop = $this->shopSession->getShop();
if (! $shop->isFreemium() && ! $shop->isGrandfathered() && ! $shop->plan) {
// They're not grandfathered in, and there is no charge or charge was declined... redirect to billing
return Redirect::route($this->getConfig('route_names.billing'), $request->input());
return Redirect::route(getShopifyConfig('route_names.billing'), $request->input());
}
}

Expand Down
Loading