0

您好,我正在使用 coinpayment api 在我的网站中接受加密货币,但不知道如何添加一条获取路线,我可以链接到一个按钮,客户点击该按钮将重定向到向他们显示地址和金额的页面. 我是使用这个 api 的新手。但我真的需要它。任何存档的方法

var express = require("express"),
    app    = express(),
    bodyparser = require("body-parser"),
    coinpayments = require("coinpayments"),

    app.use(bodyParser.urlencoded({extended: true}));

var client = new Coinpayments({
    key: "My API PUBLIC KEY",
    secret: "MY API SECRET KEY"
});

app.get('the url for the transaction page', function(req,res){
       res.render(the url)

       *then the createTransaction function is called*

       client.createTransaction({'currency1' : 'DOGE', 'currency2' : 'POT', 'amount' : 10},function(err,result){
   console.log(result);
 })
})

每件事都运作良好,但我不知道将其集成到获取链接中,以便当客户点击它时,它将它们重定向到交易页面

{ amount: '0.41899981',
  txn_id: 'CPCB7BFRNZ6XCMR1FJDUUKCDNP',
  address: 'PUXds8akQMe9xMYtEftcMnirhZpUNyK6ER',
  confirms_needed: '5',
  timeout: 3600,
  status_url: 'https://www.coinpayments.net/index.php?cmd=status&id=CPCB7BFRNZ6XCMR1FJDUUKCDNP&key=828dba80bdc1a7a6fb78443f32e3e094',
  qrcode_url: 'https://www.coinpayments.net/qrgen.php?id=CPCB7BFRNZ6XCMR1FJDUUKCDNP&key=828dba80bdc1a7a6fb78443f32e3e094' }

status_url 是交易 url,这就是我希望用户被重定向到的链接

4

2 回答 2

0

您可以获取 json 格式的 API 响应并将其发送到控制器,您将从响应中找到 status_url 并重定向到 status_url 页面。

window.location.href = response.status_url;

于 2018-10-12T07:40:41.160 回答
-1
this is complete code for API IN PHP CURL
$private_key = "SECRET";
$data['version']   = 1;
$data['cmd']       = 'create_transaction';
$data['amount']    = 100.00;
$data['currency1'] = 'USD';
$data['currency2'] = 'BTC';
$data['key']       ='public key';
$data['buyer_email']    = 'mail';
$data['format']         = 'json';
$data['success_url']    = 'url';
$data['cancel_url']     = 'url';
$post_data = http_build_query($data, '', '&');\
$hmac = hash_hmac('sha512', $post_data, $private_key);
static $ch = NULL;
if ($ch === NULL) {
  $ch = curl_init('https://www.coinpayments.net/api.php');
  curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('HMAC: '.$hmac));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$data = curl_exec($ch);            
if ($data !== FALSE) {
    return response()->json([
        'status'    => true,
        'message'   => 'Transection Created Suceesfully!',
        'data'      =>   $data
    ]);
} else {
   return array('error' => 'cURL error: '.curl_error($ch));
}
于 2021-10-18T18:36:25.193 回答