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

Added Event Listener system #212

Merged
merged 43 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8119832
fixed issue when using custom table for authentication instead of use…
nahid Aug 25, 2022
f73467d
Merge branch 'osiset:master' into master
nahid Aug 28, 2022
e00b49e
fixed charges model saving when using custom shop table
nahid Sep 7, 2022
7ab1e9a
refactor code for reusing shops table name and its foreign id
nahid Sep 8, 2022
94bf062
Merge branch 'osiset:master' into master
nahid Sep 8, 2022
54907b6
refactor getShopsTable() and added new method for getting shops table…
nahid Sep 8, 2022
2aa9a2e
Merge branch 'master' of github.com:nahid/laravel-shopify
nahid Sep 8, 2022
c099191
Remove unwanted new line feom Charge model contractor
nahid Sep 9, 2022
41c8734
auto fixes code style from php-cs-fixer
nahid Sep 9, 2022
624e0ca
Merge branch 'master' into master
nahid Sep 9, 2022
40db940
Merge branch 'osiset:master' into master
nahid Sep 9, 2022
5ddf28b
added name, email and password in create shops table migration if its…
nahid Sep 9, 2022
6ffa402
Merge branch 'master' of github.com:nahid/laravel-shopify
nahid Sep 9, 2022
b05089b
Merge branch 'osiset:master' into master
nahid Sep 9, 2022
79ff4bb
fixed get data from request issue in StoreUsageCharge
nahid Sep 27, 2022
4e510ad
Merge branch 'master' of github.com:nahid/laravel-shopify
nahid Sep 27, 2022
47d23d3
Merge branch 'osiset:master' into master
nahid Nov 28, 2022
663fe85
feat(event, listener): added various events, update Util
nahid Nov 28, 2022
fb007eb
fixed by php-cs-fixer
nahid Nov 28, 2022
94cc3f4
fixed: support for php 7.2
nahid Nov 28, 2022
7b8048a
fixed(ServiceProvider): added laravel version compatibility in servic…
nahid Nov 29, 2022
d72ea66
fixed(Request Validation): update StoreUsageChare request
nahid Nov 29, 2022
6b61682
Update README.md
Kyon147 Nov 30, 2022
de8a415
fix: cs-fix changes
nahid Dec 13, 2022
1f9a9d0
fixed iframe ancestors issue
nahid Dec 13, 2022
c38c3ad
fixed iframe ancestors issue
nahid Dec 13, 2022
13a2446
Merge branch 'gnikyt:master' into master
nahid Dec 13, 2022
ead87de
update verify shop middleware
nahid Dec 15, 2022
118cec9
Merge branch 'master' of github.com:nahid/laravel-shopify
nahid Dec 15, 2022
3686198
feat(shopdomain): validate correct shop domain when authenticate
nahid Feb 16, 2023
b21ae45
change after authenticate job fire logic
nahid Feb 17, 2023
ceffdd3
Update composer.json
nahid Mar 27, 2023
f5090af
update laravel shopify package for laravel 10
nahid Aug 27, 2023
ffad585
resolve conflict with master
nahid Sep 11, 2023
f736064
php-cs-fix and update readme
nahid Sep 11, 2023
6410733
code fix with php-cs-fix
nahid Sep 11, 2023
64d097c
added tests
nahid Sep 13, 2023
8a665ea
rollback gitigonre
nahid Sep 13, 2023
3b2507b
fixed by php-cs-fixer
nahid Sep 13, 2023
c71e073
update phpunit.xml.dist for excluding Events
nahid Sep 13, 2023
37ef397
added tests for coverage
nahid Sep 13, 2023
3d90f3e
Refactor code with PSR-12 standard
nahid Oct 1, 2023
7e1e5c8
Fix linting issue
nahid Oct 1, 2023
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: 8 additions & 0 deletions .idea/laravel-shopify.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<directory>src/Exceptions/</directory>
<directory>src/Objects/Enums/</directory>
<directory>src/resources/</directory>
<file>src/Messaging/Events/AppLoggedIn.php</file>
<directory>src/Messaging/Events/</directory>
<file>src/ShopifyAppProvider.php</file>
</exclude>
<report>
Expand Down
3 changes: 3 additions & 0 deletions src/Actions/ActivatePlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Osiset\ShopifyApp\Contracts\Objects\Values\PlanId;
use Osiset\ShopifyApp\Contracts\Queries\Plan as IPlanQuery;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Messaging\Events\PlanActivatedEvent;
use Osiset\ShopifyApp\Objects\Enums\ChargeStatus;
use Osiset\ShopifyApp\Objects\Enums\ChargeType;
use Osiset\ShopifyApp\Objects\Enums\PlanType;
Expand Down Expand Up @@ -142,6 +143,8 @@ public function __invoke(ShopId $shopId, PlanId $planId, ChargeReference $charge
$charge = $this->chargeCommand->make($transfer);
$this->shopCommand->setToPlan($shopId, $planId);

event(new PlanActivatedEvent($shop, $plan, $charge));

return $charge;
}
}
3 changes: 3 additions & 0 deletions src/Actions/AuthenticateShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Osiset\ShopifyApp\Contracts\ApiHelper as IApiHelper;
use Osiset\ShopifyApp\Messaging\Events\AppInstalledEvent;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Util;

Expand Down Expand Up @@ -109,6 +110,8 @@ public function __invoke(Request $request): array
call_user_func($this->dispatchWebhooksAction, $result['shop_id'], false);
call_user_func($this->afterAuthorizeAction, $result['shop_id']);

