diff --git a/app/PaymentDrivers/Blockonomics/Blockonomics.php b/app/PaymentDrivers/Blockonomics/Blockonomics.php index 6e3d00c851c4..1452f72d0ee3 100644 --- a/app/PaymentDrivers/Blockonomics/Blockonomics.php +++ b/app/PaymentDrivers/Blockonomics/Blockonomics.php @@ -64,13 +64,11 @@ class Blockonomics implements MethodInterface public function getBTCPrice() { - $currency_code = $this->blockonomics->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']; + + $r = Http::get('https://www.blockonomics.co/api/price', ['currency' => $this->blockonomics->client->getCurrencyCode()]); + + return $r->successful() ? $r->object()->price : 'Something went wrong'; + } public function paymentView($data) @@ -103,7 +101,7 @@ class Blockonomics implements MethodInterface try { $data = []; - $fiat_amount = $request->btc_price * $request->btc_amount; + $fiat_amount = round(($request->btc_price * $request->btc_amount), 2); $data['amount'] = $fiat_amount; $data['currency'] = $request->currency; $data['payment_method_id'] = $request->payment_method_id; diff --git a/app/PaymentDrivers/BlockonomicsPaymentDriver.php b/app/PaymentDrivers/BlockonomicsPaymentDriver.php index a702d353ab8a..6bc00f5dc720 100644 --- a/app/PaymentDrivers/BlockonomicsPaymentDriver.php +++ b/app/PaymentDrivers/BlockonomicsPaymentDriver.php @@ -65,24 +65,10 @@ class BlockonomicsPaymentDriver extends BaseDriver public function getPaymentByTxid($txid) { - return Payment::where('client_id', $this->client->id) - ->whereRaw('BINARY `transaction_reference` LIKE ?', ["%txid: " . $txid . "%"]) + return Payment::where('transaction_reference', $txid) ->firstOrFail(); } - public function getCallbackSecret() - { - $blockonomicsGatewayData = Gateway::find(64); - $intialData = json_decode($blockonomicsGatewayData, true); - $jsonString = $intialData['fields']; - $blockonomicsFields = json_decode($jsonString, true); - - // Access the value of callbackSecret - $callbackSecret = $blockonomicsFields['callbackSecret']; - return $callbackSecret; - } - - /* Returns an array of gateway types for the payment gateway */ public function gatewayTypes(): array { @@ -120,17 +106,17 @@ class BlockonomicsPaymentDriver extends BaseDriver nlog($request->all()); $url_callback_secret = $request->secret; - $db_callback_secret = $this->getCallbackSecret(); + $db_callback_secret = $this->company_gateway->getConfigField('callbackSecret'); if ($url_callback_secret != $db_callback_secret) { throw new PaymentFailed('Secret does not match'); return; } - $txid = $_GET['txid']; - $value = $_GET['value']; - $status = $_GET['status']; - $addr = $_GET['addr']; + $txid = $request->txid; + $value = $request->value; + $status = $request->status; + $addr = $request->addr; $payment = $this->getPaymentByTxid($txid);