我正在使用coinpayment gateway api(cmd = create_transfer)。 我生成了qr代码并解决了从app成功扫描的问题,但付款后我想将success_url和其他信息重定向到数据库中。
<?php
/*
CoinPayments.net API Example
Copyright 2016 CoinPayments.net. All rights reserved.
License: GPLv2 - http://www.gnu.org/licenses/gpl-2.0.txt
*/
require('./coinpayments.inc.php');
$cps = new CoinPaymentsAPI();
$public_key = "xxx";
$private_key = "xxx";
$cps->Setup($private_key, $public_key);
$req = array(
'amount' => $_POST['amount'],
'currency1' => "USD",
'currency2' => "BTC",
'address' => '', // leave blank send to follow your settings on the Coin Settings page
// 'item_name' => $_POST['item_name']
print 'ipn_url' => $_POST['ipn_url'],
print 'txn_id' => $_POST['txn_id'],
print 'status' => intval($_POST['status']),
print 'status_text' => $_POST['status_text']
);
// See https://www.coinpayments.net/apidoc-create-transaction for all of the available fields
$result = $cps->CreateTransaction($req);
if ($result['error'] == 'ok') {
$le = php_sapi_name() == 'cli' ? "\n" : '<br />';
?>
<div class="col-4">
<h2><?php print 'Buyer should send ' . sprintf('%.08f', $result['result']['amount']) . ' BTC' . $le; ?></h2>
<img width="220" height="220" alt="" src="https://blockchain.info/qr?data=bitcoin:<?php echo $result['result']['address']; ?>?amount=<?php echo $result['result']['amount']; ?>%26label=example%2520label">
<?php
} else {
print 'Error: ' . $result['error'] . "\n";
}
?>
答案 0 :(得分:0)
请在这里参考:-https://www.coinpayments.net/apidoc-get-tx-info。要使用此api,只需在coinpayments.inc.php中添加此功能
}
public function GetTransactionInformation($txId) {
$req = array(
'txid' => $txId,
);
return $this->api_call('get_tx_info', $req);
}
在打印tx id之前将其添加到您的脚本中 $ txid = strip_tags($ _ POST ['txn_id']) 为了结果
$cps = new CoinPaymentsAPI();
$cps->Setup('Your_Private_Key', 'Your_Public_Key');
$result = $cps->GetTransactionInformation('$txid');
//get the array info of transaction
if ($result['error'] == 'ok') {
print_r ($result);
} else {
print 'Error: '.$result['error']."\n";
}
您应该在Array中得到结果。要获得Json输出,只需替换。
print_r ($result);
使用
print $result['result']['status']
用其他阵列替换状态并相应地修改页面。 状态具有以下数字:- <0错误,0-99待处理,100已完成/已付费
答案 1 :(得分:-1)
如果您想要非现场结帐,您想要使用简单或高级按钮,&#39; create_transaction&#39; API用于制作您自己的自定义结帐页面。
请在此链接中查看简单或高级按钮: Coinpayments Simple and Advanced buttons link.