1

我正在使用硬币支付网关 api (cmd=create_transfer)。我生成了二维码和地址,这些都是从应用程序成功扫描的,但在付款后我想重定向 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";
    }
    ?>

在此处输入图像描述

4

2 回答 2

-1

请参考这里:- 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";
 }

你应该得到数组中的结果。为了获得 Json 输出,只需替换。

 print_r ($result);

 print $result['result']['status']

用其他数组替换状态并相应地修改您的页面。状态具有以下数字:- <0 错误、0-99 待处理、100 已完成/已支付

于 2018-06-24T12:21:30.070 回答
-2

如果您想使用“简单”或“高级”按钮进行异地结账,“create_transaction”API 用于制作您自己的自定义结账页面。

请检查此链接以获取简单或高级按钮: Coinpayments 简单和高级按钮链接。

于 2018-05-16T05:02:52.077 回答