diff --git a/app/Console/Commands/StoreGetShopifyCheckout.php b/app/Console/Commands/StoreGetShopifyCheckout.php new file mode 100644 index 00000000000..55e8f9dcc58 --- /dev/null +++ b/app/Console/Commands/StoreGetShopifyCheckout.php @@ -0,0 +1,75 @@ +. Licensed under the GNU Affero General Public License v3.0. +// See the LICENCE file in the repository root for full licence text. + +declare(strict_types=1); + +namespace App\Console\Commands; + +use App\Models\Store\Order; +use Illuminate\Console\Command; +use Shopify\ApiVersion; +use Shopify\Auth\FileSessionStorage; +use Shopify\Clients\Storefront; +use Shopify\Context; + +class StoreGetShopifyCheckout extends Command +{ + protected $signature = 'store:get-shopify-checkout {orderId}'; + + protected $description = 'Gets checkout info from shopify.'; + + public function handle() + { + $order = Order::findOrFail(get_int($this->argument('orderId'))); + if ($order->provider !== 'shopify') { + $this->error('Not a Shopify order'); + return static::INVALID; + } + + $this->comment("Getting details for Order {$order->getKey()}"); + $this->comment($order->reference); + + Context::initialize( + // public unauthenticated Storefront API doesn't need OAuth and we can't use blanks. + 'unauthenticated_only', + 'unauthenticated_only', + 'unauthenticated_read_checkouts', + $GLOBALS['cfg']['store']['shopify']['domain'], + new FileSessionStorage(), + ApiVersion::APRIL_2023, + ); + + $client = new Storefront( + $GLOBALS['cfg']['store']['shopify']['domain'], + $GLOBALS['cfg']['store']['shopify']['storefront_token'], + ); + + $id = '"'.$order->reference.'"'; + $query = <<query($query); + $body = $response->getDecodedBody() ?? ''; + $this->line(is_array($body) ? json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : $body); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 10262f13a68..44c20f7f2be 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -37,6 +37,7 @@ class Kernel extends ConsoleKernel Commands\StoreCleanupStaleOrders::class, Commands\StoreExpireProducts::class, Commands\StoreGetPaypalOrder::class, + Commands\StoreGetShopifyCheckout::class, // builds Commands\BuildsCreate::class, diff --git a/composer.json b/composer.json index 0ca341a9023..4a4990141d0 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "paypal/paypal-checkout-sdk": "*", "romanzipp/laravel-turnstile": "^1.3", "sentry/sentry-laravel": "*", + "shopify/shopify-api": "^5.6", "symfony/yaml": "*", "tightenco/ziggy": "^1.8", "xsolla/xsolla-sdk-php": "dev-php81" diff --git a/composer.lock b/composer.lock index 818e5d02471..e97a8a4c808 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4b5522bc8101c113235b144f19fe7b12", + "content-hash": "809c16eebdcc6254e933f5a511717268", "packages": [ { "name": "aws/aws-crt-php", @@ -7763,6 +7763,80 @@ ], "time": "2023-02-06T01:20:37+00:00" }, + { + "name": "shopify/shopify-api", + "version": "v5.6.0", + "source": { + "type": "git", + "url": "https://github.com/Shopify/shopify-api-php.git", + "reference": "fcb281a0021453659c3e4f09320417b264c35ee8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Shopify/shopify-api-php/zipball/fcb281a0021453659c3e4f09320417b264c35ee8", + "reference": "fcb281a0021453659c3e4f09320417b264c35ee8", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^2.0", + "ext-ctype": "*", + "ext-hash": "*", + "ext-json": "*", + "ext-mbstring": "*", + "firebase/php-jwt": "^5.2 || ^6.2", + "guzzlehttp/guzzle": "^7.0", + "guzzlehttp/psr7": "^2.0", + "php": "^8.1", + "psr/http-client": "^1.0", + "psr/http-message": "^1.0 || ^2.0", + "psr/log": "^1.1 || ^2.0 || ^3.0", + "ramsey/uuid": "^4.1" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.30", + "ext-apcu": "*", + "maglnet/composer-require-checker": "^3.0 || ^4.0", + "mikey179/vfsstream": "^1.6", + "phpunit/phpunit": "^9", + "squizlabs/php_codesniffer": "^3.6" + }, + "suggest": { + "ext-apcu": "Log fewer API deprecation warnings" + }, + "type": "library", + "autoload": { + "psr-4": { + "Shopify\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Shopify Inc.", + "email": "dev-tools-education@shopify.com" + } + ], + "description": "Shopify API Library for PHP", + "keywords": [ + "Storefront API", + "admin api", + "app", + "graphql", + "jwt", + "node", + "rest", + "shopify", + "webhook" + ], + "support": { + "issues": "https://github.com/Shopify/shopify-api-php/issues", + "source": "https://github.com/Shopify/shopify-api-php/tree/v5.6.0" + }, + "time": "2024-07-02T17:53:14+00:00" + }, { "name": "spatie/data-transfer-object", "version": "3.9.1", @@ -13952,5 +14026,5 @@ "platform-overrides": { "php": "8.3.0" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" }