Skip to content

Commit

Permalink
Merge pull request #322 from bobbrodie/9.1.x
Browse files Browse the repository at this point in the history
SP-126 Added X-BitPay-Platform-Info header
  • Loading branch information
bobbrodie authored Aug 13, 2024
2 parents 4d677af + ed2b78d commit 685bbf5
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 158 deletions.
142 changes: 80 additions & 62 deletions docs/classes/BitPaySDK-Client.html

Large diffs are not rendered by default.

214 changes: 143 additions & 71 deletions docs/classes/BitPaySDK-PosClient.html

Large diffs are not rendered by default.

80 changes: 66 additions & 14 deletions docs/classes/BitPaySDK-Util-RESTcli-RESTcli.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ <h4 id="toc-properties">
&nbsp;: string </span>
</dt>

<dt class="phpdocumentor-table-of-contents__entry -property -protected">
<a class="" href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_platformInfo">$platformInfo</a>
<span>
&nbsp;: string </span>
</dt>
<dd>Value for the X-BitPay-Platform-Info header.</dd>

<dt class="phpdocumentor-table-of-contents__entry -property -protected">
<a class="" href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_proxy">$proxy</a>
<span>
Expand Down Expand Up @@ -337,7 +344,7 @@ <h4 class="phpdocumentor-element__name" id="property_baseUrl">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">37</span>
<span class="phpdocumentor-element-found-in__line">38</span>

</aside>

Expand Down Expand Up @@ -409,7 +416,7 @@ <h4 class="phpdocumentor-element__name" id="property_ecKey">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">41</span>
<span class="phpdocumentor-element-found-in__line">43</span>

</aside>

Expand Down Expand Up @@ -445,7 +452,7 @@ <h4 class="phpdocumentor-element__name" id="property_identity">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">45</span>
<span class="phpdocumentor-element-found-in__line">48</span>

</aside>

Expand All @@ -463,6 +470,43 @@ <h4 class="phpdocumentor-element__name" id="property_identity">



</article>
<article
class="
phpdocumentor-element
-property
-protected
"
>
<h4 class="phpdocumentor-element__name" id="property_platformInfo">
$platformInfo
<a href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_platformInfo" class="headerlink"><i class="fas fa-link"></i></a>

<span class="phpdocumentor-element__modifiers">
</span>
</h4>
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">54</span>

</aside>

<p class="phpdocumentor-summary">Value for the X-BitPay-Platform-Info header.</p>


<code class="phpdocumentor-code phpdocumentor-signature ">
<span class="phpdocumentor-signature__visibility">protected</span>
<span class="phpdocumentor-signature__type">string</span>
<span class="phpdocumentor-signature__name">$platformInfo</span>
</code>







</article>
<article
class="
Expand All @@ -481,7 +525,7 @@ <h4 class="phpdocumentor-element__name" id="property_proxy">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">50</span>
<span class="phpdocumentor-element-found-in__line">59</span>

</aside>

Expand Down Expand Up @@ -522,15 +566,15 @@ <h4 class="phpdocumentor-element__name" id="method___construct">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">59</span>
<span class="phpdocumentor-element-found-in__line">69</span>

</aside>

<p class="phpdocumentor-summary">RESTcli constructor.</p>

<code class="phpdocumentor-code phpdocumentor-signature ">
<span class="phpdocumentor-signature__visibility">public</span>
<span class="phpdocumentor-signature__name">__construct</span><span>(</span><span class="phpdocumentor-signature__argument"><span class="phpdocumentor-signature__argument__return-type">string&nbsp;</span><span class="phpdocumentor-signature__argument__name">$environment</span></span><span class="phpdocumentor-signature__argument"><span>, </span><span class="phpdocumentor-signature__argument__return-type"><abbr title="\BitPayKeyUtils\KeyHelper\PrivateKey">PrivateKey</abbr>&nbsp;</span><span class="phpdocumentor-signature__argument__name">$ecKey</span></span><span class="phpdocumentor-signature__argument"><span>[</span><span>, </span><span class="phpdocumentor-signature__argument__return-type">string|null&nbsp;</span><span class="phpdocumentor-signature__argument__name">$proxy</span><span> = </span><span class="phpdocumentor-signature__argument__default-value">null</span><span> ]</span></span><span>)</span><span> : </span><span class="phpdocumentor-signature__response_type">mixed</span></code>
<span class="phpdocumentor-signature__name">__construct</span><span>(</span><span class="phpdocumentor-signature__argument"><span class="phpdocumentor-signature__argument__return-type">string&nbsp;</span><span class="phpdocumentor-signature__argument__name">$environment</span></span><span class="phpdocumentor-signature__argument"><span>, </span><span class="phpdocumentor-signature__argument__return-type"><abbr title="\BitPayKeyUtils\KeyHelper\PrivateKey">PrivateKey</abbr>&nbsp;</span><span class="phpdocumentor-signature__argument__name">$ecKey</span></span><span class="phpdocumentor-signature__argument"><span>[</span><span>, </span><span class="phpdocumentor-signature__argument__return-type">string|null&nbsp;</span><span class="phpdocumentor-signature__argument__name">$proxy</span><span> = </span><span class="phpdocumentor-signature__argument__default-value">null</span><span> ]</span></span><span class="phpdocumentor-signature__argument"><span>, </span><span class="phpdocumentor-signature__argument__return-type">string|null&nbsp;</span><span class="phpdocumentor-signature__argument__name">$platformInfo</span></span><span>)</span><span> : </span><span class="phpdocumentor-signature__response_type">mixed</span></code>

