public function testInvoiceAddressCallback() { InvoiceAddress::saveInvoiceAddress(['address' => 'mrcpH23MHKweJmzNWNbPKMxtVKMJYVpKgr', 'destination_address' => null, 'invoice_amount' => 0, 'label' => 'invoice', 'callback_url' => 'http://dummy.url.com', 'forward' => 0, 'crypto_type_id' => 1, 'user_id' => 1]); $queryString = http_build_query(['cryptotype' => 1, 'secret' => 'testbtc123', 'txid' => '151f9b43343c5cd4f2064b5ac2a722f67cc53a845d05cdf9979379fa4ed19160', 'userid' => 1, 'time' => 'xxx']); $response = $this->call('GET', 'api/callback?' . $queryString); $result = $response->getContent(); $this->assertEquals('*ok*', $result); }
public function receive() { // because it can be a long process, set execution time to a lot more ini_set('max_execution_time', 600); ini_set('memory_limit', '512M'); Log::info('=== RECEIVE STARTED ==='); $ip_address = Request::ip(); if (Input::get('cryptotype')) { $this->crypto_type_id = Input::get('cryptotype'); } $method = Input::get('method'); if ($method != 'create') { Log::error('#receive: ' . NO_CREATE_METHOD_ON_INVOICE); return Response::json(['error' => NO_CREATE_METHOD_ON_INVOICE]); } /* if API server chose private invoicing, rather than blockchain.info style invoicing API / then have to check if secret is included in URL */ $isPrivate = Config::get('bitcoin.private_invoicing'); if ($isPrivate) { $secret = Config::get('bitcoin.callback_secret'); if ($secret != Input::get('secret')) { Log::error('#receive: secret mismatch, full URL: ' . Request::fullUrl() . ', ip address: ' . $ip_address); return Response::json(['error' => '#receive: ' . SECRET_MISMATCH]); } $user_id = Input::get('userid'); if (!$user_id) { Log::error('#receive: ' . NO_USER . ', full URL: ' . Request::fullUrl() . ', ip address: ' . $ip_address); return Response::json(['error' => '#receive: ' . NO_USER]); } $this->user = User::find($user_id); } else { $this->user = User::find(1); // because its not private, then in API server its by default first user } $receiving_address = Input::get('address'); $receiving_address = isset($receiving_address) ? $receiving_address : ''; $callback_url = Input::get('callback'); $label = Input::get('label'); $forward = Input::get('forward'); $invoice_amount = Input::get('amount'); // BTC if (!empty($invoice_amount)) { $invoice_amount = bcmul($invoice_amount, SATOSHIS_FRACTION); } else { $invoice_amount = 0; } if (empty($receiving_address)) { $forward = 0; } if (!empty($receiving_address)) { $isValidAddress = BitcoinHelper::isValid($receiving_address); if (!$isValidAddress) { Log::error("#receive: non valid address: {$receiving_address} from url: " . Request::fullUrl() . ', ip address: ' . $ip_address); return Response::json(['error' => '#receive: ' . INVALID_ADDRESS]); } } $this->bitcoin_core->setRpcConnection($this->user->rpc_connection); $input_address = $this->bitcoin_core->getnewaddress('invoice'); InvoiceAddress::saveInvoiceAddress(['address' => $input_address, 'destination_address' => $receiving_address, 'invoice_amount' => $invoice_amount, 'label' => $label, 'callback_url' => $callback_url, 'forward' => $forward, 'crypto_type_id' => $this->crypto_type_id, 'user_id' => $this->user->id]); Log::info('=== RECEIVING ADDRESS: ' . $receiving_address . ', input address' . $input_address . ' ==='); $response = array('fee_percent' => 0, 'forward' => $forward, 'destination' => $receiving_address, 'input_address' => $input_address, 'callback_url' => $callback_url); return Response::json($response); }