gnikyt / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
1.24k stars 374 forks source link

App Reinstall Issue #529

Closed sergeyantonuk closed 4 years ago

sergeyantonuk commented 4 years ago

For bug reporting only! If you're posting a feature request or discussion, please ignore.

Expected Behavior

  1. Install App

  2. Remove App

  3. Install App Again with No Issues:

    • go to partners.shopify.com->Apps->Click on AppName->Test your app->Select Store->Install App
    • After click on Install App will a window appears with a list of different scopes and different install information
    • After this -> press Install App btn -After this App will be installed and index app page will appear. -After this in the merchant account in the App chapter we can see our installed App

      Current Behavior

  4. Install App

  5. Remove App(after removing app, the user still exists in my DB, users table)

  6. Try to install App again:

    • go to partners.shopify.com->Apps->Click on AppName->Test your app->Select Store->Install App this redirect me to the homepage in separate window without shopify menu. But actually App is not installed, merchant can't see this App in the App chapter

Failure Information

When after remove App, I remove current users from DB (users table) manually, then next install will successful.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

1.Install App 2.Remove App 3.Try to install App again

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Failure Logs

Please include any relevant log snippets or files here.

gnikyt commented 4 years ago

@sergeyantonuk The reason is only works if you remove the user from the table is probably because you do not have app uninstalled webhook setup?

See the wiki for more information.

sergeyantonuk commented 4 years ago

yes, when I enabled job to handle soft deleting a shop it started to work well. Thank you a lot!

gnikyt commented 4 years ago

Awesome!

senter-logistics commented 4 years ago

this is not the solution, i realized that the webhook wasn't firing anyways. So i did the following.

In shopify-app.php

    'webhooks' => [
        [
            'topic' => env('SHOPIFY_WEBHOOK_1_TOPIC', 'app/uninstalled'),
            'address' => env('SHOPIFY_WEBHOOK_1_ADDRESS', 'https://connection.e-hop.mx/api/webhook/app-uninstalled')
        ],
        ],

in /vendor/osiset/laravel-shopify/src/ShopifyApp/resources/routes.php i commented

  /*  
Route::post(
        '/webhook/{type}',
        'Osiset\ShopifyApp\Http\Controllers\WebhookController@handle'
    )
    //->middleware('auth.webhook')
    ->name('webhook');
*/

In my laravel api.php file i pasted this

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
    Route::post(
    '/webhook/app-uninstalled',
    'HomeController@handle'
);
//->middleware('auth.webhook'); i removed this middleware

And finally in my HomeController, i overrided the Osiset\ShopifyApp\Traits\WebhookController .

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Auth;
use App\Jobs\AppUninstalledJob;
use Illuminate\Http\Response as ResponseResponse;
use Illuminate\Support\Facades\Response;
use Osiset\ShopifyApp\Objects\Values\ShopDomain;

class HomeController extends Controller
{
    public function handle(Request $request)
    {
                // Get the job class and dispatch
        $jobClass = 'AppUninstalledJob';
        $jobData = json_decode($request->getContent());

        AppUninstalledJob::dispatch(
            new ShopDomain($request->header('x-shopify-shop-domain')),
            $jobData
        );

        return Response::make('', 201);
    }

}

And now it's using the webhook correctly. I know this is not the best way, but so far i just need this webhook. Is there other way to do this?