-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11511 from notbakaneko/feature/shopify-php
Add helper command for getting Shopify-related checkout details
- Loading branch information
Showing
4 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.