event(new AppInstalledEvent($result['shop_id']));

return [$result, true];
}
}
10 changes: 9 additions & 1 deletion src/Http/Middleware/IframeProtection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Cache;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Util;

/**
* Responsibility for protection against clickjaking
Expand Down Expand Up @@ -44,6 +45,7 @@ public function __construct(
public function handle(Request $request, Closure $next)
{
$response = $next($request);
$ancestors = Util::getShopifyConfig('iframe_ancestors');

$shop = Cache::remember(
'frame-ancestors_'.$request->get('shop'),
Expand All @@ -57,9 +59,15 @@ function () use ($request) {
? $shop->name
: '*.myshopify.com';

$iframeAncestors = "frame-ancestors https://$domain https://admin.shopify.com";

if (!blank($ancestors)) {
$iframeAncestors .= ' '.$ancestors;
}

$response->headers->set(
'Content-Security-Policy',
"frame-ancestors https://$domain https://admin.shopify.com"
$iframeAncestors
);

return $response;
Expand Down
39 changes: 37 additions & 2 deletions src/Http/Middleware/VerifyShopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(
* @param Request $request The request object.
* @param Closure $next The next action.
*
* @throws SignatureVerificationException If HMAC verification fails.
* @throws SignatureVerificationException|HttpException If HMAC verification fails.
*
* @return mixed
*/
Expand All @@ -102,9 +102,12 @@ public function handle(Request $request, Closure $next)
}

if (!Util::useNativeAppBridge()) {
$storeResult = !$this->isApiRequest($request) && $this->checkPreviousInstallation($request);
$shop = $this->getShopIfAlreadyInstalled($request);
$storeResult = !$this->isApiRequest($request) && $shop;

if ($storeResult) {
$this->loginFromShop($shop);

return $next($request);
}
}
Expand Down Expand Up @@ -512,4 +515,36 @@ protected function checkPreviousInstallation(Request $request): bool

return $shop && $shop->password && ! $shop->trashed();
}

/**
* Get shop model if there is a store record in the database.
*
* @param Request $request The request object.
*
* @return ?ShopModel
*/
protected function getShopIfAlreadyInstalled(Request $request): ?ShopModel
{
$shop = $this->shopQuery->getByDomain(ShopDomain::fromRequest($request), [], true);

return $shop && $shop->password && ! $shop->trashed() ? $shop : null;
}

/**
* Login and validate store
*
* @param ShopModel $shop
*
* @return void
*/
protected function loginFromShop(ShopModel $shop): void
{
// Override auth guard
if (($guard = Util::getShopifyConfig('shop_auth_guard'))) {
$this->auth->setDefaultDriver($guard);
}

// All is well, login the shop
$this->auth->login($shop);
}
}
35 changes: 35 additions & 0 deletions src/Messaging/Events/AppInstalledEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Osiset\ShopifyApp\Messaging\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Osiset\ShopifyApp\Objects\Values\ShopId;

/**
* Event fired when this
*/
class AppInstalledEvent
{
use Dispatchable;
use SerializesModels;

/**
* Shop's instance.
*
* @var ShopId
*/
public $shopId;

/**
* Create a new event instance.
*
* @param ShopId $shop_id
*
* @return void
*/
public function __construct(ShopId $shop_id)
{
$this->shopId = $shop_id;
}
}
35 changes: 35 additions & 0 deletions src/Messaging/Events/AppUninstalledEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Osiset\ShopifyApp\Messaging\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel;

/**
* Event fired when this
*/
class AppUninstalledEvent
{
use Dispatchable;
use SerializesModels;

/**
* Shop's instance.
*
* @var IShopModel
*/
public $shop;

/**
* Create a new event instance.
*
* @param IShopModel $shop
*
* @return void
*/
public function __construct(IShopModel $shop)
{
$this->shop = $shop;
}
}
53 changes: 53 additions & 0 deletions src/Messaging/Events/PlanActivatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Osiset\ShopifyApp\Messaging\Events;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Osiset\ShopifyApp\Contracts\ShopModel as IShopModel;
use Osiset\ShopifyApp\Objects\Values\ChargeId;

/**
* Event fired when this
*/
class PlanActivatedEvent
{
use Dispatchable;
use SerializesModels;

/**
* Shop's instance.
*
* @var IShopModel
*/
public $shop;

/**
* Plan's instance.
*
* @var Model
*/
public $plan;

/**
* Charge ID
*
* @var ChargeId
*/
public $chargeId;

/**
* Create a new event instance.
*
* @param IShopModel $shop
*
* @return void
*/
public function __construct(IShopModel $shop, Model $plan, ChargeId $chargeId)
{
$this->shop = $shop;
$this->plan = $plan;
$this->chargeId = $chargeId;
}
}
35 changes: 35 additions & 0 deletions src/Messaging/Events/ShopAuthenticatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Osiset\ShopifyApp\Messaging\Events;

use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Osiset\ShopifyApp\Objects\Values\ShopId;

/**
* Event fired when this
*/
class ShopAuthenticatedEvent
{
use Dispatchable;
use SerializesModels;

/**
* Shop's instance.
*
* @var ShopId
*/
public $shopId;

/**
* Create a new event instance.
*
* @param ShopId $shop_id
*
* @return void
*/
public function __construct(ShopId $shopId)
{
$this->shopId = $shopId;
}
}
Loading
Loading