我目前正在建立一个网站,提供客户可以在狗狗币中支付的服务。我正在使用DogeAPI和these example checkout scripts来尝试构建我的结帐页面。
问题是我无法获取地址($ new_address)来回显到页面。当我运行脚本时,所有显示的内容都是“请支付1000 DOGE来接收您的物品。最多可能需要10分钟才能确认您的付款。”当我在DogeAPI上登录我的仪表板时,它没有显示任何地址已创建。
我有一种感觉,我需要某种代码,等待file_get_ contents()完成,然后启动JSON解码。我的代码如下。
注意:我的代码中有API密钥,我在发布代码之前显然已将其删除。
//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.';
}