<div class="phpdocumentor-label-line">
</div>
Expand Down Expand Up @@ -558,6 +602,13 @@ <h5 class="phpdocumentor-argument-list__heading">Parameters</h5>
= <span class="phpdocumentor-signature__argument__default-value">null</span> </dt>
<dd class="phpdocumentor-argument-list__definition">

</dd>
<dt class="phpdocumentor-argument-list__entry">
<span class="phpdocumentor-signature__argument__name">$platformInfo</span>
: <span class="phpdocumentor-signature__argument__return-type">string|null</span>
</dt>
<dd class="phpdocumentor-argument-list__definition">

</dd>
</dl>

Expand Down Expand Up @@ -596,7 +647,7 @@ <h4 class="phpdocumentor-element__name" id="method_delete">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">227</span>
<span class="phpdocumentor-element-found-in__line">250</span>

</aside>

Expand Down Expand Up @@ -675,7 +726,7 @@ <h4 class="phpdocumentor-element__name" id="method_get">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">168</span>
<span class="phpdocumentor-element-found-in__line">187</span>

</aside>

Expand Down Expand Up @@ -765,7 +816,7 @@ <h4 class="phpdocumentor-element__name" id="method_getJsonDataFromResponse">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">341</span>
<span class="phpdocumentor-element-found-in__line">372</span>

</aside>

Expand Down Expand Up @@ -829,7 +880,7 @@ <h4 class="phpdocumentor-element__name" id="method_init">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">72</span>
<span class="phpdocumentor-element-found-in__line">83</span>

</aside>

Expand Down Expand Up @@ -879,7 +930,7 @@ <h4 class="phpdocumentor-element__name" id="method_post">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">108</span>
<span class="phpdocumentor-element-found-in__line">123</span>

</aside>

Expand Down Expand Up @@ -969,7 +1020,7 @@ <h4 class="phpdocumentor-element__name" id="method_update">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">288</span>
<span class="phpdocumentor-element-found-in__line">315</span>

</aside>

Expand Down Expand Up @@ -1048,7 +1099,7 @@ <h4 class="phpdocumentor-element__name" id="method_hasError">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">378</span>
<span class="phpdocumentor-element-found-in__line">409</span>

</aside>

Expand Down Expand Up @@ -1096,7 +1147,7 @@ <h4 class="phpdocumentor-element__name" id="method_parseException">
<aside class="phpdocumentor-element-found-in">
<abbr class="phpdocumentor-element-found-in__file" title="src/BitPaySDK/Util/RESTcli/RESTcli.php"><a href="files/src-bitpaysdk-util-restcli-restcli.html"><abbr title="src/BitPaySDK/Util/RESTcli/RESTcli.php">RESTcli.php</abbr></a></abbr>
:
<span class="phpdocumentor-element-found-in__line">394</span>
<span class="phpdocumentor-element-found-in__line">425</span>

</aside>

