mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
clean up functions
This commit is contained in:
parent
444803f9ca
commit
cfe26d06ec
@ -83,13 +83,6 @@ class Blockonomics implements MethodInterface
|
||||
return "Something went wrong";
|
||||
}
|
||||
|
||||
public function getTenMinutesCountDownEndTime()
|
||||
{
|
||||
$duration_in_sec = 10 * 60; // 10 minutes in seconds
|
||||
$current_time = time();
|
||||
return $current_time + $duration_in_sec;
|
||||
}
|
||||
|
||||
public function getBTCPrice()
|
||||
{
|
||||
$currency_code = $this->blockonomics->client->getCurrencyCode();
|
||||
@ -103,22 +96,19 @@ class Blockonomics implements MethodInterface
|
||||
|
||||
public function paymentView($data)
|
||||
{
|
||||
$btc_price = $this->getBTCPrice();
|
||||
$btc_address = $this->getBTCAddress();
|
||||
$fiat_amount = $data['total']['amount_with_fee'];
|
||||
$btc_amount = $fiat_amount / $btc_price;
|
||||
$_invoice = collect($this->blockonomics->payment_hash->data->invoices)->first();
|
||||
$data['gateway'] = $this->blockonomics;
|
||||
$data['amount'] = $data['total']['amount_with_fee'];
|
||||
$data['company_gateway_id'] = $this->blockonomics->getCompanyGatewayId();
|
||||
$data['amount'] = $fiat_amount;
|
||||
$data['currency'] = $this->blockonomics->client->getCurrencyCode();
|
||||
$btc_price = $this->getBTCPrice();
|
||||
$btc_amount = $data['amount'] / $btc_price;
|
||||
$data['btc_amount'] = number_format($btc_amount, 10, '.', '');
|
||||
$btc_address = $this->getBTCAddress();
|
||||
$data['btc_address'] = $btc_address;
|
||||
$data['btc_price'] = $btc_price;
|
||||
$data['invoice_id'] = $_invoice->invoice_id;
|
||||
$data['invoice_number'] = $_invoice->invoice_number;
|
||||
$data['end_time'] = $this->getTenMinutesCountDownEndTime();
|
||||
$data['invoice_redirect_url'] = "/client/invoices/{$_invoice->invoice_id}";
|
||||
|
||||
$data['websocket_url'] = 'wss://www.blockonomics.co/payment/' . $btc_address;
|
||||
return render('gateways.blockonomics.pay', $data);
|
||||
}
|
||||
|
||||
@ -129,16 +119,19 @@ class Blockonomics implements MethodInterface
|
||||
'payment_hash' => ['required'],
|
||||
'amount' => ['required'],
|
||||
'currency' => ['required'],
|
||||
'txid' => ['required'],
|
||||
'payment_method_id' => ['required'],
|
||||
]);
|
||||
|
||||
try {
|
||||
$data = [];
|
||||
$data['amount'] = $request->amount;
|
||||
$fiat_amount = $request->btc_price * $request->btc_amount;
|
||||
$data['amount'] = $fiat_amount;
|
||||
$data['currency'] = $request->currency;
|
||||
$data['payment_method_id'] = $request->payment_method_id;
|
||||
$data['payment_type'] = PaymentType::CRYPTO;
|
||||
$data['gateway_type_id'] = GatewayType::CRYPTO;
|
||||
$data['transaction_reference'] = "payment hash: " . $request->payment_hash . " txid: " . $request->txid;
|
||||
$data['txid'] = $request->txid;
|
||||
$data['transaction_reference'] = "payment hash: " . $request->payment_hash . " txid: " . $request->txid . " BTC amount: " . $request->btc_amount;
|
||||
|
||||
$statusId = Payment::STATUS_PENDING;
|
||||
$payment = $this->blockonomics->createPayment($data, $statusId);
|
||||
|
@ -43,10 +43,11 @@
|
||||
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
|
||||
@csrf
|
||||
<input type="hidden" name="gateway_response">
|
||||
<input type="hidden" name="company_gateway_id" value="{{ $gateway->getCompanyGatewayId() }}">
|
||||
<input type="hidden" name="company_gateway_id" value="{{ $company_gateway_id }}">
|
||||
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}">
|
||||
<input type="hidden" name="token">
|
||||
<input type="hidden" name="amount" value="{{ $amount }}">
|
||||
<input type="hidden" name="btc_price" value="{{ $btc_price }}">
|
||||
<input type="hidden" name="btc_amount" value="{{ $btc_amount }}">
|
||||
<input type="hidden" name="currency" value="{{ $currency }}">
|
||||
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
|
||||
@ -54,7 +55,7 @@
|
||||
</form>
|
||||
|
||||
<script>
|
||||
const = startTimer(seconds) => {
|
||||
const startTimer = (seconds) => {
|
||||
const countDownDate = new Date().getTime() + seconds * 1000;
|
||||
document.getElementById("countdown").innerHTML = "10" + ":" + "00" + " min";
|
||||
|
||||
@ -138,6 +139,7 @@
|
||||
const newBtcAmount = ({{$amount}} / 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_amount"]').value = newBtcAmount;
|
||||
document.getElementById('btc-amount').textContent = newBtcAmount;
|
||||
|
||||
@ -157,7 +159,7 @@
|
||||
}
|
||||
|
||||
const connectToWebsocket = () => {
|
||||
const webSocketUrl = "{{ $websocket_url }}";
|
||||
const webSocketUrl = "wss://www.blockonomics.co/payment/{{ $btc_address }}";
|
||||
const ws = new WebSocket(webSocketUrl);
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
|
Loading…
Reference in New Issue
Block a user