2

So, I have looked everywhere and no one seems to have this specific problem.

I have set up a e-commerce store that is accepting BTC, So far the users can only see the price of the product in USD, however, I want the user to be able to click the USD price and convert it to BTC instantly. Like you can on a blockchain.info transaction.

For example:

Blockchain transaction conversion

So far, I have only been able to display the BTC price using Blockchain API.

I want the same effect as Blockchain on my price, or atleast under it.

(Snapshots of site below to give an idea of what I want)

My images

The code I have to display the BTC price (If it helps, im a noob sorry)

<?php

  $url = "https://blockchain.info/stats?format=json";
  $stats = json_decode(file_get_contents($url), true);

  echo $stats['market_price_usd'];

  ?>

Price display:

<p class="Price">$200.50</p>
3
  • It took me a bit to realize what your question is. Could you please make that clearer?
    – Murch
    Aug 30, 2016 at 21:20
  • See here github.com/miohtama/bitcoin-prices Aug 30, 2016 at 22:16
  • @SvenWilliamson Most of these seem irrelevant to the question.
    – Nick ODell
    Aug 30, 2016 at 23:17

1 Answer 1

0

Your question is a bit confusing but it sounds like you are asking how to get a currency amount worth of bitcoin.

I want the user to be able to click the USD price and convert it to BTC instantly.

The answer is simple, division.

<?php
$url = "https://blockchain.info/stats?format=json";
$stats = json_decode(file_get_contents($url), true);
$btcValue = $stats['market_price_usd'];
$usdCost = 200;

$convertedCost = $usdCost / $btcValue;

echo $convertedCost;
?>     

http://phpfiddle.org/lite/code/cxsk-b62m

(If it helps, im a noob sorry)

That's okay. If you're looking to learn more beginner related Bitcoin coding stuff check out this mega-thread at bitcointalk https://bitcointalk.org/index.php?topic=990348.0 It's mostly PHP and JavaScript examples.

2
  • I'll test it now, thank you very much man !! Aug 31, 2016 at 17:32
  • Yep, I suppose I can work with this, thanks buddy. Aug 31, 2016 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.