show btc_address

This commit is contained in:
cnohall 2024-09-05 09:49:46 +09:00
parent f3d12fb977
commit 2be83cb897
2 changed files with 35 additions and 2 deletions

View File

@ -52,6 +52,39 @@ class Blockonomics implements MethodInterface
{ {
} }
public function getBTCAddress()
{
$api_key = $this->driver_class->api_key;
$url = 'https://www.blockonomics.co/api/new_address';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$header = "Authorization: Bearer " . $api_key;
$headers = array();
$headers[] = $header;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
echo "Error:" . curl_error($ch);
}
$responseObj = json_decode($contents);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ($status == 200) {
return $responseObj->address;
} else {
echo "ERROR: " . $status . ' ' . $responseObj->message;
}
return "Something went wrong";
}
public function getBTCPrice() public function getBTCPrice()
{ {
$currency_code = $this->driver_class->client->getCurrencyCode(); $currency_code = $this->driver_class->client->getCurrencyCode();
@ -70,6 +103,7 @@ class Blockonomics implements MethodInterface
$data['currency'] = $this->driver_class->client->getCurrencyCode(); $data['currency'] = $this->driver_class->client->getCurrencyCode();
$btc_amount = $data['amount'] / $this->getBTCPrice(); $btc_amount = $data['amount'] / $this->getBTCPrice();
$data['btc_amount'] = round($btc_amount, 10); $data['btc_amount'] = round($btc_amount, 10);
$data['btc_address'] = $this->getBTCAddress();
$data['invoice_id'] = $this->invoice_id; $data['invoice_id'] = $this->invoice_id;
return render('gateways.blockonomics.pay', $data); return render('gateways.blockonomics.pay', $data);
} }
@ -81,7 +115,6 @@ class Blockonomics implements MethodInterface
'payment_hash' => ['required'], 'payment_hash' => ['required'],
'amount' => ['required'], 'amount' => ['required'],
'currency' => ['required'], 'currency' => ['required'],
'btc_amount' => ['required'],
]); ]);
$drv = $this->driver_class; $drv = $this->driver_class;

View File

@ -9,7 +9,7 @@
<div>To pay, send exactly this BTC amount</div> <div>To pay, send exactly this BTC amount</div>
<input name="btcAmount" value="BTC {{$btc_amount}} ≈ {{$amount}} {{$currency}}" readonly> <input name="btcAmount" value="BTC {{$btc_amount}} ≈ {{$amount}} {{$currency}}" readonly>
<div>To this bitcoin address</div> <div>To this bitcoin address</div>
<input name="btcAddress" value="WIP" readonly> <input name="btcAddress" value="{{$btc_address}}" readonly>
<form action="{{ route('client.payments.response') }}" method="post" id="server-response"> <form action="{{ route('client.payments.response') }}" method="post" id="server-response">