I'm currently building a site that will offer services that customers can pay for in Dogecoin. I am using DogeAPI and these example checkout scripts to try and build my checkout pages.
The problem is I can't get the address ($new_address) to echo to the page. When I run the script all that shows up is "Please pay 1000 DOGE to to receive your item. It may take up to 10 minutes to confirm your payment." When I log into my dashboard on DogeAPI, it doesn't show that any addresses were created.
I have a feeling that I need some sort of code that will wait until file_get_ contents() is finished and then start the JSON decoding. My code is below.
NOTE: I do have the API key in my code, I just obviously removed it before posting the code here.
//set to your API_KEY
$api_key = 'MY API HERE';
//set this to your users id
//must be alphanumeric only
$user_id = 'test123';
//set this to the amount the item costs
$amount_doge = '1000';
//send a request to the API to make a new payment address
//put info about the request in
$response = file_get_contents("https://www.dogeapi.com/wow/?api_key=$api_key&a=get_new_address&address_label=$user_id");
if($response !== 'Bad Query' && $response !== '') {
$new_address = json_decode($response);
//insert the new pending payment
mysql_query("INSERT INTO `api_payments`
(`payment_label`,`payment_address`,`paid`,`amount`)
VALUES ('$user_id', '$new_address', '0', '$amount_doge')");
//give them the address or echo a widget here
//for this example we will just echo an address
echo "Please pay $amount_doge DOGE to $response to receive your item. It may take up to 10 minutes to confirm your payment.";
} else {
echo 'There was a problem processing your order.';
}