1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6declare(strict_types=1);
7
8namespace App\Console\Commands;
9
10use App\Libraries\Payments\PaypalApiContext;
11use App\Models\Store\Order;
12use Illuminate\Console\Command;
13use PayPalCheckoutSdk\Orders\OrdersGetRequest;
14
15class StoreGetPaypalOrder extends Command
16{
17 protected $signature = 'store:get-paypal-order {orderId}';
18
19 protected $description = 'Gets order info from paypal.';
20
21 public function handle()
22 {
23 $order = Order::findOrFail(get_int($this->argument('orderId')));
24 if ($order->provider !== 'paypal') {
25 $this->error('Not a Paypal order');
26 return static::INVALID;
27 }
28
29 $paypalOrderId = $order->reference;
30 if ($paypalOrderId === null) {
31 $this->error('Missing Paypal order id');
32 return static::INVALID;
33 }
34
35 $this->comment("Getting details for Order {$order->getKey()}, Paypal Id: {$paypalOrderId}");
36 $client = PaypalApiContext::client();
37 $response = $client->execute(new OrdersGetRequest($paypalOrderId));
38
39 $this->line(json_encode((array) $response->result, JSON_PRETTY_PRINT));
40 }
41}