Revert "Add back blockonomics routes"
This commit is contained in:
parent
315ee47482
commit
718dda403e
|
|
@ -13,8 +13,12 @@
|
||||||
namespace App\Http\Controllers\Gateways;
|
namespace App\Http\Controllers\Gateways;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request; // Import the Request class
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http; // Import the Http facade
|
||||||
|
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
|
||||||
|
use BaconQrCode\Renderer\ImageRenderer;
|
||||||
|
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||||
|
use BaconQrCode\Writer;
|
||||||
|
|
||||||
class BlockonomicsController extends Controller
|
class BlockonomicsController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -29,4 +33,26 @@ class BlockonomicsController extends Controller
|
||||||
|
|
||||||
return response()->json(['error' => 'Unable to fetch BTC price'], 500);
|
return response()->json(['error' => 'Unable to fetch BTC price'], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getQRCode(Request $request)
|
||||||
|
{
|
||||||
|
$qr_string = $request->query('qr_string');
|
||||||
|
$svg = $this->getPaymentQrCodeRaw($qr_string);
|
||||||
|
return response($svg)->header('Content-Type', 'image/svg+xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPaymentQrCodeRaw($qr_string)
|
||||||
|
{
|
||||||
|
|
||||||
|
$renderer = new ImageRenderer(
|
||||||
|
new RendererStyle(150, margin: 0),
|
||||||
|
new SvgImageBackEnd()
|
||||||
|
);
|
||||||
|
$writer = new Writer($renderer);
|
||||||
|
|
||||||
|
$qr = $writer->writeString($qr_string, 'utf-8');
|
||||||
|
|
||||||
|
return $qr;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { wait, instant } from '../wait';
|
||||||
class Blockonomics {
|
class Blockonomics {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Bind the method to the instance
|
||||||
this.copyToClipboard = this.copyToClipboard.bind(this);
|
this.copyToClipboard = this.copyToClipboard.bind(this);
|
||||||
this.refreshBTCPrice = this.refreshBTCPrice.bind(this);
|
this.refreshBTCPrice = this.refreshBTCPrice.bind(this);
|
||||||
this.fetchAndDisplayQRCode = this.fetchAndDisplayQRCode.bind(this);
|
this.fetchAndDisplayQRCode = this.fetchAndDisplayQRCode.bind(this);
|
||||||
|
|
@ -20,8 +21,9 @@ class Blockonomics {
|
||||||
}
|
}
|
||||||
|
|
||||||
copyToClipboard(elementId, passedElement, shouldGrabNextElementSibling) {
|
copyToClipboard(elementId, passedElement, shouldGrabNextElementSibling) {
|
||||||
|
|
||||||
const element = shouldGrabNextElementSibling ? passedElement.nextElementSibling : passedElement;
|
const element = shouldGrabNextElementSibling ? passedElement.nextElementSibling : passedElement;
|
||||||
const originalIcon = element.src;
|
const originalIcon = element.src; // Store the original icon
|
||||||
|
|
||||||
const tempInput = document.createElement("input");
|
const tempInput = document.createElement("input");
|
||||||
const elementWithId = document.getElementById(elementId);
|
const elementWithId = document.getElementById(elementId);
|
||||||
|
|
@ -41,58 +43,45 @@ class Blockonomics {
|
||||||
</svg>
|
</svg>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
// Change the icon back to the original after 5 seconds
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
element.src = originalIcon;
|
element.src = originalIcon;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadQRCodeScript() {
|
|
||||||
if (window.QRCode) return; // already loaded
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const script = document.createElement('script');
|
|
||||||
script.src = "https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js";
|
|
||||||
script.onload = resolve;
|
|
||||||
script.onerror = reject;
|
|
||||||
document.head.appendChild(script);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchAndDisplayQRCode (newBtcAmount = null) {
|
async fetchAndDisplayQRCode (newBtcAmount = null) {
|
||||||
try {
|
try {
|
||||||
await this.loadQRCodeScript();
|
|
||||||
|
|
||||||
const btcAddress = document.querySelector('meta[name="btc_address"]').content;
|
const btcAddress = document.querySelector('meta[name="btc_address"]').content;
|
||||||
const btcAmount = newBtcAmount || document.querySelector('meta[name="btc_amount"]').content;
|
const btcAmount = newBtcAmount || '{{$btc_amount}}';
|
||||||
const qrString = `bitcoin:${btcAddress}?amount=${btcAmount}`;
|
const qrString = encodeURIComponent(`bitcoin:${btcAddress}?amount=${btcAmount}`);
|
||||||
|
const response = await fetch(`/api/v1/get-blockonomics-qr-code?qr_string=${qrString}`);
|
||||||
document.getElementById('qrcode-container').innerHTML = "";
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
new QRCode(document.getElementById("qrcode-container"), {
|
}
|
||||||
text: qrString,
|
const svgText = await response.text();
|
||||||
width: 150,
|
document.getElementById('qrcode-container').innerHTML = svgText;
|
||||||
height: 150,
|
|
||||||
correctLevel: QRCode.CorrectLevel.H
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error generating QR code:', error);
|
console.error('Error fetching QR code:', error);
|
||||||
document.getElementById('qrcode-container').textContent = 'Error loading QR code';
|
document.getElementById('qrcode-container').textContent = 'Error loading QR code';
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
startTimer = (seconds) => {
|
startTimer = (seconds) => {
|
||||||
const countDownDate = new Date().getTime() + seconds * 1000;
|
const countDownDate = new Date().getTime() + seconds * 1000;
|
||||||
document.getElementById("countdown").innerHTML = "10:00 min";
|
document.getElementById("countdown").innerHTML = "10" + ":" + "00" + " min";
|
||||||
|
|
||||||
const updateCountdown = () => {
|
const updateCountdown = () => {
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const distance = countDownDate - now;
|
const distance = countDownDate - now;
|
||||||
|
|
||||||
const isRefreshing = document.getElementsByClassName("btc-value")[0].innerHTML.includes("Refreshing");
|
const isRefreshing = document.getElementsByClassName("btc-value")[0].innerHTML.includes("Refreshing");
|
||||||
if (isRefreshing) return;
|
if (isRefreshing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (distance < 0) {
|
if (distance < 0) {
|
||||||
this.refreshBTCPrice();
|
refreshBTCPrice();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,13 +89,14 @@ class Blockonomics {
|
||||||
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
||||||
const formattedMinutes = String(minutes).padStart(2, '0');
|
const formattedMinutes = String(minutes).padStart(2, '0');
|
||||||
const formattedSeconds = String(seconds).padStart(2, '0');
|
const formattedSeconds = String(seconds).padStart(2, '0');
|
||||||
document.getElementById("countdown").innerHTML = `${formattedMinutes}:${formattedSeconds} min`;
|
document.getElementById("countdown").innerHTML = formattedMinutes + ":" + formattedSeconds + " min";
|
||||||
};
|
}
|
||||||
|
|
||||||
clearInterval(window.countdownInterval);
|
clearInterval(window.countdownInterval);
|
||||||
window.countdownInterval = setInterval(updateCountdown, 1000);
|
window.countdownInterval = setInterval(updateCountdown, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async refreshBTCPrice() {
|
async refreshBTCPrice() {
|
||||||
const refreshIcon = document.querySelector('.icon-refresh');
|
const refreshIcon = document.querySelector('.icon-refresh');
|
||||||
refreshIcon.classList.add('rotating');
|
refreshIcon.classList.add('rotating');
|
||||||
|
|
@ -116,41 +106,48 @@ class Blockonomics {
|
||||||
try {
|
try {
|
||||||
const currency = document.querySelector('meta[name="currency"]').content;
|
const currency = document.querySelector('meta[name="currency"]').content;
|
||||||
const response = await fetch(`/api/v1/get-btc-price?currency=${currency}`); // New endpoint to call server-side function
|
const response = await fetch(`/api/v1/get-btc-price?currency=${currency}`); // New endpoint to call server-side function
|
||||||
|
if (!response.ok) {
|
||||||
if (!response.ok) throw new Error('Network response was not ok');
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log("BTC price data:", data);
|
|
||||||
return data.price;
|
return data.price;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('There was a problem with the BTC price fetch operation:', error);
|
console.error('There was a problem with the BTC price fetch operation:', error);
|
||||||
return null;
|
// Handle error appropriately
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newPrice = await getBTCPrice();
|
const newPrice = await getBTCPrice();
|
||||||
if (newPrice) {
|
if (newPrice) {
|
||||||
|
// Update the text content of the countdown span to the new bitcoin price
|
||||||
const currency = document.querySelector('meta[name="currency"]').content;
|
const currency = document.querySelector('meta[name="currency"]').content;
|
||||||
document.getElementsByClassName("btc-value")[0].innerHTML =
|
document.getElementsByClassName("btc-value")[0].innerHTML = "1 BTC = " + (newPrice || "N/A") + " " + currency + ", updates in <span id='countdown'></span>";
|
||||||
`1 BTC = ${newPrice || "N/A"} ${currency}, updates in <span id='countdown'></span>`;
|
|
||||||
const newBtcAmount = (document.querySelector('meta[name="amount"]').content / newPrice).toFixed(10);
|
const newBtcAmount = (document.querySelector('meta[name="amount"]').content / newPrice).toFixed(10);
|
||||||
|
|
||||||
|
// set the value of the input field and the text content of the span to the new bitcoin amount
|
||||||
document.querySelector('input[name="btc_price"]').value = newPrice;
|
document.querySelector('input[name="btc_price"]').value = newPrice;
|
||||||
document.querySelector('input[name="btc_amount"]').value = newBtcAmount;
|
document.querySelector('input[name="btc_amount"]').value = newBtcAmount;
|
||||||
document.getElementById('btc-amount').textContent = newBtcAmount;
|
document.getElementById('btc-amount').textContent = newBtcAmount;
|
||||||
|
|
||||||
const btcAddress = document.querySelector('meta[name="btc_address"]').content;
|
const btcAddress = document.querySelector('meta[name="btc_address"]').content;
|
||||||
document.getElementById('qr-code-link').href = `bitcoin:${btcAddress}?amount=${newBtcAmount}`;
|
|
||||||
document.getElementById('open-in-wallet-link').href = `bitcoin:${btcAddress}?amount=${newBtcAmount}`;
|
|
||||||
|
|
||||||
|
// set the href attribute of the link to the new bitcoin amount
|
||||||
|
const qrCodeLink = document.getElementById('qr-code-link');
|
||||||
|
const openInWalletLink = document.getElementById('open-in-wallet-link');
|
||||||
|
qrCodeLink.href = `bitcoin:${btcAddress}?amount=${newBtcAmount}`;
|
||||||
|
openInWalletLink.href = `bitcoin:${btcAddress}?amount=${newBtcAmount}`;
|
||||||
|
|
||||||
|
// fetch and display the new QR code
|
||||||
await this.fetchAndDisplayQRCode(newBtcAmount);
|
await this.fetchAndDisplayQRCode(newBtcAmount);
|
||||||
this.startTimer(600);
|
this.startTimer(600); // Restart timer for 10 minutes (600 seconds)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
refreshIcon.classList.remove('rotating');
|
refreshIcon.classList.remove('rotating');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
handle() {
|
handle() {
|
||||||
window.copyToClipboard = this.copyToClipboard;
|
window.copyToClipboard = this.copyToClipboard;
|
||||||
window.refreshBTCPrice = this.refreshBTCPrice;
|
window.refreshBTCPrice = this.refreshBTCPrice;
|
||||||
|
|
@ -166,20 +163,25 @@ class Blockonomics {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
const { status, txid, value } = data || {};
|
const { status, txid, value } = data || {};
|
||||||
console.log('Payment status:', status);
|
console.log('Payment status:', status);
|
||||||
if ([0, 1, 2].includes(status)) {
|
const isPaymentUnconfirmed = status === 0;
|
||||||
|
const isPaymentPartiallyConfirmed = status === 1;
|
||||||
|
const isPaymentConfirmed = status === 2;
|
||||||
|
// Confirmation status: 0 = unconfirmed, 1 = partially confirmed, 2 = confirmed
|
||||||
|
// If any of the statuses are true, submit the form and redirect
|
||||||
|
if (isPaymentUnconfirmed || isPaymentPartiallyConfirmed || isPaymentConfirmed) {
|
||||||
document.querySelector('input[name="txid"]').value = txid || '';
|
document.querySelector('input[name="txid"]').value = txid || '';
|
||||||
document.querySelector('input[name="status"]').value = status || '';
|
document.querySelector('input[name="status"]').value = status || '';
|
||||||
document.querySelector('input[name="btc_amount"]').value = value || '';
|
document.querySelector('input[name="btc_amount"]').value = value || '';
|
||||||
document.querySelector('input[name="btc_address"]').value = btcAddress || '';
|
document.querySelector('input[name="btc_address"]').value = btcAddress || '';
|
||||||
document.getElementById('server-response').submit();
|
document.getElementById('server-response').submit();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
this.startTimer(600);
|
|
||||||
connectToWebsocket();
|
|
||||||
this.fetchAndDisplayQRCode();
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
startTimer(600); // Start timer for 10 minutes (600 seconds)
|
||||||
|
connectToWebsocket();
|
||||||
|
fetchAndDisplayQRCode();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function boot() {
|
function boot() {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ use App\Http\Controllers\CompanyLedgerController;
|
||||||
use App\Http\Controllers\EInvoiceTokenController;
|
use App\Http\Controllers\EInvoiceTokenController;
|
||||||
use App\Http\Controllers\PurchaseOrderController;
|
use App\Http\Controllers\PurchaseOrderController;
|
||||||
use App\Http\Controllers\TaskSchedulerController;
|
use App\Http\Controllers\TaskSchedulerController;
|
||||||
use App\Http\Controllers\Gateways\BlockonomicsController;
|
use App\PaymentDrivers\BlockonomicsPaymentDriver;
|
||||||
use App\Http\Controllers\CompanyGatewayController;
|
use App\Http\Controllers\CompanyGatewayController;
|
||||||
use App\Http\Controllers\EInvoicePeppolController;
|
use App\Http\Controllers\EInvoicePeppolController;
|
||||||
use App\Http\Controllers\PaymentWebhookController;
|
use App\Http\Controllers\PaymentWebhookController;
|
||||||
|
|
@ -502,8 +502,6 @@ Route::post('api/v1/yodlee/balance', [YodleeController::class, 'balanceWebhook']
|
||||||
Route::get('api/v1/protected_download/{hash}', [ProtectedDownloadController::class, 'index'])->name('protected_download')->middleware('throttle:300,1');
|
Route::get('api/v1/protected_download/{hash}', [ProtectedDownloadController::class, 'index'])->name('protected_download')->middleware('throttle:300,1');
|
||||||
Route::post('api/v1/ppcp/webhook', [PayPalPPCPPaymentDriver::class, 'processWebhookRequest'])->middleware('throttle:1000,1');
|
Route::post('api/v1/ppcp/webhook', [PayPalPPCPPaymentDriver::class, 'processWebhookRequest'])->middleware('throttle:1000,1');
|
||||||
|
|
||||||
Route::get('api/v1/get-btc-price', [BlockonomicsController::class, 'getBTCPrice'])->middleware('throttle:100,1');
|
|
||||||
|
|
||||||
Route::get('quickbooks/authorize/{token}', [ImportQuickbooksController::class, 'authorizeQuickbooks'])->name('quickbooks.authorize');
|
Route::get('quickbooks/authorize/{token}', [ImportQuickbooksController::class, 'authorizeQuickbooks'])->name('quickbooks.authorize');
|
||||||
Route::get('quickbooks/authorized', [ImportQuickbooksController::class, 'onAuthorized'])->name('quickbooks.authorized');
|
Route::get('quickbooks/authorized', [ImportQuickbooksController::class, 'onAuthorized'])->name('quickbooks.authorized');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5622,14 +5622,5 @@
|
||||||
"GET",
|
"GET",
|
||||||
"HEAD"
|
"HEAD"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"generated::Xy7ZkLm8NpQ4Rt5V": {
|
|
||||||
"name": "generated::Xy7ZkLm8NpQ4Rt5V",
|
|
||||||
"domain": null,
|
|
||||||
"action": "App\\Http\\Controllers\\BlockonomicsController@getBTCPrice",
|
|
||||||
"uri": "api/v1/get-btc-price",
|
|
||||||
"method": [
|
|
||||||
"GET"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue