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

Commit

Permalink
Move cancel current plan action to handle function for uninstall job,…
Browse files Browse the repository at this point in the history
… solves #427
  • Loading branch information
gnikyt committed Apr 2, 2020
1 parent a71853d commit c518ef8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
35 changes: 14 additions & 21 deletions src/ShopifyApp/Messaging/Jobs/AppUninstalledJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Osiset\ShopifyApp\Actions\CancelCurrentPlan;
use Osiset\ShopifyApp\Contracts\Objects\Values\ShopDomain;
use Osiset\ShopifyApp\Contracts\Queries\Shop as IShopQuery;
use Osiset\ShopifyApp\Contracts\Commands\Shop as IShopCommand;
Expand Down Expand Up @@ -36,48 +37,40 @@ class AppUninstalledJob implements ShouldQueue
*/
protected $data;

/**
* Action for cancelling current plan.
*
* @var callable
*/
protected $cancelCurrentPlanAction;

/**
* Create a new job instance.
*
* @param ShopDomain $domain The shop domain.
* @param stdClass $data The webhook data (JSON decoded).
* @param callable $cancelCurrentPlanAction Action for cancelling current plan.
* @param ShopDomain $domain The shop domain.
* @param stdClass $data The webhook data (JSON decoded).
*
* @return self
*/
public function __construct(
ShopDomain $domain,
stdClass $data,
callable $cancelCurrentPlanAction
) {
public function __construct(ShopDomain $domain, stdClass $data)
{
$this->domain = $domain;
$this->data = $data;
$this->cancelCurrentPlanAction = $cancelCurrentPlanAction;
}

/**
* Execute the job.
*
* @param IShopCommand $shopCommand The commands for shops.
* @param IShopQuery $shopQuery The querier for shops.
* @param IShopCommand $shopCommand The commands for shops.
* @param IShopQuery $shopQuery The querier for shops.
* @param CancelCurrentPlan $cancelCurrentPlanAction The action for cancelling the current plan.
*
* @return bool
*/
public function handle(IShopCommand $shopCommand, IShopQuery $shopQuery): bool
{
public function handle(
IShopCommand $shopCommand,
IShopQuery $shopQuery,
CancelCurrentPlan $cancelCurrentPlanAction
): bool {
// Get the shop
$shop = $shopQuery->getByDomain($this->domain);
$shopId = $shop->getId();

// Cancel the current plan
call_user_func($this->cancelCurrentPlanAction, $shopId);
$cancelCurrentPlanAction($shopId);

// Purge shop of token, plan, etc.
$shopCommand->clean($shopId);
Expand Down
2 changes: 1 addition & 1 deletion src/ShopifyApp/resources/jobs/AppUninstalledJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace App\Jobs;

class AppUninstalledJob extends \Osiset\ShopifyApp\Jobs\AppUninstalledJob
class AppUninstalledJob extends \Osiset\ShopifyApp\Messaging\Jobs\AppUninstalledJob
{
}
3 changes: 1 addition & 2 deletions tests/Messaging/Jobs/AppUninstalledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function testJobSoftDeletesShopAndCharges()
// Run the job
AppUninstalledJob::dispatchNow(
$shop->getDomain(),
json_decode(file_get_contents(__DIR__.'/../../fixtures/app_uninstalled.json')),
$this->app->make(CancelCurrentPlan::class)
json_decode(file_get_contents(__DIR__.'/../../fixtures/app_uninstalled.json'))
);

// Refresh both models to see the changes
Expand Down

0 comments on commit c518ef8

Please sign in to comment.