mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Now correctly displaying btc amount
This commit is contained in:
parent
915bbd96f2
commit
f3d12fb977
@ -25,6 +25,7 @@ use Illuminate\Mail\Mailables\Address;
|
||||
use App\Services\Email\EmailObject;
|
||||
use App\Services\Email\Email;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Models\Invoice;
|
||||
|
||||
class Blockonomics implements MethodInterface
|
||||
{
|
||||
@ -36,6 +37,8 @@ class Blockonomics implements MethodInterface
|
||||
{
|
||||
$this->driver_class = $driver_class;
|
||||
$this->driver_class->init();
|
||||
// TODO: set invoice_id
|
||||
$this->invoice_id = "123";
|
||||
}
|
||||
|
||||
public function authorizeView($data)
|
||||
@ -49,12 +52,25 @@ class Blockonomics implements MethodInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function getBTCPrice()
|
||||
{
|
||||
$currency_code = $this->driver_class->client->getCurrencyCode();
|
||||
$BLOCKONOMICS_BASE_URL = 'https://www.blockonomics.co';
|
||||
$BLOCKONOMICS_PRICE_URL = $BLOCKONOMICS_BASE_URL . '/api/price?currency=';
|
||||
$response = file_get_contents($BLOCKONOMICS_PRICE_URL . $currency_code);
|
||||
$data = json_decode($response, true);
|
||||
// TODO: handle error
|
||||
return $data['price'];
|
||||
}
|
||||
|
||||
public function paymentView($data)
|
||||
{
|
||||
$data['gateway'] = $this->driver_class;
|
||||
$data['amount'] = $data['total']['amount_with_fee'];
|
||||
$data['currency'] = $this->driver_class->client->getCurrencyCode();
|
||||
|
||||
$btc_amount = $data['amount'] / $this->getBTCPrice();
|
||||
$data['btc_amount'] = round($btc_amount, 10);
|
||||
$data['invoice_id'] = $this->invoice_id;
|
||||
return render('gateways.blockonomics.pay', $data);
|
||||
}
|
||||
|
||||
@ -65,6 +81,7 @@ class Blockonomics implements MethodInterface
|
||||
'payment_hash' => ['required'],
|
||||
'amount' => ['required'],
|
||||
'currency' => ['required'],
|
||||
'btc_amount' => ['required'],
|
||||
]);
|
||||
|
||||
$drv = $this->driver_class;
|
||||
|
@ -58,7 +58,7 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
||||
return $this; /* This is where you boot the gateway with your auth credentials*/
|
||||
}
|
||||
|
||||
private function get($url, $apiKey)
|
||||
public function get($url, $apiKey = null)
|
||||
{
|
||||
// Initialize cURL session
|
||||
$ch = curl_init();
|
||||
@ -66,10 +66,13 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Authorization: Bearer ' . $apiKey,
|
||||
'Content-Type: application/json'
|
||||
]);
|
||||
|
||||
// Set HTTP headers
|
||||
$headers = ['Content-Type: application/json'];
|
||||
if ($apiKey) {
|
||||
$headers[] = 'Authorization: Bearer ' . $apiKey;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// Execute cURL session and get the response
|
||||
$response = curl_exec($ch);
|
||||
@ -93,20 +96,6 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function getBTCPrice($id_currency)
|
||||
{
|
||||
$BLOCKONOMICS_BASE_URL = 'https://www.blockonomics.co';
|
||||
$BLOCKONOMICS_PRICE_URL = $BLOCKONOMICS_BASE_URL . '/api/price?currency=';
|
||||
// Getting price
|
||||
// $currency = new Currency((int) $id_currency);
|
||||
// $options = ['http' => ['method' => 'GET']];
|
||||
// $context = stream_context_create($options);
|
||||
// $contents = Tools::file_get_contents(Configuration::get('BLOCKONOMICS_PRICE_URL') . $currency->iso_code, false, $context);
|
||||
// $priceObj = Tools::jsonDecode($contents);
|
||||
|
||||
return $priceObj->price;
|
||||
}
|
||||
|
||||
// public function get_callbackSecret()
|
||||
// {
|
||||
// return md5(uniqid(rand(), true));
|
||||
|
@ -3,9 +3,14 @@
|
||||
@section('gateway_content')
|
||||
<div class="alert alert-failure mb-4" hidden id="errors"></div>
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.payment_details')
|
||||
<!-- @include('portal.ninja2020.gateways.includes.payment_details') -->
|
||||
|
||||
<div>this is where the blockonomics QR code goes, or if needed we can redirect them to an offsite url and handle the payment there </div>
|
||||
<div>Invoice #{{$invoice_id}}</div>
|
||||
<div>To pay, send exactly this BTC amount</div>
|
||||
<input name="btcAmount" value="BTC {{$btc_amount}} ≈ {{$amount}} {{$currency}}" readonly>
|
||||
<div>To this bitcoin address</div>
|
||||
<input name="btcAddress" value="WIP" readonly>
|
||||
|
||||
|
||||
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
|
||||
@csrf
|
||||
@ -18,13 +23,13 @@
|
||||
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
|
||||
</form>
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.pay_now')
|
||||
<!-- @include('portal.ninja2020.gateways.includes.pay_now') -->
|
||||
@endsection
|
||||
|
||||
@push('footer')
|
||||
<!-- @push('footer')
|
||||
<script>
|
||||
document.getElementById('pay-now').addEventListener('click', function() {
|
||||
document.getElementById('server-response').submit();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@endpush -->
|
||||
|
Loading…
Reference in New Issue
Block a user