From 36ef3ff908b23d77fc1171b90702eae08f8a6579 Mon Sep 17 00:00:00 2001 From: Muhammad Huzaifa Date: Tue, 8 Oct 2024 22:49:07 +0500 Subject: [PATCH] refactor: update the code as the laravel best practices --- web/app/Providers/AppServiceProvider.php | 53 +------------- web/app/Providers/ShopifyServiceProvider.php | 74 ++++++++++++++++++++ web/config/app.php | 1 + web/config/shopify.php | 71 +++++++++++++++++-- 4 files changed, 141 insertions(+), 58 deletions(-) create mode 100644 web/app/Providers/ShopifyServiceProvider.php diff --git a/web/app/Providers/AppServiceProvider.php b/web/app/Providers/AppServiceProvider.php index 5f5288fa4..857898dcc 100644 --- a/web/app/Providers/AppServiceProvider.php +++ b/web/app/Providers/AppServiceProvider.php @@ -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 { @@ -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()); + // } } diff --git a/web/app/Providers/ShopifyServiceProvider.php b/web/app/Providers/ShopifyServiceProvider.php new file mode 100644 index 000000000..4a35d82a4 --- /dev/null +++ b/web/app/Providers/ShopifyServiceProvider.php @@ -0,0 +1,74 @@ + 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 @@ -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, ], ];