Hi All
Im a simple web developer and trying to understand how to verify payments/transactions.
Can anyone comment on the php code i have so far / test code (i am far from a good php programmer, but get by usually)
And the output as i am not fully understanding it.....
(sorry if these sound dumb questions, but i am loving BitCoin and want to start using it on many more sites!)
$resultBlockHeight = json_decode(file_get_contents('http://blockchain.info/latestblock'));
$current_block_height = $resultBlockHeight->height;
$resultBlockChain = json_decode(file_get_contents('http://blockchain.info/address/12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L?format=json'));
$total_received = $resultBlockChain->total_received;
$number_of_transactions = $resultBlockChain->n_tx;
if($number_of_transactions > 0){
$transaction = $resultBlockChain->txs;
foreach($transaction as $id){
$transaction_date = date('d-m-Y G:i:s', $id->time);
if($id->block_height == ''){
$confirmedTransactions = 0;
}
else {
$transaction_block_height = $id->block_height;
$confirmedTransactions = ($current_block_height - $transaction_block_height + 1);
}
// test results / output
echo '$total_received '.$total_received.'
';
echo '$transaction_date '.$transaction_date .'
';
echo '$current_block_height '.$current_block_height.'
';
echo '$transaction_block_height '. $transaction_block_height .'
';
echo '$confirmedTransactions = ' .$confirmedTransactions.'
';
// raw array output for $id/traansactions
echo '// trasnsactions output';
echo ' '
;
echo print_r($id);
echo '';
}
}else {
// if number_of_transactions !> 0
}
if($number_of_transactions >= 2){
// fuck knows what to do as it should only be 1.....
}
echo '// full object output';
echo ''
;
echo print_r($resultBlockChain);
echo '';
?>This generates the following output (with my notes and some questions to the side)
$total_received 10000
$transaction_date 11-07-2013 22:58:02
$current_block_height 246206
$transaction_block_height 246159
$confirmedTransactions = 48
// transactions output
stdClass Object
(
[result] => 0 // result number
[block_height] => 246159 // blockchain height at time of first confirmed transaction
[time] => 1373601482 // datetime
[inputs] => Array
(
[0] => stdClass Object
(
[prev_out] => stdClass Object // what does prev_out mean?
(
[n] => 0
[value] => 1030000 // i assume this is the total funds moved including spent, change and transaction fee
[addr] => 1B5W3zqE3cfnR6Zz5kDokNr1ur1hcc21Ge
[tx_index] => 80631906
[type] => 0
)
)
)
[vout_sz] => 2 // what is this?
[relayed_by] => 5.9.24.81
[hash] => d83b05e28786f37700ee10277dde4e485e38f14b25925944dd60b5c4da73d13c
[vin_sz] => 1 // what is this?
[tx_index] => 80634444
[ver] => 1 // what is this?
[out] => Array
(
[0] => stdClass Object
(
[n] => 0
[value] => 1010000 // i assume this is change less transaction fee
[addr] => 194QwtJQZjzmacigpJnWMqKWp6GQBh7ZAa
[tx_index] => 80634444
[type] => 0
)
[1] => stdClass Object
(
[n] => 1
[value] => 10000 // this is the amount i received
[addr] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
[tx_index] => 80634444
[type] => 0
)
)
[size] => 225
)
1
// full object output
stdClass Object
(
[hash160] => 100d7ae73d621b011eabcb91fd5cd368bf53ea18
[address] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
[n_tx] => 1
[total_received] => 10000
[total_sent] => 0
[final_balance] => 10000
[txs] => Array
(
[0] => stdClass Object
(
[result] => 0
[block_height] => 246159
[time] => 1373601482
[inputs] => Array
(
[0] => stdClass Object
(
[prev_out] => stdClass Object
(
[n] => 0
[value] => 1030000
[addr] => 1B5W3zqE3cfnR6Zz5kDokNr1ur1hcc21Ge
[tx_index] => 80631906
[type] => 0
)
)
)
[vout_sz] => 2
[relayed_by] => 5.9.24.81
[hash] => d83b05e28786f37700ee10277dde4e485e38f14b25925944dd60b5c4da73d13c
[vin_sz] => 1
[tx_index] => 80634444
[ver] => 1
[out] => Array
(
[0] => stdClass Object
(
[n] => 0
[value] => 1010000
[addr] => 194QwtJQZjzmacigpJnWMqKWp6GQBh7ZAa
[tx_index] => 80634444
[type] => 0
)
[1] => stdClass Object
(
[n] => 1
[value] => 10000
[addr] => 12TsxgagKmaU4ydLP1PesHFiJHvxyZpo7L
[tx_index] => 80634444
[type] => 0
)
)
[size] => 225
)
)
)
1
I am going to issue a unique payment address to all sales and get the total received to enter into my DB/ecommerce system, but what if someone then pays on the same unique address. is there a better way that i can get the amount actually received rather than the total received? (as if some one can break things, i find they usually will)
Any help at all or advice would be great (and if anyone finds this code or thread useful, great feel free to use it)
Best Regards
Ford