Skip to content

Commit

Permalink
#v3.4.1912.0-rc - Model updates and ERC_20 codes (#30)
Browse files Browse the repository at this point in the history
* - Payout batch amount round
* - Added ERC_20 support
  • Loading branch information
Antonio Buedo authored Dec 11, 2019
1 parent 58be4ea commit ce93ecc
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 60 deletions.
42 changes: 40 additions & 2 deletions src/BitPaySDK/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
* Class Client
* @package Bitpay
* @author Antonio Buedo
* @version 3.3.1911
* @version 3.4.1912
* See bitpay.com/api for more information.
* date 15.11.2019
* date 10.12.2019
*/
class Client
{
Expand Down Expand Up @@ -80,6 +80,11 @@ class Client
*/
protected $_RESTcli = null;

/**
* @var RESTcli
*/
public static $_currenciesInfo = null;

/**
* Client constructor.
*/
Expand Down Expand Up @@ -1228,6 +1233,7 @@ private function init()
try {
$this->_RESTcli = new RESTcli($this->_env, $this->_ecKey);
$this->loadAccessTokens();
$this->loadCurrencies();
} catch (Exception $e) {
throw new BitPayException("failed to build configuration : ".$e->getMessage());
}
Expand All @@ -1253,4 +1259,36 @@ private function clearAccessTokenCache()
{
$this->_tokenCache = new Tokens();
}

/**
* Load currencies info.
*
* @throws BitPayException BitPayException class
*/
private function loadCurrencies()
{
try {
self::$_currenciesInfo = json_decode($this->_RESTcli->get("currencies/", null, false), false);
} catch (Exception $e) {
throw new BitPayException("When loading currencies info : ".$e->getMessage());
}
}

/**
* Gets info for specific currency.
*
* @param $currencyCode String Currency code for which the info will be retrieved.
*
* @return object|null
*/
public static function getCurrencyInfo(string $currencyCode)
{
foreach (self::$_currenciesInfo as $currencyInfo) {
if ($currencyInfo->code == $currencyCode) {
return $currencyInfo;
}
}

return null;
}
}
2 changes: 1 addition & 1 deletion src/BitPaySDK/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface Env
const TestUrl = "https://test.bitpay.com/";
const ProdUrl = "https://bitpay.com/";
const BitpayApiVersion = "2.0.0";
const BitpayPluginInfo = "BitPay_PHP_Client_v3.3.1911";
const BitpayPluginInfo = "BitPay_PHP_Client_v3.4.1912";
}
45 changes: 42 additions & 3 deletions src/BitPaySDK/Model/Invoice/MinerFees.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ class MinerFees
protected $_btc;
protected $_bch;
protected $_eth;
protected $_usdc;
protected $_gusd;
protected $_pax;

public function __construct()
{
$this->_btc = new MinerFeesItem();
$this->_bch = new MinerFeesItem();
$this->_eth = new MinerFeesItem();
$this->_usdc = new MinerFeesItem();
$this->_gusd = new MinerFeesItem();
$this->_pax = new MinerFeesItem();
}

public function getBTH()
Expand Down Expand Up @@ -47,12 +53,45 @@ public function setETH(MinerFeesItem $eth)
$this->_eth = $eth;
}

public function getUSDC()
{
return $this->_usdc;
}

public function setUSDC(MinerFeesItem $usdc)
{
$this->_usdc = $usdc;
}

public function getGUSD()
{
return $this->_gusd;
}

public function setGUSD(MinerFeesItem $gusd)
{
$this->_gusd = $gusd;
}

public function getPAX()
{
return $this->_pax;
}

public function setPAX(MinerFeesItem $pax)
{
$this->_pax = $pax;
}

