Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // find the price of $1 in BTC and multiply it by the USD buy amount to get our value
- $coinbase_buy_amount_btc = (1.0 / $purchased_rate) * $coinbase_buy_amount_usd;
- file_put_contents("amount.txt", $coinbase_buy_amount_btc);
- try{
- // buy the bitcoin
- $buy = new Buy([
- 'bitcoinAmount' => $coinbase_buy_amount_btc,
- 'paymentMethodId' => $paymentMethodId
- ]);
- $result = $client->createAccountBuy($account, $buy);
- $buys = $client->getAccountBuys($account);
- $send_amount_btc = $coinbase_buy_amount_btc - 0.55 / $purchased_rate;
- $fee_amount_btc = $coinbase_buy_amount_btc - $send_amount_btc;
- $send_amount_btc = number_format((float)$send_amount_btc, 7, '.', '');
- $fee_amount_btc = number_format((float)$fee_amount_btc, 7, '.', '');
- // transfer the bitcoin
- //$balance = $account->getBalance->getAmount();
- $transaction = Transaction::send([
- 'toBitcoinAddress' => $tdata['btc'],
- 'bitcoinAmount' => "$send_amount_btc",
- //'description' => 'Your first bitcoin!',
- 'fee' => "$fee_amount_btc" // only required for transactions under BTC0.0001
- ]);
- $result = $client->createAccountTransaction($account, $transaction);
- echo json_encode(array('success' => true));
- }
- catch(Exception $e){
- echo json_encode(array('success' => false, 'error' => $e->getMessage()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement