Skip to content

Commit

Permalink
Merge pull request #11511 from notbakaneko/feature/shopify-php
Browse files Browse the repository at this point in the history
Add helper command for getting Shopify-related checkout details
  • Loading branch information
nanaya authored Sep 27, 2024
2 parents 57d2c7a + 3ef4315 commit de0db22
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 2 deletions.
75 changes: 75 additions & 0 deletions app/Console/Commands/StoreGetShopifyCheckout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. 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
{
node(id: $id) {
... on Checkout {
id
ready
webUrl
orderStatusUrl
completedAt
createdAt
updatedAt
order {
id
processedAt
orderNumber
}
}
}
}
QUERY;

$response = $client->query($query);
$body = $response->getDecodedBody() ?? '';
$this->line(is_array($body) ? json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : $body);
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Kernel extends ConsoleKernel
Commands\StoreCleanupStaleOrders::class,
Commands\StoreExpireProducts::class,
Commands\StoreGetPaypalOrder::class,
Commands\StoreGetShopifyCheckout::class,

// builds
Commands\BuildsCreate::class,
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
78 changes: 76 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de0db22

Please sign in to comment.