public function toArray()
{
$elements = [
'btc' => $this->getBTH()->toArray(),
'bch' => $this->getBCH()->toArray(),
'eth' => $this->getETH()->toArray(),
'btc' => $this->getBTH()->toArray(),
'bch' => $this->getBCH()->toArray(),
'eth' => $this->getETH()->toArray(),
'usdc' => $this->getUSDC()->toArray(),
'gusd' => $this->getGUSD()->toArray(),
'pax' => $this->getPAX()->toArray(),
];

foreach ($elements as $key => $value) {
Expand Down
28 changes: 26 additions & 2 deletions src/BitPaySDK/Model/Invoice/PaymentCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class PaymentCode
{
protected $_bip72b;
protected $_bip73;
protected $_eip681;
protected $_eip681b;

public function __construct()
{
Expand All @@ -16,8 +18,10 @@ public function __construct()
public function toArray()
{
$elements = [
'bip72b' => $this->getBip72b(),
'bip73' => $this->getBip73(),
'bip72b' => $this->getBip72b(),
'bip73' => $this->getBip73(),
'eip681' => $this->getEip681(),
'eip681b' => $this->getEip681b(),
];

foreach ($elements as $key => $value) {
Expand Down Expand Up @@ -48,4 +52,24 @@ public function setBip73(string $bip73)
{
$this->_bip73 = $bip73;
}

public function getEip681()
{
return $this->_eip681;
}

public function setEip681(string $eip681)
{
$this->_eip681 = $eip681;
}

public function getEip681b()
{
return $this->_eip681b;
}

public function setEip681b(string $eip681b)
{
$this->_eip681b = $eip681b;
}
}
73 changes: 56 additions & 17 deletions src/BitPaySDK/Model/Invoice/PaymentCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,18 @@ class PaymentCodes
protected $_btc;
protected $_bch;
protected $_eth;
protected $_usdc;
protected $_gusd;
protected $_pax;

public function __construct()
{
$this->_btc = new PaymentCode();
$this->_bch = new PaymentCode();
$this->_eth = new PaymentCode();
}

public function toArray()
{
$elements = [
'BTC' => $this->getBTC()->toArray(),
'BCH' => $this->getBCH()->toArray(),
'ETH' => $this->getETH()->toArray(),
];

foreach ($elements as $key => $value) {
if (empty($value)) {
unset($elements[$key]);
}
}

return $elements;
$this->_usdc = new PaymentCode();
$this->_gusd = new PaymentCode();
$this->_pax = new PaymentCode();
}

public function getBTC()
Expand Down Expand Up @@ -63,4 +52,54 @@ public function setETH(PaymentCode $eth)
{
$this->_eth = $eth;
}

public function getUSDC()
{
return $this->_usdc;
}

public function setUSDC(PaymentCode $usdc)
{
$this->_usdc = $usdc;
}

public function getGUSD()
{
return $this->_gusd;
}

public function setGUSD(PaymentCode $gusd)
{
$this->_gusd = $gusd;
}

public function getPAX()
{
return $this->_pax;
}

public function setPAX(PaymentCode $pax)
{
$this->_pax = $pax;
}

public function toArray()
{
$elements = [
'BTC' => $this->getBTC()->toArray(),
'BCH' => $this->getBCH()->toArray(),
'ETH' => $this->getETH()->toArray(),
'USDC' => $this->getUSDC()->toArray(),
'GUSD' => $this->getGUSD()->toArray(),
'PAX' => $this->getPAX()->toArray(),
];

foreach ($elements as $key => $value) {
if (empty($value)) {
unset($elements[$key]);
}
}

return $elements;
}
}
70 changes: 53 additions & 17 deletions src/BitPaySDK/Model/Invoice/PaymentTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@ class PaymentTotal
protected $_btc;
protected $_bch;
protected $_eth;
protected $_usdc;
protected $_gusd;
protected $_pax;

public function __construct()
{
}

public function toArray()
{
$elements = [
'BTC' => $this->getBTC(),
'BCH' => $this->getBCH(),
'ETH' => $this->getETH(),
];

foreach ($elements as $key => $value) {
if (empty($value)) {
unset($elements[$key]);
}
}

return $elements;
}

public function getBTC()
{
return $this->_btc;
Expand Down Expand Up @@ -60,4 +46,54 @@ public function setETH(float $eth)
{
$this->_eth = $eth;
}

public function getUSDC()
{
return $this->_usdc;
}

public function setUSDC(float $usdc)
{
$this->_usdc = $usdc;
}

public function getGUSD()
{
return $this->_gusd;
}

public function setGUSD(float $gusd)
{
$this->_gusd = $gusd;
}

public function getPAX()
{
return $this->_pax;
}

public function setPAX(float $pax)
{
$this->_pax = $pax;
}

public function toArray()
{
$elements = [
'BTC' => $this->getBTC(),
'BCH' => $this->getBCH(),
'ETH' => $this->getETH(),
'USDC' => $this->getUSDC(),
'GUSD' => $this->getGUSD(),
'PAX' => $this->getPAX(),
];

foreach ($elements as $key => $value) {
if (empty($value)) {
unset($elements[$key]);
}
}

return $elements;
}
}
Loading

0 comments on commit ce93ecc

Please sign in to comment.