Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Fedex
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 createAuthClient
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <dev@noladev.com>
8 * @copyright  Copyright (c) 2009-2027 NOLA Interactive, LLC.
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Shipping\Auth;
16
17use Pop\Http;
18use Pop\Shipping\Client\AbstractShippingClient;
19
20/**
21 * Pop shipping FedEx adapter class
22 *
23 * @category   Pop
24 * @package    Pop\Shipping
25 * @author     Nick Sagona, III <dev@noladev.com>
26 * @copyright  Copyright (c) 2009-2027 NOLA Interactive, LLC.
27 * @license    https://www.popphp.org/license     New BSD License
28 * @version    4.0.0
29 */
30class Fedex extends AbstractAuthClient
31{
32
33    /**
34     * Production API URL
35     * @var ?string
36     */
37    protected ?string $prodApiUrl = AbstractShippingClient::FEDEX_PROD_API_URL;
38
39    /**
40     * Test API URL
41     * @var ?string
42     */
43    protected ?string $testApiUrl = AbstractShippingClient::FEDEX_TEST_API_URL;
44
45    /**
46     * Auth API URL
47     * @var ?string
48     */
49    protected ?string $authApiUrl = '/oauth/token'; // POST
50
51    /**
52     * Create FedEx auth client
53     *
54     * @param  string  $clientId
55     * @param  string  $secret
56     * @param  bool    $prod
57     * @return static
58     */
59    public static function createAuthClient(string $clientId, string $secret, string $accountId, bool $prod = false): static
60    {
61        $authClient = new static();
62        $authClient->setAccountNumber($accountId)
63            ->setProduction($prod);
64
65        $client = new Http\Client([
66            'base_uri' => $authClient->getApiUrl(),
67            'method'   => 'POST',
68            'data'     => [
69                'grant_type'    => 'client_credentials',
70                'client_id'     => $clientId,
71                'client_secret' => $secret
72            ]
73        ]);
74
75        $authClient->setClient($client);
76
77        return $authClient;
78    }
79
80}