From d5270622ee636cb34ea4e3044324a6ef20c45747 Mon Sep 17 00:00:00 2001 From: Marcin Warzybok Date: Thu, 11 Jan 2024 10:14:03 +0100 Subject: [PATCH] SP-750 Code Examples: PHP --- examples/Merchant/BillRequests.php | 7 +- examples/Merchant/SettlementRequests.php | 3 - examples/Pos/BillRequests.php | 2 +- examples/Pos/InvoiceRequests.php | 11 - src/BitPaySDK/Model/Currency.php | 10 +- src/BitPaySDK/Model/Invoice/MinerFees.php | 48 ++++ .../SupportedTransactionCurrencies.php | 240 ++++++++++++++++++ src/BitPaySDK/Model/Ledger/LedgerEntry.php | 10 +- .../BitPaySDK/PayoutRecipientsClientTest.php | 3 - .../Model/Ledger/LedgerEntryTest.php | 6 +- 10 files changed, 305 insertions(+), 35 deletions(-) diff --git a/examples/Merchant/BillRequests.php b/examples/Merchant/BillRequests.php index 794dd37a..fdb541a6 100644 --- a/examples/Merchant/BillRequests.php +++ b/examples/Merchant/BillRequests.php @@ -6,6 +6,7 @@ use BitPaySDK\Model\Bill\Bill; use BitPaySDK\Model\Bill\Item; +use BitPaySDK\Model\Facade; use BitPaySDKexamples\ClientProvider; final class BillRequests @@ -25,7 +26,7 @@ public function createBill(): void $bill->setCity('MyCity'); // ... - $client->createBill($bill); + $client->createBill($bill, Facade::MERCHANT, false); } /** @@ -36,9 +37,7 @@ public function getBill(): void { $client = ClientProvider::create(); - $bill = $client->getBill('someBillId'); - - $bills = $client->getBills('draft'); + $bill = $client->getBill('someBillId', Facade::MERCHANT, false); } /** diff --git a/examples/Merchant/SettlementRequests.php b/examples/Merchant/SettlementRequests.php index 4c1fa3a3..57da76e9 100644 --- a/examples/Merchant/SettlementRequests.php +++ b/examples/Merchant/SettlementRequests.php @@ -4,7 +4,6 @@ namespace BitPaySDKexamples\Merchant; -use BitPaySDK\Model\Settlement\Settlement; use BitPaySDKexamples\ClientProvider; final class SettlementRequests @@ -29,8 +28,6 @@ public function fetchReconciliationReport(): void { $client = ClientProvider::create(); - $settlement = new Settlement(); - $client->getSettlementReconciliationReport('settlementId', 'settlementToken'); } } diff --git a/examples/Pos/BillRequests.php b/examples/Pos/BillRequests.php index f2ef587f..6ee73dce 100644 --- a/examples/Pos/BillRequests.php +++ b/examples/Pos/BillRequests.php @@ -46,6 +46,6 @@ public function deliverBillViaEmail(): void { $client = ClientProvider::createPos(); - $client->deliverBill('someBillId', 'myBillToken'); + $result = $client->deliverBill('someBillId', 'myBillToken'); } } diff --git a/examples/Pos/InvoiceRequests.php b/examples/Pos/InvoiceRequests.php index d6445497..8c22fde9 100644 --- a/examples/Pos/InvoiceRequests.php +++ b/examples/Pos/InvoiceRequests.php @@ -52,15 +52,4 @@ public function getInvoice(): void $invoiceById = $client->getInvoice('myInvoiceId'); } - - /** - * @throws \BitPaySDK\Exceptions\BitPayApiException - * @throws \BitPaySDK\Exceptions\BitPayGenericException - */ - public function requestInvoiceWebhookToBeResent(): void - { - $client = ClientProvider::createPos(); - - $client->requestInvoiceNotification('someInvoiceId'); - } } diff --git a/src/BitPaySDK/Model/Currency.php b/src/BitPaySDK/Model/Currency.php index 0d588015..a4871827 100644 --- a/src/BitPaySDK/Model/Currency.php +++ b/src/BitPaySDK/Model/Currency.php @@ -220,7 +220,7 @@ class Currency protected ?int $decimals = null; protected ?string $chain = null; protected ?string $displayCode = null; - protected ?float $maxSupply = null; + protected ?string $maxSupply = null; protected ?int $trancheDecimals = null; protected ?string $contractAddress = null; @@ -472,17 +472,17 @@ public function setDisplayCode(?string $displayCode): void } /** - * @return float|null + * @return string|null */ - public function getMaxSupply(): ?float + public function getMaxSupply(): ?string { return $this->maxSupply; } /** - * @param float|null $maxSupply + * @param string|null $maxSupply */ - public function setMaxSupply(?float $maxSupply): void + public function setMaxSupply(?string $maxSupply): void { $this->maxSupply = $maxSupply; } diff --git a/src/BitPaySDK/Model/Invoice/MinerFees.php b/src/BitPaySDK/Model/Invoice/MinerFees.php index ff693db8..854d0639 100644 --- a/src/BitPaySDK/Model/Invoice/MinerFees.php +++ b/src/BitPaySDK/Model/Invoice/MinerFees.php @@ -33,6 +33,8 @@ class MinerFees protected MinerFeesItem $ltc; protected MinerFeesItem $dai; protected MinerFeesItem $wbtc; + protected MinerFeesItem $matic; + protected MinerFeesItem $usdcM; /** * MinerFees constructor. @@ -51,6 +53,8 @@ public function __construct() $this->ltc = new MinerFeesItem(); $this->dai = new MinerFeesItem(); $this->wbtc = new MinerFeesItem(); + $this->matic = new MinerFeesItem(); + $this->usdcM = new MinerFeesItem(); } /** @@ -293,6 +297,48 @@ public function setWBTC(MinerFeesItem $wbtc): void $this->wbtc = $wbtc; } + /** + * Gets MATIC. + * + * @return MinerFeesItem + */ + public function getMATIC(): MinerFeesItem + { + return $this->matic; + } + + /** + * Sets MATIC. + * + * @param MinerFeesItem $matic + * @return void + */ + public function setMATIC(MinerFeesItem $matic): void + { + $this->matic = $matic; + } + + /** + * Gets USDC_m. + * + * @return MinerFeesItem + */ + public function getUsdcM(): MinerFeesItem + { + return $this->usdcM; + } + + /** + * Sets USDC_m. + * + * @param MinerFeesItem $usdcM + * @return void + */ + public function setUsdcM(MinerFeesItem $usdcM): void + { + $this->usdcM = $usdcM; + } + /** * Return array with details for currencies. * @@ -313,6 +359,8 @@ public function toArray(): array 'ltc' => $this->getLTC()->toArray(), 'dai' => $this->getDAI()->toArray(), 'wbtc' => $this->getWBTC()->toArray(), + 'matic' => $this->getMATIC()->toArray(), + 'usdc_m' => $this->getUsdcM()->toArray() ]; foreach ($elements as $key => $value) { diff --git a/src/BitPaySDK/Model/Invoice/SupportedTransactionCurrencies.php b/src/BitPaySDK/Model/Invoice/SupportedTransactionCurrencies.php index 2131d57e..26344620 100644 --- a/src/BitPaySDK/Model/Invoice/SupportedTransactionCurrencies.php +++ b/src/BitPaySDK/Model/Invoice/SupportedTransactionCurrencies.php @@ -29,6 +29,16 @@ class SupportedTransactionCurrencies protected SupportedTransactionCurrency $doge; protected SupportedTransactionCurrency $ltc; protected SupportedTransactionCurrency $wbtc; + protected SupportedTransactionCurrency $dai; + protected SupportedTransactionCurrency $euroc; + protected SupportedTransactionCurrency $matic; + protected SupportedTransactionCurrency $maticE; + protected SupportedTransactionCurrency $ethM; + protected SupportedTransactionCurrency $usdcM; + protected SupportedTransactionCurrency $busdM; + protected SupportedTransactionCurrency $daiM; + protected SupportedTransactionCurrency $wbtcM; + protected SupportedTransactionCurrency $shibM; /** * SupportedTransactionCurrencies constructor. @@ -46,6 +56,16 @@ public function __construct() $this->doge = new SupportedTransactionCurrency(); $this->ltc = new SupportedTransactionCurrency(); $this->wbtc = new SupportedTransactionCurrency(); + $this->dai = new SupportedTransactionCurrency(); + $this->euroc = new SupportedTransactionCurrency(); + $this->matic = new SupportedTransactionCurrency(); + $this->maticE = new SupportedTransactionCurrency(); + $this->ethM = new SupportedTransactionCurrency(); + $this->usdcM = new SupportedTransactionCurrency(); + $this->busdM = new SupportedTransactionCurrency(); + $this->daiM = new SupportedTransactionCurrency(); + $this->wbtcM = new SupportedTransactionCurrency(); + $this->shibM = new SupportedTransactionCurrency(); } /** @@ -268,6 +288,216 @@ public function setWBTC(SupportedTransactionCurrency $wbtc): void $this->wbtc = $wbtc; } + /** + * Gets DAI. + * + * @return SupportedTransactionCurrency + */ + public function getDAI(): SupportedTransactionCurrency + { + return $this->dai; + } + + /** + * Sets DAI. + * + * @param SupportedTransactionCurrency $dai + * @return void + */ + public function setDAI(SupportedTransactionCurrency $dai): void + { + $this->dai = $dai; + } + + /** + * Gets EUROC. + * + * @return SupportedTransactionCurrency + */ + public function getEUROC(): SupportedTransactionCurrency + { + return $this->euroc; + } + + /** + * Sets EUROC. + * + * @param SupportedTransactionCurrency $euroc + * @return void + */ + public function setEUROC(SupportedTransactionCurrency $euroc): void + { + $this->euroc = $euroc; + } + + /** + * Gets MATIC. + * + * @return SupportedTransactionCurrency + */ + public function getMATIC(): SupportedTransactionCurrency + { + return $this->matic; + } + + /** + * Sets MATIC. + * + * @param SupportedTransactionCurrency $matic + * @return void + */ + public function setMATIC(SupportedTransactionCurrency $matic): void + { + $this->matic = $matic; + } + + /** + * Gets MATIC_e + * + * @return SupportedTransactionCurrency + */ + public function getMaticE(): SupportedTransactionCurrency + { + return $this->maticE; + } + + /** + * Sets MATIC_e. + * + * @param SupportedTransactionCurrency $maticE + * @return void + */ + public function setMaticE(SupportedTransactionCurrency $maticE): void + { + $this->maticE = $maticE; + } + + /** + * Gets ETC_m. + * + * @return SupportedTransactionCurrency + */ + public function getEthM(): SupportedTransactionCurrency + { + return $this->ethM; + } + + /** + * Sets ETC_m. + * + * @param SupportedTransactionCurrency $ethM + * @return void + */ + public function setEthM(SupportedTransactionCurrency $ethM): void + { + $this->ethM = $ethM; + } + + /** + * Gets USDC_m. + * + * @return SupportedTransactionCurrency + */ + public function getUsdcM(): SupportedTransactionCurrency + { + return $this->usdcM; + } + + /** + * Sets USDC_m. + * + * @param SupportedTransactionCurrency $usdcM + * @return void + */ + public function setUsdcM(SupportedTransactionCurrency $usdcM): void + { + $this->usdcM = $usdcM; + } + + /** + * Gets BUSD_m. + * + * @return SupportedTransactionCurrency + */ + public function getBusdM(): SupportedTransactionCurrency + { + return $this->busdM; + } + + /** + * Sets BUSD_m. + * + * @param SupportedTransactionCurrency $busdM + * @return void + */ + public function setBusdM(SupportedTransactionCurrency $busdM): void + { + $this->busdM = $busdM; + } + + /** + * Gets DAI_m. + * + * @return SupportedTransactionCurrency + */ + public function getDaiM(): SupportedTransactionCurrency + { + return $this->daiM; + } + + /** + * Sets DAI_m. + * + * @param SupportedTransactionCurrency $daiM + * @return void + */ + public function setDaiM(SupportedTransactionCurrency $daiM): void + { + $this->daiM = $daiM; + } + + /** + * Gets WBTC_m. + * + * @return SupportedTransactionCurrency + */ + public function getWbtcM(): SupportedTransactionCurrency + { + return $this->wbtcM; + } + + /** + * Sets WBTC_m. + * + * @param SupportedTransactionCurrency $wbtcM + * @return void + */ + public function setWbtcM(SupportedTransactionCurrency $wbtcM): void + { + $this->wbtcM = $wbtcM; + } + + /** + * Gets SHIB_m. + * + * @return SupportedTransactionCurrency + */ + public function getShibM(): SupportedTransactionCurrency + { + return $this->shibM; + } + + /** + * Sets SHIB_m. + * + * @param SupportedTransactionCurrency $shibM + * @return void + */ + public function setShibM(SupportedTransactionCurrency $shibM): void + { + $this->shibM = $shibM; + } + /** * Return array with details for currencies. * @@ -287,6 +517,16 @@ public function toArray(): array 'doge' => $this->getDOGE()->toArray(), 'ltc' => $this->getLTC()->toArray(), 'wbtc' => $this->getWBTC()->toArray(), + 'dai' => $this->getDAI()->toArray(), + 'euroc' => $this->getEUROC()->toArray(), + 'matic' => $this->getMATIC()->toArray(), + 'maticE' => $this->getMaticE()->toArray(), + 'ethM' => $this->getEthM()->toArray(), + 'usdcM' => $this->getUsdcM()->toArray(), + 'busdM' => $this->getBusdM()->toArray(), + 'daiM' => $this->getDaiM()->toArray(), + 'wbtcM' => $this->getWbtcM()->toArray(), + 'shibM' => $this->getShibM()->toArray(), ]; foreach ($elements as $key => $value) { diff --git a/src/BitPaySDK/Model/Ledger/LedgerEntry.php b/src/BitPaySDK/Model/Ledger/LedgerEntry.php index 49f4c257..f8e6c12e 100644 --- a/src/BitPaySDK/Model/Ledger/LedgerEntry.php +++ b/src/BitPaySDK/Model/Ledger/LedgerEntry.php @@ -27,7 +27,7 @@ class LedgerEntry protected ?string $timestamp = null; protected ?string $currency = null; protected ?string $txType = null; - protected ?string $scale = null; + protected ?int $scale = null; protected ?string $id = null; protected ?string $supportRequest = null; protected ?string $description = null; @@ -185,9 +185,9 @@ public function setTxType(string $txType): void * * Power of 10 used for conversion * - * @return string|null the scale + * @return int|null the scale */ - public function getScale(): ?string + public function getScale(): ?int { return $this->scale; } @@ -197,9 +197,9 @@ public function getScale(): ?string * * Power of 10 used for conversion * - * @param string $scale the scale + * @param int $scale the scale */ - public function setScale(string $scale): void + public function setScale(int $scale): void { $this->scale = $scale; } diff --git a/test/functional/BitPaySDK/PayoutRecipientsClientTest.php b/test/functional/BitPaySDK/PayoutRecipientsClientTest.php index 1774661e..c92b5ba3 100644 --- a/test/functional/BitPaySDK/PayoutRecipientsClientTest.php +++ b/test/functional/BitPaySDK/PayoutRecipientsClientTest.php @@ -14,9 +14,6 @@ class PayoutRecipientsClientTest extends AbstractClientTestCase { - /** - * @throws PayoutRecipientCreationException - */ public function testSubmitPayoutRecipients(): void { $recipientsList = [ diff --git a/test/unit/BitPaySDK/Model/Ledger/LedgerEntryTest.php b/test/unit/BitPaySDK/Model/Ledger/LedgerEntryTest.php index bcfa297c..166b7100 100644 --- a/test/unit/BitPaySDK/Model/Ledger/LedgerEntryTest.php +++ b/test/unit/BitPaySDK/Model/Ledger/LedgerEntryTest.php @@ -70,7 +70,7 @@ public function testGetTxType() public function testGetScale() { - $expectedScale = 'TestScale'; + $expectedScale = 132132; $ledgerEntry = $this->createClassObject(); $ledgerEntry->setScale($expectedScale); @@ -179,7 +179,7 @@ public function testToArray() self::assertEquals('2020-01-01 18:10:10', $ledgerEntryArray['timestamp']); self::assertEquals('BTC', $ledgerEntryArray['currency']); self::assertEquals('TxType', $ledgerEntryArray['txType']); - self::assertEquals('Test scale', $ledgerEntryArray['scale']); + self::assertEquals(100000, $ledgerEntryArray['scale']); self::assertEquals('1', $ledgerEntryArray['id']); self::assertEquals('Test support request', $ledgerEntryArray['supportRequest']); self::assertEquals('Test description', $ledgerEntryArray['description']); @@ -202,7 +202,7 @@ private function setSetters(LedgerEntry $ledgerEntry) $ledgerEntry->setTimestamp('2020-01-01 18:10:10'); $ledgerEntry->setCurrency('BTC'); $ledgerEntry->setTxType('TxType'); - $ledgerEntry->setScale('Test scale'); + $ledgerEntry->setScale(100000); $ledgerEntry->setId('1'); $ledgerEntry->setSupportRequest('Test support request'); $ledgerEntry->setDescription('Test description');