From b88cd1cf5c5391daa8e92d1dc4ecb8f2f27c4933 Mon Sep 17 00:00:00 2001 From: ndeet Date: Mon, 25 Mar 2024 19:42:58 +0100 Subject: [PATCH] Create onchain wallet (#120) * Adding createStoreOnChainWallet functionality. --- examples/payout_usage.php | 2 +- examples/store_onchain_wallet.php | 16 ++++++++++ src/Client/InvoiceCheckoutOptions.php | 2 +- src/Client/StoreOnChainWallet.php | 44 +++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/examples/payout_usage.php b/examples/payout_usage.php index d14ab46..9f471bb 100644 --- a/examples/payout_usage.php +++ b/examples/payout_usage.php @@ -113,7 +113,7 @@ public function markPayoutAsPaid() public function approvePayout() { - $payoutId =''; + $payoutId = ''; try { $client = new PullPayment($this->host, $this->apiKey); var_dump($client->approvePayout( diff --git a/examples/store_onchain_wallet.php b/examples/store_onchain_wallet.php index 99751ad..77a21e8 100644 --- a/examples/store_onchain_wallet.php +++ b/examples/store_onchain_wallet.php @@ -32,6 +32,21 @@ public function getStoreOnChainWalletOverview() } } + public function createStoreOnChainWallet() + { + $cryptoCode = 'BTC'; + + try { + $client = new StoreOnChainWallet($this->host, $this->apiKey); + var_dump($client->createStoreOnchainWallet( + $this->storeId, + $cryptoCode + )); + } catch (\Throwable $e) { + echo "Error: " . $e->getMessage(); + } + } + public function getStoreOnChainWalletFeeRate() { $cryptoCode = 'BTC'; @@ -171,3 +186,4 @@ public function getStoreOnChainWalletUTXOs() $store->getStoreOnChainWalletTransactions(); //$store->getStoreOnChainWalletTransaction(); //$store->getStoreOnChainWalletUTXOs(); +//$store->createStoreOnChainWallet(); diff --git a/src/Client/InvoiceCheckoutOptions.php b/src/Client/InvoiceCheckoutOptions.php index e88d562..144ea0b 100644 --- a/src/Client/InvoiceCheckoutOptions.php +++ b/src/Client/InvoiceCheckoutOptions.php @@ -170,7 +170,7 @@ public function toArray(): array $lastIndex = strrpos($k, $separator); if ($lastIndex !== false) { - $k = substr($k, $lastIndex +1); + $k = substr($k, $lastIndex + 1); } $array[$k] = $v; } diff --git a/src/Client/StoreOnChainWallet.php b/src/Client/StoreOnChainWallet.php index 4633f54..0315a5c 100644 --- a/src/Client/StoreOnChainWallet.php +++ b/src/Client/StoreOnChainWallet.php @@ -35,6 +35,50 @@ public function getStoreOnChainWalletOverview( } } + public function createStoreOnChainWallet( + string $storeId, + string $cryptoCode, + ?string $existingMnemonic = null, + ?string $passphrase = null, + int $accountNumber = 0, + bool $savePrivateKeys = false, + bool $importKeysToRPC = false, + string $wordList = 'English', + int $wordCount = 12, + string $scriptPubKeyType = 'Segwit' + ): ResultStoreOnChainWallet { + $url = $this->getApiUrl() . 'stores/' . + urlencode($storeId) . '/payment-methods/onchain/' . + urlencode($cryptoCode) . '/generate'; + + $headers = $this->getRequestHeaders(); + $method = 'POST'; + + $body = json_encode( + [ + 'existingMnemonic' => $existingMnemonic, + 'passphrase' => $passphrase, + 'accountNumber' => $accountNumber, + 'savePrivateKeys' => $savePrivateKeys, + 'importKeysToRPC' => $importKeysToRPC, + 'wordList' => $wordList, + 'wordCount' => $wordCount, + 'scriptPubKeyType' => $scriptPubKeyType + ], + JSON_THROW_ON_ERROR + ); + + $response = $this->getHttpClient()->request($method, $url, $headers, $body); + + if ($response->getStatus() === 200) { + return new ResultStoreOnChainWallet( + json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR) + ); + } else { + throw $this->getExceptionByStatusCode($method, $url, $response); + } + } + public function getStoreOnChainWalletFeeRate( string $storeId, string $cryptoCode,