diff --git a/app/PaymentDrivers/Blockonomics/Blockonomics.php b/app/PaymentDrivers/Blockonomics/Blockonomics.php index 64436a48e99e..0ad56f1fcc55 100644 --- a/app/PaymentDrivers/Blockonomics/Blockonomics.php +++ b/app/PaymentDrivers/Blockonomics/Blockonomics.php @@ -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; diff --git a/app/PaymentDrivers/BlockonomicsPaymentDriver.php b/app/PaymentDrivers/BlockonomicsPaymentDriver.php index f3abba427362..77f5ddf2e439 100644 --- a/app/PaymentDrivers/BlockonomicsPaymentDriver.php +++ b/app/PaymentDrivers/BlockonomicsPaymentDriver.php @@ -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)); diff --git a/resources/views/portal/ninja2020/gateways/blockonomics/pay.blade.php b/resources/views/portal/ninja2020/gateways/blockonomics/pay.blade.php index 1c2c22885166..95571376f4e1 100644 --- a/resources/views/portal/ninja2020/gateways/blockonomics/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/blockonomics/pay.blade.php @@ -3,9 +3,14 @@ @section('gateway_content')
- @include('portal.ninja2020.gateways.includes.payment_details') + -