0

Hello am using coinpayment api for accepting crypto coins in my site but don't know how i can add a get route which i can link to a button where a client clicks to be redirected to a page where the address and amount is shown to them. Am new to using this api. but i really need it. Any way to archieve this

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);
 })
})

every thing works well but i don't have a knowledge of integrating it into a get link so that when a client hits on it, it will redirect them to the transaction page

{ 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' }

The status_url is the transaction url, thats the link i want the user to be redirected to

wowkin2
  • 5,022
  • 4
  • 19
  • 55
Fillipo Sniper
  • 387
  • 1
  • 10
  • 27
  • Possible duplicate of [Nodejs - Redirect url](https://stackoverflow.com/questions/4062260/nodejs-redirect-url) – rlemon Feb 26 '18 at 14:33
  • no that's not a duplicate i am not requesting for how to redirect in node js, my question is on how to pass in the status url @rlemon – Fillipo Sniper Feb 26 '18 at 20:18
  • "The status_url is the transaction url, thats the link i want the user to be redirected to" and "every thing works well but i don't have a knowledge of integrating it into a get link so that when a client hits on it, it will redirect them to the transaction page" indicate you want to redirect. if this isn't true, your question makes no sense. – rlemon Feb 26 '18 at 20:30

2 Answers2

0

You can get the response of API in the json format and send it to the controller where you will find the status_url from response and redirect to the status_url page.

window.location.href = response.status_url;

-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));
}