简体   繁体   中英

Blockchain api v2: Send payment not working

I am trying to send the btc to the user using blockchain V2 API. I have gone through the documentation and using the below code to send the btc to the user. But it is not being executed.

<?php



echo " send test<br>";
include 'db_config/connection.php';


$action = "completed";
$order_id = "12345";

$sql = "SELECT * from wallet_config";
$result= $conn->query($sql) or die(mysqli_error($conn));

if ($result->num_rows > 0) {
     while($row = $result->fetch_array()) {
        $guid = $row['wallet_id'];
        $main_password = $row['password'];
        $from = $row['wallet'];

      }

    $amount = 0.01 * 100000000;  // 100000000satoshi = 1 btc
    $to = "1J528hXvotieFZJkLA66g7NntXCXtNSm78";


    $json_url = "https://blockchain.info/merchant/$guid/payment?password=$main_password&to=$to&amount=$amount&from=$from";

    echo $json_url;

    $json_data = file_get_contents($json_url);

    $json_feed = json_decode($json_data);

    $message = $json_feed->message;
    $tx_hash = $json_feed->tx_hash;

    print_r($json_feed);


    $sql1 = "UPDATE buy_order set status ='$action', tx_id = '$tx_hash' where order_id = '$order_id'";

    $result1=$conn->query($sql1) or die (mysqli_error($conn));

    if($result1){
      if(!isset($tx_hash)){
        echo "Transaction for Order id $order_id not porceeded. Try sending BTC manually.";
      }
      echo "Order id $order_id marked as $action..";
    }else{
      echo "Something went wrong... Try Again";
    }

}else{
  echo "Something went wrong... Try Checking wallet config";
}
echo "<br>last";

?>

The problem is that the transaction is not completed. I even tried to echo the $json_feed and it shows nothing.

I really do not understand why it is not working here.

When i paste the $json_url in the browser, it shows the following error

`<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>`

Did you install library at your local from https://github.com/blockchain/service-my-wallet-v3 ? if not, install it firstly.

Did you create your GUID with this api call? as per your error msg, seems you did not create GUID. http://localhost:3000/api/v2/create check documentation for details if not created

then call payment api, your url would be your localhost url like

http://localhost:3000/merchant/$guid/payment?password=$main_password&second_password=$second_password&to=$address&amount=$amount&from=$from&fee=$fee



$json_url = "http://localhost:3000/merchant/$guid/payment?password=$main_password&second_password=$second_password&to=$address&amount=$amount&from=$from&fee=$fee";    
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);
var_dump($json_feed);

Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM