mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 10:44:35 -04:00
Fixes for blockonomics
This commit is contained in:
parent
7f936ad18b
commit
6f7cb38e37
@ -64,13 +64,11 @@ class Blockonomics implements MethodInterface
|
|||||||
|
|
||||||
public function getBTCPrice()
|
public function getBTCPrice()
|
||||||
{
|
{
|
||||||
$currency_code = $this->blockonomics->client->getCurrencyCode();
|
|
||||||
$BLOCKONOMICS_BASE_URL = 'https://www.blockonomics.co';
|
$r = Http::get('https://www.blockonomics.co/api/price', ['currency' => $this->blockonomics->client->getCurrencyCode()]);
|
||||||
$BLOCKONOMICS_PRICE_URL = $BLOCKONOMICS_BASE_URL . '/api/price?currency=';
|
|
||||||
$response = file_get_contents($BLOCKONOMICS_PRICE_URL . $currency_code);
|
return $r->successful() ? $r->object()->price : 'Something went wrong';
|
||||||
$data = json_decode($response, true);
|
|
||||||
// TODO: handle error
|
|
||||||
return $data['price'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function paymentView($data)
|
public function paymentView($data)
|
||||||
@ -103,7 +101,7 @@ class Blockonomics implements MethodInterface
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$data = [];
|
$data = [];
|
||||||
$fiat_amount = $request->btc_price * $request->btc_amount;
|
$fiat_amount = round(($request->btc_price * $request->btc_amount), 2);
|
||||||
$data['amount'] = $fiat_amount;
|
$data['amount'] = $fiat_amount;
|
||||||
$data['currency'] = $request->currency;
|
$data['currency'] = $request->currency;
|
||||||
$data['payment_method_id'] = $request->payment_method_id;
|
$data['payment_method_id'] = $request->payment_method_id;
|
||||||
|
@ -65,24 +65,10 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
public function getPaymentByTxid($txid)
|
public function getPaymentByTxid($txid)
|
||||||
{
|
{
|
||||||
return Payment::where('client_id', $this->client->id)
|
return Payment::where('transaction_reference', $txid)
|
||||||
->whereRaw('BINARY `transaction_reference` LIKE ?', ["%txid: " . $txid . "%"])
|
|
||||||
->firstOrFail();
|
->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 */
|
/* Returns an array of gateway types for the payment gateway */
|
||||||
public function gatewayTypes(): array
|
public function gatewayTypes(): array
|
||||||
{
|
{
|
||||||
@ -120,17 +106,17 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||||||
nlog($request->all());
|
nlog($request->all());
|
||||||
|
|
||||||
$url_callback_secret = $request->secret;
|
$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) {
|
if ($url_callback_secret != $db_callback_secret) {
|
||||||
throw new PaymentFailed('Secret does not match');
|
throw new PaymentFailed('Secret does not match');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$txid = $_GET['txid'];
|
$txid = $request->txid;
|
||||||
$value = $_GET['value'];
|
$value = $request->value;
|
||||||
$status = $_GET['status'];
|
$status = $request->status;
|
||||||
$addr = $_GET['addr'];
|
$addr = $request->addr;
|
||||||
|
|
||||||
$payment = $this->getPaymentByTxid($txid);
|
$payment = $this->getPaymentByTxid($txid);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user