Stuck while using call back address and ipn url in coinpayment net gateway

0 votes

I'm using coinpayment gateway api (cmd=create_transfer). I generated qr code and address those are successfully scanned from app but after payment I want to redirect success_url and other information submitted into database.

<?php
/*
  CoinPayments.net API Example
  Copyright 2016 CoinPayments.net. All rights reserved.
 
 */
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";
    }
    ?>

Aug 31, 2018 in Blockchain by slayer
• 29,370 points
3,481 views

1 answer to this question.

0 votes

To make use of this api, just add this function in coinpayments.inc.php

}

public function GetTransactionInformation($txId) {      
$req = array(
    'txid' => $txId,

);
return $this->api_call('get_tx_info', $req);
}

Add this in you's script before printing tx id $txid = strip_tags($_POST['txn_id']) And for results

 $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";
 }

You should get result in Array. For getting in Json output just replace.

 print_r ($result);

With

 print $result['result']['status']
answered Aug 31, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers

Challenge while setting up Hyperledger Fabric 1.0 in Ubuntu 16.04

The rocksdb error you're seeing wouldn't be ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points

edited Jun 8, 2020 by Sirajul 1,153 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,219 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
886 views
0 votes
1 answer

Send Payment error in Blockchain API

The following code should help: $address = null; try ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
1,753 views
0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 26,740 points
2,757 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP