blockonomics->api_key; // $params = config('ninja.environment') == 'development' ? '?reset=1' : ''; $url = 'https://www.blockonomics.co/api/new_address'; $r = Http::withToken($api_key) ->post($url, []); if($r->successful()) return $r->object()->address ?? 'Something went wrong'; return $r->object()->message ?? 'Something went wrong'; } public function getBTCPrice() { $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) { $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['company_gateway_id'] = $this->blockonomics->getCompanyGatewayId(); $data['amount'] = $fiat_amount; $data['currency'] = $this->blockonomics->client->getCurrencyCode(); $data['btc_amount'] = number_format($btc_amount, 10, '.', ''); $data['btc_address'] = $btc_address; $data['btc_price'] = $btc_price; $data['invoice_number'] = $_invoice->invoice_number; return render('gateways.blockonomics.pay', $data); } public function paymentResponse(PaymentResponseRequest $request) { $request->validate([ 'payment_hash' => ['required'], 'amount' => ['required'], 'currency' => ['required'], 'txid' => ['required'], 'payment_method_id' => ['required'], ]); try { $data = []; $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; $data['payment_type'] = PaymentType::CRYPTO; $data['gateway_type_id'] = GatewayType::CRYPTO; $data['transaction_reference'] = $request->txid; $statusId = Payment::STATUS_PENDING; $payment = $this->blockonomics->createPayment($data, $statusId); SystemLogger::dispatch( ['response' => $payment, 'data' => $data], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_BLOCKONOMICS, $this->blockonomics->client, $this->blockonomics->client->company, ); return redirect()->route('client.payments.show', ['payment' => $payment->hashed_id]); } catch (\Throwable $e) { $blockonomics = $this->blockonomics; PaymentFailureMailer::dispatch($blockonomics->client, $blockonomics->payment_hash->data, $blockonomics->client->company, $request->amount); throw new PaymentFailed('Error during Blockonomics payment : ' . $e->getMessage()); } } // Not supported yet public function refund(Payment $payment, $amount) { return; } }