Skip to content

Commit

Permalink
Create onchain wallet (#120)
Browse files Browse the repository at this point in the history
* Adding createStoreOnChainWallet functionality.
  • Loading branch information
ndeet authored Mar 25, 2024
1 parent 8b119a8 commit b88cd1c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/payout_usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function markPayoutAsPaid()

public function approvePayout()
{
$payoutId ='';
$payoutId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->approvePayout(
Expand Down
16 changes: 16 additions & 0 deletions examples/store_onchain_wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -171,3 +186,4 @@ public function getStoreOnChainWalletUTXOs()
$store->getStoreOnChainWalletTransactions();
//$store->getStoreOnChainWalletTransaction();
//$store->getStoreOnChainWalletUTXOs();
//$store->createStoreOnChainWallet();
2 changes: 1 addition & 1 deletion src/Client/InvoiceCheckoutOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
44 changes: 44 additions & 0 deletions src/Client/StoreOnChainWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b88cd1c

Please sign in to comment.