Expand Down Expand Up @@ -1266,6 +1317,7 @@ <h5 class="phpdocumentor-tag-list__heading" id="tags">
<li class=""><a href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_client">$client</a></li>
<li class=""><a href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_ecKey">$ecKey</a></li>
<li class=""><a href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_identity">$identity</a></li>
<li class=""><a href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_platformInfo">$platformInfo</a></li>
<li class=""><a href="classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_proxy">$proxy</a></li>
</ul>
</li>
Expand Down
10 changes: 10 additions & 0 deletions docs/js/searchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -9250,6 +9250,11 @@ Search.appendIndex(
"name": "env",
"summary": "",
"url": "classes/BitPaySDK-PosClient.html#property_env"
}, {
"fqsen": "\\BitPaySDK\\PosClient\u003A\u003A\u0024platformInfo",
"name": "platformInfo",
"summary": "Value\u0020for\u0020the\u0020X\u002DBitPay\u002DPlatform\u002DInfo\u0020header",
"url": "classes/BitPaySDK-PosClient.html#property_platformInfo"
}, {
"fqsen": "\\BitPaySDK\\PosClient\u003A\u003A\u0024token",
"name": "token",
Expand Down Expand Up @@ -9390,6 +9395,11 @@ Search.appendIndex(
"name": "identity",
"summary": "",
"url": "classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_identity"
}, {
"fqsen": "\\BitPaySDK\\Util\\RESTcli\\RESTcli\u003A\u003A\u0024platformInfo",
"name": "platformInfo",
"summary": "Value\u0020for\u0020the\u0020X\u002DBitPay\u002DPlatform\u002DInfo\u0020header.",
"url": "classes/BitPaySDK-Util-RESTcli-RESTcli.html#property_platformInfo"
}, {
"fqsen": "\\BitPaySDK\\Util\\RESTcli\\RESTcli\u003A\u003A\u0024proxy",
"name": "proxy",
Expand Down
13 changes: 8 additions & 5 deletions src/BitPaySDK/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct(RESTcli $restCli, Tokens $tokenCache)
* @param string|null $privateKeySecret Private Key encryption password.
* @param string|null $proxy The url of your proxy to forward requests through. Example:
* http://********.com:3128
* @param string|null $platformInfo Value for the X-BitPay-Platform header.
* @return Client
* @throws BitPayApiException
* @throws BitPayGenericException
Expand All @@ -80,12 +81,13 @@ public static function createWithData(
string $privateKey,
Tokens $tokens,
?string $privateKeySecret = null,
?string $proxy = null
?string $proxy = null,
?string $platformInfo = null,
): Client {
try {
$key = self::initKeys($privateKey, $privateKeySecret);

$restCli = new RESTcli($environment, $key, $proxy);
$restCli = new RESTcli($environment, $key, $proxy, $platformInfo);
$tokenCache = $tokens;

return new Client($restCli, $tokenCache);
Expand All @@ -99,11 +101,12 @@ public static function createWithData(
/**
* Constructor for use if the keys and SIN are managed by this library.
*
* @param string $configFilePath The path to the configuration file.
* @param string $configFilePath The path to the configuration file.
* @param string|null $platformInfo Value for the X-BitPay-Platform header.
* @return Client
* @throws BitPayGenericException
*/
public static function createWithFile(string $configFilePath): Client
public static function createWithFile(string $configFilePath, ?string $platformInfo = null): Client
{
try {
$configData = self::getConfigData($configFilePath);
Expand All @@ -113,7 +116,7 @@ public static function createWithFile(string $configFilePath): Client
$key = self::initKeys($config['PrivateKeyPath'], $config['PrivateKeySecret']);
$proxy = $config['Proxy'] ?? null;

$restCli = new RESTcli($env, $key, $proxy);
$restCli = new RESTcli($env, $key, $proxy, $platformInfo);
$tokenCache = new Tokens($config['ApiTokens']['merchant'], $config['ApiTokens']['payout']);

return new Client($restCli, $tokenCache);
Expand Down
18 changes: 13 additions & 5 deletions src/BitPaySDK/PosClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,30 @@
class PosClient extends Client
{
protected string $env;

/**
* Value for the X-BitPay-Platform-Info header
* @var string
*/
protected string $platformInfo;
protected Tokens $token;
protected RESTcli $RESTcli;

/**
* Constructor for the BitPay SDK to use with the POS facade.
*
* @param $token string The token generated on the BitPay account.
* @param string|null $environment string The target environment [Default: Production].
* @param string $token The token generated on the BitPay account.
* @param string|null $environment The target environment [Default: Production].
* @param string|null $platformInfo Value for the X-BitPay-Platform-Info header.
*
* @throws BitPayGenericException
*/
public function __construct(string $token, string $environment = null)
public function __construct(string $token, string $environment = null, ?string $platformInfo = null)
{
try {
$this->token = new Tokens(null, null, $token);
$this->env = strtolower($environment) === "test" ? Env::TEST : Env::PROD;
$this->platformInfo = $platformInfo !== null ? trim($platformInfo) : '';
$this->init();
parent::__construct($this->RESTcli, new Tokens(null, null, $token));
} catch (Exception $e) {
Expand All @@ -60,7 +68,7 @@ public function __construct(string $token, string $environment = null)
private function init(): void
{
try {
$this->RESTcli = new RESTcli($this->env, new PrivateKey());
$this->RESTcli = new RESTcli($this->env, new PrivateKey(), null, $this->platformInfo);
} catch (Exception $e) {
BitPayExceptionProvider::throwGenericExceptionWithMessage(
'failed to build configuration : ' . $e->getMessage()
Expand All @@ -71,7 +79,7 @@ private function init(): void
/**
* Fetch the supported currencies.
*
* @return array A list of BitPay Invoice objects.
* @return array A list of BitPay Invoice objects.
* @throws BitPayGenericException
* @throws BitPayApiException
*/
Expand Down
Loading

0 comments on commit 685bbf5

Please sign in to comment.