Fixes for blockonomics

This commit is contained in:
David Bomba 2024-09-18 21:11:25 +10:00
parent 7f936ad18b
commit 6f7cb38e37
2 changed files with 12 additions and 28 deletions

View File

@ -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;

View File

@ -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);