Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1.    // find the price of $1 in BTC and multiply it by the USD buy amount to get our value
  2.     $coinbase_buy_amount_btc = (1.0 / $purchased_rate) * $coinbase_buy_amount_usd;
  3.  
  4.     file_put_contents("amount.txt", $coinbase_buy_amount_btc);
  5.  
  6.     try{
  7.         // buy the bitcoin
  8.         $buy = new Buy([
  9.             'bitcoinAmount' => $coinbase_buy_amount_btc,
  10.             'paymentMethodId' => $paymentMethodId
  11.         ]);
  12.  
  13.         $result = $client->createAccountBuy($account, $buy);
  14.  
  15.         $buys = $client->getAccountBuys($account);
  16.  
  17.         $send_amount_btc = $coinbase_buy_amount_btc - 0.55 / $purchased_rate;
  18.         $fee_amount_btc  = $coinbase_buy_amount_btc - $send_amount_btc;
  19.  
  20.         $send_amount_btc = number_format((float)$send_amount_btc, 7, '.', '');
  21.         $fee_amount_btc = number_format((float)$fee_amount_btc, 7, '.', '');
  22.  
  23.         // transfer the bitcoin
  24.         //$balance = $account->getBalance->getAmount();
  25.  
  26.         $transaction = Transaction::send([
  27.             'toBitcoinAddress' => $tdata['btc'],
  28.             'bitcoinAmount'    => "$send_amount_btc",
  29.             //'description'      => 'Your first bitcoin!',
  30.             'fee'              => "$fee_amount_btc" // only required for transactions under BTC0.0001
  31.         ]);
  32.  
  33.         $result = $client->createAccountTransaction($account, $transaction);
  34.  
  35.         echo json_encode(array('success' => true));
  36.     }
  37.     catch(Exception $e){
  38.         echo json_encode(array('success' => false, 'error' => $e->getMessage()));
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement