Skip to content

Commit 1bc7dc5

Browse files
authored
Merge pull request #20 from QuadraEcommerce/feature/add-partner-key-support
Feature/add partner key support
2 parents 48d9bc4 + 1db9357 commit 1bc7dc5

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ After installing via composer you will need to publish the configuration:
3333
php artisan vendor:publish
3434
```
3535
This will create the configuration file for your API key and API secret key at ```config/shipstation.php```. You will need to obtain your API & Secret key from ShipStation: [How can I get access to ShipStation's API?](https://help.shipstation.com/hc/en-us/articles/206638917-How-can-I-get-access-to-ShipStation-s-API-)
36+
37+
If ShipStation has provided you with a partner API key, set it in your configuration file.
3638
## Dependencies
3739
LaravelShipStation uses ```GuzzleHttp\Guzzle```
3840
## Endpoints

config/config.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

33
return [
4-
'apiURL' => env('SS_URL', 'https://ssapi.shipstation.com'),
5-
'apiKey' => env('SS_KEY', ''),
6-
'apiSecret' => env('SS_SECRET', ''),
4+
'apiURL' => env('SS_URL', 'https://ssapi.shipstation.com'),
5+
'apiKey' => env('SS_KEY', ''),
6+
'partnerApiKey' => env('SS_PARTNER_KEY', ''),
7+
'apiSecret' => env('SS_SECRET', ''),
78
];

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<php>
2020
<env name="SHIPSTATION_TESTING" value="false"/>
2121
<env name="KEY" value=""/>
22+
<env name="PARTNER_KEY" value=""/>
2223
<env name="SECRET" value=""/>
2324
<env name="API_URL" value=""/>
2425
</php>

src/ShipStation.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,29 @@ class ShipStation extends Client
4747
*
4848
* @param string $apiKey
4949
* @param string $apiSecret
50+
* @param string $apiURL
51+
* @param string|null $partnerApiKey
5052
* @throws \Exception
5153
*/
52-
public function __construct($apiKey, $apiSecret, $apiURL)
54+
public function __construct($apiKey, $apiSecret, $apiURL, $partnerApiKey = null)
5355
{
5456
if (!isset($apiKey, $apiSecret)) {
5557
throw new \Exception('Your API key and/or private key are not set. Did you run artisan vendor:publish?');
5658
}
5759

5860
$this->base_uri = $apiURL;
5961

62+
$headers = [
63+
'Authorization' => 'Basic ' . base64_encode("{$apiKey}:{$apiSecret}"),
64+
];
65+
66+
if (! empty($partnerApiKey)) {
67+
$headers['x-partner'] = $partnerApiKey;
68+
}
69+
6070
parent::__construct([
6171
'base_uri' => $this->base_uri,
62-
'headers' => [
63-
'Authorization' => 'Basic ' . base64_encode("{$apiKey}:{$apiSecret}"),
64-
]
72+
'headers' => $headers,
6573
]);
6674
}
6775

src/ShipStationServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function register()
2929
return new ShipStation(
3030
config('shipstation.apiKey'),
3131
config('shipstation.apiSecret'),
32-
config('shipstation.apiURL')
32+
config('shipstation.apiURL'),
33+
config('shipstation.partnerApiKey')
3334
);
3435
});
3536
}

tests/ShipStationTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public function setUp()
2222
exit();
2323
}
2424

25-
$this->shipStation = new LaravelShipStation\ShipStation(getenv('KEY'), getenv('SECRET'), getenv('API_URL'));
25+
$this->shipStation = new LaravelShipStation\ShipStation(
26+
getenv('KEY'),
27+
getenv('SECRET'),
28+
getenv('API_URL'),
29+
getenv('PARTNER_KEY')
30+
);
2631
}
2732

2833
/** @test */
@@ -126,4 +131,19 @@ public function rate_limits_are_set_after_request()
126131
$this->assertGreaterThanOrEqual(0, $this->shipStation->getSecondsUntilReset());
127132
$this->assertInternalType('boolean', $this->shipStation->isRateLimited());
128133
}
134+
135+
/** @test */
136+
public function partner_api_key_header_is_set_when_defined()
137+
{
138+
if (empty(getenv('PARTNER_KEY'))) {
139+
// nothing to test
140+
return;
141+
}
142+
143+
$this->shipStation->webhooks->get();
144+
145+
$headers = $this->shipStation->request->getConfig('headers');
146+
147+
$this->assertArrayHasKey('x-partner', $headers);
148+
}
129149
}

0 commit comments

Comments
 (0)