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

refactor: update the code as the laravel best practices #524

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
53 changes: 1 addition & 52 deletions web/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

namespace App\Providers;

use App\Lib\DbSessionStorage;
use App\Lib\Handlers\AppUninstalled;
use App\Lib\Handlers\Privacy\CustomersDataRequest;
use App\Lib\Handlers\Privacy\CustomersRedact;
use App\Lib\Handlers\Privacy\ShopRedact;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;
use Shopify\Context;
use Shopify\ApiVersion;
use Shopify\Webhooks\Registry;
use Shopify\Webhooks\Topics;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -26,49 +16,8 @@ public function register()
//
}

/**
* Bootstrap any application services.
*
* @return void
* @throws \Shopify\Exception\MissingArgumentException
*/
public function boot()
{
$host = str_replace('https://', '', env('HOST', 'not_defined'));

$customDomain = env('SHOP_CUSTOM_DOMAIN', null);
Context::initialize(
env('SHOPIFY_API_KEY', 'not_defined'),
env('SHOPIFY_API_SECRET', 'not_defined'),
env('SCOPES', 'not_defined'),
$host,
new DbSessionStorage(),
ApiVersion::LATEST,
true,
false,
null,
'',
null,
(array)$customDomain,
);

URL::forceRootUrl("https://$host");
URL::forceScheme('https');

Registry::addHandler(Topics::APP_UNINSTALLED, new AppUninstalled());

/*
* This sets up the mandatory privacy webhooks. You’ll need to fill in the endpoint to be used by your app in
* the “Privacy webhooks” section in the “App setup” tab, and customize the code when you store customer data
* in the handlers being registered below.
*
* More details can be found on shopify.dev:
* https://shopify.dev/docs/apps/webhooks/configuration/mandatory-webhooks
*
* Note that you'll only receive these webhooks if your app has the relevant scopes as detailed in the docs.
*/
Registry::addHandler('CUSTOMERS_DATA_REQUEST', new CustomersDataRequest());
Registry::addHandler('CUSTOMERS_REDACT', new CustomersRedact());
Registry::addHandler('SHOP_REDACT', new ShopRedact());
//
}
}
74 changes: 74 additions & 0 deletions web/app/Providers/ShopifyServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Providers;

use App\Lib\DbSessionStorage;
use App\Lib\Handlers\AppUninstalled;
use App\Lib\Handlers\Privacy\CustomersDataRequest;
use App\Lib\Handlers\Privacy\CustomersRedact;
use App\Lib\Handlers\Privacy\ShopRedact;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Shopify\ApiVersion;
use Shopify\Context;
use Shopify\Webhooks\Registry;
use Shopify\Webhooks\Topics;

class ShopifyServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}

/**
* Bootstrap shopify service.
*
* @return void
*
* @throws \Shopify\Exception\MissingArgumentException
*/
public function boot()
{
$host = str_replace('https://', '', config('shopify.host'));

Context::initialize(
config('shopify.api_key'),
config('shopify.api_secret'),
config('shopify.scopes'),
$host,
new DbSessionStorage(),
ApiVersion::LATEST,
true,
false,
null,
'',
null,
(array) config('shopify.shop_custom_domain'),
);

URL::forceRootUrl("https://$host");
URL::forceScheme('https');

Registry::addHandler(Topics::APP_UNINSTALLED, new AppUninstalled());

/*
* This sets up the mandatory privacy webhooks. You’ll need to fill in the endpoint to be used by your app in
* the “Privacy webhooks” section in the “App setup” tab, and customize the code when you store customer data
* in the handlers being registered below.
*
* More details can be found on shopify.dev:
* https://shopify.dev/docs/apps/webhooks/configuration/mandatory-webhooks
*
* Note that you'll only receive these webhooks if your app has the relevant scopes as detailed in the docs.
*/
Registry::addHandler('CUSTOMERS_DATA_REQUEST', new CustomersDataRequest());
Registry::addHandler('CUSTOMERS_REDACT', new CustomersRedact());
Registry::addHandler('SHOP_REDACT', new ShopRedact());
}
}
1 change: 1 addition & 0 deletions web/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ShopifyServiceProvider::class,

],

Expand Down
71 changes: 65 additions & 6 deletions web/config/shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,65 @@

return [

/*
|--------------------------------------------------------------------------
| Shopify host
|--------------------------------------------------------------------------
|
| The URL origin where the app will be accessed when it's deployed, excluding the protocol. This will be provided by your platform.
| Example: my-deployed-app.fly.dev
|
| Learn more about in documentation: https://shopify.dev/docs/apps/launch/deployment/deploy-web-app/deploy-to-hosting-service#step-4-set-up-environment-variables
|
*/
'host' => env('HOST'),

/*
|--------------------------------------------------------------------------
| Shopify custom domain
|--------------------------------------------------------------------------
|
| One or more regexps to use when validating domains.
|
*/
'shop_custom_domain' => env('SHOP_CUSTOM_DOMAIN'),

/*
|--------------------------------------------------------------------------
| Shopify API Key
|--------------------------------------------------------------------------
|
| The client ID of the app, retrieved using Shopify CLI.
|
| Learn more about in documentation: https://shopify.dev/docs/apps/launch/deployment/deploy-web-app/deploy-to-hosting-service#step-4-set-up-environment-variables
|
*/
'api_key' => env('SHOPIFY_API_KEY'),

/*
|--------------------------------------------------------------------------
| Shopify API Secret
|--------------------------------------------------------------------------
|
| The client secret of the app, retrieved using Shopify CLI.
|
| Learn more about in documentation: https://shopify.dev/docs/apps/launch/deployment/deploy-web-app/deploy-to-hosting-service#step-4-set-up-environment-variables
|
*/
'api_secret' => env('SHOPIFY_API_SECRET'),

/*
|--------------------------------------------------------------------------
| Shopify Scopes
|--------------------------------------------------------------------------
|
| The app's access scopes, retrieved using Shopify CLI. This is optional if you're using Shopify-managed installation.
|
| Learn more about in documentation: https://shopify.dev/docs/apps/launch/deployment/deploy-web-app/deploy-to-hosting-service#step-4-set-up-environment-variables
|
*/
'scopes' => env('SCOPES'),

/*
|--------------------------------------------------------------------------
| Shopify billing
Expand All @@ -17,14 +76,14 @@
| Learn more about billing in our documentation: https://shopify.dev/docs/apps/billing
|
*/
"billing" => [
"required" => false,
'billing' => [
'required' => false,

// Example set of values to create a charge for $5 one time
"chargeName" => "My Shopify App One-Time Billing",
"amount" => 5.0,
"currencyCode" => "USD", // Currently only supports USD
"interval" => EnsureBilling::INTERVAL_ONE_TIME,
'chargeName' => 'My Shopify App One-Time Billing',
'amount' => 5.0,
'currencyCode' => 'USD', // Currently only supports USD
'interval' => EnsureBilling::INTERVAL_ONE_TIME,
],

];
Loading